[FLWOR] Convert string to list


I have a little problem. In my XML-File I have a date in the following format: DD-MM-YYYY (i.e. 15-02-2005) and i would like to order the list after this date. The problem is, that flwor doesn´t recognize this date as a date, it does the sorting in the wrong way (it begins to sort after the day, not after the year, so 13-05-2007 is before 15-02-2005).

I tried to convert the date to a date the DB understands (YYYY-MM-DD), but the reverse()-function doesn´t accept the string which I have created with the replace()-function as a list, so at the end I have again 15-02-2005 instead of 2005-02-15.

Has somebody any idea how to convert the date or to convert the string to a list which can be used in the reverse()-function? Is it possible to do that in the “order by”-clause? Because this is dynamically generated.

Here is the code I use to get the elements from the DB:

{let $item := 
for $p in collection("/db/bka/opu")//OP_OffenePunkte/OP_OffenerPunkt[@ID="ffa29eb7442ac0bdeceb8ab98f5f5e60"]/OP_Prozesse/OP_Prozess
order by replace(reverse((replace($p//OP_Datum, '-', ', '))), ', ', '-') descending
return $p,
$count := count($item),
$begin := 1,
$max := 5,
$end := if($count >= $max) then $max else $count 
for $i in $begin to $end 
let $cur := item-at($item, $i) 

Thanks in advance,


you are definitely not using Tamino, as order by is sort by in Tamino, and replace is not yet supported. But anyway, here is a query that does your job (in Tamino;-)
declare namespace xs = “XML Schema
let $data:=<OP_OffenePunkte><OP_OffenerPunkt ID=“ffa29eb7442ac0bdeceb8ab98f5f5e60”><OP_Prozesse><OP_Prozess ID=“3”><OP_Datum>10-05-2005</OP_Datum></OP_Prozess ><OP_Prozess ID=“1”><OP_Datum>12-04-2005</OP_Datum></OP_Prozess ><OP_Prozess ID=“2”><OP_Datum>11-05-2005</OP_Datum></OP_Prozess ></OP_Prozesse></OP_OffenerPunkt></OP_OffenePunkte>

{let $item := for $pp in
(for $p in $data//OP_OffenePunkte/OP_OffenerPunkt[@ID=“ffa29eb7442ac0bdeceb8ab98f5f5e60”]/OP_Prozesse/OP_Prozess return


xs:date(let $d:=$p/OP_Datum
let $day:=substring-before($d,“-”),
$month := substring-before(substring-after($d,“-”),“-”),
$year := substring-after(substring-after($d,“-”),“-”)
return string-join(($year,$month,$day),“-”))}) sort by (./D
descending ) return $pp/P/OP_Prozess
$count := count($item),
$begin := 1,
$max := 5

for $cur in $item