
300 • XML & Related Technologies
6.4.6 Defining Variables Using
<xsl:variable>
Like full-fledged programming languages, the XSLT allows us to define and use variables in our application
programs.
The syntax for defining a variable in XSLT is:
<xsl:variable name = “name of the variable” select = “…” />
The syntax for using a variable in XSLT is:
<xsl:value-of select = “$name of the variable”/>
Let us consider an example. Suppose that we have a list of players and the runs scored by them. This is
shown in Figure 6.61.
<?xml version=”1.0”?>
<?xml-stylesheet type=”text/xsl” href=”players.xsl”?>
<PLAYERS>
<PLAYER>
<NAME>Sachin Tendulkar</NAME>
<RUNS>1,000</RUNS> ...