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

xquery distinct-values

Michael Kay mhk at mhk.me.uk
Mon Apr 10 09:18:37 PDT 2006

distinct values xquery
> First, please accept my apologies if this is the wrong place to post.

It's the right place to post. Is your name really Jane Doe?

I think the following works:

declare variable $f1 := doc("file1.xml");
declare variable $f2 := doc("file2.xml");
  [count(distinct-values(for $x in carids return $f2/id($x)/style)) gt 1]

assuming that @id is an ID attribute

Michael Kay

> I have two xml files.
> file1.xml has
> <namelist><person>
> <name>John</name>
> <carids>1</carids>
> <carids>3</carids>
> <carids>4</carids>
> </person></namelist>
> file2.xml has
> <carlist>
> <car id='1'>
> <style>sedan</style>
> <car id='3'>
> <style>coupe</style>
> <car id='4'>
> <style>sedan</style>
> </carlist
> I am trying to write an xquery that will return the names 
> with more than 2 
> 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 me.
> Thanks,
> D
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today 
> - it's FREE! 
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
> _______________________________________________
> http://xquery.com/mailman/listinfo/talk
> http://xquery.com/mailman/listinfo/talk


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.