problem with xsl:for-each

M

matatu

Hi to everybody,

It's possible to exit from a cycle for-each?

I have this code:

1: <xsl:for-each select="field">
2: <xsl:variable name="tagfield" select="@tag"/>
3: <xsl:variable name="pos" select="position()"/>
4: <xsl:for-each select="/root/ass/istance">
5: <xsl:choose>
6: <xsl:when test="number($tagfield) != number(tag/@name)">
7: <xsl:call-template name="handle-tilde"/>
8: </xsl:when>
9: <xsl:when test="number($tagfield) = number(tag/@name)">
10: <xsl:apply-templates select="/root/record/fields/field[$pos]"/>
11: </xsl:when>
12: </xsl:choose>
13: </xsl:for-each>
14: <xsl:value-of select="'
'"/>
15: </xsl:for-each>

if the condition to the line 9 are verified it has to jump to the
"field" element following. It's possible?

thanks for the possible answers
 
K

Kenneth Stephen

matatu said:
Hi to everybody,

It's possible to exit from a cycle for-each?

I have this code:

1: <xsl:for-each select="field">
2: <xsl:variable name="tagfield" select="@tag"/>
3: <xsl:variable name="pos" select="position()"/>
4: <xsl:for-each select="/root/ass/istance">
5: <xsl:choose>
6: <xsl:when test="number($tagfield) != number(tag/@name)">
7: <xsl:call-template name="handle-tilde"/>
8: </xsl:when>
9: <xsl:when test="number($tagfield) = number(tag/@name)">
10: <xsl:apply-templates select="/root/record/fields/field[$pos]"/>
11: </xsl:when>
12: </xsl:choose>
13: </xsl:for-each>
14: <xsl:value-of select="'
'"/>
15: </xsl:for-each>

if the condition to the line 9 are verified it has to jump to the
"field" element following. It's possible?
Hi,

Disclaimer : I have not executed the following. Try this :

<xsl:for-each select="field">
<xsl:variable name="tagfield" select="@tag" />
<xsl:variable name="pos" select="position()" />

<xsl:for-each select="/root/ass/istance[number($tagfield) !=
number(tag/@name)]">
<xsl:call-template name="handle-tilde" />
</xsl:for-each>

<xsl:value-of select="'
'" />

<xsl:for-each select="/root/ass/istance[number($tagfield) =
number(tag/@name)]">
<xsl:apply-template select="/root/record/fields/field[$pos]" />
</xsl:for-each>
</xsl:for-each>

This is not equivalent in processing to what you want if your input
/root/ass/istance elements need to be processed in document order. If
not, then the logic should work.

Regards,
Kenneth
 
J

Joris Gillis

Is it possible to exit from a cycle for-each?

I don't think that possible.

But this template should mimic the behaviour you want:

<xsl:for-each select="field">
<xsl:variable name="tagfield" select="number(@tag)"/>
<xsl:variable name="pos" select="position()"/>
<xsl:for-each select="/root/ass/istance[not($tagfield=
preceding-sibling::istance/tag/@name|tag/@name)]">
<xsl:call-template name="handle-tilde"/>
</xsl:for-each>
<xsl:choose>
<xsl:when
test="count(/root/ass/istance[$tagfield = number(tag/@name)])
&gt; 0">
<xsl:apply-templates select="/root/record/fields/field[$pos]"/>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="'
'"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:for-each>


Joris Gillis
 

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

No members online now.

Forum statistics

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

Latest Threads

Top