参数和变量必须位于模板的顶部吗?
我认为参数和变量必须位于模板的顶部..但我可以成功编译此代码:
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据规范,您可以编写
;
作为
和
的子级(或
,它是 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.
只有
xsl:template
中的xsl:param
必须是xsl:template
指令的子级。对于
xsl:variable
没有这样的要求 - W3C XSLT 1.0 和 XSLT 2.0 规范允许它们出现在 XSLT 样式表中的任何深度。Only an
xsl:param
within anxsl:template
must be a child of thexsl: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.