Hi Pragya,


Feels like similar questions have been asked before recently. But here
another go:



The blunt way would be to process the document with XQuery, and count
manually:



for $v in distinct-values($input//o)

let $count := count($input//o[. = $v])

return

    <o count=”{$count}”>{$v}</o>



You can make this a bit less blunt by using a map:map, and using keys to
get the distinct values, and add 1 to each key that gets repeated saving on
looping through the input for each count over and over.



But the best way to do this in MarkLogic, is simply use the value lexicon
of a range index. Create a string type range index on element o, then do:



for $v in cts:element-values(xs:QName(“o”))  (: optionally pass in a
cts:document-query if you want to restrict to one document :)

let $count := cts:frequency($v)

return

    <o count=”{$count}”>{$v}</o>



Kind regards,

Geert





*Van:* [email protected] [mailto:general-bou
[email protected]] *Namens *Pragya Kapoor
*Verzonden:* dinsdag 20 augustus 2013 6:24
*Aan:* [email protected]
*Onderwerp:* [MarkLogic Dev General] String array



Hi,



I  want to do the following:



Input

<p>

                <q>

                  <o>pragya</o>

                <o>kapoor</o>

                </q>

                <q>

                  <o>pragya</o>

                  </q>

                <q>

                  <o>kapoor</o>

                  </q>

                <q>

                  <o>amit</o>

  </q>



</p>



Output :

<p>

                                           <o count ="2">pragya"</o>

          <o count ="2">kapoor"</o>

          <o count ="1">amit"</o>



</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***
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to