This page was generated
June  25,  2015
8:15  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:annotation Returns the named annotation from the function.
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.
xdmp:function-parameter-name Returns the name of the parameter at the designated (1-based) position from the given function's signature.
xdmp:function-parameter-type Returns the type of the parameter at the designated (1-based) position from the given function's signature.
xdmp:function-return-type Returns the return type from the given function's signature.
xdmp:function-signature Returns the signature of the function that the argument refers to.
xdmp:functions Returns all in-scope functions.
Function Detail
xdmp:annotation(
$function as function(*),
$name as xs:QName
)  as   item()*
Summary:

Returns the named annotation from the function.

Parameters:
$function : The function value.
$name : The annotation name.

Example:

            

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"

xdmp:function-parameter-name(
$function as function(*),
$position as xs:integer
)  as   xs:QName
Summary:

Returns the name of the parameter at the designated (1-based) position from the given function's signature.

Parameters:
$function : The function value.
$position : The 1-based position of the parameter.

Example:

            

xdmp:function-parameter-type(
$function as function(*),
$position as xs:integer
)  as   xs:string
Summary:

Returns the type of the parameter at the designated (1-based) position from the given function's signature.

Parameters:
$function : The function value.
$position : The 1-based position of the parameter.

Example:

            

xdmp:function-return-type(
$function as function(*)
)  as   xs:string
Summary:

Returns the return type from the given function's signature.

Parameters:
$function : The function value.

Example:

            

xdmp:function-signature(
$function as function(*)
)  as   xs:string?
Summary:

Returns the signature of the function that the argument refers to.

Parameters:
$function : The function value.

Example:

            

xdmp:functions(  ) as  function(*)*
Summary:

Returns all in-scope functions.

Example: