Ah, thnx for testing it.
You can circumvent that issue, by moving the ascending clause after the if.. Cheers.. *Van:* [email protected] [mailto: [email protected]] *Namens *David Lee *Verzonden:* woensdag 27 maart 2013 20:41 *Aan:* MarkLogic Developer Discussion *Onderwerp:* Re: [MarkLogic Dev General] How to program the order by clause in FLWOR? Does that actually work ? My tests show it doesnt ... the ascending clause is not variable. Ie. This fails for me : for $x in (1,3,2,5) order by if( fn:true() ) then $x ascending else () return $x You can make a function that inverts the sort order ... declare function local:f( $value , $order ) { if( $order ) then $value else - $value }; for $x in (1,3,2,5) order by local:f($x,fn:true()) return $x ----------------------------------------------------------------------------- David Lee Lead Engineer MarkLogic Corporation [email protected] Phone: +1 812-482-5224 Cell: +1 812-630-7622 www.marklogic.com *From:* [email protected] [ mailto:[email protected]<[email protected]>] *On Behalf Of *Tim *Sent:* Wednesday, March 27, 2013 3:28 PM *To:* 'MarkLogic Developer Discussion' *Subject:* Re: [MarkLogic Dev General] How to program the order by clause in FLWOR? Thanks Geert! Tim *From:* [email protected] [ mailto:[email protected]<[email protected]>] *On Behalf Of *Geert Josten *Sent:* Wednesday, March 27, 2013 3:23 PM *To:* MarkLogic Developer Discussion *Subject:* Re: [MarkLogic Dev General] How to program the order by clause in FLWOR? Hi Tim, Just leave out the braces, and replace $default with ().. J Cheers, Geert *Van:* [email protected] [mailto: [email protected]] *Namens *Tim *Verzonden:* woensdag 27 maart 2013 20:19 *Aan:* 'MarkLogic Developer Discussion' *Onderwerp:* [MarkLogic Dev General] How to program the order by clause in FLWOR? Hi Folks, Is there a simple way to program the order by clause in FLWOR to make it optional based on parameters? I have a web page that I want to sort as indicated by the user. For example, this code illustrates what I’d like to do but doesn’t work: let $sort-option := “a descending” return for $row in $rows let $a := $row/a/text() let $b := $row/b/text() order by *{if ($sort-option eq “a ascending”) then $a ascending else $default}* return <tr><td>{$a}</td><td>{$b}</td></tr> Thanks! Tim Meagher
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
