<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="xpath-api" page="jaxp-xpath" subpage="context-node"/>
      <!--
           Generated at 2010-10-29T18:20:48.427+01:00--><title>Saxonica: XSLT and XQuery Processing: Setting the context item</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: Setting the context item"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Setting the context item</h1>
      <p>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 <code>Object</code>. 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
<code>NodeInfo</code> representation. Note that if a <code>NodeInfo</code> is supplied, the tree must have been 
constructed using the same Saxon <code>Configuration</code> as the one used by the <code>XPathEvaluator</code> itself.</p>
      <p>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, then the node supplied to the Saxon-specific method <code>setContextNode()</code>
is used, and if that is null, the expression is evaluated with the context item undefined (which will cause a dynamic
error if the expression actually refers to the context item).</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="return-types.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>