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.

Web Service Data Mapping

Stylus Studio makes it possible for you to use Web services as live XML data sources for XML mapping projects.

XML Unicode Encoding

Stylus Studio supports over 300 different file encodings, including UTF-8, UTF-16, EUC-JP, SHIFT-JIS, and more, alowing you to work with any XML document. Robust text editors support standard editing features, and Sense:X intelligent auto-completion.

Using Stylus Studio's Database-to-XML Editor to Query and Update Relational Databases using SQL/XML

Watch and learn how easy it is to define relational-to-XML mappings for getting XML out of relational databases and updating databases from XML using industry-standard SQL/XML extensions and Stylus Studio's DB-to-XML data-source editor.

Apache XML Project

The Apache XML Project provides standards-based, open-source XML solutions for working with W3C XML technologies including XML, XSL, XSLT, XSL:FO XPath, Web services and more. Learn how Stylus Studio provides support for all Apache XML projects.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member