xsl-list
[Top] [All Lists]

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

2011-03-18 05:01:20
On Fri, March 18, 2011 12:00 am, Mark 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,

If you're using Saxon, Saxon's collection() implementation [1] can recurse
through subdirectories.

(2) if the file does not require editing, drop it and move on to the next
file; or

That's a bit tougher to do with only XSLT.

You could, as others have said, traverse through the files to produce a
list of files to process in a second transformation or a second pass or
you could apply an identity transform on the other files such that every
file gets processed one way or the other.

(3) if the file requires editing, make the editing change and write the
file
out to its original location.

I don't expect that to be possible.  What if the XSLT processor opens the
file for output before it's finished reading it as input?

You could, as Liam said, write the files to another location and copy them
over the originals after the XSLT has been run.

Regards,


Tony Graham                         
Tony(_dot_)Graham(_at_)MenteithConsulting(_dot_)com
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd                               XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2

[1] http://www.saxonica.com/documentation/sourcedocs/collections.xml

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--