xsl:variable

Declares a variable and binds a value to that variable.

Format

<xsl:variable name="variable_name" 
               
  [select = "expression2"] 
               
  [expr = "expression3"]>
               
template_body
               
</xsl:variable>
               

            

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:

  • Specify the select attribute. The value of the select attribute must be an expression. The XSLT processor evaluates the expression, and the result is the value of the variable. If you specify the select attribute, you must not specify any contents for the xsl:variable instruction. In other words, do not specify template_body.
  • Specify the expr attribute. It is interpreted as an attribute value template. It allows computation of the value expression.

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.

  • Specify template_body. The XSLT processor instantiates this template to obtain the value of the variable. If you specify template_body, you must not specify the select attribute.
  • Specify none of the above. In this case, the value of the variable is an empty string.

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.

Scope

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.

Microsoft .NET XML Tools for System.XML 1.0 and System.XML 2.0

Stylus Studio features integrated XML validation, XSLT transformation and XSLT debugging using the official Microsoft .NET XML processing components: System.XML 1.0 and System.XML 2.0.

Oil, Gas & Electric Companies That Use Stylus Studio

Oil, gas & electric companies know a good resource when they see it. That's why they use Stylus Studio as their #1 XML resource. Come see which of these top oil, gas & electric companies are conserving their time and labor with Stylus Studio.

Learn XSLT

Free online video demonstrations for learning XSLT and how to design XSLT stylesheets to convert XML to HTML in publishing applications, or how to convert HTML to XML.

Xerces - Parsing and Validating XML with the Apache Xerces Parser

The Xerces Parser supports the XML 1.0 recommendation and W3C's XML Schema recommendation version 1.0, DOM and SAX. Learn how easy it is to use Apache Xerces directly in Stylus Studio to parse and validate XML with ease.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member