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

后端 未结 3 1451
梦毁少年i
梦毁少年i 2020-12-06 10:07

What expression would select all text nodes which are:

  • not blank
  • not inside a, or script o
3条回答
  •  猫巷女王i
    2020-12-06 10:41

    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.

提交回复
热议问题