Section 18.7.  Variables and parameters

Prev don't be afraid of buying books Next

18.7. Variables and parameters

XSLT variables and parameters are closely related in that both involve replacing a name with an associated value (much like an XML entity).

18.7.1 Variables

An XSLT variable is a value that a stylesheet creator stores away for use in some other part of the stylesheet. A top-level variable is one defined outside any template rule. The value is automatically available for use in any template. For instance a variable could hold the company name. The value that the variable holds could even be extracted from the input XML document. Example 18-24 demonstrates.

Example 18-24. Defining a variable
 <xsl:variable name="company-name" select="/doc/creator/company"/> 

Variables can be referred to in XPath expressions by preceding the variable name with a dollar-sign ($). Example 18-25 demonstrates.

Example 18-25. Referencing a variable
 <xsl:value-of select="$company-name"/> 

Amazon


XML in Office 2003. Information Sharing with Desktop XML
XML in Office 2003: Information Sharing with Desktop XML
ISBN: 013142193X
EAN: 2147483647
Year: 2003
Pages: 176

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net