'Same XPath Node returns different result
Imagine I got the following simple .xml file
<a>
<b>
<c>
<n id = "1"/>
</c>
<n id = "2"/>
<n id = "3"/>
</b>
</a>
and the following to queries and their respective result:
"//n[preceding::n]/@id" result = 2 3
"//n[preceding::n and following-sibling::n]/@id" result = 2
To me, both queries "stop" at the same node, which is <n id = "2"/> , because it is the first node called n, which has a preceding::n (a preceding node called an) and is also the first node called n, with a preceding::n (a preceding node called n) a following-sibling::n (a following sibling called n)
So why do I get different results?
Solution 1:[1]
preceding::n refers to any node in the structure
preceding Indicates all the nodes that precede the context node in the document except any ancestor, attribute and namespace nodes.
This one would get same results
xmllint --xpath '//n[preceding-sibling::n or following-sibling::n]/@id' test.xml
id="2" id="3"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | LMC |
