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

时间:2011-06-08 10:44:01

标签: html xml xslt xpath transformation

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

   <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>

所以我想知道什么是捕获

2 个答案:

答案 0 :(得分:2)

根据the spec,您可以将<xsl:param>写为<xsl:template><xsl:stylesheet>(或<xsl:transform>的子项,这是XSLT中的替代顶级元素)。

如果您的样式表编译,那么您的XSLT处理器就会表现为非标准。

答案 1 :(得分:1)

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

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