FW: [xsl] XSL variable out of scope

Subject: FW: [xsl] XSL variable out of scope
From: "Martinez, Brian" <brian.martinez@xxxxxxxx>
Date: Thu, 23 Jan 2003 14:01:43 -0700
This is very odd--I was unable to reply to this at first because the filters
on our Exchange server rejected this due to the possibility I was
transmitting a list of telephone numbers.  No joke.  Anyway, I apologize for
the intentional misspellings in the following.  - b.

-----Original Message-----
From: Martinez, Brian 
Sent: Thursday, January 23, 2003 1:55 PM
To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: RE: [xsl] XSL variable out of scope


> From: Nischal Muthana [mailto:nischal_muthana@xxxxxxxxx]
> Sent: Thursday, January 23, 2003 1:04 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] XSL variable out of scope
> 
> But I get an error saying variable out of scope. And I
> know I am using a variable declared in a different
> scope. I am kinda stuck here and I dont have any more
> ideas to counter this. Can someone help me find a way
> to tackle this problem. 
> 
> < XML snipped >
>
> <xsl:for-each select="//PhxneList/Phxne">
> 	<xsl:variable name="PhUseCode"
> select="PhxneUseCode"/>
> 	<xsl:choose>
> 		<xsl:when test="$PhUseCode='HOME'">
> <xsl:variable name="HomePhxne" select="PhxneNumber"/>
> 	</xsl:when>
> 	<xsl:when test="$PhUseCode='BUS'">
> <xsl:variable name="BusPhxne" select="PhxneNumber"/>
> 	</xsl:when>
> </xsl:choose>
> </xsl:for-each>

Your xsl:variable declarations are within the xsl:for-each loop, so they go
out of scope and aren't available in the following block of code.  This is a
common error.

The structure of your stylesheet is suspect, I think.  If your intention is
to output a list of home and business phones for a group of people, then you
might try to wrap the entire block (including the table rows) in a for-each,
then your variables will be in scope for each iteration of PhxneList.  If
your XML always has just one HOME and one BUS phone, however, then the
following would be more efficient, without iteration:

<xsl:variable name="HomePhxne"
select="/PhxneList/Phxne[PhxneUseCode='HOME']/PhxneNumber"/>
<xsl:variable name="BusPhxne"
select="/PhxneList/Phxne[PhxneUseCode='BUS']/PhxneNumber"/>

Then use your table code as before.

hth,
b.

| brian martinez                              brian.martinez@xxxxxxxx |
| senior gui programmer                                  303.708.7248 |
| trip network, inc.                                 fax 303.790.9350 |
| 6436 s. racine cir.                             englewood, co 80111 |
| http://www.cheaptickets.com/                   http://www.trip.com/ |

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


Current Thread