Loading TOC...

xdmp:invoke

xdmp:invoke(
   $path as xs:string,
   [$vars as item()*],
   [$options as (element()|map:map)?]
) as item()*

Summary

Returns the result of evaluating a module at the given path.

Parameters
path The path of the module to be executed as a string. The path is resolved against the root of the App Server evaluating the query, the Modules directory, or relative to the calling module. The module is considered to be JavaScript if the module path ends with a file extension matching the ones configured for application/vnd.marklogic-javascript in MarkLogic's Mimetypes configuration. For details on resolving paths, see "Importing XQuery Modules and Resolving Paths" in the Application Developer's Guide.
$vars The external variable values for this evaluation. This can either be a sequence of map:map objects, or a sequence of even length, alternating QNames and items.

Each key in the map(s) is a string representing the name of the parameter in Clark notation: "{namespaceURI}localname". The function xdmp:key-from-QName is a convenient way to generate these keys. Each entry in the map is the value of the corresponding external variable.

Alternatively, the alternating sequence should contain QName and item pairs that specify a variable name and value for an external variable.

options The options node. The default value is (). The node must be in the xdmp:eval namespace. See the xdmp:eval section for a list of options.

Required Privileges

http://marklogic.com/xdmp/privileges/xdmp-invoke

Example

  xdmp:invoke("http://example.com/modules/foo.xqy")
  => 2

Example

  This example invokes a module using external variables.
 
  Assume you have a module in the modules database with a URI
  "http://example.com/application/module.xqy" containing the
  following code:

  xquery version "1.0-ml";
  declare namespace my="my-namespace-uri";
  declare variable $my:var as xs:string external;
  xdmp:log($my:var)

  Then you can call this module using xdmp:invoke as follows:

  xquery version "1.0-ml";
  declare namespace my="my-namespace-uri";
  xdmp:invoke("module.xqy",
        (xs:QName("my:var"), "log this to ErrorLog.txt"),
        <options xmlns="xdmp:eval">
          <modules>{xdmp:modules-database()}</modules>
	  <root>http://example.com/application/</root>
         </options>)
	
  => Invokes an XQuery module from the modules database
     with the URI http://example.com/application/module.xqy.
     The invoked module will then be executed, logging the
     message sent in the external variable to the log file. 

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