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

后端 未结 6 1945
死守一世寂寞
死守一世寂寞 2020-12-03 13:52

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

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 14:42

    XSLT isn't a procedural language; don't think of for-each as being a "loop" in the way you have a loop in Java. For-each is a way to apply a template to each of a bunch of items. It doesn't necessarily happen in a particular order, so you can't think of it as "apply this template to each of a bunch of items until such-and-such happens, then stop".

    That said, you can use the select attribute to filter the results, so it becomes more like "apply a template to each of a bunch of items, but only if such-and-such is true of them".

    If what you really want is "apply a template to each of a bunch of items, where such-and-such is true of them, but only to the first one this is true of", you can combine the select attribute with the position() function.

提交回复
热议问题