[xquery-talk] xquery distinct-values

Jane Doe becauseur at hotmail.com
Mon Apr 10 21:45:57 PDT 2006

This query did it!  I tried the one previously recommended, but since the ID 
was not of ID type, I wasn't able to get it to work, even with playing 
around with it.

This did the job.

Thanks so much for all of your help, and for your QUICK response.  It's very 
much appreciated.

>From: "Jeff Dexter" <jeff.dexter at rainingdata.com>
>To: "'Jane Doe'" <becauseur at hotmail.com>, <talk at xquery.com>
>Subject: RE: [xquery-talk] xquery distinct-values
>Date: Mon, 10 Apr 2006 00:20:36 -0700
>	You're either working with an XQuery engine with a glitch or
>your file1.xml contains additional data, because as written your
>query+data	 should be fine. Since $x is the outer iterate it can
>never produce duplicate values... unless your <namelist> document
>contains duplicate <name> elements.
>	Assuming this is the case, you can re-write your query as
>follows to eliminate the duplicates.
>	for $name in distinct-values(
>          for $x in doc('file1.xml')/namelist/person
>          let $y := doc('file2.xml')/carlist/car[@id=$x/carids]
>          for $value in ($y/style)
>          where count($y/style[.=$value]) ge 2
>          return $x/name
>       )
>       order by $name descending
>       return <name>{ $name }</name>
>Jeff Dexter
>-----Original Message-----
>From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On Behalf
>Of Jane Doe
>Sent: Sunday, April 09, 2006 11:03 PM
>To: talk at xquery.com
>Subject: [xquery-talk] xquery distinct-values
>First, please accept my apologies if this is the wrong place to post.
>I have two xml files.
>file1.xml has
>file2.xml has
><car id='1'>
><car id='3'>
><car id='4'>
>I am trying to write an xquery that will return the names with more than
>of any style:
>for $x in doc("file1.xml")/namelist/person
>let $y := doc("file2.xml")/carlist/car[@id=$x/carids]
>for $value in ($y/style)
>where count($y/style[.=$value]) ge 2
>order by ($x/name) descending
>return <name>{data($x/name)}</name>
>This returns the names of everyone with more than 2 of any style, but it
>returns that same name multiple times (in relation to the number of
>duplicate styles).
>I hope it's not too confusing, and I appreciate any help you can give
>Express yourself instantly with MSN Messenger! Download today - it's
>talk at xquery.com
>talk at xquery.com

Is your PC infected? Get a FREE online computer virus scan from McAfee® 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

More information about the talk mailing list