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

后端 未结 3 1446
梦毁少年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条回答
  •  隐瞒了意图╮
    2020-12-06 10:46

    I used Dimitre Novatchev's answer, but then i stumbled upon the problem described by the topic starter:

    not descendant of a, style or script

    Dimitre's answer excludes style tag but includes its children. This version excludes also style, script, noscript tags and their descendants:

    //div[@id='???']//*[not(ancestor-or-self::script or ancestor-or-self::noscript or ancestor-or-self::style)]/text()
    

    Anyway, thanks to Dimitre Novatchev.

提交回复
热议问题