Subject: Re: [xsl] Batch transform into one file From: "Gary E. Daniels" <gdaniels@xxxxxxxxxxx> Date: Wed, 16 Jan 2008 09:21:17 -0600 |
Gary,
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>
or
<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:
<set> <file>one.xml</file> <file>two.xml</file> <file>three.xml</file> <file>four.xml</file> </set>
(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']"/> </xsl:if> </xsl:for-each>
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, Wendell
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.
Gary
=========================================================================================
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 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' -->
<!-- Select specific Node or Form based on its id -->
<xsl:if test="@id='W1L'">
File #<xsl:copy-of select="field[@id='4']"/>
</xsl:if>
</xsl:template>
====================================================================== 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Batch transform into one , Wendell Piez | Thread | Re: [xsl] Batch transform into one , Wendell Piez |
[xsl] Testing XSLT with xmlconf, Jesper Tverskov | Date | Re: [xsl] Batch transform into one , Wendell Piez |
Month |