Re: [xsl] Batch transform into one file

Subject: Re: [xsl] Batch transform into one file
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 15 Jan 2008 11:32:57 -0500

You could go several different ways with this.

One approach is simply to use your batch process to concatenate the results of a series of transformations. For example, if you simply had the transform write:

<file source="W1L">filename1.xml</file>


<file source="W1S">filename23.xml</file>

you could bang these into a single file with your script, wrapping the lot of them in a pair of tags (there are several ways to do that: I might even use a "wrapper" XML calling the list as a parsed entity), and then process that as input to sort your file lists.

Another approach is to use the document() function. There are several ways you could do it. Given that you have many files, the easiest way could be to create a "driver" XML that listed them:


(Either create this by hand, write a Perl or Python script, or use any of several available utilities to do it for you, such as XMLStarlet.)

Use this file as your input and call document(/set/file) to pull the instances together. For example:

<xsl:for-each select="document(/set/file)">
  <!-- your context is now the root of each of the documents listed -->
  <xsl:if test="/wheres/your/@id='W1S'">
    <xsl:text>File #</xsl:text>
    <xsl:copy-of select="/wheres/your/field[@id='4']"/>

But note: this sort of thing can be memory-hungry in XSLT.

The best solution depends on factors like how often you need to do this (thus, how neat, clean, portable, scaleable it needs to be), performance constraints etc.

I hope this helps,

Hi. I need to alter the stylesheet below to create 1 text file with the data extracted from multiple XML files from a batch transform. Right now it will create 1 text file for each XML file transformed.

Background: I receive XML files that I batch transform. These files are from two sources: source 1 is W1L, source 2 is W1S. When I receive these files, they are mixed so I do not know which files are from which source. I want to have the below stylesheet create one text file that will contain a list of all file numbers (File #<xsl:copy-of select="field[@id='4']"/) where the "@id='W1L'", and ignore anything else.

Thanks in advance.


<xsl:stylesheet xmlns:xsl=""; version="1.0">

<xsl:output method="text"/>

<xsl:template match="filename"/>
<xsl:template match="mimetype"/>
<xsl:template match="mimedata"/>

<xsl:template match="AppraisalForm">

<!-- This is file 'Long Form.xsl' -->

<!-- Use this to batch transform XML files and make one file that contains a list of file

names where where "@id='W1L'". If "@id<>'W1L'", then nothing is extracted from that XML

file -->

<!-- Select specific Node or Form based on its id -->

<xsl:if test="@id='W1S'">

File #<xsl:copy-of select="field[@id='4']"/>



Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
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