RE: [xsl] Transforming XML to CSV

Subject: RE: [xsl] Transforming XML to CSV
From: "KIENLE, STEVEN C [IT/0200]" <steven.c.kienle@xxxxxxxxxxxxx>
Date: Tue, 15 Oct 2002 08:05:33 -0500
The following transform will do what you want:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
<xsl:output method="text"/>

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

<xsl:template match="root">
	<xsl:apply-templates select="row" />

<xsl:template match="row">
	<xsl:apply-templates select="column" />

<xsl:template match="column">
	<xsl:value-of select="."/>
	<xsl:if test="position() != last()">


This assumes the document root in <root>.

The main thing here is the use of the text output method, along with the
&#xA; (New line) character.  The xsl:if is used to determine if a comma is
needed after a column.

I hope this helps,

-----Original Message-----
From: Ryan.Asleson@xxxxxxxxxx [mailto:Ryan.Asleson@xxxxxxxxxx]
Sent: Tuesday, October 15, 2002 8:31 AM
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Transforming XML to CSV


I wish to transform XML which looks like this:

      <column>Value 1</column>
      <column>Value 2</column>
      <column>Value 3</column>
      <column>Value 4</column>
      <column>Value 5</column>
      <column>Value 6</column>

Into a comma separated values (CSV) format looking like this:

"Value 1","Value 2", "Value 3"
"Value 4","Value 5", "Value 6"

so it can be read in a spreadsheet program.  What XSL will do this?  I'm
having trouble because the result is not a hierarchical result.


 XSL-List info and archive:

 XSL-List info and archive:

Current Thread