this is a follow-up question of my previous thread:
Please help me on understanding this XPath
I have an XPath as:
All answers with the exception of @Alejandro 's have the same common fault:
It is not true that:
preceding-sibling::*
selects all preceding-sibling nodes.
It only selects all preceding-sibling elements.
To select all preceding-sibling nodes use:
preceding-sibling::node()
There are these kind of nodes in XPath:
The root node (denoted as /
), also denoted as document-node()
in XPath 2.0
Text nodes. In Hello
the text node is the only child of a
and has a string value of " Hello "
Comment nodes.
Processing instruction nodes.
Namespace nodes.
a
has a namespace node with value "my:namespace" and name (prefix) my
Nodes of the first 5 kinds can be selected using the preceding-sibling::
axis:
preceding-sibling::node()
selects all sibling nodes of kind 1 to 5.
preceding-sibling::*
selects all element preceding siblings
preceding-sibling::someName
selects all elemens named "someName" preceding siblings
preceding-sibling::text()
selects all text nodes preceding siblings (useful in mixed content)
preceding-sibling::comment()
selects all comment node preceding siblings.
preceding-sibling::processing-instruction()
selects all preceding siblings that are PIs
preceding-sibling::processing-instruction('someName')
selects all preceding siblings that are PIs and are named "someName".