Hi John
The code you gave works but I am afraid of hard coding the index value
Because, the length of the string may vary and the tokens may increase from 5
to 8 or even 10.
E.g.
let $data := document {
<standards>
<standard>SC.3.P</standard>
<standard>SC.3.P.10</standard>
<standard>SC.3.C.2</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.8.1.a</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
Here I have included SC.3.C.2, this will not get sorted as expected.
Is there any dynamic way to specify the sort order?
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: [email protected]
[mailto:[email protected]] On Behalf Of
[email protected]
Sent: Monday, July 02, 2012 3:27 PM
To: [email protected]
Subject: General Digest, Vol 97, Issue 4
Send General mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
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
([email protected])
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: <[email protected]>
Subject: [MarkLogic Dev General] Sorting untypedAtomic Datatypes
To: <[email protected]>
Message-ID:
<[email protected]>
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 <[email protected]>
Subject: Re: [MarkLogic Dev General] Sorting untypedAtomic Datatypes
To: [email protected]
Message-ID: <[email protected]>
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, [email protected] 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 <[email protected]>
Subject: Re: [MarkLogic Dev General] Sorting untypedAtomic Datatypes
To: MarkLogic Developer Discussion <[email protected]>
Message-ID: <[email protected]>
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:* [email protected] [mailto:
[email protected]] *Namens *
[email protected]
*Verzonden:* maandag 2 juli 2012 11:33
*Aan:* [email protected]
*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
[email protected]
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
[email protected]
http://developer.marklogic.com/mailman/listinfo/general