Reputation: 533
I need to get the text but only before the certain text ('---------------'). E.g. example of HTML code:
...
<p> This is correct text. Everything after it is wrong</p>
<p>---------------------</p>
<p><strong>This is wrong text</strong></p>
<p> This is wrong another text</p>
...
I'm trying to solve this with the next XPath expression:
/p/text()[normalize-space()][not(ancestor::p[contains(.,'---')])]
But unfortunately this doesn't work as expected.
Would be appreciate for the correct solution.
Upvotes: 1
Views: 70
Reputation: 111491
This XPath will select the text of a p
whose immediately following sibling contains ---
:
//p[following-sibling::p[contains(.,'---')]][1]/text()
Upvotes: 2