1. Registering custom spreadsheet functions with XXE
Prev | Chapter 5. Defining custom spreadsheet functions | Next

## 1. Registering custom spreadsheet functions with XXE

Custom spreadsheet functions must be defined in an XML document conforming to (XMLmind proprietary) W3C XML Schema having `http://www.xmlmind.com/xmleditor/schema/spreadsheet/functions` as its target namespace.

Example, `myspreadsheetfunctions.xml` (found in ``XXE_install_dir`/doc/spreadsheet/custom_functions/`)

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <f:functions xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:ns="http://www.w3.org/1999/xhtml"
                 xmlns:f="http://www.xmlmind.com/xmleditor/schema/spreadsheet/functions">
      <f:function>
        <f:name>factorial</f:name>
        <f:parameters>n</f:parameters>
        <f:category>Mathematical</f:category>
        <f:description>
          <body>
            <p>Returns the factorial of <i>n</i>.</p>
          </body>
        </f:description>
        <f:macro><![CDATA[= if(n = 1, 1, n*factorial(n-1))]]></f:macro>
      </f:function>
    </f:functions>

This XML document must be referenced in an XXE configuration file using configuration element `spreadsheetFunctions`. See Section 24, “spreadsheetFunctions” in XMLmind XML Editor - Configuration and Deployment.

- If you add this to ``XXE_user_preferences_dir`/addon/customize.xxe` (after copying `myspreadsheetfunctions.xml` to ``XXE_user_preferences_dir`/addon/`):

      <spreadsheetFunctions location="myspreadsheetfunctions.xml" />

  you'll be able to use custom function `factorial()` whatever is the type of the document that you open in XXE. That is, function `factorial()` and its documentation will always show up in the Formula Editor, just like `sin()` or `cos()`.

- If you add this to an XXE configuration file which is specific to an XML application, for example ``XXE_install_dir`/addon/config/docbook/docbook.xxe` (after copying `myspreadsheetfunctions.xml` to ``XXE_install_dir`/addon/config/docbook/`):

      <spreadsheetFunctions location="myspreadsheetfunctions.xml" />

  you'll be able to use custom function `factorial()` only when you open a DocBook document.

Prev | Up | Next
Chapter 5. Defining custom spreadsheet functions | Home | 2. Specifying custom spreadsheet functions