Subject: RE: [xsl] Frustrated by result-document From: "Michael Kay" <mhk@xxxxxxxxx> Date: Sun, 6 Jun 2004 16:22:48 +0100 |
> I've had a lot of fun learning XSLT, and it's mostly been > straightforward but was surprised to find > that result-document appears only to update a file once. This > with Saxon 7.9.1. xsl:result-document doesn't update a file, it creates a new file, overwriting any previous file at the same location. You aren't allowed to use the same URI more than once, or to use the URI of an input document, but Saxon doesn't currently detect these errors. The "no-side-effects" rule for XSLT applies to xsl:result-document just as much as to any other instruction. If you were allowed to update the same file several times, the results would depend on order of execution, which is taboo. > > I have an input that suggests files to update, and often this > results in files needing multiple > updates. > > Using a <for-each input, update the result-document suggested > in the current input>, I find only the > last update is being made. The word "last" is a give-away: you are making assumptions about the order of execution. > > I'm taking this to suggest the result-document isn't > releasing a new file at </result-document>. It's not a good idea to think of the end-tag </result-document> representing an instruction. But what is actually happening is that each time you evaluate the <xsl:result-document> instruction, the relevant file is being overwritten. Your example shows that you have incorrect assumptions about the document() function as well. If you call the document() function multiple times, you get the same node back each time. You can't use result-document to write a file, and then document() to read it back in. This is exactly like trying to update variables. > > Example of the problem > The transform below acting on this input > <?xml version="1.0" encoding="utf-8"?> > <data> > <item name="x" id="136">item1</item> > <item name="y" id="137"/> > <item name="z" id="138">item3</item> > </data> > > > I would hope to give this output > <?xml version="1.0" encoding="utf-8"?> > <data> > <item name="newinput" id="136">newinput2</item> > <item name="newinput" id="136">newinput1</item> > <item name="x" id="136">item1</item> > <item name="y" id="137"/> > <item name="z" id="138">item3</item> > </data> > I can't really see how this output relates to the input, so I can't suggest the correct way of tackling this problem. Perhaps you want to do a sequence of transformations, with each one except the last producing a temporary tree as its output. You can do this with a recursive template, that does one stage of the transformation and then passes its result as a parameter to the next stage. Michael Kay
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Frustrated by result-document, davidpbrown | Thread | Duplicate elements. HELP!, Stoaks, Max |
Re: [xsl] Recursive selection, eleg, Robert Koberg | Date | Duplicate elements. HELP!, Stoaks, Max |
Month |