[
Lists Home |
Date Index |
Thread Index
]
At 2004-04-07 15:59 -0700, Jerry Lake wrote:
>I'm still working on my xslt. Can someone give me an example or point me
>in the right direction to convert my XML to CSV
You don't say where you are having problems so it is difficult to advise.
A simple example is below ... it would need to be beefed up to accommodate
escaping of characters following CSV conventions, but it should give you
the flavour of what you need. You don't give an example of your data
either, so I have no idea how applicable the structure is to your work.
I hope this helps.
.................... Ken
T:\ftemp>type jerry.xml
<records>
<record>
<field1>abc</field1><field2>def</field2>
</record>
<record>
<field1>abc</field1><field2>def</field2>
</record>
<record>
<field1>abc</field1><field2>def</field2>
</record>
<record>
<field1>abc</field1><field2>def</field2>
</record>
</records>
T:\ftemp>type jerry.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="records">
<xsl:for-each select="record">
<xsl:apply-templates select="*"/>
<xsl:text><!--new line at the end of the information-->
</xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template match="*"><!--put out element content in quotes-->
<xsl:if test="position()>1">,</xsl:if><!--more than one being processed-->
<xsl:text/>"<xsl:apply-templates/>"<xsl:text/>
</xsl:template>
</xsl:stylesheet>
T:\ftemp>saxon jerry.xml jerry.xsl
"abc","def"
"abc","def"
"abc","def"
"abc","def"
T:\ftemp>
--
Public courses: Spring 2004 world tour of hands-on XSL instruction
Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO
Hong Kong May 17-21; Bremen Germany May 24-28; Helsinki June 14-18
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/x/bc
|