Loading TOC...

fn:function-lookup

fn:function-lookup(
   $name as xs:QName,
   $arity as xs:integer
) as function(*)?

Summary

Returns a function with the given name and arity, or the empty sequence if none exists. You can use the returned function reference with xdmp:apply. For more details, see XPath 3.0 Functions and Operators.

Parameters
$name The QName of the function.
$arity The number of arguments the function takes.

Example

let $fn := fn:function-lookup(fn:QName("http://www.w3.org/2005/xpath-functions","concat"),4)
return
  xdmp:function-signature($fn)
=> "function(xs:anyAtomicType?, xs:anyAtomicType?, xs:anyAtomicType?, xs:anyAtomicType?) as xs:string"

Example

let $fn := fn:function-lookup(
  fn:QName("http://www.w3.org/2005/xpath-functions","concat"),4)
return
xdmp:apply($fn, "here", "is", "an", "example")

==> "hereisanexample"

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

Comments

  • Would love to see more examples of calling this function and using the return as part of the code.
    • fn:function-lookup returns a function reference, which can then be passed to xdmp:apply. Building on the provided example: let $fn := fn:function-lookup(fn:QName("http://www.w3.org/2005/xpath-functions","concat"),4) return xdmp:apply($fn, "here", "is", "an", "example") => "hereisanexample" And another example: let $str-ct := xdmp:random(4) + 1 let $strs as xs:string* := for $i in (1 to $str-ct) return xs:string($i) let $fn := fn:function-lookup(fn:QName("http://www.w3.org/2005/xpath-functions","string-join"),2) return xdmp:apply($fn, $strs, ", ")
      • Thanks David! I have tested and confirmed that you can also use the function without having to use xdmp:apply(). You can call it like any other function, as long as you pass the # of variables you define in the arity value you set when calling fn:function-lookup().
        • Neat, I didn't realize you could do that. let $str-ct := xdmp:random(4) + 1 let $strs as xs:string* := for $i in (1 to $str-ct) return xs:string($i) let $fn := fn:function-lookup(fn:QName("http://www.w3.org/2005/xpath-functions","string-join"),2) return $fn($strs, ", ")