Every stylesheet has built-in template rules to match nodes
for which there are no explicit template rules. The built-in template rules
recurse down the tree, and the built-in rules for text nodes output the contents
of the text node.
Thanks for taking the time to explain. It was helpful.
However, I still don't understand why a stylesheet that selects nothing has a
result tree that contains anything. It would seem logical that since the
sytlesheet selects nothing, the result would contain nothing. Am I
totally off base? Thanks.
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
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
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.
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
I have attached a simple test to help demonstrate the
org.apache.crimson.tree.DomEx: HIERARCHY_REQUEST_ERR: This node isn't
org.apache.crimson.tree.DomEx: HIERARCHY_REQUEST_ERR: This node
isn't allowed there.