Xpath: Select only non-nested pre tags
Can anyone help me with a xpath selector to select all the pre
tags with开发者_JAVA技巧in a page, but only if they are not within another pre
tag? (even if multiple levels deep)
It would be awesome if this could all be done within one selector, rather than just selecting all pre
tags and breaking if they have pre
as a parent.
Like this? //pre[not(ancestor::pre)]
Or for completeness, in XPath 2.0
//pre except //pre//pre
Try:
//pre[not(ancestor::pre)]
精彩评论