Loading TOC...

xdmp:annotation

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

xquery version "1.0-ml";

declare %local:annotation(1,2,"foo")
  function local:function() { () };
  
xdmp:annotation(local:function#0,xs:QName("local:annotation"))
=> (1, 2, "foo")

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.
  • adding annotations to function declarations is a method of relating out of band metadata to a function. the following example illustrates the usage of annotations declare namespace ex="http//example.org/ns"; declare  function ex:check-project-not-archive($project) { if(name($project) eq "project" and $project/@archive) then fn:true() else () }; declare %ex:unit-test function ex:check-project-exists($project) {   exists($project) }; declare %ex:unit-test("complex") function ex:check-project-not-empty($project) { if(name($project) eq "project" and $project/task) then fn:true() else () }; for $f in xdmp:functions() return if(xdmp:annotation($f,fn:QName("http//example.org/ns","unit-test")) ) then ( fn:function-name($f) || ": " || xdmp:annotation($f,fn:QName("http//example.org/ns","unit-test")) ) else () we use xdmp:functions() to provide a list of function items that are available and test each if they contain an annotation. fn:function-name() prints out the name of those functions which contain annotations along with either a boolean value to indicate existence or a value supplied by the annotation itself e.g. you will notice how %ex:unit-test("complex") returns the string 'complex'.