Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > by-pkgid > 5e43f5d92fadaa0a1cc4664249b615d0 > files > 2896

xalan-c-doc-1.1-8mdk.i586.rpm

<HTML><HEAD><SCRIPT language="JavaScript" src="resources/script.js" type="text/javascript"></SCRIPT><TITLE>Xalan-C++ Extension Functions</TITLE></HEAD><BODY alink="#ff0000" bgcolor="#ffffff" leftmargin="4" link="#0000ff" marginheight="4" marginwidth="4" text="#000000" topmargin="4" vlink="#0000aa"><TABLE border="0" cellpadding="0" cellspacing="0" width="620"><TR><TD align="left" height="60" rowspan="3" valign="top" width="135"><IMG border="0" height="60" hspace="0" src="resources/logo.gif" vspace="0" width="135"></TD><TD align="left" colspan="4" height="5" valign="top" width="456"><IMG border="0" height="5" hspace="0" src="resources/line.gif" vspace="0" width="456"></TD><TD align="left" height="60" rowspan="3" valign="top" width="29"><IMG border="0" height="60" hspace="0" src="resources/right.gif" vspace="0" width="29"></TD></TR><TR><TD align="left" bgcolor="#0086b2" colspan="4" height="35" valign="top" width="456"><IMG alt="" border="0" height="35" hspace="0" src="graphics/extensions-header.jpg" vspace="0" width="456"></TD></TR><TR><TD align="left" height="20" valign="top" width="168"><IMG border="0" height="20" hspace="0" src="resources/bottom.gif" vspace="0" width="168"></TD><TD align="left" height="20" valign="top" width="96"><A href="http://xml.apache.org/" onMouseOut="rolloverOff('xml');" onMouseOver="rolloverOn('xml');" target="new"><IMG alt="http://xml.apache.org/" border="0" height="20" hspace="0" name="xml" onLoad="rolloverLoad('xml','resources/button-xml-hi.gif','resources/button-xml-lo.gif');" src="resources/button-xml-lo.gif" vspace="0" width="96"></A></TD><TD align="left" height="20" valign="top" width="96"><A href="http://www.apache.org/" onMouseOut="rolloverOff('asf');" onMouseOver="rolloverOn('asf');" target="new"><IMG alt="http://www.apache.org/" border="0" height="20" hspace="0" name="asf" onLoad="rolloverLoad('asf','resources/button-asf-hi.gif','resources/button-asf-lo.gif');" src="resources/button-asf-lo.gif" vspace="0" width="96"></A></TD><TD align="left" height="20" valign="top" width="96"><A href="http://www.w3.org/" onMouseOut="rolloverOff('w3c');" onMouseOver="rolloverOn('w3c');" target="new"><IMG alt="http://www.w3.org/" border="0" height="20" hspace="0" name="w3c" onLoad="rolloverLoad('w3c','resources/button-w3c-hi.gif','resources/button-w3c-lo.gif');" src="resources/button-w3c-lo.gif" vspace="0" width="96"></A></TD></TR></TABLE><TABLE border="0" cellpadding="0" cellspacing="0" width="620"><TR><TD align="left" valign="top" width="120"><IMG border="0" height="14" hspace="0" src="resources/join.gif" vspace="0" width="120"><BR>
 
  
   
  <A href="overview.html" onMouseOut="rolloverOff('side-overview');" onMouseOver="rolloverOn('side-overview');"><IMG alt="Overview" border="0" height="12" hspace="0" name="side-overview" onLoad="rolloverLoad('side-overview','graphics/overview-label-2.jpg','graphics/overview-label-3.jpg');" src="graphics/overview-label-3.jpg" vspace="0" width="120"></A><BR>   
                        
  <IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>
  
  <A href="getstarted.html#download" onMouseOut="rolloverOff('side-ext-8');" onMouseOver="rolloverOn('side-ext-8');"><IMG alt="Downloads" border="0" height="12" hspace="0" name="side-ext-8" onLoad="rolloverLoad('side-ext-8','graphics/ext-8-label-2.jpg','graphics/ext-8-label-3.jpg');" src="graphics/ext-8-label-3.jpg" vspace="0" width="120"></A><BR>

  <A href="getstarted.html" onMouseOut="rolloverOff('side-getstarted');" onMouseOver="rolloverOn('side-getstarted');"><IMG alt="Getting Started" border="0" height="12" hspace="0" name="side-getstarted" onLoad="rolloverLoad('side-getstarted','graphics/getstarted-label-2.jpg','graphics/getstarted-label-3.jpg');" src="graphics/getstarted-label-3.jpg" vspace="0" width="120"></A><BR>
            
  <IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>
  
  <A href="faq.html" onMouseOut="rolloverOff('side-faq');" onMouseOver="rolloverOn('side-faq');"><IMG alt="FAQs" border="0" height="12" hspace="0" name="side-faq" onLoad="rolloverLoad('side-faq','graphics/faq-label-2.jpg','graphics/faq-label-3.jpg');" src="graphics/faq-label-3.jpg" vspace="0" width="120"></A><BR>

  <IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>  
            
  <A href="samples.html" onMouseOut="rolloverOff('side-samples');" onMouseOver="rolloverOn('side-samples');"><IMG alt="Sample Apps" border="0" height="12" hspace="0" name="side-samples" onLoad="rolloverLoad('side-samples','graphics/samples-label-2.jpg','graphics/samples-label-3.jpg');" src="graphics/samples-label-3.jpg" vspace="0" width="120"></A><BR>            
            
  <A href="commandline.html" onMouseOut="rolloverOff('side-commandline');" onMouseOver="rolloverOn('side-commandline');"><IMG alt="Command Line" border="0" height="12" hspace="0" name="side-commandline" onLoad="rolloverLoad('side-commandline','graphics/commandline-label-2.jpg','graphics/commandline-label-3.jpg');" src="graphics/commandline-label-3.jpg" vspace="0" width="120"></A><BR>
            
  <A href="usagepatterns.html" onMouseOut="rolloverOff('side-usagepatterns');" onMouseOver="rolloverOn('side-usagepatterns');"><IMG alt="Usage Patterns" border="0" height="12" hspace="0" name="side-usagepatterns" onLoad="rolloverLoad('side-usagepatterns','graphics/usagepatterns-label-2.jpg','graphics/usagepatterns-label-3.jpg');" src="graphics/usagepatterns-label-3.jpg" vspace="0" width="120"></A><BR>

  <IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>
   
  <A href="apidocs/index.html" onMouseOut="rolloverOff('side-ext-26');" onMouseOver="rolloverOn('side-ext-26');"><IMG alt="C++ API" border="0" height="12" hspace="0" name="side-ext-26" onLoad="rolloverLoad('side-ext-26','graphics/ext-26-label-2.jpg','graphics/ext-26-label-3.jpg');" src="graphics/ext-26-label-3.jpg" vspace="0" width="120"></A><BR>
   
  <IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>                  
            
  <IMG alt="Extensions" border="0" height="12" hspace="0" src="graphics/extensions-label-1.jpg" vspace="0" width="120"><BR>
            
 <IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>
          
 <A href="readme.html" onMouseOut="rolloverOff('side-readme');" onMouseOver="rolloverOn('side-readme');"><IMG alt="Release Notes" border="0" height="12" hspace="0" name="side-readme" onLoad="rolloverLoad('side-readme','graphics/readme-label-2.jpg','graphics/readme-label-3.jpg');" src="graphics/readme-label-3.jpg" vspace="0" width="120"></A><BR> 
            
 <IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>
 
 <A href="http://xml.apache.org/bugs/" onMouseOut="rolloverOff('side-ext-38');" onMouseOver="rolloverOn('side-ext-38');"><IMG alt="Bug reporting" border="0" height="12" hspace="0" name="side-ext-38" onLoad="rolloverLoad('side-ext-38','graphics/ext-38-label-2.jpg','graphics/ext-38-label-3.jpg');" src="graphics/ext-38-label-3.jpg" vspace="0" width="120"></A><BR>
 
 <A href="http://xml.apache.org/xalan-j/test/run.html#how-to-run-c" onMouseOut="rolloverOff('side-ext-40');" onMouseOver="rolloverOn('side-ext-40');"><IMG alt="Testing" border="0" height="12" hspace="0" name="side-ext-40" onLoad="rolloverLoad('side-ext-40','graphics/ext-40-label-2.jpg','graphics/ext-40-label-3.jpg');" src="graphics/ext-40-label-3.jpg" vspace="0" width="120"></A><BR>

