Re: [xsl] For each with parallel nodelist

Subject: Re: [xsl] For each with parallel nodelist
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 31 Aug 2006 17:33:19 +0100
<xsl:for-each
select="/CommandList/CheckRouting/RouterList/Router[Complete='true']/GroupLi
st/Group/OutwardList/Outward" >
<xsl:variable name="root"
select="/CommandList/CheckRouting/RouterList/Router[Complete='true']/GroupLi
st/Group/ReturnList/Return" />


the variable here does not depend on the current node set up by the
for-each so $root will have the same value on every iteration. If you
are lucky your processor's optimiser willl re-write teh expression to
take the constant subterm out of the loop and write it as

<xsl:variable name="root"
select="/CommandList/CheckRouting/RouterList/Router[Complete='true']/
GroupList/Group/ReturnList/Return" />

<xsl:for-each
select="/CommandList/CheckRouting/RouterList/Router[Complete='true']/
GroupList/Group/OutwardList/Outward" > 

again this clause will have the same value at each iteration.
<xsl:otherwise>
<xsl:value-of select="//Group/Price/Amount/text()"/>


> The problem is <xsl:value-of select="number($root/Price/Amount)"/>
> Return the same results...

It's cleay why $root has teh same value at each iteration, but as you
haven't shown your input form or what you intend to calculate it's a bit
hard to suggest what changes to make.

Perhaps you want
<xsl:for-each
select="/CommandList/CheckRouting/RouterList/Router[Complete='true']/
GroupList/Group/OutwardList/Outward" > 
<xsl:variable name="root" select="../../ReturnList/Return" />

and I suspect that you want that otherwise clause to also depend on the
current node, something like
<xsl:otherwise>
<xsl:value-of select="../../Price/Amount"/>

It may be simpler to for-each over just Groups

<xsl:for-each
select="/CommandList/CheckRouting/RouterList/Router[Complete='true']/
GroupList/Group">
<xsl:variable name="root" select="ReturnList/Return" />

etc but without knowing what transformation you intend it's hard to say.

David

Current Thread