Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

XQuery/Registered Functions

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Motivation You want a list of all functions or all modules and their functions. Method 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 functions 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 module 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> {let $functions := util:catch("*",util:registered-functions($module), ()) (: added because one module (console ) has a missing namespace and throws an error - not sure why :) return if (exists($functions)) then for $function in $functions order by $function return <function>{$function}</function> else <error>Namespace undefined</error> } </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> ...