Reputation:
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>
Upvotes: 0
Views: 985
Reputation: 338316
Extending on Pavel Minaev's answer - I would write a loop, like this ("i
" being the loop index):
<terminating>
nodes with the help of/sample/terminating
./preceding-sibling::a[count(preceding-sibling::terminating) = {i}]
<terminating>
node, also find the./following-sibling::a
Upvotes: 0
Reputation: 101615
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-sibling
and following-sibling
:
/sample/terminating/preceding-sibling::a
/sample/terminating/following-sibling::a
Upvotes: 1