In XSLT there isn't any possibility for a "break" out of an <xsl:for-each>
or out of <xsl:apply-templates>
, except using <xsl:message terminate="yes"/>
which you probably don't want. This is due to the fact that XSLT is a functional language and as in any functional language there isn't any concept of "order of execution" -- for example the code can be executing in parallel on all the nodes that are selected.
The solution is to specify in the select
attribute an expression selecting exactly the wanted nodes.
Use:
<xsl:for-each select="/*/*[not(self::item)][1]/preceding-sibling::*">
<!-- Processing here -->
</xsl:for-each>
This selects for processing all preceding elements siblings of the first child element of the top element that isn't item
-- that means the starting group of adjacent item
elements that are the first children of the top element.