Subject: Re: [xsl] Processing mutiple files in multiple directories individually From: "Mark" <mark@xxxxxxxxxxxx> Date: Fri, 18 Mar 2011 06:00:24 -0700 |
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.
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
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 , Philip Fearon | Thread | Re: [xsl] Processing mutiple files , Tony Graham |
Re: [xsl] Processing mutiple files , Tony Graham | Date | Re: [xsl] Processing mutiple files , Mark |
Month |