0

I learned xdmp:value function.

Use like this

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

Then, I get 5.

What is difference when I write this:

let $var := 5
return $var

I also get 5 here. Maybe I miss some points.

Please explain this function.

THANKS IN ADVANCE.

Prince Vegeta
  • 719
  • 6
  • 21
tesnirs
  • 57
  • 6

1 Answers1

4

There's really no difference if you use xdmp:value() or not in your example. Although I'd caution against using xdmp:value() unnecessarily in order to maximize your query performance.

One of the most common use cases for xdmp:value() is to evaluate a string of text as code without losing context (such as you would with xdmp:eval()).

For example:

let $x := 1
return xdmp:value("$x + 1")

Another common use case for xdmp:value() is to integrate a variable into an XPath expression dynamically.

For example:

/path/to/mystery/element/xdmp:value($elementName)
Rob S.
  • 3,599
  • 6
  • 30
  • 39