logo       

RE: xquery distinct-values: msg#00018

Subject: RE: xquery distinct-values
No it's not Jane Doe :)  I forgot that I setup the hotmail account this way.
Thanks for your rapid replies, I will try the query you suggested. Let me give you more information. It was late last night and I'd spent the whole day on various queries.

Here's a better sample set:
file1.xml:
<people>
<driver>
 <name>John</name>
 <bus>1</bus>
 <bus>3</bus>
 <bus>4</bus>
 <bus>5</bus>
</driver>
<driver>
 <name>Sally</name>
 <bus>1</bus>
 <bus>3</bus>
 <bus>5</bus>
 <bus>6</bus>
</driver>
<driver>
 <name>Alex</name>
 <bus>3</bus>
 <bus>6</bus>
</driver>
<driver>
 <name>Bob</name>
 <bus>1</bus>
 <bus>2</bus>
 <bus>5</bus>
</driver>
</people>

file2.xml:
<buses>
 <vehicle id='1'>
   <type>van</type>
 </vehicle>
 <vehicle id='2'>
   <type>bus</type>
 </vehicle>
 <vehicleid='3'>
   <type>van</type>
 </vehicle>
 <vehicle id='4'>
   <type>van</type>
 </vehicle>
 <vehicle id='5'>
   <type>car</type>
 </vehicle>
 <vehicle id='6'>
   <type>car</type>
 </vehicle>
</buses>

"id" is just an attribute of element vehicle, not specifically an ID type (that I know of, I'm still learning xquery). IDs are unique (defined as keys in xsd). Names are also unique. More than one driver can be assigned to the same vehicle.

My xquery:
for $x in doc("file1.xml")/people/driver
let $y := doc("file2.xml")/buses/vehicle[@id=$x/bus]
for $value in ($y/type)
where count($y/type[.=$value]) ge 2
order by ($x/name) descending
return
        <answer>
        <name>{data($x/name)}</name>

The results I get are as follows:
John is listed three times (3 of the same type), Sally is listed four times (2 for van, 2 for car) and the other two are not listed at all. So I'm getting the correct results, just too many of the correct results!

I will try your suggestion, and let you know how it goes.

Thanks again for your quick response and your help.
D

From: "Michael Kay" <mhk-uGS4jv4rpPNaa/9Udqfwiw@xxxxxxxxxxxxxxxx>
To: "'Jane Doe'" 
<becauseur-PkbjNfxxIARBDgjK7y7TUQ@xxxxxxxxxxxxxxxx>,<talk-KUd/JJajPrLQT0dZR+AlfA@xxxxxxxxxxxxxxxx>
Subject: RE: [xquery-talk] xquery distinct-values
Date: Mon, 10 Apr 2006 08:18:37 +0100

> 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");
$f1/namelist/person
  [count(distinct-values(for $x in carids return $f2/id($x)/style)) gt 1]
  /name

assuming that @id is an ID attribute

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

>
> 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/
>
> _______________________________________________
> talk-KUd/JJajPrLQT0dZR+AlfA@xxxxxxxxxxxxxxxx
> http://xquery.com/mailman/listinfo/talk
>


_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar ? get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
region.costa-ri...    user-groups.lin...    lang.prothon.us...    xfree86.cvs/200...    finance.aqbanki...    ietf.smtp/1993-...    web.turbogears....    jakarta.cactus....    yellowdog.gener...    php.gtk+.genera...    org.region.indo...    hurd.l4/2005-10...    culture.religio...    apple.fink.gene...    db.mysql.window...    bluez.devel/200...    security.pgp-ba...    video.blender.d...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe