January 1, 2002 - Setting Variables in XSLT | WebReference

January 1, 2002 - Setting Variables in XSLT

Yehuda Shiran January 1, 2002
Setting Variables in XSLT
Tips: January 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

XSLT supports variables. You can set a variable in one place and reuse it somewhere else. Use variables to make your code more flexible and well-organized. You define a variable with the xsl:param tag. You position this tag in the front section of your script, before the HEAD statament. Here is an example:

<xsl:param name="forecast" select="50000"/>
And here is an example for the whole front section:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="https://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:param name="forecast" select="50000"/>
<xsl:template match="/">
<HTML>
...
...
...
You use a variable by prefixing its name with a $ sign. For example:

$forecast