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

xquery distinct-values

Jeff Dexter jeff.dexter at rainingdata.com
Mon Apr 10 01:20:36 PDT 2006

xquery distinct

	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: http://xquery.com/mailman/listinfo/talk [mailto:http://xquery.com/mailman/listinfo/talk] On Behalf
Of Jane Doe
Sent: Sunday, April 09, 2006 11:03 PM
To: http://xquery.com/mailman/listinfo/talk
Subject:  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



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.
First Name
Last Name
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-2013 All Rights Reserved.