Re: [xsl] Document function isn't realoding document.

Subject: Re: [xsl] Document function isn't realoding document.
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Fri, 11 Jan 2008 09:20:52 +0100
Adam Komisarek wrote:
Hello!

I have very big problem with my XSLT transformation... I'm using
Xalan, stylesheet is version 1.0. At some point of the transformation
stylesheet reads value which is needed later in transformation. To
avoid passing this variable through all apply-templates and using
parameters in xsl:template I use xalan:redirect extension - simply
write to file value of interesting element making with it XML document
(<myValue>readed value</myValue>) and then I read that file with
document(myFile) function. The problem is when I change that file with
consequents invoking of redirect:write instructions and read them
again using processor doesn't see changes in that document - value of
<myValue> is still the same as at the first time!
Does processor cache in some way documents? Can I reload documents in some way?
I want to avoid working with params...
Thanks!

It is not possible to both write and read a document. Not even with extension functions. The reason is simple: the document() function is "stable" which, the way I understand it, means that multiple calls to the document() function with the same value as a parameter, will result in the same node set. If you consider that it is undetermined in what order the processor executes your statements and declarations, it becomes apparent that this restriction to the language is a necessary one.


However, this restriction does not mean that what you want cannot be achieved. You use Xalan, which has the capability of using the EXSLT extension function exslt:node-set(). You can use it to do what you want: "store" it first and apply it later:

<xsl:template match="/">
    <xsl:variable name="test">
          <someNode>with a value</someNode>
          <xsl:apply-templates select="foo/bar" />
    </xsl:variable>
    <xsl:apply-templates select="exslt:node-set($test)/*" />
<xsl:template>

<xsl:template match="someNode" >
     .....
</


Or something along that line.


HTH,
Cheers,
-- Abel Braaksma

Current Thread