You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Beasty kuku <be...@hotmail.com> on 2003/06/19 21:50:35 UTC

Can one change the source document while processing it with Xalan

It might not be the obvious use of XSLT, but my needs are to use the XSL as 
a scripting language.
Meaning I start with a source XML document, but along my XSL processing, 
using mainly xalan-extension java function, I need to add and replace 
elements to the source document.

Is it possible to alter/modify the source document after the XSL mechnism 
began its transformation?

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail


Re: Can one change the source document while processing it with Xalan

Posted by Joseph Kesselman <ke...@us.ibm.com>.



The XSLT processing model assumes that the source tree will not be altered.
This permits optimizations in both how that data is stored and how it's
processed which couldn't be applied if the document was mutable.

If you really need to do this, there are a couple of approaches you might
try. One is to have the stylesheet actually generate a document which
describes how to patch the source, then run a post-processing stage which
interprets and applies those patch requests. (Of course you'd need to find
or create that patch interpreter.) Another would be to create a non-XSLT
tool which uses our XPath engine to find the nodes you're interested in and
runs its own code to apply the changes... but note that you've probably
have to use a non-cached XPath interpreter to keep the changes made after
one query from breaking future queries. (The experimental DOM2DTM2 code
attempts to avoid that need to flush and rebuild the document model, but is
Not Ready For Prime Time; due to time constraints we had to set it aside
while still in the proof-of-concept stage. I'm hoping to revive that
approach before the end of the year, but no promises...)

In the longer term... The XQuery working group has considered giving that
language the ability to update its source data. If that happens, using an
XQuery rather than XSLT might address your needs; the two languages have
similar capabilites though they're biased in different directions.

______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk


Re: Can one change the source document while processing it with Xalan

Posted by da...@us.ibm.com.



No, the source tree in XSLT is immutable, and you cannot change it.

Dave



|---------+--------------------------->
|         |           "Beasty kuku"   |
|         |           <beasty396@hotma|
|         |           il.com>         |
|         |                           |
|         |           06/19/2003 12:50|
|         |           PM              |
|         |           Please respond  |
|         |           to xalan-dev    |
|---------+--------------------------->
  >-----------------------------------------------------------------------------------------------------------------|
  |                                                                                                                 |
  |        To:      xalan-dev@xml.apache.org                                                                        |
  |        cc:      (bcc: David N Bertoni/Cambridge/IBM)                                                            |
  |        Subject: Can one change the source document while processing it with Xalan                               |
  >-----------------------------------------------------------------------------------------------------------------|



It might not be the obvious use of XSLT, but my needs are to use the XSL as

a scripting language.
Meaning I start with a source XML document, but along my XSL processing,
using mainly xalan-extension java function, I need to add and replace
elements to the source document.

Is it possible to alter/modify the source document after the XSL mechnism
began its transformation?

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail




RE: Can one change the source document while processing it with Xalan

Posted by Robert Koberg <ro...@koberg.com>.
Hi,

You could do this with multiple transformation using the result of the
previous transformation in the next. For example:

Transformer t1 = StylesheetCache.newTransformer(xsl1);
File f = File.createTempFile("stream", ".xml");
Result result = new StreamResult(f);    
t1.setParameter("uname", name);
t1.transform(new StreamSource(source), result);

Transformer t2 = StylesheetCache.newTransformer(xsl2);
t2.transform(new StreamSource(result.getSystemId()), new StreamResult(out));
f.delete();

best,
-Rob


> -----Original Message-----
> From: Beasty kuku [mailto:beasty396@hotmail.com]
> Sent: Thursday, June 19, 2003 12:51 PM
> To: xalan-dev@xml.apache.org
> 
> It might not be the obvious use of XSLT, but my needs are to use the XSL
> as
> a scripting language.
> Meaning I start with a source XML document, but along my XSL processing,
> using mainly xalan-extension java function, I need to add and replace
> elements to the source document.
> 
> Is it possible to alter/modify the source document after the XSL mechnism
> began its transformation?
> 
> _________________________________________________________________
> Tired of spam? Get advanced junk mail protection with MSN 8.
> http://join.msn.com/?pageþatures/junkmail