Last modified on 15 March 2010, at 23:18

XQuery/Registered Functions

MotivationEdit

You want a list of all functions or all modules and their functions.

MethodEdit

There are two functions that we can use to get a list of functions in the current run-time system:

  util:registered-functions()
  util:registered-functions($module)

The first function returns all registered functions, the second returns all registered functions for a given module.

List all registered functionsEdit

The following XQuery creates a list of all the XQuery functions in alphabetical order. The output will depend on the modules configured in the installation.

xquery version "1.0";
import module namespace util = "http://exist-db.org/xquery/util"; 
<results>{
   for $function in util:registered-functions()
   order by $function
   return
     <function>{ $function}</function>
   }
    <total-count>{count(util:registered-functions())}</total-count>
</results>

Run

<results>
    <function>compression:gzip</function>
    <function>compression:tar</function>
    <function>compression:zip</function>
    <function>datetime:count-day-in-month</function>
    <function>datetime:date-for</function>
    ...


Note that if there is no namespace prefix, the function is an XPath library function. (or the math module which also appears without a prefix ??)

Listing all functions by moduleEdit

A more useful format would be to list functions by module:

xquery version "1.0";
import module namespace util = "http://exist-db.org/xquery/util";
<results>{
   for $module in util:registered-modules()
   order by $module
   return
   <module>
      <module-uri>{$module}</module-uri>
      {for $function in util:registered-functions($module)
       order by $function
       return
            <function>{$function}</function>
      }
   </module>
   }
</results>

Run

Sample Output:

<results>
    <module>
        <module-uri>http://exist-db.org/xquery/compression</module-uri>
        <function>compression:gzip</function>
        <function>compression:tar</function>
        <function>compression:zip</function>
    </module>
 
    <module>
        <module-name>http://exist-db.org/xquery/datetime</module-name>
        <function>datetime:count-day-in-month</function>
        <function>datetime:date-for</function>
 
    ...