Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


transform xml to csv > and then ...?

From: esdeees@-------.--- (------)
To: NULL
Date: 11/1/2004 7:58:00 AM
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:output 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>&#xA;</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>&#xA;</xsl:text>
</xsl:for-each>
  </xsl:template>
</xsl:stylesheet>


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent