xsl:variable 与 xsl:param (原创)

先看个例子:

1<xsl:call-template name="footer">
2<xsl:with-param name="date" select="@lastupdate"></xsl:with-param>
3</xsl:call-template>
1<xsl:template name="footer">
2<xsl:param name="date">today</xsl:param>
3<hr/>
4<xsl:text>Last update: </xsl:text>
5<xsl:value-of select="$date"></xsl:value-of>
6</xsl:template>

对xml模板 来说,name属性是很关键的 call-template /apply-template 的name必须要和模板的name

相对应。模板相当于一个函数,可以暂时这么看。而name相当于函数名称把。


在call-template中 使用xsl:with-param 相当于函数参数输入


而参数声明相当就是在xsl:template的 xsl:param


说到xsl:variable。


可以用
1<xsl:variable name="ShowDepth">&lt;计算的值&gt;</xsl:variable>

来声明

相当于c中的  const 因为变量一旦声明就无法再被改变。


对于xsl:param和xsl:variable 都可以用 $+name 来直接选择比如
1<xsl:value-of select="$date"></xsl:value-of>

就是选择date变量或者参数

变量和参数,都是有声明范围的 这点和语言中的道理一样。


最后 ** _ _最最重要一点 :xsl的variable是常量不能再改变__**


**__不要被它的名称迷惑、__**


**____**
Published At
Categories with Web编程
Tagged with
comments powered by Disqus