How to do this in XSLT

S

Sandy

Hi,

I have following XML. I want to write an XSL file which can take the first
and second <NAME> elements and put them in the output (which is a csv file
as shown below).
But i am not able to find how to do this using XSLT transformations.

Any help is greatly appreciated.

Input XML file
<?xml version="1.0"?>
<?xml-stylesheet type="text/xml" href="test.xsl"?>
<LIST>
<NAME>
<FIRST>first1</FIRST>
<LAST>last1</LAST>
</NAME>
<NAME>
<FIRST>first2</FIRST>
<LAST>last2</LAST>
</NAME>
<NAME>
<FIRST>first3</FIRST>
<LAST>last3</LAST>
</NAME>
<NAME>
<FIRST>first4</FIRST>
<LAST>last4</LAST>
</NAME>
................
..................... (n number of NAME's)
</LIST>

*****************************************************************
Output

first1,Last1
first2,last2
 
J

JAPISoft

Hi Sandy,

Here a sample, please use an editor for checking the syntax, it is
written without one :

....

<xsl:eek:utput method="text"/>

<xsl:template match="LIST">
<xsl:apply-templates select="NAME"/>
</xsl:template>

<xsl:template match="NAME">
<xsl:value-of select="FIRST"/>,<xsl:value-of select="LAST"/>
</xsl:template>

Best regards,

A.Brillant
Editix - XML Editor and XSLT Debugger
http://www.editix.com
 
M

Matt Sannes

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="text" />
<xsl:template match="*">
<apply-templates/>
</xsl:template>

<xsl:template match="LIST">
<xsl:for-each select="NAME">
<xsl:value-of select="FIRST"/>,<xsl:value-of
select="LAST"/><xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Matthew Sannes
Docsoft .NET Developer

Try our new Enterprise Search Engine geared towards XML repositories.
Go to www.whatthexml.com for info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top