We are using XPath in a Java app and I was wondering: How do I select a set of nodes where the “terminating point” is a node not belonging to the same kind as it’s siblings.
For example, I want to get two sets of <a> tags of size 3 and 2 from the example below:
<sample>
<a />
<a />
<a />
<terminating />
<a />
<a />
</sample>
First of all, the result of an XPath expression is always either an atomic value, or a single node-set (or sequence in XPath 2.0). You cannot get a list of node-sets.
That said, for your specific example with just two groups and one terminator, you can just use
preceding-siblingandfollowing-sibling: