transform xml to csv > and then ...?

Discussion in 'XML' started by Sharon, Nov 1, 2004.

  1. Sharon

    Sharon Guest

    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>
    Sharon, Nov 1, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andrei

    csv file upload and transform

    andrei, Jun 29, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    401
    andrei
    Jun 29, 2004
  2. Replies:
    1
    Views:
    741
    Esmond Pitt
    Mar 27, 2005
  3. Mufasa
    Replies:
    7
    Views:
    411
    Alexey Smirnov
    Sep 4, 2007
  4. Replies:
    0
    Views:
    272
  5. Replies:
    4
    Views:
    537
    cwdjrxyz
    Jan 17, 2006
Loading...

Share This Page