XSLT 的调试(转)
来源:互联网 发布:知乎怎样匿名提问 编辑:程序博客网 时间:2024/05/22 17:51
新建(vc/c#控制台程序(vc/c#控制台都可以)CAStudy.在应用程序中,添加books.xml,belowAvg.xsl 代码分别如下:
books.xml
<?xmlversion='1.0'?>
<!-- This file represents a fragment of a book store inventory database-->
<bookstore>
<bookgenre="autobiography"publicationdate="1981"ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<bookgenre="novel"publicationdate="1967"ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<bookgenre="philosophy"publicationdate="1991"ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
books.xml一看就知道是一个bookstore,里面包含了三个book. 每个book都会有一些attribute和property.例如genre,publicationdate,ISBN 就是attribute.而诸如title,author,price 就是book的property 了。
belowAvg.xsl:
<?xmlversion='1.0'?>
<xsl:stylesheetversion="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:outputmethod="xml"encoding="utf-8"/>
<xsl:templatematch="/">
<xsl:variablename="bookCount"select="count(/bookstore/book)"/>
<xsl:variablename="bookTotal"select="sum(/bookstore/book/price)"/>
<xsl:variablename="bookAverage"select="$bookTotal div $bookCount"/>
<books>
<!--Books That Cost Below Average-->
<xsl:for-eachselect="/bookstore/book">
<xsl:iftest="price< $bookAverage">
<xsl:copy-ofselect="."/>
</xsl:if>
</xsl:for-each>
</books>
</xsl:template>
</xsl:stylesheet>
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 =newXslCompiledTransform(true);
// Compile the style sheet.
xslt.Load(stylesheet);
// Execute the XSLT transform.
FileStream outputStream =newFileStream(outputFile,FileMode.Append);
xslt.Transform(sourceFile, null, outputStream);
}
}
在这里由于使用的是相对路径,所以要将books.xml和belowAvg.xsl 属性修改如下:
还要将XslCompiledTransform xslt =newXslCompiledTransform(true);
参数传递为true,代表enableDebug.
就可以看到如下界面了:
使用代码调试的话,不需要设置断点,只要enableDebug为true的话,会自动在xsl中中断。
本人猜测估计是调用了Debugger.Break() 方法。
可能遇到的问题:http://blog.csdn.net/dragoo1/article/details/49302895
- XSLT 的调试(转)
- [转]XSLT
- 使用VS.NET调试XSLT
- 使用VS.NET调试XSLT
- XSLT入门 -- 第1章 入门篇:带领初学者开始XSLT的旅行 [转]
- XSLT轻松入门第一章:XSLT的概念
- XSLT轻松入门第一章:XSLT的概念
- XSLT轻松入门第一章:XSLT的概念
- XSLT简单教程--XSLT的实例
- XSLT轻松入门第一章:XSLT的概念
- XSLT轻松入门:XSLT的元素语法
- XSLT轻松入门第一章:XSLT的概念
- XSLT简单教程--XSLT的实例
- XSLT的元素语法
- XSLT的资源
- XSLT的元素语法
- 服务器上的XSLT
- XSLT的概念
- Appium实例搭建过程中遇到的问题
- selenium2+webdriver+java利用firepath定位隐藏div中的问题
- 不能为虚拟电脑 centOS 打开一个新任务.The VM session was closed before any at
- 获取时间
- null和undefined的区别
- XSLT 的调试(转)
- LeetCode 19: Remove Nth Node From End of List
- 南邮编程在线编程题五:输出所有的3位数字的质数
- Eigen 使用
- Android Studio中常用插件及浅释
- SAT考试备考的高分原则
- Android中Application类的详细解释
- Java回收机制
- UrlRewriteFilter