[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

how to generate an inventory of elements in a listfor whole collection?

Michael Kay mike at saxonica.com
Thu Aug 6 18:21:20 PDT 2009


  how to generate an inventory of elements in a
	listfor whole collection?
>At each step I would need to compare the elements I just extracted to the
ones I've already found. Repeat elements would cause the value for that
element to increase by one.

You've given a description of a (very) procedural algorithm for computing
the result. XQuery is a declarative language, so the hard work of devising
an algorithm is the processor's job, not yours. You have to say what you
want done, not how you want it to be done.

Am I right in thinking that when you say "elements" you don't mean it in the
XML sense, you mean tokens within the text content of an element?

I think, from reverse engineering your description, that what you want is
along these lines:

let $tokens := //highlight/@subject/tokenize(.,';')
for $x in distinct-values($tokens)
return 
  <token value="{.}" count="{count($tokens[. eq $x])}"/>

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay  

> -----Original Message-----
> From: http://x-query.com/mailman/listinfo/talk 
> [mailto:http://x-query.com/mailman/listinfo/talk] On Behalf Of David Epstein
> Sent: 06 August 2009 16:57
> To: http://x-query.com/mailman/listinfo/talk
> Subject:  how to generate an inventory of 
> elements in a listfor whole collection? 
> 
> Hi everyone,
> 
> I'm hoping someone here may be able to point me in the right 
> direction. I need to write a query that does the following 
> for each node in the path:
> 
> 1) extracts a string from a parameter (see example fragment below)
> 2) splits the string into distinct elements on the semi-colon 
> character
> 3) keeps a running tally of unique elements for the WHOLE collection
> 3) keeps a running tally of how many times each unique element occured
> 4) returns a XML doc in which each element is paired with a 
> number representing the times it occured.
> 
> I understand how to split a string. I understand how to 
> structure an XML return.
> But, I don't understand how to create a master list or hash 
> for the whole collection. I think I could do this in Perl or 
> Python. But, I'm new to XQuery.
> At each step I would need to compare the elements I just 
> extracted to the ones I've already found. Repeat elements 
> would cause the value for that element to increase by one. 
> New elements would be added to the list with a value of 1 
> (one occurrence so far).
> 
> Here is what the start of a node looks like. I want the list 
> stored in "subject".
> <highlight coords="702.25,157.096,1035.829093,157.096,702.25,142.8205"
> title="example" creationdate="D:20090727164124-04'00'"
> subject="q;def:environmental 
> management;human-env-interact;heath;env;" page="12"
> date="D:20090727164241-04'00'" flags="print"
> 
> When the query is complete, the element "q" may have been 
> encountered 200 times (in 200 nodes) and the element "health" 
> may have been encountered 70 times.
> 
> Any suggestions would be appreciated. Thank you!
> 
> -david
> 
> 
> 
> 
> 
> _______________________________________________
> http://x-query.com/mailman/listinfo/talk
> http://x-query.com/mailman/listinfo/talk



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.