Loading TOC...

xdmp:apply

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 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)

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.

Comments

The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.
  • So is there any particular advantage in using the xdmp:apply function instead of say a normal procedure like directly implementing the functions we need?
    • @Guruji_89:disqus This article talks about higher-order functions and why you might wish to use them: http://www.joelonsoftware.com/items/2006/08/01.html I think that it answers your question but is an interesting read anyway even if it doesn't There are other ways to implement this pattern in XQuery 3.0, but xdmp:apply existed before XQuery 3.0 came out
    • I am using this function to implement a Workflow importer (conversion to CPF pipelines). For a particular element name I find in the process model I'm invoking a function for that element name, where the function name contains the element name. This enables me to avoid case/switch or if/then/else statements - it becomes a one liner! The same function could be used to implement callbacks within XQuery.