When I look up XQuery examples i sometimes see the operator =>
used.
I tried searching for the meaning of it, but could not find anything. Since i am using MarkLogic, it is possible that it is only for MarkLogic, but i doubt that.
From the examples i am aware that it somehow chains functions together, but i would like to know what is happening.
These are some examples i have found:
let $map := map:map()
=>map:with("some-key",<info>45683</info>)
return <result>{$map}</result>
let $employees := op:from-view("main", "employees")
let $expenses := op:from-view("main", "expenses")
let $totalexpenses := op:col("totalexpenses")
return $employees
=> op:join-inner($expenses, op:on(
op:view-col("employees", "EmployeeID"),
op:view-col("expenses", "EmployeeID")))
=> op:group-by(op:view-col("employees", "EmployeeID"),
("FirstName", "LastName",
op:view-col("expenses", "Category"),
op:sum($totalexpenses,
op:view-col("expenses", "Amount"))))
=> op:order-by(op:view-col("employees", "EmployeeID"))
=> op:result()
XQuery (like XSLT and XPath before it) has extended the concept of XML names and namespaces by using namespace-qualified names not only for elements and attributes, but also for variables and functions. The namespace prefix "local" is just a shorthand for the real name of the namespace.
XQuery provides the following types of comparison operators: General comparison operators. Value comparison operators. Node comparison operators.
Every mapping is a relation but every relation is not a mapping.
It is the Arrow Operator, which lets you supply the first argument to a function call from the outside.So if you have a function call foo($a, $b, $c)
, you can equivalently write it as $a => foo($b, $c)
. This is handy if you have lots of nested function calls as first arguments:
string-join(reverse(tokenize(upper-case('a;b;c'), ';')), '_')
With the arrow operator this can be written as a nice pipeline
'a;b;c' => upper-case() => tokenize(';') => reverse() => string-join('_')
giving the same result "C_B_A"
.
One disadvantage of the arrow operator is that you have to take it into account when you want to find out at a glance which function is referenced by a function call in XQuery code. If you declared the two functions local:foo($seq) {...}
and local:foo($seq, $accum) {...}
, then $asdf => local:foo($x)
looks like it calls the one-argument version, but actually calls the two-argument variant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With