For-each or recursion in XSLT

Discussion in 'Java' started by Oleg Konovalov, May 14, 2005.

  1. Hi,

    I am new to XSLT, modifying somebody else's code:

    I have the following data (leaves in parallel branches):
    mystruct/myarray1/myvar/var2 and
    mystruct/myarray2/myvar/var3

    I need to implement the find the first occurence of :
    <xsl:if test="position() != last() and
    number(var2) = number(var2[position()+1]) and
    number(var3) = number(var3[position()+1])">
    <value-of select="position()">
    </xsl:if>

    A few questions to XSLT gurus:
    1) Does it make sense to do in the for-each loop or it will require a
    recursion ?
    All I need is to get the position of the 1st occurrence.
    How would that recursion look like?

    2) Will I be able to get a node from the parallel branch in for-each loop ?
    Something like:
    <xsl:for-each mystruct/myarray1/myvar>
    <xsl:if test=" ...and number(../../myarray2/myvar/var3) =
    number((../../myarray2/myvar/var3)[position()+1]) and...">
    <value-of select="position()">
    </xsl:if>
    </xsl:for-each>)
    I know it looks awful :-(

    3) Is there a way to somehow start the for-each loop
    from position other than 1 ?
    Like with j>1:
    <xsl:for-each mystruct/myarray1/myvar[j]>
    .....
    </xsl:for-each>

    I am using XSLT 1.x

    Thank you in advance,
    Oleg.
    Oleg Konovalov, May 14, 2005
    #1
    1. Advertising

  2. Oleg Konovalov

    Danny Guest

    I don't think you've worded your query well and concise enough, all I can
    tell is that you want to iterate some nodes using XSL but not using the
    1st node in the as the starting point or so.

    Danny

    On Fri, 13 May 2005 20:06:58 -0700, Oleg Konovalov <>
    wrote:

    > Hi,
    >
    > I am new to XSLT, modifying somebody else's code:
    >
    > I have the following data (leaves in parallel branches):
    > mystruct/myarray1/myvar/var2 and
    > mystruct/myarray2/myvar/var3
    >
    > I need to implement the find the first occurence of :
    > <xsl:if test="position() != last() and
    > number(var2) = number(var2[position()+1]) and
    > number(var3) = number(var3[position()+1])">
    > <value-of select="position()">
    > </xsl:if>
    >
    > A few questions to XSLT gurus:
    > 1) Does it make sense to do in the for-each loop or it will require a
    > recursion ?
    > All I need is to get the position of the 1st occurrence.
    > How would that recursion look like?
    >
    > 2) Will I be able to get a node from the parallel branch in for-each
    > loop ?
    > Something like:
    > <xsl:for-each mystruct/myarray1/myvar>
    > <xsl:if test=" ...and number(../../myarray2/myvar/var3) =
    > number((../../myarray2/myvar/var3)[position()+1]) and...">
    > <value-of select="position()">
    > </xsl:if>
    > </xsl:for-each>)
    > I know it looks awful :-(
    >
    > 3) Is there a way to somehow start the for-each loop
    > from position other than 1 ?
    > Like with j>1:
    > <xsl:for-each mystruct/myarray1/myvar[j]>
    > ....
    > </xsl:for-each>
    >
    > I am using XSLT 1.x
    >
    > Thank you in advance,
    > Oleg.
    >
    >




    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
    Danny, Jun 4, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Blair
    Replies:
    1
    Views:
    397
    Eliyahu Goldin
    Aug 3, 2005
  2. Leo Kirch

    XSLT recursion with signals

    Leo Kirch, Oct 27, 2003, in forum: XML
    Replies:
    1
    Views:
    377
    Dimitre Novatchev
    Oct 28, 2003
  3. Oleg Konovalov

    For-each or recursion in XSLT

    Oleg Konovalov, May 14, 2005, in forum: XML
    Replies:
    1
    Views:
    995
    Danny
    Jun 4, 2005
  4. shaun roe
    Replies:
    3
    Views:
    922
    Dimitre Novatchev
    Sep 28, 2005
  5. Replies:
    8
    Views:
    718
    John Reye
    Apr 26, 2012
Loading...

Share This Page