ruhagen
ruhagen

Reputation: 43

XPath. Extract value of attribute from other attribute

Could you please clarify is it possible to extract the value of an attribute by requesting other attribute via XPath?

For Example:

<Attributes>
 <Attribute>
   <Id>5</Id>
   <Value>56757364</Value>
 </Attribute>
</Attributes>

<Attributes>
 <Attribute>
   <Id>6</Id>
   <Value>23372670</Value>
 </Attribute>
</Attributes>

I have to get '23372670' by requesting Id = 6.

And I can't use

//Attributes/Attribute[1]/Value 

because my XML files contains many Attributes with different order of attributes.

Upvotes: 1

Views: 39

Answers (1)

Andersson
Andersson

Reputation: 52665

This one should work:

/Attributes/Attribute[Id=6]/Value

or if you need to preserve Attribute node structure

/Attributes/Attribute/Id[.=6]/following-sibling::Value

Upvotes: 1

Related Questions