Latest web development tutorials

XSLT <xsl: variable> element

XSLT Elements Reference Manual Complete XSLT Element Reference Manual

Definition and Usage

<Xsl: variable> element is used to declare local or global variables.

Note: If, as a top-level element (top-level element) to declare, it is a global variable.If you declare a variable within a template, it is a local variable.

Note: Once you have set the value of the variable, you can not change or modify this value!

Tip: You can <xsl: variable> element or content through select properties, add value to a variable!


grammar

<xsl:variable
name="name"
select="expression">

<!-- Content:template -->

</xsl:variable>

Attributes

属性 描述
name name 必需。规定变量的名称。
select expression 可选。定义变量的值。

Example 1

If the select attribute, <xsl: variable> element can not contain any content. If the select attribute contains a text string, the string in quotes must be given. The following two examples for the variable "color" assigned "red":

<xsl:variable name="color" select="'red'" />

<xsl:variable name="color" select='"red"' />

Example 2

If <xsl: variable> element contains only the name attribute, and no content, the value of the variable is an empty string:

<xsl:variable name="j" />

Example 3

The following examples by <xsl: variable> element contents of the variable "header" Assignment:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name="header">
<tr>
<th>Element</th>
<th>Description</th>
</tr>
</xsl:variable>

<xsl:template match="/">
<html>
<body>
<table>
<xsl:copy-of select="$header" />
<xsl:for-each select="reference/record">
<tr>
<xsl:if category="XML">
<td><xsl:value-of select="element"/></td>
<td><xsl:value-of select="description"/></td>
</xsl:if>
</tr>
</xsl:for-each>
</table>
<br />
<table>
<xsl:copy-of select="$header" />
<xsl:for-each select="table/record">
<tr>
<xsl:if category="XSL">
<td><xsl:value-of select="element"/></td>
<td><xsl:value-of select="description"/></td>
</xsl:if>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


XSLT Elements Reference Manual Complete XSLT Element Reference Manual