0

Is there any way to preserve sort order in xquery? My problem is that the data has to get passed to the MVC framework's get-response() function on the return, so I think it's automatically reverting to document order. I thought that doing the sort right in the first paramter of the subsequence() function would capture the first 'n' items after they are sorted, but it does not. I also tried having the $search-results parameter sorted before the call to subsequence(), but that did not work either. See the following code:

let $data := 
    <figures count="{$count}" 
             mediatypes="{$mtypes}"
             start="{$start}"
             end="{$start+$myns:image-paging-default}"

             page="{$page}" 
             increment="{$myns:image-paging-default}" 
             total-pages="{
               if ($count lt $myns:image-paging-default) then 
                   1 
               else 
                   ceiling(($count + 1) div $myns:image-paging-default)
             }"
             { 
               subsequence(
                 (  for $item in ($search-results)
                    order by $item//figure/@ftype descending
                    return $item), 
                 $start, 
                 $myns:image-paging-default) 
             }          
    </figures>
let $sidebar :=  xdmp:get-server-field('imagefacets')
return utils:get-response($req, ($data,$sidebar) )
Sofia
  • 771
  • 1
  • 8
  • 22
kalinma
  • 486
  • 5
  • 16
  • Are you saying that the `$data` passed to `utils:get-response` is not ordered as it is in this flwor? – wst Jul 03 '13 at 22:09
  • Nothing obviously wrong here, so I'd focus on making sure the symptoms are real. How confident are you that the results are not sorted as specified? How confident are you $item//figure/@ftype is returning a single atomic value? – C. M. Sperberg-McQueen Jul 03 '13 at 22:57
  • Yes, I'm sure the results are not sorted as specified and I also certain that @ftype is an atomic value, specifically a string, that is one of two values. The $data that is passed to utils:get-response() probably is sorted, but what I'm getting back from that function is not. – kalinma Jul 08 '13 at 19:25
  • possible duplicate of [Questions About Sort Order Using XQuery in SQL Server](http://stackoverflow.com/questions/15258516/questions-about-sort-order-using-xquery-in-sql-server) – Paul Sweatte Jun 24 '14 at 16:26

0 Answers0