transform xml to csv > and then ...?

S

Sharon

Hi y'all,
I have a Delphi dll which generates XML from data in a db. I then use
an XSL to transform and display the data in tabular form. Now what I
want is a link saying 'export table', and make it so that either the
user can save a generated csv or (this would be really great) that
MSExcel is opened, displaying the table. I have already written an XSL
that generates data in CSV format as well as a transform function but
when I save and open this output, all the data appear in one cell.
Does anyone know a better/working solution or have tips on how to do
this? Thanks in advance!

The generated XML looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<?xml:stylesheet type="text/xsl" href="/lib/xtable/xTable.xsl"?>
<general>
<Appname value=""/>
<data>
<literal_xhtml_header>
</literal_xhtml_header>
<global>
<orderby value=""/>
<clientno value="/lib/xtable/css/0.css"/>
<created value="1-11-2004 16:52:32"/>
</global>
<cols>
<fid caption="id" color="" width="200" type="number" visible="True"/>
<fnaam caption="Naam" color="" width="200" type="text"
visible="True"/>
<fachternaam caption="Achternaam" color="" width="200" type="text"
visible="True"/>
<fsoort caption="Soort" color="" width="100" type="text"
visible="True"/>
<fgeboren caption="Geboren" color="" width="150" type="date"
visible="True"/>
<fhuisvesting caption="Huis" color="" width="100" type="text"
visible="True"/>
<ftentakels caption="Tentakels" color="" width="100" type="number"
visible="True"/>
<ftotaal caption="Totaal" color="" width="100" type="number"
visible="True"/>
</cols>
<rows>
<row>
<id value="0"/>
<fid value="0"/>
<fnaam value="Eugene"/>
<fachternaam value="Krabs"/>
<fsoort value="Krab"/>
<fgeboren value="1922-01-08T"/>
<fhuisvesting value=""/>
<ftentakels value="4"/>
<ftotaal value="4"/>
</row>
<row>
<id value="2"/>
<fid value="2"/>
<fnaam value="Patrick"/>
<fachternaam value="Star"/>
<fsoort value="Zeester"/>
<fgeboren value="2002-05-18T"/>
<fhuisvesting value="Steen"/>
<ftentakels value="5"/>
<ftotaal value="5"/>
</row>
<row>
<id value="13"/>
<fid value="13"/>
<fnaam value="Plankton"/>
<fachternaam value=""/>
<fsoort value="Plankton"/>
<fgeboren value="1999-02-22T"/>
<fhuisvesting value="Chumburger"/>
<ftentakels value="6"/>
<ftotaal value="6"/>
</row>
<row>
<id value="4"/>
<fid value="4"/>
<fnaam value="Sandy"/>
<fachternaam value=""/>
<fsoort value="Eekhoorn"/>
<fgeboren value="1985-04-20T"/>
<fhuisvesting value="Stolp"/>
<ftentakels value="5"/>
<ftotaal value="5"/>
</row>
<row>
<id value="5"/>
<fid value="5"/>
<fnaam value="Spongebob"/>
<fachternaam value="Squarepants"/>
<fsoort value="Spons"/>
<fgeboren value="1986-07-14T"/>
<fhuisvesting value="Ananas"/>
<ftentakels value="4"/>
<ftotaal value="4"/>
</row>
</rows>
</data>
<literal_xhtml_footer>
</literal_xhtml_footer>
</general>


The XSL looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput omit-xml-declaration="yes" indent="no" method="text"
version="1.0" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:for-each select="general/data/cols/*[@visible='True']">
<xsl:text>"</xsl:text>
<xsl:value-of select= "@caption" />
<xsl:text>"</xsl:text>
<xsl:if test = "not(position()=last())">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:call-template name="data" />
</xsl:template>

<xsl:template name="data">
<xsl:for-each select="general/data/rows/row">
<xsl:for-each select="*">
<xsl:if test="../../../cols/*[name()=name(current())]/@visible='True'">
<xsl:text>"</xsl:text>
<xsl:value-of select="@value" />
<xsl:text>"</xsl:text>
<xsl:if test = "not(position()=last())">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
 

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,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top