For-each or recursion in XSLT

O

Oleg Konovalov

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.
 
D

Danny

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

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top