什么时候用
要临时存储某个节点内容或者节点属性值的时候
用在哪儿
xslt的根节点下面可以定义全局变量,在任意的template中都可以使用
定义
1、值为节点内容
<xsl:variable name="local-language" select="./article/p"/>
- name:变量名称
- select: 变量值
注:其中的select属性为可选,值可以在标签内部嵌套语句来获取
2、值为节点属性值
<xsl:variable name="pub-type" select="@pub-type"/>
- name:变量名称
- select: 变量值 @属性即为取属性值
使用
要取得pub-type(variable的name属性)的值,判断后做后续处理
- 取值
$pub-type
- 处理
<xsl:variable name="pub-type" select="@pub-type"/>
<xsl:if test="$pub-type = 'ppub'">
<PubDate PubStatus="ppublish">
<xsl:call-template name="format-date-func"/>
</PubDate>
</xsl:if>