XSLT 2.0 新特性分析
对于XSLT 2.0中的新特性,本文将除开那些现在无益的特性,主要讨论那些能够立即满足应用程序开发需求的特性……
多文档输出
在使用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> |
- 本文关键词:

