MadManMoon
MadManMoon

Reputation: 85

XPath: get the element with same tag but different attribuite

I've something like:

<a>
 <b>
  <c>
    <d name='pa'/>
    <d name='pb'/>
   </c>
 </b>
</a>
<a>
 <b>
  <c>
    <d name='pc'/>
    <d name='pb'/>
   </c>
 </b>
</a>

with xpath how can I retrieve the element parent a which has both attribute name=pa and name=pc of tag d?

I tried with this one but it doesnt work:

(/a/b/c/d[@name='pa']) and (/a/b/c/d[@name='pc'])

but it just outputs Boolean='true'

Upvotes: 2

Views: 913

Answers (1)

Andersson
Andersson

Reputation: 52665

Try to use

//a[.//d[@name="pa"] and .//d[@name="pb"]]

which should return your desired output

Upvotes: 1

Related Questions