XSLT 2.0应用实践
在安装了 AltovaXML 2007 之后,使用 XSLT2.0 起来也很简单,只需要添加一个引用即可,如图片 C 所示。
图片 C ——添加一个引用
现在预备知识已经讲解完了,我们现在来创建一个 C# 程序,列表 A 是 XML 文档,列表 B 是 XSLT 文档,列表 C 是我们使用的 C# 程序代码。
列表 A —— XML 文档
<?xml version="1.0" encoding="UTF-8"?>
< world >
<country name="
< city>
< city>
</country>
<country name="
< city>
< city> Ocho Rios</city>
</country>
<country name="
< city>
< city>
</country>
<country name="
< city>
< city>
</country>
<country name="
< city>
< city> Nice</city>
</country>
<country name="
< city>
< city>
</country>
</world>
列表 B —— XSLT2.0 样式表
<?xml version="1.0" encoding="UTF-8"?>
< xsl:stylesheet version="2.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:fo="
http://www.w3.org/1999/XSL/Format"xmlns:xs="http://www.w3.org/2001/XMLSchema"xmlns:fn="
http://www.w3.org/2005/xpath-functions"xmlns:xdt="http://www.w3.org/2005/xpath-datatypes">
< xsl :template match="/">
< xsl :element name="world">
< xsl :for -each-group select="//country" group-by="@continent">
< xsl :sort select="@continent" data-type="text" order="ascending"/>
< xsl :variable name="continent" select="@continent"/>
< xsl :apply -templates select="//country[@continent = $continent]" mode="group">
< xsl :sort select="@name" data-type="text" order="ascending"/>
</ xsl :apply -templates>
</ xsl :for -each-group>
</ xsl :element >
</ xsl :template >
< xsl :template match="*" mode="group">
< xsl :copy -of select="."/>
</ xsl :template >
</ xsl :stylesheet >
内容导航
- 第1页:XSLT 2.0应用实践
- 第2页:XSLT 2.0应用实践(2)
- 第3页:XSLT 2.0应用实践(3)


















文章评论
共有 位CH网友发表了评论 查看完整内容