Transforming parentless element on .NET
From Max Toro <firstname.lastname@example.org> on the Saxon help list:
I'm using Saxon-HE 18.104.22.168 for .NET
I'm having trouble with a transformation that uses a root element node
(doesn't have a parent document node) as initial context node. I get a
NullReferenceException on Saxon.Api.XsltTransformer.Run(XmlDestination
destination), looking with reflector I suspect the issue might be with
one of these lines:
DocumentInfo doc = this.initialContextNode.getDocumentRoot();
this.controller.registerDocument(doc, (doc.getBaseURI() ==
null) ? null : new DocumentURI(doc.getBaseURI()));
I think it's trying to get the root node as a document node, which it
isn't. This element node is constructed in an XSLT transformation,
passed as argument to an integrated extension function which uses it
as initial context node in a new transformation, which is the one that
Besides the NullReferenceException, does XSLT allow you to start a
transformation with a parentless element?
#1 Updated by Michael Kay almost 4 years ago
My response: Yes, the specification allows a parentless element to be supplied as the
initial context node, and it's an oversight in the implementation (and
the test cases) that this isn't working. We'll treat it as a bug.
Note: I've checked that this works on Java (with an amended version of the unit test TestQueryToTransform. We need a similar test on .NET.
#3 Updated by O'Neil Delpratt almost 4 years ago
- Status changed from In Progress to Resolved
A parentless element returns null on a
getDocumentRoot() call, therefore I have added a conditional statement to the code in question:
this.controller.registerDocument(doc, (doc.getBaseURI() == null) ? null : new DocumentURI(doc.getBaseURI()));, which prevents the NullReferenceException from being thrown.
Bug fixed and committed to subversion. Thanks to Max for the pointer.