我的实时 XSLT 文件有问题。基于此,我在这里提出我的问题。我有 3 个 xslt 文件,例如 1.xsl
、2.xsl
和 master.xsl
。此master.xsl
导入到1.xsl
和2.xsl
在 master.xsl 上,我正在使用下面的代码
<xsl:call-template name="content">
<xsl:with-param name="request" select="$request"/>
<xsl:call-template>
像明智的,在1.xsl
,
<xsl:template name="content">
<xsl:param name="request" as="node()"/>
....
</xsl:template>
在2.xsl
<xsl:template name="content">
....
</xsl:template>
当我执行此2.xsl
时,出现以下错误:
XTSE0680: Parameter request is not declared in the called template
实际上,请求变量仅在我执行1.xsl
时才需要。另外,我不会在模板上声明虚拟变量2.xsl
.像这样,我有很多实时的 xslt 文件。因此,我无法在许多 xslt 文件中声明相同的变量,因为它会花费更多时间并且不一致。
谁能给我一个克服这个问题的想法?
XSLT 2.0 的规则在 http://www.w3.org/TR/xslt20/#err-XTSE0680 中明确指出:"在 xsl:call-template 的情况下,将名为 x 的非隧道参数传递给没有名为 x 的模板参数是一个静态错误,除非为 xsl:call-template 指令启用了向后兼容的行为。
因此,如果您想使用代码,请使用 XSLT 2.0
<xsl:call-template name="content">
<xsl:with-param name="request" select="$request"/>
<xsl:call-template>
然后,您需要确保request
声明任何被调用的模板content
都具有该参数。
我认为apply-templates
的规则是不同的,因此您可以检查是否可以简单地编写具有match
属性的模板并使用apply-templates
。