XPath for all nested text except the text "n" nested tags
I have the following html.
<div id="content"> <h3>Title</h3> <p>Some stuff</p> <p>other stuff</p> <p>other other stuff</p> <p>unnecessary stuff</p> <p>other unnecessary stuff</p> </div> I have written this expression so far.
//div[@id="content"]//text() Which works, but I want not to extract text from the last 2 <p> elements, because this is not necessary. I tried to write this ...
//div[@id="content"]/p[not(position() > last() - 2)]//text() Which does not work properly. Then I tried this ...
//div[@id="content"]/[not(self::p[position() > last() - 2])]//text() Which didn't work either.