I'd like preceding-sibling-or-self
functionality in my xpath and I'm using ../(self::*|preceding-sibling::*)
and it's giving me Expression must evaluate to a node-set.
, so I must be doing it wrong.
This bombs no matter what context node you are on or what the xml looks like. I want to use this functionality after a /
so I need the right syntax for that.
The xpath expression (self::*|preceding-sibling::*)
does not give an error, so it has to do with the place in the xpath which I'm trying to use it.
EDIT:
My mistake is actually more basic. You can't even do ../(.|.)
without that error. In general, I want to go to a node, then look through a set of nodes from there. The error seems to correlate with trying to use the union operator |
after a slash /
.
The preceding axis selects all nodes that come before the current node in the document, except ancestor, attribute nodes, and namespace nodes. Let us consider the login button as current node on the Facebook web page as shown below screenshot. Let's first, find the XPath of current node i.e XPath of login button.
XPath using Preceding-Sibling 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.
In XPath, if you want to use the union operator, you must use it at the beginning of the path.
(self::*|preceding-sibling::*)/Child
is ok.
If you need to do Something/(self::*|preceding-sibling::*)/Child
, you have to expand the left part out like this:
(Something/self::*|Something/preceding-sibling::*)/Child
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