Reputation: 1651
I am trying to come up with an XPath to the following XML:
<A>
<Target attr1="foo" attr2="bar"/>
<B>
<Target attr1="forest" attr2="gump"/>
<C>
<Target attr1="foo" attr2="aDifferentKindOfBar"/>
</C>
<C/>
</B>
</A>
It should give me the value of attribute named "attr2" for all elements Target that have an attribute "attr1" with value "foo".
So in my example I would like to get "bar" and "aDifferentKindOfBar" but not "gump".
I came as far as:
//Target[@attr1='foo']
But I can't figure out how to get the navigation to the attribute "attr2".
Upvotes: 1
Views: 42
Reputation: 241738
Just add the next step to the path:
//Target[@attr1='foo']/@attr2
Upvotes: 3