How-to break a for-each loop in XSLT?

XSLT is written in a very functional style, and in this style there is no equivalent of a break statement. What you can do is something like this:

<xsl:for-each select="...nodes...">
    <xsl:if test="...some condition...">
        ...body of loop...
    </xsl:if>
</xsl:for-each>

That way the for-each will still iterate through all the nodes, but the body of the loop will only be executed if the condition is true.

Leave a Comment