XSLT-2.0:输出到文件

XSLT-2.0: Output to file

使用 SaxonHE 9.7/XPath-2.0

为什么这个标识模板在将其输出发送到文件时返回 "Cannot write more than one result document to the same URI"?没有 xsl:result-document 它会按预期将其发送到标准输出。

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:template match="@*|node()">
        <xsl:result-document href="Output.xml">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:result-document>
    </xsl:template>
</xsl:stylesheet>

使用

<xsl:template match="/">
  <xsl:result-document href="Output.xml">
    <xsl:apply-templates/>
  </xsl:result-document>
</xsl:template>

加上正常的身份转换模板,这样样式表创建的输出就会转到 Output.xml。您当前的代码匹配任何节点,并且对于每个匹配的节点都试图打开同一个文件,这是不允许的。