I was afraid that something was doing exactly that--resetting to document 
order. I'm guessing that using the function fn:subsequence() is the culprit.

Thanks,
Mary Kalinosky
Senior Technical Developer, eProducts
Thieme Medical Publishers
333 Seventh Avenue, New York, NY 10001 USA
Ruedigerstrasse 14, 70469 Stuttgart, Germany
Email: [email protected] 
Tel: +1 212 584-4684 
www.thieme.com
Thieme eNeurosurgery:
The world's most comprehensive neurosurgical resource online.

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Michael Blakeley
Sent: Tuesday, July 09, 2013 5:50 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] preserve sort order

If that isn't it, take a look and see if you have any XPath operations that 
might reset the sequence to document order. For example:

let $n := <test><a/><b/><c/></test>
let $sorted := for $i in $n/* order by local-name($i) descending return $i 
return (
  xdmp:describe($sorted),
  xdmp:describe($sorted/.))
=>
(<c/>, <b/>, <a/>)
(<a/>, <b/>, <c/>)

-- Mike

On 9 Jul 2013, at 12:00 , Danny Sokolsky <[email protected]> wrote:

> Hi Mary,
>  
> I think the order of the attributes does not have any meaning as XML does not 
> have a notion of order in attributes.
>  
> http://www.w3.org/TR/REC-xml/#sec-starttags
>  
> If you want to preserve the order, consider putting these in elements instead 
> of attributes.
>  
> -Danny
>  
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of 
> Kalinosky, Mary
> Sent: Tuesday, July 09, 2013 11:52 AM
> To: [email protected]
> Subject: [MarkLogic Dev General] preserve sort order
>  
> 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) )
>  
>  
> Many Thanks,
>  
> Mary Kalinosky
> Senior Technical Developer, eProducts
> Thieme Medical Publishers
> 333 Seventh Avenue, New York, NY 10001 USA Ruedigerstrasse 14, 70469 
> Stuttgart, Germany
> 
> Email: [email protected]
> Tel: +1 212 584-4684
> www.thieme.com
> Thieme eNeurosurgery:
> The world's most comprehensive neurosurgical resource online.
>  
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to