XSLT <xsl:variable>
Element
Definition and Usage
The <xsl:variable>
element is used to declare local or global variables.
Note: If declared as a top-level element, it becomes a global variable. If declared within a template, it is a local variable.
Note: Once you set the value of a variable, you cannot change or modify that value!
Tip: You can add values to variables either through the content of the <xsl:variable>
element or through the select attribute!
Syntax
Attributes
Attribute | Value | Description |
---|---|---|
name | name | Required. Specifies the name of the variable. |
select | expression | Optional. Defines the value of the variable. |
Example 1
If the select attribute is set, the <xsl:variable>
element cannot contain any content. If the select attribute contains a literal string, the string must be quoted. The following two examples assign the value "red" to the variable "color":
Example 2
If the <xsl:variable>
element only contains the name attribute and no content, the value of the variable is an empty string:
Example 3
The following example assigns the value to the variable "header" through the content of the <xsl:variable>
element: