xsl:variable 与 xsl:param (原创)

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

先看个例子:

<xsl:call-template name="footer">

<xsl:with-param name="date" select="@lastupdate"/>

</xsl:call-template>

<xsl:template name="footer">

<xsl:param name="date">today</xsl:param>

<hr/>

<xsl:text>Last update: </xsl:text>

<xsl:value-of select="$date"/>

</xsl:template>

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

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

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

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

说到xsl:variable。

可以用<xsl:variable name="ShowDepth"><计算的值></xsl:variable>来声明

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

对于xsl:param和xsl:variable 都可以用 $+name 来直接选择比如

<xsl:value-of select="$date"/> 就是选择date变量或者参数

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

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

不要被它的名称迷惑、

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航