相关资源
搜索
广告是为了发展
你的位置:首页 > 学习 > 代码
 
应用程序开发者应了解XSLT 2.0新特性
 
作者:不详   来源:网络   编辑:阿志
[字体: ]
 

列表D——分组结果

<?xml version="1.0" encoding="UTF-8"?>

<world>

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

<city>Tokyo</city>

<city>Osaka</city>

</country>

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

<city>Paris</city>

<city>Nice</city>

</country>

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

<city>London</city>

<city>Dundee</city>

</country>

<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>

</world>

多文档输出

在使用XSLT 1.0时,我经常遇到式样表输出限制。我指的是文档输出问题,它一次只允许输出一个文档。这表示有必要在结果文档生成时进行处理。

以列表A中的XML文档为例,假设我们要把它分成几个XML文档,每个国家一个。过去必须用选择的语言编写一些代码建立单独的XML文档。XSLT 2.0改变了这种做法。

现在XSLT 2.0使用xsl:result-document元素,它与xsl:output元素结合生成几个输出文档。有趣的是,使用方法属性,不同的xsl:output文档可以用来生成不同的文档类型。列表E中的式样表说明了使用这种特性的一种可能方法,列表F-L中的XML文档为处理结果。

列表E——在XSLT 2.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:output name="xml" method="xml"/>

<xsl:template match="/">

<xsl:apply-templates select="//country"/>

</xsl:template>

<xsl:template match="country">

<xsl:variable name="name" select="concat(@name,'.xml')"/>

<xsl:result-document href="" format="xml">

<xsl:copy-of select="."/>

</xsl:result-document>

</xsl:template>

</xsl:stylesheet>

列表F -- Canada.xml

<?xml version="1.0" encoding="UTF-8"?>

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

<city>Toronto</city>

<city>Vancouver</city>

</country>

列表H -- Jamiaca.xml

<?xml version="1.0" encoding="UTF-8"?>

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

<city>Kingston</city>

<city>Ocho Rios</city>

</country>

列表I -- United States.xml

<?xml version="1.0" encoding="UTF-8"?>

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

<city>Allentown</city>

<city>Mobile</city>

</country>

列表J -- United Kingdom.xml

<?xml version="1.0" encoding="UTF-8"?>

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

<city>London</city>

<city>Dundee</city>

</country>

列表K -- France.xml

<?xml version="1.0" encoding="UTF-8"?>

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

<city>Paris</city>

<city>Nice</city>

</country>

列表 L -- Japan.xml

<?xml version="1.0" encoding="UTF-8"?>

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

<city>Tokyo</city>

<city>Osaka</city>

</country>

其它特性

除已经列举的特性外,我的最喜爱特性列表中还有其它一些特性。第一个是XPath 2.0支持。作为一个XML爱好者,我期待着试用这些新特性和XPath 2.0的功能。第二个特性,XQuery 1.0,可帮助其他人更易于理解XSLT。XQuery 1.0有望帮助那些对XPath“过敏”的用户使用XSLT 2.0。

应用XSLT 2.0

不幸的是,如果你对试用XSLT 2.0版本的新特性感兴趣,当前只能使用少数几个处理器。第一个为Michael Kay的Saxon处理器,如果你希望遵从万维网联盟的推荐,这个开源XSLT处理器为你提供了一个选择。另一个是Altova的XMLSpy处理器,它是我见过的速度最快的XML编辑器。它们的网站提供这个处理器的30天试用版本。唯一的问题是,30天试用到期后,你就想购买这个处理器了!

[从此长大]

上一页 [1] [2] 

 
--------------------------------------------------------------------------www.Cbcz.com
发表评论】【加入收藏】【告诉好友】【关闭窗口