Okay, I think I now have a plan using an approach such as:
order by if ($boolean1) then $id else $title ascending,
if ($boolean2) then $year else () descending
I'm not real clear on the value of using xdmp:value() because I will still
have to create the logic to build the order by clause.
Thanks to all!
Tim
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Michael
Blakeley
Sent: Friday, May 22, 2009 2:16 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] Can an xquery orderby
clausebeconstructed?
Danny pointed out that I pasted the wrong link: sorry about that.
http://markmail.org/thread/rpc3unlqlj72loah
-- Mike
On 2009-05-22 11:11, Michael Blakeley wrote:
> http://lists.marklogic.com/thread/rpc3unlqlj72loah
>
> Using a static approach gets much more complex as you add more fields.
>
> -- Mike
>
> On 2009-05-22 10:35, McBeath, Darin W (ELS-STL) wrote:
>> Tim.
>>
>> I can get the following to work when ordering by a 'single' field. If
you need to sort on multiple fields, I could not get that to work . I would
get a syntax error.
>>
>> But, if you need to sort on multiple fields, then you may need to use
xdmp:value() . or you could also use xdmp:eval(). They are fairly similar .
one distinction is that the 'current context' namespaces, variables etc. are
readily available when using xdmp:value (in other words you don't have to
redeclare namespaces, etc.). So, I believe that is the more preferable
approach nowadays.
>>
>> let $test :=<entries>
>> <entry>
>> <a>darin</a><b>darby</b>
>> </entry>
>> <entry>
>> <a>darby</a><b>darin</b>
>> </entry>
>> </entries>
>>
>> for $x in $test/entry
>> let $a := $x/a
>> let $b := $x/b
>> order by if (true()) then $b else $a
>> return
>> $x
>> ________________________________
>> From: [email protected]
[mailto:[email protected]] On Behalf Of Tim Meagher
>> Sent: Friday, May 22, 2009 1:26 PM
>> To: 'General Mark Logic Developer Discussion'
>> Subject: RE: [MarkLogic Dev General] Can an xquery order by
clausebeconstructed?
>>
>> Hi Danny,
>>
>> Hmm - I'm not sure how to use the xdmp:value() function in this case,
plus I've tried to dynamically construct the OrderByClause with one or 2
sort elements and an OrderSpec as well. Do you have any examples?
>>
>> Thanks,
>>
>> Tim
>>
>> ________________________________
>> From: [email protected]
[mailto:[email protected]] On Behalf Of Danny Sokolsky
>> Sent: Friday, May 22, 2009 1:03 PM
>> To: General Mark Logic Developer Discussion
>> Subject: RE: [MarkLogic Dev General] Can an xquery order by clause
beconstructed?
>>
>> Each "orderspec" is an expression, and the expression can be any XQuery
expression (for example an if/then/else):
>>
>> http://www.w3.org/TR/xquery/#prod-xquery-OrderByClause
>>
>> This will work for many things, but not if you want to manipulate more
than the expression. But you can get a long way with if/then/else.
>>
>> If you want to do something more complex, then David's xdmp:value
suggestion is a good one, where you construct a string that is your new
flwor expression and evaluate it with xdmp:value.
>>
>> -Danny
>>
>> From: [email protected]
[mailto:[email protected]] On Behalf Of David Steiner
>> Sent: Friday, May 22, 2009 8:51 AM
>> To: General Mark Logic Developer Discussion
>> Subject: RE: [MarkLogic Dev General] Can an xquery order by clause be
constructed?
>>
>> You could always construct the entire for clause as a string and pass it
to xdmp:value(.).
>> The MarkLogic folk probably have a better solution though.
>>
>> From: [email protected]
[mailto:[email protected]] On Behalf Of Tim Meagher
>> Sent: Friday, May 22, 2009 8:16 AM
>> To: 'General Mark Logic Developer Discussion'
>> Subject: [MarkLogic Dev General] Can an xquery order by clause be
constructed?
>>
>>
>> Hi folks,
>>
>>
>>
>> I would like to know if the order by clause can be programmatically
constructed. For example, given a query such as the following:
>>
>>
>>
>> for $el in cts:search(xdmp:directory("/SomeDir/","infinity")/SomeNode,
>>
>> cts:element-value-query(xs:QName("SomeElement"), "SomeElementValue",
>>
>> ("case-insensitive", "punctuation-insensitive",
"diacritic-insensitive")))
>>
>>
>>
>> let $id := string($e/@ID)
>>
>> let $author := string($el/author[1])
>>
>> let $title := string($el/title[1])
>>
>>
>>
>> order by $id, $title, $author
>>
>>
>>
>> return $el
>>
>>
>>
>> I would like to be able to programmatically construct the order clause to
be something like "$author, $title" instead of "$id, $title, $author".
>>
>>
>>
>> Thank you!
>>
>>
>>
>> Tim - aaom consulting
>>
>>
>> NOTICE: This email message is for the sole use of the intended
recipient(s) and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited. If you
are not the intended recipient, please contact the sender by reply email and
destroy all copies of the original message.
>>
>
>
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general