xsl-list
[Top] [All Lists]

Re: [xsl] Newbie wonders why the variable can change value?

2011-02-21 17:27:20

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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>