Changes

Jump to navigation Jump to search
666 bytes added ,  20:23, 30 October 2014
FLWOR expressions have been extended to include the [http://www.w3.org/TR/xquery-30/#id-group-by group by] clause, which is well-established among relational database systems. <code>group by</code> can be used to apply value-based partitioning to query results:
'''ExampleXQuery:'''
<pre class="brush:xquery">
for $ppl in doc('xmark')//people/person
order by $income
return element { $income } { count($ppl) }
 
</pre>
return element { $income } { $ppl }
</pre>
 
'''Result:'''
<pre class="brush:xml">
</challenge>
</pre>
 
Moreover, a value can be assigned to the grouping variable. This is shown in the following example:
 
'''XQuery:'''
<pre class="brush:xquery">
let $data :=
<xml>
<person country='USA' name='John'/>
<person country='USA' name='Jack'/>
<person country='Germany' name='Johann'/>
</xml>
for $person in $data/person
group by $country := $person/@country/string()
return element persons {
attribute country { $country },
$person/@name ! element name { data() }
}
</pre>
 
'''Result:'''
<pre class="brush:xml">
<persons country="USA">
<name>John</name>
<name>Jack</name>
</persons>
<persons country="Germany">
<name>Johann</name>
</persons>
</pre>
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu