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>
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With