Loading TOC...


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


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. If the module-path ends with a file extension matching the ones configured for application/vnd.marklogic-javascript in your MarkLogic Mimetypes configuration, and the function's namespace URI is empty, the module is considered to be JavaScript. In this case, the function parameter can be empty.

$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 when the function is used with xdmp:apply.
$module-path 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).


xquery version "1.0-ml";



xquery version "1.0-ml";

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



xquery version "1.0-ml";

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

=> hello world

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


The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.
  • This also works with XQuery 3.0 calling syntax, which is a bit cleaner than xdmp:apply. let $fn := xdmp:function(xs:QName('fn:concat')) return $fn('a', 'b') Caveat: don't name your function variable $function or you'll confuse the parser (as of 7.0-2.1 anyway)
    • Is there any way to do this without using xdmp:function? It seems like in the specs all they say is just $f(parameters) - they never say what type $f is. I've also seen syntax like let $f := fn:concat#2 How does that work here? I thought I could use that syntax, but I get some "not a singleton function value" that apparently no one else has had.
      • That sounds more like XQuery 3.0 inline function expressions. Good question for http://stackoverflow.com/questions/tagged/marklogic or http://developer.marklogic.com/mailman/listinfo/general - or https://github.com/mblakele/taskbot/blob/master/src/taskbot.xqm has some examples. But it's getting off topic for xdmp:function.