Changes

Jump to navigation Jump to search
23 bytes removed ,  10:50, 29 July 2020
This article is part of the [[XQuery|XQuery Portal]]. It provides a summary of the most important features of the [httphttps://www.w3.org/TR/xquery-30/ XQuery 3.0] Recommendation.
=Enhanced FLWOR Expressions=
==group by==
FLWOR expressions have been extended to include the [httphttps://www.w3.org/TR/xquery-30/#id-group-by group by] clause, which is well-established in SQL. <code>group by</code> can be used to apply value-based partitioning to query results:
'''XQuery:'''
</syntaxhighlight>
This query is a rewrite of [httphttps://www.ins.cwi.nl/projects/xmark/Assets/xmlquery.txt Query #20] contained in the [httphttps://www.insprojects.cwi.nl/projectsxmark/xmark XMark Benchmark Suite] to use <code>group by</code>.
The query partitions the customers based on their income.
for $n in (1 to 10)[. mod 2 = 1]
count $c
return &lt;<number count="{ $c }" number="{ $n }"/&gt;>
</syntaxhighlight>
start at $s when fn:true()
only end at $e when $e - $s eq 2
return &lt;<window&gt;>{ $w }&lt;</window&gt;>
</syntaxhighlight>
More information on window clauses, and all other enhancements, can be found in the [httphttps://www.w3.org/TR/xquery-30/#id-windows specification].
=Function Items=
=Simple Map Operator=
The [httphttps://www.w3.org/TR/xquery-30/#id-map-operator simple map] operator {{Code|!}} provides a compact notation for applying the results of a first to a second expression: the resulting items of the first expression are bound to the context item one by one, and the second expression is evaluated for each item. The map operator may be used as replacement for FLWOR expressions:
'''Example:'''
=Try/Catch=
The [httphttps://www.w3.org/TR/xquery-30/#id-try-catch try/catch] construct can be used to handle errors at runtime:
'''Example:'''
=Switch=
The [httphttps://www.w3.org/TR/xquery-30/#id-switch switch] statement is available in many other programming languages. It chooses one of several expressions to evaluate based on its input value.
'''Example:'''
declare option output:omit-xml-declaration "no";
declare option output:method "xhtml";
&lt;<html/&gt;>
</syntaxhighlight>
'''Result:''' <code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;html&gt;&lt;/html&gt;</code>
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu