I have a quite simple problem but i can't seem to resolve it. Let's say i have the following code:
<a> <b property="p1">zyx</b> <b>wvu</b> <b>tsr</b> <b property="p2">qpo</b> <b>qcs</b> </a>
I want to select the nodes between the b
node who has a property="p1"
and the b
node who has property="p2"
. I can do either of those with the preceding-sibling and the following-sibling axis but I can't seem to find how to combine both.
This is a concept very similar to Following-Siblings. The only difference in functionality is that of preceding. So, here, in contrast to Following-Sibling, you get all the nodes that are siblings or at the same level but are before your current node.
The following-sibling and preceding-sibling axes contain the siblings before or after the context node, and the following and preceding axes contain all nodes in the document before or after the context node, but: None of these axes contain attribute or namespace nodes.
The following-sibling axis indicates all the nodes that have the same parent as the context node and appear after the context node in the source document.
XPath 1.0:
/a/b[preceding-sibling::b/@property='p1' and following-sibling::b/@property='p2']
XPath 2.0:
The expression above has some quirks in XSLT 2.0, it is better to use the new and safer operators <<
(before) and >>
(after).
/a/b[../b[@property='p2'] << . and . >> ../b[@property='p1']]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With