开发者

XPath to find an element with a similar sibling

开发者 https://www.devze.com 2023-01-04 03:15 出处:网络
Suppose I have this XML: <x> <e a=\'1\' b=\'A\'/> <e a=\'1\' b=\'B\'/> <e a=\'1\' b=\'A\'/>

Suppose I have this XML:

<x>
    <e a='1' b='A'/>
    <e a='1' b='B'/>
    <e a='1' b='A'/>
</x>

I'd like to write an xpath to find any elements e which:

  1. Have attribute @b = 'A'
  2. Have the same value for attribute @a

The xpath can't reference the literal value of attribute @a, however. It can reference t开发者_运维百科he literal value of attribute @b.

Or more generally, I want to find if there are any instances where there are two or more elements e[@b=A'] with the same value for attribute @a.

Is this possible?


I solved my problem with the following xpath:

//e[b='A' and @a=following-sibling::e[b='A']/@a]

0

精彩评论

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