Hi Gnanaprakash,


You can put expressions within the order clause, or add a let variable in
which you put a derived value for sorting. You could do something like the
following, but whether it is sufficiently robust depends on your data:



let $data := document {

<standards>

  <standard>SC.3.P</standard>

  <standard>SC.3.P.10</standard>

  <standard>SC.3.P.10.2</standard>

  <standard>SC.3.P.11</standard>

  <standard>SC.3.P.11.1</standard>

  <standard>SC.3.P.8</standard>

  <standard>SC.3.P.8.3</standard>

  <standard>SC.3.P.9</standard>

  <standard>SC.3.P.9.1</standard>

</standards> }

for $each in $data//standard

*order by number(substring-after($each, '.P.'))*

return $each



Kind regards,

Geert



*Van:* general-boun...@developer.marklogic.com [mailto:
general-boun...@developer.marklogic.com] *Namens *
gnanaprakash.bodire...@cognizant.com
*Verzonden:* maandag 2 juli 2012 11:33
*Aan:* general@developer.marklogic.com
*Onderwerp:* [MarkLogic Dev General] Sorting untypedAtomic Datatypes



Hi



Need help in sorting untypedAtomic Datatypes.



I am facing issue while sorting untypedAtomic types (i.e. combination of
string and integer)



E.g.



let $data := document {

<standards>

  <standard>SC.3.P</standard>

  <standard>SC.3.P.10</standard>

  <standard>SC.3.P.10.2</standard>

  <standard>SC.3.P.11</standard>

  <standard>SC.3.P.11.1</standard>

  <standard>SC.3.P.8</standard>

  <standard>SC.3.P.8.3</standard>

  <standard>SC.3.P.9</standard>

  <standard>SC.3.P.9.1</standard>

</standards> }

for $each in $data//standard

order by $each

return $each



*Result:*

<?xml version="1.0" encoding="UTF-8"?>

<results warning="more than one root item">

  <standard>SC.3.P</standard>

  <standard>SC.3.P.10</standard>

  <standard>SC.3.P.10.2</standard>

  <standard>SC.3.P.11</standard>

  <standard>SC.3.P.11.1</standard>

  <standard>SC.3.P.8</standard>

  <standard>SC.3.P.8.3</standard>

  <standard>SC.3.P.9</standard>

  <standard>SC.3.P.9.1</standard>

</results>



*Expected Result:*

<?xml version="1.0" encoding="UTF-8"?>

<results warning="more than one root item">

  <standard>SC.3.P</standard>

  <standard>SC.3.P.8</standard>

  <standard>SC.3.P.8.3</standard>

  <standard>SC.3.P.9</standard>

  <standard>SC.3.P.9.1</standard>

  <standard>SC.3.P.10</standard>

  <standard>SC.3.P.10.2</standard>

  <standard>SC.3.P.11</standard>

  <standard>SC.3.P.11.1</standard>

</results>



How can you sort the given input so that we get the expected result. Is
there any way to sort it using a regular expression or tokenizing mechanism?



*Thanks and Regards,*

* *

*Gnanaprakash Bodireddy*

Sr Associate - Projects | IME

Cognizant Technology Solutions

VNET: 682831

(O): +91 (40) 44514444 extn: 682831

(M): +91-8897575644



This e-mail and any files transmitted with it are for the sole use of
the intended recipient(s) and may contain confidential and privileged
information.

If you are not the intended recipient, please contact the sender by
reply e-mail and destroy all copies of the original message.

Any unauthorized review, use, disclosure, dissemination, forwarding,
printing or copying of this email or any action taken in reliance on
this e-mail is strictly prohibited and may be unlawful.
_______________________________________________
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to