When variable defined the stylesheet level
|
|
||
---|---|---|---|
Table 13.28 | |||
xsl:processing-instruction | |||
|
|
||
|
|
||
Variable Examples
The xsl:variable is typically used to grab information from the source XML that will be reused repeatedly throughout the stylesheet or to store information. Once you grab the information, you can use it again and again by referencing the variable name with a $ prefix, as in $variable_name. Avariable’s value is set as part of its definition, making it quite different from the variables you use in other programming languages. Those variables must be defined and their value must be changed many times over the life of the programs in which they are found. In this way, variables act like constants.
xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
<xsl:variable name=”row_num” select=”0”/>
XSLT In-Depth | 333 |
---|
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>The results of this example are shown in Figure 13.3. The first time $row_num is referenced, it takes the value of the stylesheet-level row_num variable because no template-body-level $row_num exists at that point. The second time it is referenced, it takes the value of the attribute “num” of the current row.