XSLT 调用模板,在不同的模板上使用 xsl:with-param

  • 本文关键字:xsl with-param 调用 XSLT xslt
  • 更新时间 :
  • 英文 :


我的实时 XSLT 文件有问题。基于此,我在这里提出我的问题。我有 3 个 xslt 文件,例如 1.xsl2.xslmaster.xsl 。此master.xsl导入到1.xsl2.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

最新更新