This page was generated
September  12,  2012
5:59  AM
XQuery & XSLT Built-In & Modules Function Reference

Built-In: Extension - Function Values Functions

The function values functions allow you to pass a function value as a parameter to another function. You can also pass in the location of the implementation of a function, allowing the caller to specify a different version of a function to use in the context of making that function.

Function Summary
xdmp:apply Applies an xdmp:function with the given parameters.
xdmp:function Returns a function value as an xdmp:function type.
xdmp:function-module Returns the module location (if any) that the xdmp:function value refers to.
xdmp:function-name Returns the QName of the function(s) that the xdmp:function refers to.
Function Detail
xdmp:apply(
$function as xdmp:function,
[$params-1-to-N as item()*]
)  as   item()*
Summary:

Applies an xdmp:function with the given parameters.

Parameters:
$function : The xdmp:function value to be applied.
$params-1-to-N (optional): The parameters to pass into the specified function value. Specify one parameter for each parameter that the specified function takes, with the first parameter corresponding to the first parameter in the specified function's signature, the second parameter corresponding to the second, and so on. Omit this parameter if the specified function takes no parameters.

Example:
  let $function := xdmp:function(xs:QName("fn:empty"))
  return
    xdmp:apply($function, ())

  => true
Example:
  let $function := xdmp:function(xs:QName("fn:concat"))
  return
    xdmp:apply($function, "hello", " world")

  => hello world
Example:
  let $function := xdmp:function(xs:QName("fn:current-date"))
  return
    xdmp:apply($function)

  => 2009-02-14-08:00  (or whatever is the current date)

xdmp:function(
$function as xs:QName,
[$module-path as xs:string?]
)  as   xdmp:function
Summary:

Returns a function value as an xdmp:function type. You can return an xdmp:function from an expression or a function. You can execute the function referred to by an xdmp:function by passing the xdmp:function value to xdmp:apply.

Parameters:
$function : The function QName, which includes its local name and namespace. If the function is not found in the current query context or in the module specified in the second parameter, then an exception is thrown.
$module-path (optional): The optional path to the module where the function specified in the first parameter is defined. If the module-path is not supplied, the function QName must be in-scope in the query context. If the empty sequence is supplied, the function behaves as if the parameter is not supplied (that is, it uses the in-scope query context).

Example:
xquery version "1.0-ml";

xdmp:function(xs:QName("fn:empty"))
Example:
xquery version "1.0-ml";

declare namespace admin="http://marklogic.com/xdmp/admin";

xdmp:function(xs:QName("admin:get-configuration"), 
      "/MarkLogic/admin.xqy")
Example:
xquery version "1.0-ml";

let $function := xdmp:function(xs:QName("fn:concat"))
return
   xdmp:apply($function, "hello", " world")

=> hello world

xdmp:function-module(
$function as xdmp:function
)  as   xs:string
Summary:

Returns the module location (if any) that the xdmp:function value refers to.

Parameters:
$function : The function value.

Example:
  let $fn := xdmp:function(xs:QName("admin:get-configuration"),"/MarkLogic/admin.xqy")
  return
    xdmp:function-module($fn)
  ==> "/MarkLogic/admin.xqy"

xdmp:function-name(
$function as xdmp:function
)  as   xs:QName
Summary:

Returns the QName of the function(s) that the xdmp:function refers to.

Parameters:
$function : The xdmp:function value.

Example:
  let $fn := xdmp:function(xs:QName("fn:empty"))
  return
    xdmp:function-name($fn)
  ==> "fn:empty"