How-to break a for-each loop in XSLT?
Put the condition for stopping the "loop" in the select attribute of the for-each element. For instance, to "break" after four elements:
select
for-each
To iterate up to but not including a node that satisfied some particular condition: