[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Scope of variable defined in <xsl:choose>

Subject: RE: Scope of variable defined in <xsl:choose>
From: Joshua.Kuswadi@xxxxxxxxxxxxxxxxxxxx
Date: Mon, 21 May 2001 12:54:07 +1000
scope of variable
Hi Tim,

For your first example you have declared the variable 'numberdisplayed' within the when and within the otherwise. Therefore, it is out of scope when you try to select its value after the choose.

One solution I've seen around (Check out http://www.dpawson.co.uk/xsl/xslfaq.html for heaps of great XSLT examples) is to use:

<xsl:variable name="numberdisplayed">
	<xsl:choose>
		<xsl:when test="data/merchant/customer">
			<xsl:value-of select="count(data/merchant/customer)" />
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="count(data/merchant/orders)" />
		</xsl:otherwise>
	</xsl:choose>
</xsl:variable>

This will set the variable based on the choose, ready for later use.

Cheers,
Joshua

> I can't understand this error message
> 
> > Error [code:222] [node:
> > element '<xsl:value-of>']
> >   variable not found
> > search/search - text/html
> 
> for the following code:
> 
> > <xsl:choose>
> >	<xsl:when test="data/merchant/customer">
> >		<xsl:variable name="numberdisplayed"><xsl:value-of
> select="count(data/merchant/customer)" /></xsl:variable>
> >	</xsl:when>
> >	<xsl:otherwise>
> >		<xsl:variable name="numberdisplayed"><xsl:value-of
> select="count(data/merchant/orders)" /></xsl:variable>
> >	</xsl:otherwise>
> > </xsl:choose>
> > <xsl:value-of select="$numberdisplayed" />
> 
> The variable has just been defined, but it can't be used 
> outside of the
> <xsl:choose>
> 
> Yet, if I have
> 
> > <xsl:choose>
> >	<xsl:when test="/document/data/merchant/customer">
> >		<xsl:variable name="numberdisplayed"><xsl:value-of
> select="count(/document/data/merchant/customer)" />
> > </xsl:variable>
> >		<xsl:value-of select="$numberdisplayed" />
> >	</xsl:when>
> >	<xsl:otherwise>
> >		<xsl:variable name="numberdisplayed"><xsl:value-of
> select="count(/document/data/merchant/orders)" />
> > </xsl:variable>
> >		<xsl:value-of select="$numberdisplayed" />
> >	</xsl:otherwise>
> > </xsl:choose>
> 
> the output is displayed.
> 
> How can the variable be used throughout the scope of the 
> template it has
> been defined in?
> 
> Thanks,
> 
> Tim Watts
> 
> PS. Am using Sablotron 0.51.
> 
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 

------------------------------------------------------------------------------
This message and any attachment is confidential and may be privileged or otherwise protected from disclosure.  If you have received it by mistake please let us know by reply and then delete it from your system; you should not copy the message or disclose its contents to anyone.





 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.