XSLT 2.0应用实践

『 更新时间:2008-1-25 』『 字体:变小 变大 』『 作者:佚名 | 来源:互联网 』

在安装了 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="Canada" continent="North America">

< city> Toronto</city>

< city> Vancouver</city>

</country>

<country name="Jamaica" continent="North America">

< city> Kingston</city>

< city> Ocho Rios</city>

</country>

<country name="United States" continent="North America">

< city> Allentown</city>

< city> Mobile</city>

</country>

<country name="United Kingdom" continent="Europe">

< city> London</city>

< city> Dundee</city>

</country>

<country name="France" continent="Europe">

< city> Paris</city>

< city> Nice</city>

</country>

<country name="Japan" continent="Asia">

< city> Tokyo</city>

< city> Osaka</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] [2] [3] 下一页

【点击数:】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口

关文章

您的姓名:
评分等级:
1分 2分 3分 4分 5分
评论内容:
1、严禁发表危害国家安全、政治、黄色淫秽等内容的评论。
2、用户需对自己在使用金石网服务过程中的行为承担法律责任。
3、本站管理员有权保留或删除评论内容。
4、评论内容只代表网友个人观点,与本网站立场无关。
  • 金石网
  • | 设为首页 | 加入收藏 | 联系我们 | 版权申明 | 友情链接 | 站点地图 | 网站帮助 | 网站留言 | 广告服务 |
  • Copyright © 2001-2008 KingsNet.biz All Rights Reserved. 闽ICP备05026663号
  • 返回网站顶部