Link to home
Start Free TrialLog in
Avatar of Garve
Garve

asked on

Transform XML using XSL, write element with a specific attribute value

Real beginner question. I have this XML file.

<?xml version="1.0" encoding="utf-8"?>
<results>
<result id="1">
<attribute name="name"><![CDATA[The Name]]></attribute>
<attribute name="translation"><![CDATA[The Translation]]></attribute>
</result>
</results>

It's not my XML and I can't do anything about the structure

The following XSL outputs "The Name"

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
      <xsl:for-each select="/results/result">
              <xsl:value-of select="attribute" />
      </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Instead, I want to output the value of the 2nd item named attribute - ie my output should be "The Translation"
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Garve
Garve

ASKER

Brilliant! Thanks very much.