Hi John/Geert My data a bit more complex than we are discussing now.
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.C.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.A.8.3</standard> <standard>SC.3.P.9</standard> <standard>LACC.3.A.9</standard> <standard>LACC.3.A.10</standard> <standard>SC.3.P.9.1</standard> </standards> } for $each in $data//standard order by number(substring-after($each, '.P.')) return $each Or for $each in $data//standard let $tokens := tokenize($each,"\.") order by number($tokens[4]), number($tokens[5]) return $each These both fails in my case as there are few other values like "SC.3.C.11" and "SC.3.A.8.3" and "LACC.3.A.9" and " LACC.3.A.10". So the strings are not in any patterns as of now. They may be in any format except that they will be having "." in between. I should be able to sort it for each token and I should avoid hardcoding of indexes or value here. Thanks in advance for your help :) Thanks and Regards, Gnanaprakash Bodireddy Sr Associate - Projects | IME Cognizant Technology Solutions VNET: 682831 (O): +91 (40) 44514444 extn: 682831 (M): +91-8897575644 -----Original Message----- From: general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] On Behalf Of general-requ...@developer.marklogic.com Sent: Monday, July 02, 2012 3:27 PM To: general@developer.marklogic.com Subject: General Digest, Vol 97, Issue 4 Send General mailing list submissions to general@developer.marklogic.com To subscribe or unsubscribe via the World Wide Web, visit http://developer.marklogic.com/mailman/listinfo/general or, via email, send a message with subject or body 'help' to general-requ...@developer.marklogic.com You can reach the person managing the list at general-ow...@developer.marklogic.com When replying, please edit your Subject line so it is more specific than "Re: Contents of General digest..." Today's Topics: 1. Sorting untypedAtomic Datatypes (gnanaprakash.bodire...@cognizant.com) 2. Re: Sorting untypedAtomic Datatypes (John Snelson) 3. Re: Sorting untypedAtomic Datatypes (Geert Josten) ---------------------------------------------------------------------- Message: 1 Date: Mon, 2 Jul 2012 15:03:10 +0530 From: <gnanaprakash.bodire...@cognizant.com> Subject: [MarkLogic Dev General] Sorting untypedAtomic Datatypes To: <general@developer.marklogic.com> Message-ID: <efde5c6ae399d54dbe366cfcc3b587d001983...@ctsinhydsxuh.cts.com> Content-Type: text/plain; charset="us-ascii" 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://developer.marklogic.com/pipermail/general/attachments/20120702/626cdb51/attachment-0001.html ------------------------------ Message: 2 Date: Mon, 02 Jul 2012 10:54:02 +0100 From: John Snelson <john.snel...@marklogic.com> Subject: Re: [MarkLogic Dev General] Sorting untypedAtomic Datatypes To: general@developer.marklogic.com Message-ID: <4ff16fba.4080...@marklogic.com> Content-Type: text/plain; charset=UTF-8; format=flowed Maybe something like this: 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 let $tokens := tokenize($each,"\.") order by number($tokens[4]), number($tokens[5]) return $each John On 02/07/12 10:33, gnanaprakash.bodire...@cognizant.com wrote: > 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. > -- John Snelson, Lead Engineer http://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ------------------------------ Message: 3 Date: Mon, 2 Jul 2012 11:56:49 +0200 From: Geert Josten <geert.jos...@dayon.nl> Subject: Re: [MarkLogic Dev General] Sorting untypedAtomic Datatypes To: MarkLogic Developer Discussion <general@developer.marklogic.com> Message-ID: <6de9936a198b90ede73975741a0a6...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://developer.marklogic.com/pipermail/general/attachments/20120702/15b84240/attachment.html ------------------------------ _______________________________________________ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general End of General Digest, Vol 97, Issue 4 ************************************** 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