参数和变量必须位于模板的顶部吗?

发布于 2024-11-14 13:51:55 字数 611 浏览 5 评论 0原文

我认为参数和变量必须位于模板的顶部..但我可以成功编译此代码:

   <xsl:template name="WriteOptions">
      <xsl:param name="input"/>
      <xsl:choose>
      <xsl:when test="true()">
      </xsl:when>
      <xsl:otherwise>
         <xsl:param name="head" select="substring-before($input, ',')"/>
         <xsl:variable name="tail" select="substring-after($input, ',')"/>
         <option value="{$head}"><xsl:value-of select="$head"/></option>
      </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

所以我想知道有什么问题

I'd thought that params and variables must be at the top of a template.. yet i can successfully compile this code:

   <xsl:template name="WriteOptions">
      <xsl:param name="input"/>
      <xsl:choose>
      <xsl:when test="true()">
      </xsl:when>
      <xsl:otherwise>
         <xsl:param name="head" select="substring-before($input, ',')"/>
         <xsl:variable name="tail" select="substring-after($input, ',')"/>
         <option value="{$head}"><xsl:value-of select="$head"/></option>
      </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

So i was wondering what's the catch

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

翻身的咸鱼 2024-11-21 13:51:55

根据规范,您可以编写; 作为 的子级(或,它是 XSLT 中的替代顶级元素。

如果您的样式表可以编译,那么您的 XSLT 处理器的行为就是非标准的。

Per the spec, you can write <xsl:param> as a child of <xsl:template> and <xsl:stylesheet> (or <xsl:transform>, which is the alternative top level element in XSLT).

If your stylesheet compiles, then your XSLT processor behaves non-standard.

当梦初醒 2024-11-21 13:51:55

只有 xsl:template 中的 xsl:param 必须是 xsl:template 指令的子级。

对于 xsl:variable 没有这样的要求 - W3C XSLT 1.0 和 XSLT 2.0 规范允许它们出现在 XSLT 样式表中的任何深度。

Only an xsl:param within an xsl:template must be a child of the xsl:template instruction.

There is no such requirement for an xsl:variable -- the W3C XSLT 1.0 and XSLT 2.0 specifications allow them to appear at any depth in the XSLT stylesheet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文