Solved

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

Posted on 2009-05-15
3
510 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
  • 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
File names with & character 6 59
RSS Feed Enclosure URL 1 66
AngularJS directive issue 6 54
XSL-FO - show results in 2 columns 5 24
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now