Pragya Kapoor wrote:
Hi,
> I need to sort the xml on element A.
> let $result :=
> <x><z><A>1000</A><A>10</A><A>117</A><A>61</A><A>971</A></z></x>
> for $y in $result
> order by $y/x/z descending
> return $y
> Let me know what I am missing.
That's hard to tell without knowing what you precisely want to
get. Usually it helps to post your actual result and and example
of what you want.
In the above query, you loop over one element ($result is the
one element 'x' and "for $y in $result" will loop over that
single element). BTW $y/x/z doe snot select anything because the
element 'x' has not itself any child element named 'x'.
If you want to return the elements 'A' in an ordered sequence,
you can use the following (note also that the ordering is a
numerical one, but you can use the string value instead):
let $result := ...
for $a in $result/z/A
order by xs:integer($a) descending
return
$a
If you want to create a new element 'x' with the same structure
but another order for the elements 'A', then something like the
following (or maybe more complex depending on your exact needs):
<x>
<z> {
let $result := ...
for $a in $result/z/A
order by xs:integer($a) descending
return
$a
}
</z>
</x>
Regards,
--
Florent Georges
http://fgeorges.org/
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general