Andrew,
It's your xsl:for-each loop that is causing it to grab only the direct
children of Account, and not the children of the children. Probably would be
better to just make a massive, recursive template.
And, since XML-to-CSV falls in the realm of xmlLinguist, I'm also going to
suggest taking a look that product at http://www.xmllinguist.com . Mainly
depends on your production environments (i.e. will this be run on Windows or
not), xmlLinguist would solve your problem in a snap. It's a simple-to-use,
bi-directional Text-to-XML translator that supports hierarchical structures,
such as the Name nested beneath Account. Download the trial, see if it's a
match or not for you.
HTH,
Bryce K. Nielsen
SysOnyx, Inc. (www.sysonyx.com)
Makers of xmlLinguist, the Text-to-XML Translator
http://www.sysonyx.com/products/xmllinguist
----- Original Message -----
From: <ashushujev(_at_)pixelimp(_dot_)com>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Thursday, July 29, 2004 2:08 AM
Subject: [xsl] XML To CSV
Hi,
I have an XML stream that I would like to convert to CSV file thru XSL
transformation. I use the following stylesheet, but the problem is it
only selects top elements within an 'Account' node and does not process
elements for 'Name' element.
Stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="//Account[1]"/>
</xsl:template>
<xsl:template match="Account">
<xsl:for-each select="*"><xsl:value-of select="."/><xsl:if test="last()
position()">,</xsl:if></xsl:for-each><xsl:text></xsl:text>
</xsl:template>
</xsl:stylesheet>
XML:
<?xml version="1.0"?>
<Data>
<Account>
<AccountNumber>1000748</AccountNumber>
<SequenceNo>1</SequenceNo>
<AccountBalance>1052.35</AccountBalance>
<Name>
<CitizenNameTitle>Mr</CitizenNameTitle>
<CitizenNameForename>Joe</CitizenNameForename>
<CitizenNameSurname>Bloggs</CitizenNameSurname>
</Name>
</Account>
</Data>
Output:
1000748,1,1052.35,MrJoeBloggs
I would appreciate any help in this matter.
Andrew
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--