Don’t think the empty greates/least add much value here, unless the input occasionally lacks a’s or b’s of course..
Kind regards, Geert *Van:* [email protected] [mailto: [email protected]] *Namens *Ryan Dew *Verzonden:* woensdag 27 maart 2013 20:42 *Aan:* MarkLogic Developer Discussion *Onderwerp:* Re: [MarkLogic Dev General] How to program the order by clause in FLWOR? I was thinking you would have to do something like this (obviously very tailored to the example given): let $sort-options := fn:tokenize("a descending", " ") let $sort-node := $sort-options[1] let $sort-direction := $sort-options[2] for $row in (<row><a>0</a><b>5</b></row>,<row><a>3</a><b>4</b></row>,<row><a>1</a><b>2</b></row>) let $a := $row/a/text() let $b := $row/b/text() order by if ($sort-direction eq "descending") then $row/*[fn:local-name(.) eq $sort-node] else () descending empty least, if ($sort-direction ne "descending") then $row/*[fn:local-name(.) eq $sort-node] else () ascending empty greatest return <tr><td>{$a}</td><td>{$b}</td></tr> On Wed, Mar 27, 2013 at 1:28 PM, Tim <[email protected]> wrote: Thanks Geert! Tim *From:* [email protected] [mailto: [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
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
