Re: [xsl] Write to and read form same file

Subject: Re: [xsl] Write to and read form same file
From: Colin Paul Adams <colin@xxxxxxxxxxxxxxxxxx>
Date: Thu, 20 Sep 2007 23:54:39 +0100
>>>>> "Jesper" == Jesper Tverskov <jesper@xxxxxxxxxxx> writes:

    Jesper> Hi List In the XSLT 2.0 spec I have problems understanding
    Jesper> the following:

    Jesper> "It is a recoverable dynamic error for a stylesheet to
    Jesper> write to an external resource and read from the same
    Jesper> resource during a single transformation, whether or not
    Jesper> the same URI is used to access the resource in both
    Jesper> cases. The optional recovery action is

That should be straight-forward.

    Jesper> implementation-dependent: implementations are not required
    Jesper> to detect the error condition. Note that if the error is
    Jesper> not detected, it is undefined whether the document that is
    Jesper> read from the resource reflects its state before or after
    Jesper> the result tree is written."

This is the interesting part. There is no way that you can expect an
implementation to be able to detect all the possible aliasing of
resources via different URIs. About all you can expect is that (most
of the time) if you use the identical URI to both read and write, the
processor will probably be able to see the error.

    Jesper> Is it a bug in XMLSpy 2008 that document() works anyway?

Not necessarily.
For a start, the base URIs may be different for input and output.

Even if they are the same: "implementations are not required to detect
the error condition".

So all bets are off.

    Jesper> It does not in SAXON. Is it a bug in SAXON that
    Jesper> collection() works anyway?

Again, not necessarily.
There is no guarentee that a given collection URI maps predictably to
a given document URI. In Gestalt, for file URIs, there is a
predictable relationship, and it would report the error for the same
file resource. Saxon does not attempt to maintain the tie. In general,
there are problems doing so.

    Jesper> Here is a stylesheet for writing to and reading from same
    Jesper> file both in AltovaXML and SAXON:

A good example.
There are other ways to cheat - symbolic links under Linux, for
instance. In all of these cases, all bets are off as to what happens.

For instance, I think (I haven't tested it), that if you try to read
from file:a as the principal source document, and write to file:b as
the principal output destination (i.e. not using document() of
xsl:result-document) where b is a symbolic link for a,
using Gestalt, the first thing that happens is that file:b gets opened
- it is now empty. Then a gets parsed and the XML parser complains of
a syntax error at the first line (because it is empty).
-- 
Colin Adams
Preston Lancashire

Current Thread