Setting the context item

Many of the methods in the JAXP interface take an argument to represent the context node. Because the API is designed to be used with multiple object models, this is typed simply as an Object. In the case of Saxon, this can be an object in any of the supported data models: DOM, JDOM, DOM4J, XOM, or Saxon's native NodeInfo representation. Note that if a NodeInfo is supplied, the tree must have been constructed using the same Saxon Configuration as the one used by the XPathEvaluator itself.

It is also possible to supply an atomic value as the context item. This must be supplied as an implementation of the Saxon AtomicValue class; no conversion is attempted.

Many of these methods specify that if the context node supplied is null, the XPath expression will be evaluated using an empty document node as the context node. Saxon does not implement this rule. There are two reasons for this. Firstly, it's unnatural in XPath 2.0, where it is permissible for the context item for an expression to be undefined. Secondly, it's not clear what kind of document node it would be appropriate to create, given that Saxon supports multiple object models. Instead, if null is supplied, the expression is evaluated with the context item undefined (which will cause a dynamic error if the expression actually refers to the context item).