You can define a variable and set its value using the
<xsl:variable>
element. Once you have defined a variable, you can refer
to it in any XPath expression by using a dollar sign
($) followed by
the name of a variable.
There are two kinds of variables:
A global variable's value
is available everywhere in your stylesheet. To
define a global variable, place the <xsl:variable> element as a
child of the root stylesheet element.
The value of a local variable is available only inside the element where it is declared.
There are two ways to specify the value of your
variable. You can use an XPath expression in the select attribute and the
variable will take on the value of that expression. You
can, instead, place the value in the content of the
<xsl:variable>
element. For example, these two elements have the same
effect:
<xsl:variable name="child-page" select="'child.html'"/>
<xsl:variable name="child-page">child.html</xsl:variable>Note in the first example above that the value of the
select attribute has
two levels of quotes. This is necessary because in XPath
names usually refer to child elements. If you want an
attribute to have a string constant as its value, you
must provide a second level of quotes inside the quotes
that surround the attribute value.
Here are the attributes of the <xsl:variable> element:
selectThe value you are assigning to this variable.