Greetings.
I'm getting an error (XTDE1490) when I use the Saxon 8.9 Transformer
multiple times.
It's not obvious to me what I'm doing wrong, the explanation of
XTDE1490 at [1] doesn't apply, and there's no obvious insight in the
list archive for the various searches I've tried.
My (complete) test program is
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
public class SaxonTry {
public static void main(String[] args) {
String xsltFile = "identity.xslt";
Source[] sources = new Source[args.length];
Result[] results = new Result[args.length];
for (int i=0; i<args.length; i++) {
sources[i] = new StreamSource(args[i]);
results[i] = new StreamResult(args[i]+"-res");
}
try {
Transformer trans = TransformerFactory.newInstance()
.newTransformer(new StreamSource(xsltFile));
for (int i=0; i<args.length; i++) {
System.err.println("Transforming: " + sources
[i].getSystemId()
+ " -> " + results[i].getSystemId
());
trans.transform(sources[i], results[i]);
}
} catch (Exception e) {
System.err.println("Exception: " + e);
}
}
}
The identity.xslt is the usual XSLT identity transform.
Running this with the default transformer works fine:
% CLASSPATH=. java SaxonTry test-in{1,2}.xml
Transforming: test-in1.xml -> test-in1.xml-res
Transforming: test-in2.xml -> test-in2.xml-res
%
and produces two output files as expected. Using the Saxon 8.9
transformer, however, produces errors:
% CLASSPATH=$T/saxon-8.9/saxon8.jar:. java \
-
Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryI
mpl \
SaxonTry test-in1.xml test-in2.xml
Warning: at xsl:transform on line 3 of file:///Volumes/Lagrange/
checkouts/me/code/misc/identity.xslt:
Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor
Transforming: test-in1.xml -> test-in1.xml-res
Transforming: test-in2.xml -> test-in2.xml-res
Error at xsl:copy on line 6 of file:///Volumes/Lagrange/checkouts/me/
code/misc/identity.xslt:
XTDE1490: Cannot write an implicit result document if an explicit
result document has been
written to the same URI: test-in1.xml-res
Exception: net.sf.saxon.trans.DynamicError: Cannot write an implicit
result document if an explicit result document has been written to
the same URI: test-in1.xml-res
%
There's no result-document element in the identity transformation,
but there's no need for once, since the
javax.xml.transform.Transformer.transform() method is being given
explicit Source and Result arguments.
The javax.xml.transform.Transformer documentation[2] indicates that
the Transformer `may be used multiple times', and that it `may then
be used to process XML from a variety of sources and write the
transformation output to a variety of sinks.' That certainly
suggests that I _ought_ to be able to do what I'm doing by reusing
the Transformer with multiple Sources and Results. What appears to
be happening, however, is that the Saxon Transformer is attempting to
use the first Result for both transformations (or something like that).
I've looked at Templates, but as far as I can tell from the javadocs,
the only issue there is that a Template is thread-safe, and so can
produce multiple (unsafe) Transformers implementing a single
transformation, which can themselves be used in separate threads.
But that's not my situation here.
Am I doing something dim?
Thanks for any pointers. Best wishes,
Norman
[1] http://www.w3.org/TR/xslt20/#err-XTDE1490
[2] http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/transform/
Transformer.html
--
------------------------------------------------------------------
Norman Gray : http://nxg.me.uk
eurovotech.org : University of Leicester, UK
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--