xsl-list
[Top] [All Lists]

[xsl] Creating csv from multiple input files

2008-05-06 06:25:40
Hi,
this question has been asked a few times in this list but i couldn't
find an answer that works for me.
I want to process multiple xml-files in one folder and write the
output to one single file.

My input files are very simple and look like this:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<invdoc>
   <objid>3196575</objid>
   <cdate>15.02.2006</cdate>
   <user>Smith</user>
</invdox>

<?xml version="1.0" encoding="ISO-8859-1" ?>
<invdoc>
   <objid>3196576</objid>
   <cdate>15.02.2006</cdate>
   <user>Doe</user>
</invdox>

My XSLT ist very simple too and should create a csv-file where the
values are separated by tabulators:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
   <xsl:output name="csv" method="text" encoding="UTF-8"/>
   <xsl:template match="/">
      <xsl:result-document format="csv" href="result.csv">
         <xsl:apply-templates/>
         <xsl:text>&#x0d;&#x0a;</xsl:text>
      </xsl:result-document>
   </xsl:template>
   <xsl:template match="//objid">
      <xsl:value-of select="concat(.,'&#00009;')"/>
   </xsl:template>
   <xsl:template match="//cdate">
      <xsl:value-of select="concat(.,'&#00009;')"/>
   </xsl:template>
   <xsl:template match="//user">
      <xsl:value-of select="."/>
   </xsl:template>
</xsl:stylesheet>

For a single file this works fine.
But the supposed output after processing all files should be a single
"result.csv" that looks like this:

3196575   15.02.2006   Smith
3196576   15.02.2006   Doe
4194550   07.03.2007   Smith

Given that i don't know the number and names of the files in the input
folder, how can i archive this result?

I'm using Saxon8 for the tranformation but couldn't find out how to
process multiple files on the command line. I also tried Kernow which
makes it easy to pass a folder to saxon, but i didn't manage to create
a single output file. It would be nice if someone could toss me to the
right direction. Is there a pure XSLT-solution or do i have to use
specific command-line options for saxon that i do not know?

Georg.

--~------------------------------------------------------------------
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>
--~--