//br/preceding-sibling::normalize-space(text())
i am getting invalid xpath expression with nokogiri
normalize-space is a function. You can't use it there.
You need a node-set.
maybe you mean
//br/preceding-sibling::*
or you could use normalize-space in a predicate, inside square brackets. Think of the predicate as a filter or selector on the node-set. So you can do this:
//br/preceding-sibling::*[normalize-space()='Fred']
In English that translates to "all elements preceding <br>
in the document, and for which the (normalized) text is 'Fred' ". In this document:
<html>
<p>
<h2>Fred</h2>
<br/>
</p>
<table>
<tr>
<td>
<br/>
</td>
</tr>
</table>
</html>
...the xpath expression selects the <h2>
node.
I figured this out with the free XpathVisualizer tool available on codeplex.
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