Just in way of showing there are several ways this can be done, another way
you can do this is with fn:distinct-values and fn:compare with a
case-insensitive collation. Borrowing from the code previously shared, I
came up with the following:

let $input := <p>
                                                                <q>

    <o>pragya</o>
                                                                </q>
                                                                <q>

    <o>PRAGYA</o>
                                                                </q>
                                                                <q>

    <o>pragya</o>
                                                                </q>
                                                                <q>

<o>kapoor</o>
                                                                </q>
                                                                <q>

    <o>KAPOOR</o>
                                                                </q>
                                                </p>

let $output := <p>{
                  for $each in fn:distinct-values($input//q/o, "
http://marklogic.com/collation/en/S1";)
                  let $b := $input//q[fn:compare(o,$each,"
http://marklogic.com/collation/en/S1";)=0]
                  let $count := count($b)
                  let $final :=<q>


                                        <o
count="{$count}">{fn:upper-case($each)}</o>




                           </q>
                  return $final
                }</p>
return $output

-Ryan Dew


On Mon, Aug 12, 2013 at 1:41 AM, <[email protected]> wrote:

>  Hi Pragya,
>
>
>
> You need to use upper-case and lower-case.
>
>
>
> let $input := <p>
>
>                                                                 <q>
>
>
> <o>pragya</o>
>
>                                                                 </q>
>
>                                                                 <q>
>
>
> <o>PRAGYA</o>
>
>                                                                 </q>
>
>                                                                 <q>
>
>
> <o>pragya</o>
>
>                                                                 </q>
>
>                                                                 <q>
>
>
> <o>kapoor</o>
>
>                                                                 </q>
>
>                                                                 <q>
>
>
> <o>KAPOOR</o>
>
>                                                                 </q>
>
>                                                 </p>
>
>
>
> let $output := <p>{
>
>
> for $each in fn:distinct-values($input//q/fn:lower-case(o))
>
>
> let $b := $input//q[fn:lower-case(o)[.=$each]]
>
>
> let $count := count($input//q/fn:lower-case(o)[.=$each])
>
>
> let $xml := <p>{$b[1]}</p>
>
>
> let $final :=<q>{ for $each in $xml//q
>
>
> return
>
>
> (
>
>
>
> <o count="{$count}">{$xml//q/fn:upper-case(o/text())}</o>
>
>
>
>
>
> )
>
>
> }</q>
>
>
>    return $final
>
>                                                                 }</p>
>
> return  $output
>
>
>
> Regards,
>
> Asit Nautiyal
>
>
>
> *From:* [email protected] [mailto:
> [email protected]] *On Behalf Of *Pragya Kapoor
> *Sent:* Monday, August 12, 2013 12:57 PM
> *To:* [email protected]
> *Subject:* [MarkLogic Dev General] FW: string array
>
>
>
> Hi,
>
>
>
> I have to do the following:
>
>
>
> Input:
>
> <p>
>
> <q>
>
>   <o>pragya</o>
>
>   </q>
>
> <q>
>
>   <o>PRAGYA</o>
>
>   </q>
>
> <q>
>
> <o>pragya</o>
>
>   </q>
>
> <q>
>
>   <o>kapoor</o>
>
>  </q>
>
> <q>
>
>   <o>KAPOOR</o>
>
>  </q>
>
> <q>
>
>
>
> </p>
>
>
>
> output :
>
>
>
> <p>
>
>                 < q>
>
>                                 <o count ='3'>PRAGYA</o>
>
>
>
>                 </q>
>
>                 <q>
>
>                                 <o count ="2">KAPOOR</o>
>
>                 </q>
>
>
>
>
>
> </p>
>
>
>
>
>
> Thanks
>
> Pragya
>
>
>
> **************** CAUTION - Disclaimer *****************
>
> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
>
> for the use of the addressee(s). If you are not the intended recipient, please
>
> notify the sender by e-mail and delete the original message. Further, you are 
> not
>
> to copy, disclose, or distribute this e-mail or its contents to any other 
> person and
>
> any such actions are unlawful. This e-mail may contain viruses. Infosys has 
> taken
>
> every reasonable precaution to minimize this risk, but is not liable for any 
> damage
>
> you may sustain as a result of any virus in this e-mail. You should carry out 
> your
>
> own virus checks before opening the e-mail or attachment. Infosys reserves the
>
> right to monitor and review the content of all messages sent to or from this 
> e-mail
>
> address. Messages sent to or from this e-mail address may be stored on the
>
> Infosys e-mail system.
>
> ***INFOSYS******** End of Disclaimer ********INFOSYS***
>
>
>  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(s), please reply to the
> sender and destroy all copies of the original message. Any unauthorized
> review, use, disclosure, dissemination, forwarding, printing or copying of
> this email, and/or any action taken in reliance on the contents of this
> e-mail is strictly prohibited and may be unlawful.
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to