<IMG border="0" height="14" hspace="0" src="resources/close.gif" vspace="0" width="120"><BR></TD><TD align="left" valign="top" width="500"><TABLE border="0" cellpadding="3" cellspacing="0"><TR><TD>
<UL>
<LI><A href="#intro">Introduction</A></LI>
<LI><A href="#implement">Implementing an extension function</A></LI>
<LI><A href="#install">Installing an extension function</A></LI>
<LI><A href="#use">Using an extension function</A></LI>
</UL><A name="intro"><!--anchor--></A>
  <TABLE border="0" cellpadding="0" cellspacing="0" width="494"><TR><TD bgcolor="666699" colspan="2" width="494"><TABLE border="0" cellpadding="0" cellspacing="0" width="494"><TR><TD bgcolor="#039acc" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#039acc" height="1" width="492"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="492"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#039acc" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" width="492"><FONT color="#ffffff" face="arial,helvetica,sanserif" size="+1"><IMG border="0" height="2" hspace="0" src="resources/void.gif" vspace="0" width="2"><B>Introduction</B></FONT></TD><TD bgcolor="#017299" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#017299" height="1" width="492"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="492"></TD><TD bgcolor="#017299" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE></TD></TR><TR><TD width="10">&nbsp;</TD><TD width="484"><FONT color="#000000" face="arial,helvetica,sanserif">
