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

Newbie wonders why the variable can change value?

Subject: Newbie wonders why the variable can change value?
From: thehulk@xxxxxxxxxxx
Date: Mon, 21 Feb 2011 21:53:39 +0000 (UTC)
 Newbie wonders why the variable can change value?
I am making a hierarchy from a flattened input XML. It works, and it outputs a nested hierarchy which is correct. But I do not understand how the XSL variables can work. 

For instance, say that my original 5 ACCTs represent one "organization" with two "subsidiaries" and each sub has two "branches". In the input, attributes "Acct_ID and "Parent_Acct_ID" link things into a tree. The output will look like
<ORG ...>
<SUBS ...>
<BRAN ...>
</BRAN>
<BRAN ...>
</BRAN>
</SUBS ...>
<SUBS ...>
<BRAN ...>
</BRAN>
<BRAN ...>
</BRAN>
</SUBS ...>
</ORG>

A template that only matches the top of the tree, the Org-level ACCT, processes and nests the appropriate siblings as follows :

<xsl:variable name="currentOR" select="HIERARCHY_Info/@Acct_ID"/>
<xsl:apply-templates  mode="RE" select="../ACCT[HIERARCHY_Info/@Prnt_Acct_ID=$currentOR]"/>	
				
I use the variable, because the following alternative coding returns none of the sibling nodes,  nodes, because (I think) it compares the siblings' parent-acct-IDs to their own acct-IDs: 

<xsl:apply-templates  mode="RE" select="../ACCT[HIERARCHY_Info/@Prnt_Acct_ID=HIERARCHY_Info/@Acct_ID]"/>	

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? 

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.