#796 Ordering by a non-grouping key

eXist-db 2.0
open
XQuery (3)
1
2012-11-27
2012-11-25
Hungerburg
No
0 up votes | 0 down votes | 0%
2 comments

This is with eXist-2.0.RC:

At http://www.w3.org/TR/xquery-30-use-cases/#groupby_q6 the w3c mentions ordering by a non-grouping key - I do not even know, if their example is valid syntax at all. I read it as "my masters voice" though.

The sample there fails in eXist with the message: Cannot compile xquery: exerr:ERROR err:XPST0003: No closing end tag found for element constructor

I would expect both revisions of the code below to be equivalent. The puzzle: are statements ordered like this valid xquery? If so, then eXist does not conform…

for, let, group, let, order

Works in eXist 2.0.RC: anonymous key ordering

xquery version "3.0";

let $zoo :=
    <zoo>
        <dweller kind="dog" name="frodo"/>
        <dweller kind="cat" name="mimi"/>
        <dweller kind="dog" name="nero"/>
        <dweller kind="dog" name="bello"/>
        <dweller kind="cat" name="mitzi"/>
        <dweller kind="cow" name="berta"/>
    </zoo>

return
    <animals>{
        for $dwellers in $zoo//dweller
        let $kind := $dwellers/@kind
        group by $kind
        order by count($dwellers)
        return
            <species kind="{$kind}" count="{count($dwellers)}">{
                for $animal in $dwellers
                order by $animal/@name
                return
                    <animal name="{$animal/@name}"/>
            }</species>
    }</animals>

Fails in eXist 2.0.RC: named key ordering

xquery version "3.0";

let $zoo :=
    <zoo>
        <dweller kind="dog" name="frodo"/>
        <dweller kind="cat" name="mimi"/>
        <dweller kind="dog" name="nero"/>
        <dweller kind="dog" name="bello"/>
        <dweller kind="cat" name="mitzi"/>
        <dweller kind="cow" name="berta"/>
    </zoo>

return
    <animals>{
        for $dwellers in $zoo//dweller
        let $kind := $dwellers/@kind
        group by $kind
        let $count := count($dwellers)
        order by $count
        return
            <species kind="{$kind}" count="{$count}">{
                for $animal in $dwellers
                order by $animal/@name
                return
                    <animal name="{$animal/@name}"/>
            }</species>
    }</animals>

Discussion

  • Dannes Wessels
    Dannes Wessels
    2012-11-27

    • assigned_to: Wolfgang M. Meier
     
  • Dannes Wessels
    Dannes Wessels
    2012-11-27

    • labels: --> XQuery