'''Example:'''
<syntaxhighlight pre lang="'xquery"'>
for $country in db:get('factbook')//country
where $country/@population > 100000000
'''XQuery:'''
<syntaxhighlight pre lang="'xquery"'>
for $ppl in doc('xmark')//people/person
let $ic := $ppl/profile/@income
In contrast to the relational GROUP BY statement, the XQuery counterpart concatenates the values of all non-grouping variables that belong to a specific group. In the context of our example, all nodes in <code>//people/person</code> that belong to the <code>preferred</code> partition are concatenated in <code class="brush:xquery">$ppl</code> after grouping has finished. You can see this effect by changing the return statement to:
<syntaxhighlight pre lang="'xquery"'>
...
return element { $income } { $ppl }
'''XQuery:'''
<syntaxhighlight pre lang="'xquery"'>
let $data :=
<xml>
The {{Code|count}} clause enhances the FLWOR expression with a variable that enumerates the iterated tuples.
<syntaxhighlight pre lang="'xquery"'>
for $n in (1 to 10)[. mod 2 = 1]
count $c
The {{Code|allowing empty}} provides functionality similar to outer joins in SQL:
<syntaxhighlight pre lang="'xquery"'>
for $n allowing empty in ()
return 'empty? ' || empty($n)
Window clauses provide a rich set of variable declarations to process sub-sequences of iterated tuples. An example:
<syntaxhighlight pre lang="'xquery"'>
for tumbling window $w in (2, 4, 6, 8, 10, 12, 14)
start at $s when true()
<ul>
<li>Declaring a new ''inline function'':
<syntaxhighlight pre lang="'xquery"'>let $f := function($x, $y) { $x + $y }
return $f(17, 25)</syntaxhighlight>
'''Result:''' <code>42</code>
</li>
<li>Getting the function item of an existing (built-in or user-defined) XQuery function. The arity (number of arguments) has to be specified as there can be more than one function with the same name:
<syntaxhighlight pre lang="'xquery"'>let $f := math:pow#2
return $f(5, 2)</syntaxhighlight>
'''Result:''' <code>25</code>
</li>
<li>''Partially applying'' another function or function item. This is done by supplying only some of the required arguments, writing the placeholder <code>?</code> in the positions of the arguments left out. The produced function item has one argument for every placeholder.
<syntaxhighlight pre lang="'xquery"'>let $f := substring(?, 1, 3)
return (
$f('foo123'),
'''Example:'''
<syntaxhighlight pre lang="'xquery"'>
(: Simple map notation :)
(1 to 10) ! element node { . },
'''Example:'''
<syntaxhighlight pre lang="'xquery"'>
try {
1 + '2'
'''Example:'''
<syntaxhighlight pre lang="'xquery"'>
for $fruit in ("Apple", "Pear", "Peach")
return switch ($fruit)
'''Example:'''
<syntaxhighlight pre lang="'xquery"'>
for $fruit in ("Apple", "Cherry")
return switch ($fruit)
New namespaces can be created via so-called 'Computed Namespace Constructors'.
<syntaxhighlight pre lang="'xquery"'>
element node { namespace pref { 'http://url.org/' } }
</syntaxhighlight>
Two vertical bars <code>||</code> (also named ''pipe characters'') can be used to concatenate strings. This operator is a shortcut for the {{Code|concat()}} function.
<syntaxhighlight pre lang="'xquery"'>
'Hello' || ' ' || 'Universe'
</syntaxhighlight>
Default values can be attached to external variable declarations. This way, an expression can also be evaluated if its external variables have not been bound to a new value.
<syntaxhighlight pre lang="'xquery"'>
declare variable $user external := "admin";
"User:", $user
'''Example:'''
<syntaxhighlight pre lang="'xquery"'>
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:omit-xml-declaration "no";
'''Example:'''
<syntaxhighlight pre lang="'xquery"'>
declare context item := document {
<xml>
'''Example:'''
<syntaxhighlight pre lang="'xquery"'>
declare %private function local:max($x1, $x2) {
if($x1 > $x2) then $x1 else $x2