Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xpath return all non-blank text nodes not descendant of `a`, `style` or `script`

Tags:

xpath

What expression would select all text nodes which are:

  • not blank
  • not inside a, or script or style?
like image 418
Majid Fouladpour Avatar asked Dec 07 '10 15:12

Majid Fouladpour


1 Answers

Use:

//*[not(self::a or self::script or self::style)]/text()[normalize-space()]

Not only is this expression shorter than the one in the currently accepted answer, but it also may be much more efficient.

Do note that the expression doesnt use any (back/up)-ward axes at all.

like image 160
Dimitre Novatchev Avatar answered Sep 20 '22 13:09

Dimitre Novatchev