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

Re: Newbie wonders why the variable can change value?

Subject: Re: Newbie wonders why the variable can change value?
From: Brandon Ibach <brandon.ibach@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 21 Feb 2011 17:54:15 -0500
Re:  Newbie wonders why the variable can change value?
On Mon, Feb 21, 2011 at 4:53 PM,  <thehulk@xxxxxxxxxxx> wrote:
> The template that processes the sibling ACCT uses a "choose" to determine
the level of that ACCT and does much the same to nest BRANs within SUBS:
>
> <xsl:variable name="currentSU" select="HIERARCHY_Info/@Acct_ID"/>
> <xsl:apply-templates  mode="RE"
select="../ACCT[HIERARCHY_Info/@Prnt_Acct_ID=$currentSU]"/>
>
> All that works, but, it seems to me that it is resetting the variable
$currentSU for each of the ACCTs that are Subsidiary-level. But you cannot
reset a variable, it says on all the tutorials. Why does it work?

Every variable exists within a particular "scope".  For a "global"
variable, defined outside of any template, the scope is the entire
transform, and it will only ever have one value during the entire run.
 For other variables, the scope is the parent element, such as an
xsl:template, xsl:for-each, or even an xsl:if.  The variable only
exists until the end of that scope and only has one value during that
time.

However, every time that scope is executed, the variable gets a
different value, generally because the scope is executing with a
different context node, etc.  Think of a template as a function.  The
value you get out of it will depend on the parameters you pass in
(including the context) and the local variables within that function
will take on different values during the course of its execution, as
well.  The only difference (compared to many programming languages) is
that the variable's value is fixed until the end of the function.

Hope this makes things clearer...

-Brandon :)

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.