Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XSLT Display Label Name 1 42
PHP Soap Server returning XML but < & > as &lt; / &gt; 9 133
I'm using XML(xslt) - How to fix the BOM issue 5 31
Problem to copy file 14 92
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

752 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