[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Processing mutiple files in multiple directories individually
Subject: Re: [xsl] Processing mutiple files in multiple directories individually From: Philip Fearon <pgfearo@xxxxxxxxxxxxxx> Date: Fri, 18 Mar 2011 08:54:24 +0000 |
You're right that this is a common use case, XSLT itself can't do an in-place update, but there are XSLT tools with this capability built in. CoherentWeb[1] addresses both the problem of ignoring certain XML files (and all non-XML files) and performing the equivalent of a 'replace' operation on a directory structure, but in a safe way. In CoherentWeb, there would be 3 main steps: 1. Write an XSLT identity transform that will both: a: raise an error when the file is identified by an XPath rule as one that does not need processing and b: modify the parts of a targeted file as required 2. Drag and drop the input directory and XSLT files onto the CoherentWeb Input and XSLT lists respectively. 3. From the Control Panel, check the 'Auto-Export' option and then press 'Run' The XSLT processor will perform, as a multi-threaded batch job, a transform on all XML files (ignoring non-XML files automatically) found in the input directory and sub-directories. It then creates a deep-copy of your input directory, with the only difference being the original files that were transformed without error are replaced with the new modified versions. As Andrew and Liam describe, replacing files in-place has one main disadvantage, its not reversible. CoherentWeb overcomes this because the 'replace' operation only works on a copy of the original directory, you can repeat this operation therefore as often as needed. Also, any ZIP files encountered can (as an option) be treated by CoherentWeb as ordinary directories, allowing you to modify XML within ZIP-archives (though the included EXPath ZIP Module[2] implementation provides much greater flexibility in this respect). An XML report summarises all the files in the directory that were modified, but you can see this at a glance from file icons in the CoherentWeb file-list that provides a flattened view of all the files in the input directory. [1] http://coherentweb.com [2] http://www.expath.org/modules/zip/ Phil Fearon http://qutoric.com On Fri, Mar 18, 2011 at 12:00 AM, Mark <mark@xxxxxxxxxxxx> wrote: > I am using XSLT 2.0. > > I have several hundred XML data files stored in a number of directories each > with subdirectories of their own that descend to various levels. From them, > I need to locate 137 specific files and make editing changes to each. I > believe I can write the template that can determine if a specific XML file > requires editing or not, and if so to then apply the editing change. > > What I do not know how to do is: > > (1) search through all the directories and subdirectories and open each XML > file one at a time, > > (2) if the file does not require editing, drop it and move on to the next > file; or > > (3) if the file requires editing, make the editing change and write the file > out to its original location. > > I suspect this is not that uncommon a task, but it is not clear to me where > to look for cookbook code to accomplish my goal. I am not even sure what > terms to search under. Can anyone help? > > Thanks, > Mark
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Processing mutiple files , Andrew Welch | Thread | Re: [xsl] Processing mutiple files , Mark |
[xsl] Why namespace-alias result pr, Karl Stubsjoen | Date | Re: [xsl] Why namespace-alias resul, David Carlisle |
Month |