使用像 Saxon 9 或 AltovaXML 或 XmlPrime 这样的 XSLT 2.0 处理器,您可以使用如下方法:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* , node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="alert/info" mode="split"/>
</xsl:template>
<xsl:template match="info" mode="split">
<xsl:result-document href="language-{language}.xml">
<xsl:apply-templates select="/*">
<xsl:with-param name="info" select="current()" tunnel="yes"/>
</xsl:apply-templates>
</xsl:result-document>
</xsl:template>
<xsl:template match="info">
<xsl:param name="info" tunnel="yes"/>
<xsl:if test=". is $info">
<xsl:next-match/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
如果输入在某个命名空间中,则使用 eg <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xpath-default-namespace="urn:oasis:names:tc:emergency:cap:1.2">
。
如果要独立于命名空间运行 XSLT,请使用
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* , node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="*:alert/*:info" mode="split"/>
</xsl:template>
<xsl:template match="*:info" mode="split">
<xsl:result-document href="language-{language}.xml">
<xsl:apply-templates select="/*">
<xsl:with-param name="info" select="current()" tunnel="yes"/>
</xsl:apply-templates>
</xsl:result-document>
</xsl:template>
<xsl:template match="*:info">
<xsl:param name="info" tunnel="yes"/>
<xsl:if test=". is $info">
<xsl:next-match/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>