Next / Previous / Contents / Shipman's homepage

8.2. xsl:variable: Define a global or local variable

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:

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:


The value you are assigning to this variable.