Loading TOC...

xdmp:value

xdmp:value(
   $expr as xs:string,
   [$map as map:map?],
   [$context as item()?]
) as item()*

Summary

Evaluate an expression in the context of the current evaluating statement. This differs from xdmp:eval in that xdmp:value preserves all of the context from the calling query, so you do not need to re-define namespaces, variables, and so on. Although the expression retains the context from the calling query, it is evaluated in its own transaction with same-statement isolation.

Parameters
$expr The string representing an expression to evaluate.
$map A map of namespace bindings. The keys should be namespace prefixes and the values should be namespace URIs. These namespace bindings will be added to the in-scope namespace bindings in the evaluation of the expression.
$context Bind the context item to this value during evaluation of the expression.

Required Privileges

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

Usage Notes

You can only evaluate expressions with xdmp:value; no prolog definitions (namespace declarations, function definitions, module imports, and so on) are allowed.

If the expression references something not in the context of either the calling query or the value expression, then an error is thrown. For example, the following throws an undefined variable exception:

xdmp:value("$y")

Example

  let $var := 5
  return
  xdmp:value("$var")
  => 5
  

Example

xquery version "1.0-ml";

xdmp:document-insert("/test.xml",
 <root>
   <step1>this is step1</step1>
   <step2>this is step2</step2>
 </root>)
;

(:
use xdmp:value to dynamically specify a step
in an XPath expression
:)
for $x in ("step1", "step2")
return
/root/xdmp:value($x)

=>
<step1>this is step1</step1>
<step2>this is step2</step2>
  

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.
  • "Although the expression retains the context from the calling query, it is evaluated in its own transaction with same-statement isolation" Is this correct? A simple test would seem to indicate that it is the same transaction: <pre><code> xdmp:transaction() eq xdmp:value("xdmp:transaction()") => true </code></pre> Behaviour when attempting to mix query and update transactions backs this up. Seems like xdmp:value() actually has the same semantics as xdmp:eval() in 'same-statement' isolation mode.