栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C# > C#教程

基于XSLT调试的相关问题

C#教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于XSLT调试的相关问题

新建控制台程序CAStudy.在应用程序中,添加books.xml,belowAvg.xsl 代码分别如下:

books.xml

 

    The Autobiography of Benjamin Franklin

   

      Benjamin

      Franklin

   

    8.99

 

 

    The Confidence Man

   

      Herman

      Melville

   

    11.99

 

 

    The Gorgias

   

      Plato

   

    9.99

 

books.xml一看就知道是一个bookstore,里面包含了三个book. 每个book都会有一些attribute和property.例如genre,publicationdate,ISBN 就是attribute.而诸如title,author,price 就是book的property 了。

belowAvg.xsl:

      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 

 

   

   

   

   

     

     

       

         

       

     

   

 

belowAvg.xsl:名字就代表了,小于平均值的xsl.

XSLT: 可扩展样式表语言转换Extensible Stylesheet Transformation (XSLT)

这个belowAvg.xsl 主要就是将book.xml 中小于平均值的那些book找出来,输出成xml。

match=”/”:这样就可以匹配三个book节点了。

接着声明3个变量,bookCount,bookTotal,在第三个变量中使用$符号来引用前面声明的变量得到平均值。

接着进行for-each的循环,在循环里面进行if 测试,测试的条件是price < $bookAverage. < 在xml里面是< lt 是less than 的意思,同理> 在xml里面是> gt 就是great than的意思。

接着进行copy-of 操作,”.” 代表的就是self::node(),也就是book节点。

 

调试xslt 有两种方式:

第一种:使用VS

打开xsl,可以发现菜单多了XML,点击XML菜单的调试XSLT,然后选择book.xml 就可以进行调试了。

同样F9设置断点,

第二种方法:使用代码.

class XmlXsltDemo

{

    private const string sourceFile = @"books.xml";

    private const string stylesheet = @"belowAvg.xsl";

    private const string outputFile = @"output.xml";

    public static void Main()

    {

        // Enable XSLT debugging.

        XslCompiledTransform xslt = new XslCompiledTransform(true);

        // Compile the style sheet.

        xslt.Load(stylesheet);

        // Execute the XSLT transform.

        FileStream outputStream = new FileStream(outputFile, FileMode.Append);

        xslt.Transform(sourceFile, null, outputStream);

    }

}

在这里由于使用的是相对路径,所以要将books.xml和belowAvg.xsl 属性修改如下:

还要将XslCompiledTransform xslt = new XslCompiledTransform(true);

参数传递为true,代表enableDebug.

就可以看到如下界面了:

 

使用代码调试的话,不需要设置断点,只要enableDebug为true的话,会自动在xsl中中断。

本人猜测估计是调用了Debugger.Break() 方法。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/127326.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号