<P>At times, you may want to call your own custom C functions from a stylesheet. For these situations, Xalan-C++ supports the creation and use of extension functions.</P>
<P>You can think of extension functions as extending the core library of functions that XPath provides. Like the
XPath functions, an extension function returns an XObject, which may contain a value of any of the five XSLT
data types: node-set, result-tree-fragment, string, boolean, or number.</P> 
<P>You can send arguments to an extension function in the form of XPath expressions, literals (for string, boolean, and number), the values returned by other functions, and XSL variables or parameters set to any of the preceding.</P>
<P>For an example that implements, installs, and uses three extension functions, see the 
<A href="samples.html#externalfunctions">External Functions</A> sample.</P>
<TABLE border="0" cellpadding="0" cellspacing="3" width="100%"><TR><TD valign="top" width="20"><IMG alt="Note" border="0" height="24" hspace="0" src="resources/note.gif" vspace="0" width="20"></TD><TD valign="top"><FONT color="#000000" face="arial,helvetica,sanserif" size="-1"><I>Xalan-C++ does not support extension elements.</I></FONT></TD></TR></TABLE>
</FONT></TD></TR></TABLE><BR><A name="implement"><!--anchor--></A>
<TABLE border="0" cellpadding="0" cellspacing="0" width="494"><TR><TD bgcolor="666699" colspan="2" width="494"><TABLE border="0" cellpadding="0" cellspacing="0" width="494"><TR><TD bgcolor="#039acc" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#039acc" height="1" width="492"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="492"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#039acc" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" width="492"><FONT color="#ffffff" face="arial,helvetica,sanserif" size="+1"><IMG border="0" height="2" hspace="0" src="resources/void.gif" vspace="0" width="2"><B>Implementing an extension function</B></FONT></TD><TD bgcolor="#017299" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#017299" height="1" width="492"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="492"></TD><TD bgcolor="#017299" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE></TD></TR><TR><TD width="10">&nbsp;</TD><TD width="484"><FONT color="#000000" face="arial,helvetica,sanserif">
  <P>Like the standard XPath functions, the functions you create derive from the Function base class. Set up your 
  extension function class as follows:</P>
  <OL>
  <LI>The body of a function is the execute() method. Use the appropriate XObjectFactory method -- createNumber()
  in the example below -- to create an XObject corresponding to the XSLT data type the function returns.<BR><BR></LI>
  <LI>Implement a clone() method to enable Xalan to create and maintain a copy of the extension
  function.<BR><BR></LI> 
  <LI>(Optional) As Xalan does for the XPath functions, you may want to prevent the compiler from generating 
  an assignment or equality operator for this function.</LI>
  </OL>
  <P>These features all appear in the following example.</P>
<DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="4" width="464"><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#ffffff" width="462"><FONT size="-1"><PRE>// Base header file.  Must be first.
#include &lt;Include/PlatformDefinitions.hpp&gt;

#include &lt;cmath&gt;
#include &lt;ctime&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;

#include &lt;util/PlatformUtils.hpp&gt;
#include &lt;PlatformSupport/DOMStringHelper.hpp&gt;
#include &lt;DOMSupport/DOMSupportDefault.hpp&gt;
#include &lt;XPath/XObjectFactoryDefault.hpp&gt;
#include &lt;XPath/XPath.hpp&gt;
#include &lt;XPath/XPathSupportDefault.hpp&gt;
#include &lt;XPath/XPathFactoryDefault.hpp&gt;
#include &lt;XSLT/StylesheetConstructionContextDefault.hpp&gt;
#include &lt;XSLT/StylesheetExecutionContextDefault.hpp&gt;
#include &lt;XSLT/XSLTEngineImpl.hpp&gt;
#include &lt;XSLT/XSLTInputSource.hpp&gt;
#include &lt;XSLT/XSLTProcessorEnvSupportDefault.hpp&gt;
#include &lt;XSLT/XSLTResultTarget.hpp&gt;

#include &lt;XercesParserLiaison/XercesDOMSupport.hpp&gt;
#include &lt;XercesParserLiaison/XercesParserLiaison.hpp&gt;

// This class defines a function that will return the square root
// of its argument.
class FunctionSquareRoot : public Function
{
public:

  /**
   * Execute an XPath function object.  The function must return a valid
   * XObject.
   *
   * @param executionContext executing context
   * @param context          current context node
   * @param opPos            current op position
   * @param args             vector of pointers to XObject arguments
   * @return                 pointer to the result XObject
   */
  virtual XObject*
  execute(
      XPathExecutionContext&amp; executionContext,
      XalanNode* context,
      int  /* opPos */,
      const XObjectArgVectorType&amp;    args)
  {
    if (args.size() != 1)
    {
      executionContext.error(&quot;The square-root() function takes one argument!&quot;, 
                              context);
    }
    assert(args[0] != 0);
    // Use the XObjectFactory createNumber() method to create an XObject 
    // corresponding to the XSLT number data type.
    return executionContext.getXObjectFactory().createNumber(
                                                        sqrt(args[0]-&gt;num()));
  }

