At 2011-02-04 17:51 +0530, mano m wrote:
>I would like to sort a squence of items in alphabetical order with 
>high precedence to capital case letters.
>
>For example
>
>let $sequence := ("PROFESSIONAL", "Technical", "Biographies", 
>"Literature" , "TRAVEL", "HISTORY", "Health", "Law",  "Photography" 
>, "BUSINESS")
>
>for $category in $sequence
>order by $category ascending
>return <category>{$category}</category>
>
>Output:
>
>   <category>Biographies</category>
>   <category>BUSINESS</category>
>   <category>Health</category>
>   <category>HISTORY</category>
>   <category>Law</category>
>   <category>Literature</category>
>   <category>Photography</category>
>   <category>PROFESSIONAL</category>
>   <category>Technical</category>
>   <category>TRAVEL</category>

This output surprises me, though perhaps you are running "1.0-ml" and 
not "1.0" ... you don't say which.

You are not specifying the collation URI and so in XQuery 1.0 the 
collation order should be Unicode code-point order, which has upper-case first.

>     Expected output : Order in ascendingwith hight precedence to 
> capital case. i.e "BUSINESS" should get listed before "Biographies" 
> , similarly "HISTORY" should get listed before "Health"
>
>       <category>BUSINESS</category>
>  <category>Biographies</category>
>    <category>HISTORY</category>
>   <category>Health</category>
>   <category>Law</category>
>   <category>Literature</category>
>   <category>PROFESSIONAL</category>
>    <category>Photography</category>
>   <category>TRAVEL</category>
>   <category>Technical</category>
>
>
>Please let me know is there any possiblilty to sort in this 
>way.Thanks in Advance.

Here I have your example using another processor:

~/t/ftemp $ cat mano.xq
let $sequence := ("PROFESSIONAL", "Technical", "Biographies", 
"Literature" , "TRAVEL", "HISTORY", "Health", "Law",  "Photography" , 
"BUSINESS")

for $category in $sequence
order by $category ascending
return (<category>{$category}</category>,"
")~/t/ftemp $ xquery mano.xq
<?xml version="1.0" encoding="UTF-8"?><category>BUSINESS</category>
<category>Biographies</category>
<category>HISTORY</category>
<category>Health</category>
<category>Law</category>
<category>Literature</category>
<category>PROFESSIONAL</category>
<category>Photography</category>
<category>TRAVEL</category>
<category>Technical</category>
~/t/ftemp $


What I suggest you do is explicitly specify what is supposed to be the default:

~/t/ftemp $ cat mano.xq
let $sequence := ("PROFESSIONAL", "Technical", "Biographies", 
"Literature" , "TRAVEL", "HISTORY", "Health", "Law",  "Photography" , 
"BUSINESS")

for $category in $sequence
order by $category ascending
          collation 
"http://www.w3.org/2005/xpath-functions/collation/codepoint";
return (<category>{$category}</category>,"
")~/t/ftemp $ xquery mano.xq
<?xml version="1.0" encoding="UTF-8"?><category>BUSINESS</category>
<category>Biographies</category>
<category>HISTORY</category>
<category>Health</category>
<category>Law</category>
<category>Literature</category>
<category>PROFESSIONAL</category>
<category>Photography</category>
<category>TRAVEL</category>
<category>Technical</category>
~/t/ftemp $


In the above it produces the same result.  In your situation it may 
give you what you want.

One caveat is, though, that this destroys language-based sorting, so 
accented characters will not come out in the correct order.

In XSLT your requirement is easily met with case-order="upper-first" 
which maintains any language-based sort yet addresses your need for 
upper-case letters first.

I hope this helps.

. . . . . . . . . . . Ken

--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
G. Ken Holman                 mailto:[email protected]
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

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

Reply via email to