Your stylesheet seems to be creating a result tree that
contains a document node with a text node as its child. This is allowed in
the XPath data model, but it isn't allowed in DOM: see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-1590626202. Passing
a transformation result that isn't a well-formed document (ie one where the
document node has text nodes, or zero element nodes, or multiple elements
nodes, as its children) seems inadvisable.
Saxon could arguably get round this by creating a
DocumentFragment rather than a Document node as the root of the tree.
However, I suspect this would stop many applications from working. Perhaps
this is what the Xalan/Xerces combination is doing ("Java 1.5 without Saxon in my
classpath").
In the case of a SAXResult, Saxon explicitly checks
that the result represents a well-formed document. Arguably it should do a
similar check for a DOMResult, to give a cleaner failure
message.
You should only really use DOM with Saxon if you have
to, because of incompatibilities in the data model (of which this is an
example). Doing what your application here is doing, constructing a DOM
representation of the input file and then passing that as the source to
Saxon, is incredibly inefficient. If you're starting with serial XML, always
use a SAXSource or StreamSource.
Michael Kay
I have a
problem in Saxon 8.4. Transforming with a empty stylesheet
gives the error below. This works in Saxon 6.5.3, but now
fails in 8.4. Also, if I run the test in Java 1.4.2 without Saxon in
my classpath, it fails. Running the test in Java 1.5 without Saxon
in my classpath, it completes. Running in either Java 1.4.2 or 1.5
with Saxon 8.4 in my classpath fails. Does this look like a
bug?
I have attached a simple test to help demonstrate the
issue.
Thanks.
,
Josh.
net.sf.saxon.trans.DynamicError:
org.apache.crimson.tree.DomEx: HIERARCHY_REQUEST_ERR: This node isn't
allowed there.
at
net.sf.saxon.dom.DOMEmitter.characters(DOMEmitter.java:121)
at
net.sf.saxon.event.ProxyReceiver.characters(ProxyReceiver.java:202)
at
net.sf.saxon.event.ComplexContentOutputter.characters(ComplexContentOutputter.java:110)
at
net.sf.saxon.instruct.ApplyTemplates.defaultAction(ApplyTemplates.java:341)
at
net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:289)
at
net.sf.saxon.instruct.ApplyTemplates.defaultAction(ApplyTemplates.java:331)
at
net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:289)
at
net.sf.saxon.instruct.ApplyTemplates.defaultAction(ApplyTemplates.java:331)
at
net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:289)
at
net.sf.saxon.Controller.transformDocument(Controller.java:1367)
at
net.sf.saxon.Controller.transform(Controller.java:1195)
at SaxonTest.main(SaxonTest.java:43)
Caused by:
org.apache.crimson.tree.DomEx: HIERARCHY_REQUEST_ERR: This node
isn't allowed there.
at
org.apache.crimson.tree.XmlDocument.checkChildType(XmlDocument.java:616)
at
org.apache.crimson.tree.ParentNode.appendChild(ParentNode.java:341)
at
org.apache.crimson.tree.XmlDocument.appendChild(XmlDocument.java:664)
at
net.sf.saxon.dom.DOMEmitter.characters(DOMEmitter.java:119)
... 11
more