Hi Violeta!
Currently, the "order by" clause of the
FLWOR-expression is not supported in Sedna.
However, if you want to get the result ordered by
an attribute value, you can use the following XQuery query as an
example:
(: Lower-level function :)
declare function
local:insert_in_proper_position(
$e as node(), $seq as node()*,
$attr_name as xs:string) as node()* {
if( empty($seq) )
then
$e
else
if(
$e/ <at> *[name(.) eq
$attr_name] < $seq[position()=1]/ <at> *[name(.) eq $attr_name] )
then
($e, $seq)
else
($seq[position()=1],
local:insert_in_proper_position($e, $seq[position() > 1],
$attr_name))
};
(: Sorts a sequence $seq in the ascending order of
attribute that has the
name $attr_name :)
declare function
local:sort_by_attr($seq as node()*, $attr_name as xs:string)
as
node()* {
if( empty($seq) ) (: Empty is sorted
:)
then ()
else
local:insert_in_proper_position(
$seq[position()=1],
local:sort_by_attr($seq[position() > 1],
$attr_name),
$attr_name)
};
(: Sort result in the ascending order of the attribute "a"
:)
local:sort_by_attr(
for $n in (8, 5, 3, 1,
9)
return
<elem>{attribute {"a"}
{$n},
"text"}</elem>,
"a"
)
The above XQuery query returns the following
reordered sequence:
<elem a="1">text</elem>
<elem a="3">text</elem>
<elem a="5">text</elem>
<elem a="8">text</elem>
<elem
a="9">text</elem>
If you need the result sorted in descending order,
you can apply the local:reverse function to a sequence afterwards:
declare function local:reverse($s as item()*) as
item()* {
if (empty($s)) then ()
else (
local:reverse($s[position()>1]), $s[position()=1] )
};
Hope this helps
you.
Dmitry,
Sedna team
----- Original Message -----
Sent: Thursday, July 14, 2005 10:11
PM
Subject: [Sedna-discussion] XQuery -
order by Clause
Hi Sedna Team,
I would like to know if Sedna supports the XQuery FLWOR expression. I
would like to get the result ordered by an attribute value and I got the
following error
XQuery parser syntax error
Details: unexpected token: 'order' , line 3
How can I get the result from an XQuery ordered ascending or
descending?
Thank you.
Violeta
__________________________________________________
Do You
Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com