Reputation: 9
XML example
<item>
<name>AW</name>
<name>Car</name>
</item>
XSLT Code
<xsl:if test="item/name='AW'">
<xsl:value-of select="item[name='AW']/[name='Car']"/>
</xsl:if>
My problem is how to choose the value in the second attribute name if the value is not known
For example
<item>
<name>AW</name>
<name>Unknown</name>
</item>
<item>
<name>BW</name>
<name>Unknown</name>
</item>
Upvotes: 0
Views: 542
Reputation: 117165
There are no attributes in your XML. Both item
and name
are elements.
If you have multiple item
elements, each containing 2 (or more) name
elements, and you want to return the string-value of the 2nd name
element from the item
element where the 1st name
element contains the string "AW"
, you could use simply:
<xsl:value-of select="item[name[1]='AW']/name[2]"/>
Demo: https://xsltfiddle.liberty-development.net/jxNakAc
Upvotes: 1