Re: [xsl] For-each loop or recursion

Subject: Re: [xsl] For-each loop or recursion
From: Oleg Konovalov <olegkon@xxxxxxxxx>
Date: Mon, 16 May 2005 08:30:10 -0400
> > I need to compare current and next values of the node var2 [and var3]
> > and find the first occurrence when var2[position()] = var2[next, i.e.
> > position()+1]
> > Are you saying that is impossible to do in XSLT ?
>
> It's almost certainly possible to do what you want but your decription
> is pretty hard to follow. You need to describe the transformation that
> you want to do not just use bits of XPath and hope that we understand
> what you want.  Xpath's position() function for example does not relate
> to the position of a node within a tree (a node can have any number of
> values returned buy position(), depending on how the node is
> selected). I'm _guessing_ that what you want to know is the sibling order
> of the node in the input tree in which case you might want
> following-sibling::*[1] but that is just a guess.

OK, lets try to get a position of the first occurrence when var2 = max node.
As I said, I don't want to change the order of the nodes in a tree with sort.
What would be a correct syntax ?

<xsl:for-each select=mystruct/myarray1[1]/myvar>
  <xsl:if var2=*[last()]>
    <xsl:value-of select="position()">
  </xsl:if>
</xsl:for-each>

The goal is to trim the table [see my previous post],
get rid of multiple identical occurrences of rebate1 & rebate2.

Do you understand me ?

Thank you,
Oleg.



>
>   I want from inside for-each loop mystruct/myarray1[i]/myvar
>   [or does it require recursion?]
>   compare the values is the parallel branch,
>   of parallel "current" node ../../myarray2[i]/myvar/var3 and its "next
node".
>   Again, where:
>   mystruct/myarray1[i]/myvar/var2 and
>   mystruct/myarray2[i]/myvar/var3
>
> Again you are just typing in syntactically correct XPath and asking "can
> I do that" since the Xpath you typed above is syntactically correct then
> clearly you can do that, but I have no idea if that will do what you
> want, as you've not said what you are trying to do. For example do your
> elements with name myarray1 have child elements with name i ? If they do
> not, then the above XPath's will select nothing.
>
> > Is there an easy way to find out the max value of the node (child
elements)
> > without sorting it ?
> > The sequence of nodes I am dealing with is supposed to be in increasing
order,
>
> If you know it's already sorted, just take the last
> select="*[last()]"
> or in your case take the last of each then you only have two itemsto
> compare which you can do with &gt; to work out the overall maximum.
>
>
> David
>
> ________________________________________________________________________
> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> ________________________________________________________________________

Current Thread