开发者

XPath query : select only node with unique child

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