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.

Why XQuery - The Case for XQuery

Read "The Case for XQuery" - an article that debuted in the November 2005 issue of SOA WebServices Journal, written by Jerry King, Vice President of DataDirect Technologies.

XML Processing

Learn how to simplify XML Processing using Stylus Studio XML Pipeline, the easiest way to visually design and deploy virtually any XML processing tasks.

Text File to XML

Stylus Studio provides several easy-to-use document wizards that allow you to quickly convert text files to XML. Create XML from text and EDI, create XML Schema from EDIFACT, and more!

Stylus Studio Enables Multi-Channel Publishing for University of Pittsburg Professor

Learn how Dr. David Birnbaum of the University of Pittsburgh uses Stylus Studio to develop customized XSLT stylesheets that produce enhanced versions of source documents in different output formats, including Web and print.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member