Re: [xslt] Creating directories

Ben Godfrey wrote:
> I would like to create a directory structure based on an XML tree. I 
> searched the mailing list archive and had a look around the net but 
> found nothing. I guess it's not possible to do this with XSLT at this 
> point. I wondered if anyone here had tried a similar thing and had any 
> best practice advice.

One simple approach is to have the XSL stylesheet produce a
script (using the 'text' output method) that is then subsequently
evaluated - a post-transformation step instead of pre-xform.
You may use the scripting language of your choice,
of course, but on Unix systems Bourne shell would be a good choice.

> Would produce three output HTML files:
> index.html
> content/index.html
> content/page2.html

Using the above approach, you could actually produce four files,
the three html files and a script that gets evaluated post-xform
that creates the directories and moves the files into their
final location.

A more sophisticated approach is to use extensions.  For example,
I use TclXSLT, a package that allows libxslt to be embedded in
the Tcl scripting language.  My application defines an XSLT
extension function 'resource:mkdir' that simply evaluates
the Tcl command 'file mkdir' with the given argument.
You could do the same thing with Perl or Python.  Heck, you could
even write an extension in C that makes the appropriate
library calls.  The point is to use the XSLT extension mechanism
to effectively hide the implementation language, so that
your stylesheet is more easily portable.

Steve Ball

Steve Ball            |   XSLT Standard Library   | Training & Seminars
Zveno Pty Ltd         |     Web Tcl Complete      |   XML XSL Schemas |      TclXML TclDOM        | Tcl, Web Development  +---------------------------+---------------------
Ph. +61 2 6242 4099   |   Mobile (0413) 594 462   | Fax +61 2 6242 4099

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]