[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Multiple file XSL conversion

Subject: Re: Multiple file XSL conversion
From: JBryant@xxxxxxxxx
Date: Tue, 28 Jun 2005 15:50:21 -0500
xml to xsl conversion
I decided to do some testing to get this thing working. This'll do it:

<xsl:for-each select="document('filelist.xml')/files/filename">
  <xsl:result-document href="{concat('out', position(), '.xml')}">
    <xsl:apply-templates select="document(.)/*"/>
  </xsl:result-document>
</xsl:for-each>

Of course, you may want something more useful for file names.

Tested with Saxon 8.4.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




JBryant@xxxxxxxxx 
06/28/2005 03:28 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
cc

Subject
Re:  Multiple file XSL conversion






Oops. forgot to open the individual documents.

<xsl:for-each select="document('filelist.xml')/filename">
  <xsl:variable name="thisDocument" select="document(.)"/>
  <xsl:result-document href="someoutputname">
    <xsl:apply-templates select="$thisDocument"/>
  </xsl:result-document>
</xsl:for-each>

(Not tested, by the way, so might take some tinkering to get going.)

That assumes that filelist.xml looks like

<files>
  <filename>somefile.xml</filename>
  <filename>etc.xml</filename>
</files>

As Mike Kay pointed out while I was writing this correction, the XSL way 
is not likely to be the most efficient way. Still, it's a problem you can 
solve with XSL if you want to do so.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)





JBryant@xxxxxxxxx 
06/28/2005 03:07 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
cc

Subject
Re:  Multiple file XSL conversion






Hi, Andrew,

If you just want to apply the stylesheet to each file in turn, it's a more 


or less (depending on your operating system) simple scripting problem. If 
you want to stick purely to XML and XSL, you can create a list of the 
files in an XML file, open it with the document function from your 
stylesheet, and then open each file with the document function, process 
the document, and write out the transformed content. In the latter case, 
you'll need XSLT2.0 (for the xsl:result-document instruction) or an 
extension that lets you write files in XSLT 1.0.

The general pattern looks like:

<xsl:for-each select="document('filelist.xml')/filename">
  <xsl:result-document href="someoutputname">
    <xsl:apply-templates/>
  </xsl:result-document>
</xsl:for-each>

You can get fancier by writing an extension function to read the contents 
of a directory. Then your controlling XML file can be a list of 
directories rather than a list of files. I recently did this because I 
couldn't know in advance which files to read from which directories.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)





Andrew Borsz <andrew@xxxxxxxxxxxxxxx> 
06/28/2005 02:53 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
cc

Subject
 Multiple file XSL conversion






Hello,
I'm trying to figure out a good way to convert multiple XML files at 
the same time. Does anyone know the best way to take hundreds XML 
documents and transform them all with the same XSL stylesheet in one or 
two steps?

Any advice would be appreciated.

Thanks,

Andrew Borsz

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.