2

我想使用 xpath 3.1 fn:transform 创建一个输出文档。以下是 A.xsl。它在直接运行时(从氧气中)创建 A.xml:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:math="http://www.w3.org/2005/xpath-functions/math"
    exclude-result-prefixes="xs math"
    version="3.0">
    
    <xsl:output name="xml" method="xml" indent="true" />
    
    <xsl:template name="xsl:initial-template">
        <xsl:message select="'A'"/>
        
        <xsl:result-document href="file:/C:/Work/test/A.xml" format="xml">
            <resultDoc>
                <text>The result of A.</text>
            </resultDoc>
        </xsl:result-document>
    </xsl:template>
</xsl:stylesheet>

结果:使用所需输出创建 A.xml:

<?xml version="1.0" encoding="UTF-8"?>
<resultDoc>
   <text>The result of A.</text>
</resultDoc>

现在,使用转换函数调用 A.xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="3.0">
    
    <xsl:output name="xml" method="xml" encoding="UTF-8" indent="true" />
    
    <!-- Global Constants -->
    
    <xsl:variable name="xsl-file-base" select="'file:/C:/Work/test/'" as="xs:string"/>
    <xsl:variable name="xsl-pipeline" select="'A.xsl'" as="xs:string"/>
    
    <!-- Entry Point -->
    
    <xsl:template name="xsl:initial-template">
        <xsl:iterate select="$xsl-pipeline">
            <xsl:variable name="file" select="$xsl-file-base || ." as="xs:string"/>
            
            <xsl:result-document href="file:/C:/Work/test/A.xml" format="xml">
                <xsl:sequence select="transform(map{'stylesheet-location' : $file})?output"/>
            </xsl:result-document>
        </xsl:iterate>       
    </xsl:template>
</xsl:stylesheet>

结果:A.xml 已创建但不完整。任何帮助表示赞赏。

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

1 回答 1

1

transform函数的结果是一个映射,其中包含output为主要结果文档命名的条目以及为辅助结果文档命名的更多条目。您调用的样式表使用 URI 创建辅助结果,file:/C:/Work/test/A.xml因此

<xsl:sequence 
   select="transform(map{'stylesheet-location' : $file})('file:/C:/Work/test/A.xml')"/>

更有可能产生输出。

于 2021-08-14T07:38:04.870 回答