The <xsl:variable> Element: Creating Variables

You use <xsl:variable>to create variables in XSLT. This element has the following attributes:

  • name(mandatory). The name of the variable, set to a QName.

  • select(optional). An XPath expression that specifies the value of the variable. If you omit this attribute, the value of the variable is specified by the contents of <xsl:variable>.

This element can either be a top-level element or be used inside a template body. This element can contain a template body; but if a body is present, you should not use the select attribute.

You create a variable by assigning its name to the <xsl:variable> element’s name attribute, and its value to the select attribute, as in this case, where I’m creating a new variable ...

Get Inside XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.