Solved

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

Posted on 2009-05-15
3
519 Views
Last Modified: 2013-11-18
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"
0
Comment
Question by:Garve
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 125 total points
ID: 24399298
           <xsl:value-of select="attribute[@name = 'translation']" />
if you need the selection to be based on the value of the attribute

or
           <xsl:value-of select="attribute[2]" />
if you simply need the second
0
 
LVL 7

Author Closing Comment

by:Garve
ID: 31582082
Brilliant! Thanks very much.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24399484
welcome
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question