[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: Michael Kay <mike@xxxxxxxxxxxx>
Date: Mon, 21 Feb 2011 23:27:11 +0000
Re:  Newbie wonders why the variable can change value?
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]"/>


Brandon has given you an excellent explanation of how variables in XSLT work. But I suspect that might only part of your difficulty here. The essential reason the two examples above give different results is that the expression HEIREARCHY/@Acct_ID is evaluated in a different context in the two cases. Inside a predicate (i.e. in square brackets) a relative path expression is evaluated relative to the node you are testing - in this case, the ACCT element.


Michael Kay
Saxonica

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.