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

RE: Scope of variables

Subject: RE: Scope of variables
From: "Martinez, Brian" <brian.martinez@xxxxxxxxxxx>
Date: Thu, 8 May 2003 14:56:23 -0600
define scope
> From: Karl J. Stubsjoen [mailto:karl@xxxxxxxxxxxxx]
> Sent: Thursday, May 08, 2003 1:00 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Scope of variables
> 
> 
> I have 2 questions:
> 1)  If I define a variable at the top of a template rule and 
> then later try
> to update the value of this variable later down in the 
> template, I always
> get the error "Can't define variable twice...".  So how do 
> you reassign a
> value to a variable.

VFAQ #1.  You can't reassign a value to a variable once it is bound.  You
can, however, define a top-level variable in a stylesheet that is then
imported into another stylesheet, and then override its value (the rules of
precedence for imported modules apply).

> 2) About scope:  Within a for-each loop I have a choose.  In 
> the choose I
> have a single test and an otherwise.  The result of the 
> choose is setting
> the value of a variable.  Just below this choose logic I am 
> referencing the
> value but am getting the error "A reference to variable or parameter
> 'currentVAL' cannot be resolved".  Where did I lose scopE on 
> this variable
> (currentVAL)?

VFAQ #2.  Variables only exist within the scope of their containing element.
If you do:

<xsl:if test="$foo = 'true'">
  <xsl:variable name="bar" select="'false'"/>
</xsl:if>

then $bar never exists outside the xsl:if element, and can't be referenced
anywhere else in the stylesheet.  You want:

<xsl:variable name="bar">
  <xsl:choose>
    <xsl:when test="$foo = 'true'">false</xsl:when>
    <xsl:otherwise>true</xsl:otherwise>
  </xsl:choose>
</xsl:variable>

hth,
b.

| brian martinez                           brian.martinez@xxxxxxxxxxx |
| lead gui programmer                                    303.708.7248 |
| cheap tickets, part of trip network                fax 303.790.9350 |
| 6436 s. racine cir.                             englewood, co 80111 |
| cendant travel distribution services   http://www.cheaptickets.com/ |

 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.