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"><![CDAT A[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"
<?xml version="1.0" encoding="utf-8"?>
<results>
<result id="1">
<attribute name="name"><![CDATA[The Name]]></attribute>
<attribute name="translation"><![CDAT
</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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
welcome
ASKER