<xsl:template>的match属性定义此模板规则应用于哪些节点。我认为,匹配的节点是隐式地来自初始源文档。
例如,下面是我的XSLT模板的一部分:
<xsl:mode name="unroll" on-no-match="shallow-copy"/>
<xsl:template match="StructFormat[@repeat]" mode="unroll">
...
</xsl:template>
<xsl:variable name="complete-struct">
<xsl:apply-templates mode="unroll"/>
</xsl:variable>这个模板处理初始源文件,结果保存在一个变量中。如何将此模板规则应用于document()函数加载的临时文档?我试着这样做,但不起作用:
<xsl:template match="/" mode="unroll">
<xsl:apply-templates select="document('a.xml')/*"/>
</xsl:template>
<xsl:template match="@*|node()" mode="unroll">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>发布于 2018-12-17 18:20:39
带有全局变量的部分
<xsl:variable name="complete-struct">
<xsl:apply-templates mode="unroll"/>
</xsl:variable>构建一个处理全局上下文项(https://www.w3.org/TR/xslt-30/#dt-global-context-item)的子节点的变量
您可以将其更改为
<xsl:variable name="complete-struct">
<xsl:apply-templates select="doc('a.xml')/node()" mode="unroll"/>
</xsl:variable>要处理来自另一个文档的节点,或者如果您使用XSLT处理器的API运行它,请检查在哪里/如何根据需要/需要将全局上下文项设置为特定文档(请参见http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#setGlobalContextItem-net.sf.saxon.s9api.XdmItem- for Saxon9.9)。
我认为你试图添加
<xsl:template match="@*|node()" mode="unroll">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>是错误的,您的初始代码有一个声明<xsl:mode name="unroll" on-no-match="shallow-copy"/>,它应该做得很好,如果您想清楚地说明它,您将需要
<xsl:template match="@*|node()" mode="unroll">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="#current"/>
</xsl:copy>
</xsl:template>https://stackoverflow.com/questions/53812772
复制相似问题