  /**
   * Implement clone() so Xalan can copy the square-root function into
   * its own function table.
   *
   * @return pointer to the new object
   */
// For compilers that do not support covariant return types,
// clone() must be declared to return the base type.
#if defined(XALAN_NO_COVARIANT_RETURN_TYPE)
  virtual Function*
#else
  virtual FunctionSquareRoot*
#endif
  clone() const
  {
    return new FunctionSquareRoot(*this);
  }

private:
  // The assignment and equality operators are not implemented...
  FunctionSquareRoot&amp;
  operator=(const FunctionSquareRoot&amp;);
  bool
  operator==(const FunctionSquareRoot&amp;) const;
}</PRE></FONT></TD><TD bgcolor="#0086b2" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE></DIV>   
</FONT></TD></TR></TABLE><BR><A name="install"><!--anchor--></A>
<TABLE border="0" cellpadding="0" cellspacing="0" width="494"><TR><TD bgcolor="666699" colspan="2" width="494"><TABLE border="0" cellpadding="0" cellspacing="0" width="494"><TR><TD bgcolor="#039acc" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#039acc" height="1" width="492"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="492"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#039acc" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" width="492"><FONT color="#ffffff" face="arial,helvetica,sanserif" size="+1"><IMG border="0" height="2" hspace="0" src="resources/void.gif" vspace="0" width="2"><B>Installing an extension function</B></FONT></TD><TD bgcolor="#017299" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#017299" height="1" width="492"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="492"></TD><TD bgcolor="#017299" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE></TD></TR><TR><TD width="10">&nbsp;</TD><TD width="484"><FONT color="#000000" face="arial,helvetica,sanserif">
<P>When you set up an XSLT processor, you instantiate an XSLTProcessorEnvSupportDefault object, which provides
methods for installing (and uninstalling) extension functions:</P>
<UL>
  <LI>installExternalFunctionGlobal() is a static method for making a function available globally</LI>
  <LI>installExternalFunctionLocal() makes the function available to the XSLTProcessorEnvSupport instance in which the function is
  installed.</LI>
