xsl:variable

Declares a variable and binds a value to that variable.

Format

Description

The name attribute is required, and it must be a string. The value of the name attribute is a qualified name.

The value that you bind to a variable can be an object of any of the types that are returned by expressions. You can specify the value of the variable in several ways:

The expr attribute of the xsl:variable instruction is an extension of the XSLT standard. If you want to use an XSLT processor other than the Stylus Studio processor, you cannot specify the expr attribute in your stylesheet.

The difference between the xsl:param and xsl:variable instructions is that xsl:param defines a default value while xsl:variable defines a fixed value.

For any use of the xsl:variable element, there is a region of the stylesheet tree within which the binding is visible. This region includes the siblings that follow the xsl:variable instruction together with their descendants. Within this region, any binding of the variable that is visible on the xsl:variable element itself is hidden. Thus, only the innermost binding of a variable is visible. The set of variable bindings in scope for an expression consists of those bindings that are visible at the point in the stylesheet where the expression occurs.

The xsl:variable instruction can be a top-level element. If it is, it declares a global variable that is visible to the entire stylesheet. When the XSLT processor evaluates the select or expr attribute in a top-level xsl:variable instruction, the current node is the root node of the document. The xsl:variable instruction is also allowed anywhere in a template that an XSLT instruction is allowed.

 
Free Stylus Studio XML Training: