Re: [xsl] Creating csv from multiple input files

Subject: Re: [xsl] Creating csv from multiple input files
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 06 May 2008 09:54:11 -0400
Georg,

The usual way of concatenating results into a single file is to use a shell script or application.

This is because such a mechanism isn't strictly within the confines of XSLT, having to do with processing architectures and not transformations. To standardize a mechanism would necessarily favor one sort of platform, environment or framework, so the best a spec can do is make it optional or leave it out entirely. Accordingly, you're not going to find what you want as a standard mechanism, and many (most) processors aren't going to give you a way of writing many results to one file at all; if they do it'll be via extension mechanisms. (Many processors won't want to do this in any case since it raises the question of how to define an order for the results of many transformations.)

But if you are invoking Saxon from the command line, it should be straightforward to invoke it from a script that also concatenates all the result files into one when it's done.

Cheers,
Wendell

At 09:24 AM 5/6/2008, you wrote:
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.


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread