开发者

XPath query : select only node with unique child

开发者 https://www.devze.com 2023-02-15 21:02 出处:网络
I wish to select al开发者_StackOverflow社区l <span> that have only <br> as children :

I wish to select al开发者_StackOverflow社区l <span> that have only <br> as children :

<html>
..
<span>
...
</span>
<span>     <!-- I want those ones -->
  <br/>
</span>

How would I select these elements?


Assuming you mean elements with no children except br elements, where br is mandatory:

/html/span
    [br and not(
        *[not(self::br)]
    )]

Meaning: All span elements which have at least one br child and no other elements as children.

0

精彩评论

暂无评论...
验证码 换一张
取 消