Subject: Re: [xsl] Multiple file XSL conversion From: JBryant@xxxxxxxxx Date: Tue, 28 Jun 2005 15:50:21 -0500 |
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: [xsl] 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: [xsl] 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 [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Multiple file XSL convers, JBryant | Thread | RE: [xsl] Multiple file XSL convers, tomas.vanek |
Re: [xsl] Multiple file XSL convers, JBryant | Date | [xsl] Sort, group, flatten, consecu, Midnit |
Month |