Re: [xsl] Is it possible to modify an XML by XSLT "in-place" (directly replace) ?

Subject: Re: [xsl] Is it possible to modify an XML by XSLT "in-place" (directly replace) ?
From: pgfearo <pgfearo@xxxxxxxxxxxxxx>
Date: Fri, 9 Oct 2009 07:37:42 +0100
CoherentWeb, a bulk xslt processing GUI tool, has an overwrite mode, along with the necessary undo facility. But this overwrite is achieved as you suggest by a second copy operation after the transfom.

(This tool was withdrawn due to lack of interest, but it will be back soon probably)

Phil Fearon

On 8 Oct 2009, at 22:08, "Michael Kay" <mike@xxxxxxxxxxxx> wrote:

Normally the user applys an XSLT style sheet onto a source
XML file or variable and the result XML will be stored into
ANOTHER file or variable.
Thats the "traditional" way of processing XSLT.

But what, if I want to replace the original file or variable
completely?
Ok, I could do this after the actual XSLT processing in
another step by copying the result file/variable back to the
source and delete the temporary help file/variable.

I would not recommend writing the output of a transformation to the same
file as the input unless you have a backup of the input. It is likely that
if the transformation fails for any reason, the input file will be lost. The
XSLT 2.0 specification explicitly states that when a transformation fails,
the state of any persistent resources updated by the transformation is
undefined.


I spent many years working on an operating system with versioned filestore
(ICL VME) that did not have this problem: if a failure occurred you could
always revert to the previous version of the file. Unfortunately "modern"
operating systems are generally less sophisticated than this.


The usual procedure therefore is to write to a file with a new name, and
then rename the file (to the original name) if the process completes
successfully.


Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay

Current Thread