Changes

Jump to navigation Jump to search
542 bytes added ,  15:50, 31 October 2018
{{Mark|Introduced with Version 9.1:}} ternary if, elvis operator, if without else
 
Some of the extensions that have been added to BaseX may also be made available in other XQuery processors in the near future.
==Ternary If==
The [https://en.wikipedia.org/wiki/%3F: ternary if] operator provides a short syntax for conditions. It is also called '''conditional operator''' or '''ternary operator'''. In most languages the syntax is <code>a ? b : c</code>. As <code>?</code> and <code>:</code> have already been taken in XQuery, the syntax of Perl 6 syntax is used:
<pre class="brush:xquery">
==Elvis Operator==
The Elvis operator returns is also available in other languages; it is sometimes called [https://en.wikipedia.org/wiki/Null_coalescing_operator](null-coalescing operator). The value of the first operand will be returned if it’s it is a non-empty sequence. Otherwise, or the value of the second operand otherwisewill be returned. It is equivalent to the {{Function|Utility|util:or}} function:
<pre class="brush:xquery">
let $number := 123return ( (: if/then/else :) if (exists($number)) then $number else 0, (: function call :) util:or($number, 0), (: elvis operator :) $number ?: 0)
</pre>
 
It is equivalent to the {{Function|Utility|util:or}} function.
==If Without Else==
In the XQuery standard3.1, both branches of the <code>if</code> expression need to be specified. As in In many cases, only one branch is required, so the <code>else</code> branch is was made optional in BaseX. If the second branch is omitted, an empty sequence is will be returned if the effective boolean value of the test expression is false. Some examples:
<pre class="brush:xquery">
</pre>
As in other languagesIn general, it is recommendable to use if you have multiple of nested if expressions, additional parentheses to make a query better readablecan improve the readibility of your code:
<pre class="brush:xquery">
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu