Global variable can be shadowed by a local one. It means that if local variable has the same name as a global one, the value of the local one is used.
|
XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> <xsl:variable name="xxx">xxx-global</xsl:variable> <xsl:variable name="yyy">yyy-global</xsl:variable> <xsl:template match="/aaa"> <xsl:variable name="xxx">xxx-local</xsl:variable> <xsl:variable name="zzz">zzz-local</xsl:variable> <i> <xsl:value-of select="$xxx"/> </i> <ii> <xsl:value-of select="$yyy"/> </ii> <iii> <xsl:value-of select="$zzz"/> </iii> </xsl:template> </xsl:stylesheet> |
|
|
XML
<aaa/> |
Output
<i>xxx-local</i> <ii>yyy-global</ii> <iii>zzz-local</iii> |
| Previous chapter: | Named-Templates |
| Next chapter: | Stylesheet Functions |
| Previous page: | Problems with scope of variables |
| Next page: | Shadowing local variables |