Reputation: 4346
I want to select the previous node only if it is a text node (and contains only whitespace). I have an XPath like so: path/preceding-sibling::node()[1][normalize-space()='']
. This works great but matches both text and element nodes (if the nodes contain only whitespace). Using path/preceding-sibling::text()[1][normalize-space()='']
will select the first preceding node that is a text node which is definitely not what I want if there are any elements in between.
How can I combine the two tests?
Upvotes: 1
Views: 196
Reputation: 89315
You can use self::text()
to test if current node
is a text node, like so :
path/preceding-sibling::node()[1][self::text() and normalize-space()='']
Upvotes: 1