【问题标题】:XSLT calling template based on the condition基于条件的 XSLT 调用模板
【发布时间】:2018-04-05 17:29:33
【问题描述】:

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

在这种情况下,在文件 1.xsl 上,有一段时间,对于模板“内容”,parameter 请求将不会通过。过段时间就会过去的。

所以,上面的模板在某些情况下会(不带参数'request')

<xsl:template name="content">

    ....
</xsl:template>

当没有参数时,现在显示错误

XTSE0680: Parameter request is not declared in the called template

所以,在这种情况下,请给我一些想法来修改master.xsl上的编码

【问题讨论】:

  • @markdark,看起来一样,但这是不同的。我用相同的代码问了另一个问题。有任何想法吗?请
  • 'as' 是什么意思?在 as="node()"
  • 这是一个参数,通过一组xml标签传递
  • 如果 xsl:choose 元素不存在 'Content' 参数,您可以传递虚拟元素。

标签: xslt


【解决方案1】:

错误信息的原因已在XSLT calling template with xsl:with-param on different template的回复中指出。您必须修改模板以声明参数。或者您需要更改master.xsl 中的代码以仅使用例如传递参数

<xsl:choose>
   <xsl:when test="$request">
     <xsl:call-template name="content">
       <xsl:with-param name="request" select="$request"/>
     <xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
     <xsl:call-template name="content"/>
   </xsl:otherwise>
</xsl:choose>

只有在$request 是非空序列时才会传递。当然,如果您的代码包含在模板确实声明了参数并且变量$request 不为空的样式表中,您将继续遇到错误。无法在运行时检查模板是否需要参数。

【讨论】:

  • a / 缺少关闭第一个
猜你喜欢
  • 2016-08-06
  • 1970-01-01
  • 1970-01-01
  • 2021-01-01
  • 1970-01-01
  • 2020-10-10
  • 1970-01-01
  • 1970-01-01
  • 2020-12-09
相关资源
最近更新 更多