Re: [xsl] Processing mutiple files in multiple directories individually

Subject: Re: [xsl] Processing mutiple files in multiple directories individually
From: "Mark" <mark@xxxxxxxxxxxx>
Date: Fri, 18 Mar 2011 06:00:24 -0700
Liam, Dan, Andrew, and Philip,
I will look at both avenues. Thanks for the leads - I was unaware of these technologies.
Mark


-----Original Message----- From: Philip Fearon
Sent: Friday, March 18, 2011 1:54 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Processing mutiple files in multiple directories individually


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