<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="extensibility" page="function-result.net" subpage=""/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: Converting the Result of a .NET Extension Function</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: Converting the Result of a .NET Extension Function"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Converting the Result of a .NET Extension Function</h1>
      <p>This section explains how the value returned by a .NET extension function is converted
to an XPath value.</p>
      <p>The result type of the method is converted to an XPath value as follows.</p>
      <ul>
         <li content="para">
            <p>If the method returns void, the XPath value is an empty sequence.</p>
         </li>
         <li content="para">
            <p>If the method returns null, the XPath value is an empty sequence.</p>
         </li>
         <li content="para">
            <p>If the method is a constructor, the XPath value is of type "wrapped .NET object". The only way of
using this is by passing it to another external function, or by converting it to one of the standard
XPath data types as described above.</p>
         </li>
         <li content="para">
            <p>If the returned value is an <code>XdmValue</code> or one of its subclasses such as <code>XdmNode</code>
or <code>XdmAtomicValue</code>, then it is used <i>as is</i>, after unwrapping. 
(These types are defined in the Saxon.Api namespace). Note that if the method constructs a new XdmNode and
returns it, then it must be built using the Name Pool that is in use by the transformation or query, which
means in practice that it must be built using a <code>DocumentBuilder</code> derived from the same 
<code>Saxon.Api.Processor</code>.</p>
         </li>
         <li content="para">
            <p>If the returned value is a .NET bool, the XPath result is a boolean.</p>
         </li>
         <li content="para">
            <p>If the returned value is a .NET double, the XPath result is a double.</p>
         </li>
         <li content="para">
            <p>If the returned value is a .NET float, the XPath result is a float.</p>
         </li>
         <li content="para">
            <p>If the returned value is a .NET Int64, Int32, or Int16, or one of their object wrapper
equivalents, the XPath result is an integer.</p>
         </li>
         <li content="para">
            <p>If the returned value is a .NET string, the XPath result is a string.</p>
         </li>
         <li content="para">
            <p>If the returned value is an instance of the Saxon class <code>net.sf.saxon.om.NodeInfo</code>
 (a node in a Saxon tree), the XPath value will be a sequence containing a single node.</p>
         </li>
         <li content="para">
            <p>If the returned value is an instance of the Saxon class <code>net.sf.saxon.value.Value</code>,
the returned value is used unchanged.</p>
         </li>
         <li content="para">
            <p>If the returned value is is an instance of the Saxon class <code>net.sf.saxon.om.SequenceIterator</code>
(an iterator over a sequence), the XPath
value will be the sequence represented by this iterator. It is essential that this iterator
properly implements the method <code>getAnother()</code> which returns a new iterator over the
same sequence of nodes or values, positioned at the start of the sequence.</p>
         </li>
         <li content="para">
            <p>If the returned value is an instance of the .NET interface <code>System.Collections.IEnumerable</code>, 
or if it is an array,
 the XPath value will be the
sequence represented by the contents of this collection or array. The members of the list or array
will each be converted
to an XPath value, as if each member was supplied from a separate function call. An error is reported if
the result contains a list or array nested within another list or array. 
The contents of the list or array are copied immediately on return from the
function, so the original collection or array object itself may be safely re-used.</p>
         </li>
         <li content="para">
            <p>If the result is any other Java object (including null), it is returned as a "wrapped Java object".</p>
         </li>
      </ul>
      <p>In XSLT, the system function <code>function-available(String name)</code> returns true if there appears
to be a method available with the right name. The function also has an optional second argument to test whether
there is a method with the appropriate
number of arguments. However, it is not possible to test whether the arguments are of appropriate types.
 If the function name is "new" it
returns true so long as the class is not an abstract class or interface, and so long as it has at least
one constructor.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="instructions.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>