dlofrodloh
dlofrodloh

Reputation: 1744

How to get the attribute of a child element based on the attribute of the parent element

Let's say I have this XML:

<data>
  <options mode="Any Value"  currentValue="0">
     <option value="0" alias="No Donation"/>
  </options>
</data>

In XSL, how could I write:

<xsl:value-of select="data/options/option[@value=XXX]/@alias"/>

where XXX equals the value of the "currentValue" attribute of it's parent element? :

<xsl:value-of select="data/options/@currentValue"/>

I basically want to merge these two statements into one by replacing the XXX in the first one with the result of the second statement but I'm not sure how to integrate them.

Upvotes: 0

Views: 34

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122364

You can use .. in the predicate to navigate up to the parent element of the option you're testing:

<xsl:value-of select="data/options/option[@value=../@currentValue]/@alias"/>

Upvotes: 1

Related Questions