On Aug 31, 2011, at 8:16 PM, Michael Blakeley wrote:

> The final XPath step '.../dateline' reorders the results into node order, as 
> specified by the W3C. A sequence of constructed nodes has indeterminate node 
> order, so you will see unpredictable results. You can see similar behavior 
> with sequences of attributes, which also have indeterminate node order. I 
> would write '...return $art/dateline' instead.
> 
> In passing, there's no need for the 'let-return-for-return' syntax. You can 
> simply write 'let-for-return' and save some typing.

   Or even just for-return:

for $art in
   ( <article><dateline>2011-08-21</dateline></article>,
     <article><dateline>2011-04-21</dateline></article>,
     <article><dateline>2011-02-21</dateline></article>,
     <article><dateline>2011-10-03</dateline></article>,
     <article><dateline>2011-05-03</dateline></article>,
     <article><dateline>2011-04-22</dateline></article> )
order by xs:date($art/dateline) descending
return $art/dateline

=>

<dateline>2011-10-03</dateline>
<dateline>2011-08-21</dateline>
<dateline>2011-05-03</dateline>
<dateline>2011-04-22</dateline>
<dateline>2011-04-21</dateline>
<dateline>2011-02-21</dateline>

> On 31 Aug 2011, at 11:58 , Jake Trent wrote:
> 
>> MarkLogic friends,
>> 
>> When I run this script in CQ, why does the resulting order change every time 
>> I run it?:
>> 
>> let $articles :=
>>    ( <article><dateline>2011-08-21</dateline></article>
>>    , <article><dateline>2011-04-21</dateline></article>
>>    , <article><dateline>2011-02-21</dateline></article>
>>    , <article><dateline>2011-10-03</dateline></article>
>>    , <article><dateline>2011-05-03</dateline></article>
>>    , <article><dateline>2011-04-22</dateline></article>
>>    )
>> 
>> return
>> (for $art in $articles
>> order by xs:date($art/dateline) descending
>> return $art)/dateline
>> 
>> If I remove the parenthesis from around the for clause, and return 
>> $art/dateline, it's consistently ordered correctly:
>> 
>> <dateline>2011-10-03</dateline>
>> <dateline>2011-08-21</dateline>
>> <dateline>2011-05-03</dateline>
>> <dateline>2011-04-22</dateline>
>> <dateline>2011-04-21</dateline>
>> <dateline>2011-02-21</dateline>
>> 
>> 
>> But if I return the top level element as a supposedly ordered sequence and 
>> then return child elements off it, it seems like the articles aren't in 
>> order at all:
>> 
>> <dateline>2011-04-21</dateline>
>> <dateline>2011-08-21</dateline>
>> <dateline>2011-05-03</dateline>
>> <dateline>2011-02-21</dateline>
>> <dateline>2011-10-03</dateline>
>> <dateline>2011-04-22</dateline>
>> 
>> Or
>> 
>> 
>> <dateline>2011-02-21</dateline>
>> <dateline>2011-05-03</dateline>
>> <dateline>2011-04-21</dateline>
>> <dateline>2011-08-21</dateline>
>> <dateline>2011-04-22</dateline>
>> <dateline>2011-10-03</dateline>
>> 
>> Etc.
>> 
>> I've gotta be missing some basic concept here.  This doesn't seem right.
>> 
>> Thanks for taking a look,
>> Jake
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
> 
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general

---
Ron Hitchens {mailto:[email protected]}   Ronsoft Technologies
     +44 7879 358 212 (voice)          http://www.ronsoft.com
     +1 707 924 3878 (fax)              Bit Twiddling At Its Finest
"No amount of belief establishes any fact." -Unknown




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

Reply via email to