</UL>
<P>These methods include arguments for the namespace, the function name, and the function implementation.</P>
<TABLE border="0" cellpadding="0" cellspacing="3" width="100%"><TR><TD valign="top" width="20"><IMG alt="Note" border="0" height="24" hspace="0" src="resources/note.gif" vspace="0" width="20"></TD><TD valign="top"><FONT color="#000000" face="arial,helvetica,sanserif" size="-1"><I>These XSLTProcessorEnvSupportDefault methods call XPathEnvSupportDefault methods of the same name which provide 
the actual implementation.</I></FONT></TD></TR></TABLE>
<P>When you install an extension function, the function inhabits the namespace you designate. For information about XML namespaces, see <A href="http://www.w3.org/TR/REC-xml-names/">Namespaces in XML</A>.</P>
<P>The following code fragment installs the square root function defined above as a global function, and binds it to the extension-function name &quot;square-root&quot; in the namespace &quot;http://ExternalFunction.xalan-c.xml.apache.org&quot; so it can be accessed from stylesheets. Keep in mind that the function name does not need to be the same as the name of the function class, and that a function name may be used more than once provided that each function with that name is installed in a different namespace.</P>
<DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="4" width="464"><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#ffffff" width="462"><FONT size="-1"><PRE>// You have created a header file for FunctionSquareRoot.
#include &lt;MyFunctions/FunctionSquareRoot.hpp&gt;
// The namespace...
const XalanDOMString	
    theNamespace(&quot;http://ExternalFunction.xalan-c.xml.apache.org&quot;);
// Install the function in the global space so all processor
// instances can use it.
XSLTProcessorEnvSupportDefault::installExternalFunctionGlobal(
    theNamespace,
    &quot;square-root&quot;,
    FunctionSquareRoot());</PRE></FONT></TD><TD bgcolor="#0086b2" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE></DIV>
<TABLE border="0" cellpadding="0" cellspacing="3" width="100%"><TR><TD valign="top" width="20"><IMG alt="Note" border="0" height="24" hspace="0" src="resources/note.gif" vspace="0" width="20"></TD><TD valign="top"><FONT color="#000000" face="arial,helvetica,sanserif" size="-1"><I>We do not recommend this, but you can also install a function directly into the XPath function table, in which
case it is not really an extension function. The XPath parser treats it like any other XPath function, and no namespace declaration or prefix is involved.</I></FONT></TD></TR></TABLE>
<P>For an example that installs a global extension function, a local extension function, and adds a function to the
 XPath function table, see the <A href="samples.html#externalfunctions">External Functions</A> sample.</P>
</FONT></TD></TR></TABLE><BR><A name="use"><!--anchor--></A>
<TABLE border="0" cellpadding="0" cellspacing="0" width="494"><TR><TD bgcolor="666699" colspan="2" width="494"><TABLE border="0" cellpadding="0" cellspacing="0" width="494"><TR><TD bgcolor="#039acc" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#039acc" height="1" width="492"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="492"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#039acc" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" width="492"><FONT color="#ffffff" face="arial,helvetica,sanserif" size="+1"><IMG border="0" height="2" hspace="0" src="resources/void.gif" vspace="0" width="2"><B>Using an extension function</B></FONT></TD><TD bgcolor="#017299" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#017299" height="1" width="492"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="492"></TD><TD bgcolor="#017299" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE></TD></TR><TR><TD width="10">&nbsp;</TD><TD width="484"><FONT color="#000000" face="arial,helvetica,sanserif">
<P>To use the extension function in a stylesheet, you must do the following:</P>
<OL>
<LI>Declare the extension function namespace.<BR><BR>
<CODE><FONT face="courier, monospaced">xmlns:<I>prefix</I>=<I>URI</I></FONT></CODE><BR><BR>
The <I>prefix</I> identifies the namespace, and <I>URI</I> matches the namespace specified when the function
is installed.<BR><BR>
By default, namespace declarations are included in the transformation output. To exclude namespaces from the output, 
use<BR><BR>
<CODE><FONT face="courier, monospaced">exclude-result-prefixes=&quot;<I>prefix-1 prefix-2 ...</I>&quot;</FONT></CODE><BR><BR>
in the stylesheet element or<BR><BR>
<CODE><FONT face="courier, monospaced">xsl:exclude-result-prefixes=&quot;<I>prefix-1 prefix-2 ...</I>&quot;</FONT></CODE><BR><BR>
in a literal result element or extension element.<BR><BR></LI>
<LI>Call the extension function in the same manner you would call an XPath function. The function name you use in the stylesheet is a Qualified Name (QName) made up of the prefix you declared in step 1 and the function name you specified when you installed the function.<BR><BR>
You can use XPath expressions, literals (for string, boolean, and number), and values returned by other functions to
specify function arguments.</LI></OL>
<P>Suppose, for example, you are working with XML documents containing area elements like
<CODE><FONT face="courier, monospaced">&lt;area value=&quot;397&quot;/&gt;</FONT></CODE>, where the value attribute identifies the area of a square.</P>
<P>The following stylesheet declares the square-root function namespace (the prefix is up to you), instructs 
the processor not to copy the namespace declaration to the result tree, and uses the square-root function to return
the square root of //area/@value:</P>
<DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="4" width="464"><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#ffffff" width="462"><FONT size="-1"><PRE>&lt;?xml version=&quot;1.0&quot;?&gt; 
&lt;xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; 
  version=&quot;1.0&quot;
	xmlns:external=&quot;http://ExternalFunction.xalan-c.xml.apache.org&quot;
  exclude-result-prefixes=&quot;external&quot;&gt;
  
    &lt;xsl:template match=&quot;//area&quot;&gt;
    &lt;out&gt;
      The area of the square is
      &lt;xsl:value-of select=&quot;@value&quot;/&gt; square units.
      The length of each side is 
      &lt;xsl:value-of select=&quot;external:square-root(@value)&quot;/&gt; units
    &lt;/out&gt;</PRE></FONT></TD><TD bgcolor="#0086b2" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE></DIV>
<P>This stylesheet converts  <CODE><FONT face="courier, monospaced">&lt;area value=&quot;397&quot;/&gt;</FONT></CODE> into the following output:</P>
<DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="4" width="464"><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#ffffff" width="462"><FONT size="-1"><PRE>&lt;out&gt;
  The area of the square is 
  397 square units.
  The length of each side is 
  19.9249 units.
&lt;/out&gt;</PRE></FONT></TD><TD bgcolor="#0086b2" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE></DIV>
<P>For a slightly more complex variation on this example,  
see the <A href="samples.html#externalfunctions">External Functions</A> sample.</P>
<TABLE border="0" cellpadding="0" cellspacing="0" width="484"><TR><TD bgcolor="666699" colspan="2" width="484"><TABLE border="0" cellpadding="0" cellspacing="0" width="484"><TR><TD bgcolor="#039acc" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#039acc" height="1" width="482"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="482"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#039acc" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" width="482"><FONT color="#ffffff" face="arial,helvetica,sanserif"><IMG border="0" height="2" hspace="0" src="resources/void.gif" vspace="0" width="2"><B>Passing Nodes to a function</B></FONT></TD><TD bgcolor="#017299" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#017299" height="1" width="482"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="482"></TD><TD bgcolor="#017299" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE></TD></TR><TR><TD width="10">&nbsp;</TD><TD width="474"><FONT color="#000000" face="arial,helvetica,sanserif" size="-1">
<P>Please keep in mind that <B>all</B> LocationPath expressions return a node-set, even if the expression only 
returns a single attribute or a text node (node-sets with one member). You can use the XSLT string() function 
to convert a node-set value to string, and the number() function to convert a node-set value to number (a double).</P>
<P>If you want to pass a node-set to an extension function, set up the function to accept a <A href="apidocs/class_xnodeset.html">XNodeSet</A>.</P>
<P>Suppose, for example, you have a ProcessNodes function class that uses<BR><BR> 
<CODE><FONT face="courier, monospaced">const NodeRefListBase&amp; theNodeList = args[0]-&gt;nodeset();</FONT></CODE><BR><BR>
in the execute() method to get a reference to the node-set.</P>
<P>Assuming you install the function as &quot;ProcessNodes&quot; and use the &quot;node-ext&quot; prefix in a stylesheet to refer to the ProcessNodes function namespace, any of the following function calls are syntactically possible:</P>
<P><CODE><FONT face="courier, monospaced">&lt;!--Process the current node--&gt;</FONT></CODE><BR>
<CODE><FONT face="courier, monospaced">&lt;xsl:variable name=&quot;success&quot; select=&quot;node-ext:ProcessNodes(.)&quot;/&gt;</FONT></CODE></P>
<P><CODE><FONT face="courier, monospaced">&lt;!--Process all nodes in current context--&gt;</FONT></CODE><BR>
<CODE><FONT face="courier, monospaced">&lt;xsl:variable name=&quot;success&quot; select=&quot;node-ext:ProcessNodes(*)&quot;/&gt;</FONT></CODE></P>
<P><CODE><FONT face="courier, monospaced">&lt;!-- Process all nodes --&gt;</FONT></CODE><BR>
<CODE><FONT face="courier, monospaced">&lt;xsl:variable name=&quot;success&quot; select=&quot;node-ext:ProcessNodes(/*)&quot;/&gt;</FONT></CODE></P>
<P><CODE><FONT face="courier, monospaced">&lt;!--Process the foo/baz nodes in current context --&gt;</FONT></CODE><BR>
<CODE><FONT face="courier, monospaced">&lt;xsl:variable name=&quot;success&quot; select=&quot;node-ext:ProcessNodes(foo/baz)&quot;/&gt;</FONT></CODE></P>
<P><CODE><FONT face="courier, monospaced">&lt;!--Process the/foo/baz and /bar/saz nodes --&gt;</FONT></CODE><BR>
<CODE><FONT face="courier, monospaced">&lt;xsl:variable name=&quot;success&quot; select=&quot;node-ext:ProcessNodes(/foo/baz | /bar/saz)&quot;/&gt;</FONT></CODE></P>
<P>The NodeRefListBase is in fact a list of references into the XML document, so keep in mind that getNextSibling(), 
for example, gets you the next sibling in the document, which may not be the next Node in the node-set.</P>
</FONT></TD></TR></TABLE><BR>
</FONT></TD></TR></TABLE><BR>
</TD></TR></TABLE></TD></TR></TABLE><BR><TABLE border="0" cellpadding="0" cellspacing="0" width="620"><TR><TD bgcolor="#0086b2"><IMG height="1" src="images/dot.gif" width="1"></TD></TR><TR><TD align="center"><FONT color="#0086b2" size="-1"><I>
              Copyright &copy; 2000 The Apache Software Foundation.
              All Rights Reserved.
            </I></FONT></TD></TR></TABLE></BODY></HTML>