Bug #1675

Transforming parentless element on .NET

Added by Michael Kay over 5 years ago. Updated about 5 years ago.

Start date:
Due date:
% Done:


Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:


From Max Toro <> on the Saxon help list:

I'm using Saxon-HE 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 over 5 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.

#2 Updated by O'Neil Delpratt over 5 years ago

  • Status changed from New to In Progress

So far I have managed to reproduce the exception with a test case. Currently investigating.

#3 Updated by O'Neil Delpratt over 5 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.

#4 Updated by O'Neil Delpratt about 5 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in version set to

Bug closed. Fixed in Saxon maintenance release

Please register to edit this issue

Also available in: Atom PDF