Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to do a continue in an xslt for-each

Tags:

xml

xslt

How to do a continue in an xslt for-each (not exiting the for-each, but rather continue the for-each?

Like:

<xsl:for-each select="asd">

    <xsl:if test="$test1">
        <!--some stuff-->
        <xsl:if test="$test1A">
            <!--CONTINUE()-->
        </xsl:if>
    </xsl:if>

    <xsl:if test="$test2">
        <!--some stuff-->
        <!--CONTINUE()-->
    </xsl:if>

    <!--main stuff-->
</xsl:for-each>
like image 309
jaytufch Avatar asked Jul 12 '11 04:07

jaytufch


2 Answers

In this specific case, seems you want possibly execute both codes according to a condition. In fact you want to continue from the first if only if $test1A is true.

In this case xsl:choose does not help you. You have to work with pure logic and emulate the wanted behavior:

<xsl:for-each select="asd">
    <xsl:if test="$test1">
        <!--some stuff-->
        <xsl:if test="$test1A">
            <!--CONTINUE()-->
        </xsl:if>
    </xsl:if>
    <xsl:if test="$test2 and not($test1A)">
        <!--some stuff-->
        <!--CONTINUE()-->
    </xsl:if>
    <!--main stuff-->
</xsl:for-each>

Use conditions as above, you will execute the second if only if the nested if in the first branch is false.

like image 80
Emiliano Poggi Avatar answered Sep 23 '22 08:09

Emiliano Poggi


Think you need xml:choose and xml:when. xsl:choose element selects one among a number of possible alternatives. So when expression is evaluate to true, it execute that block and then goes to the next loop.

like image 20
Jasonw Avatar answered Sep 22 '22 08:09

Jasonw