XSLT 设置结果文档结束的目录



下面的 XSLT 根据需要创建结果文档,但有一个例外:结果文档最终位于调用样式表的目录中。我希望结果文档位于找到它的位置(即用转换版本覆盖自身)。

我该怎么做?

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0" xpath-default-namespace="http://www.w3.org/1999/xhtml">
    <xsl:template match="/">
        <xsl:for-each select="collection(iri-to-uri('file:///home/paul/Text/?select=*.xhtml'))">
            <xsl:variable name="filename">
                <xsl:value-of select="tokenize(document-uri(.), '/')[last()]"/>
            </xsl:variable>
            <xsl:result-document indent="yes" method="xml" href="{$filename}">
                <xsl:apply-templates/>
            </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
    <xsl:template match="node()|@*">    
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>
    <!-- transform templates removed -->
</xsl:stylesheet>

尝试仅使用 href="{document-uri(.)}" 将完整的 uri 用作目标,而不是进行标记化以拉出最后一个段。

最新更新