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

distinct-values in Where Clauses

Michael Kay mike at saxonica.com
Thu Jan 17 18:14:27 PST 2008


  distinct-values in Where Clauses
Yes. If you do

for $find in doc("resume.xml")//div,
$head in $find/head,
  ...

and there is one <div> element with two <head> children, then you are going
to go round the loop twice (or technically, you are going to process a
stream containing two tuples), and <p>{$find/p}</p> is going to give the
same value for both.

You need to define clearly what your input is and what your desired output
is, otherwise you are wasting everyone's time including your own.

Incidentally, when I see someone post something like this:

<head type="main>

then I know you're not showing us your real input because it's not
well-formed. We can't find bugs in your code unless you show us the actual
code, not some idealized version of it.

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

> -----Original Message-----
> From: http://x-query.com/mailman/listinfo/talk 
> [mailto:http://x-query.com/mailman/listinfo/talk] On Behalf Of Wei, Alice J.
> Sent: 17 January 2008 17:36
> To: http://x-query.com/mailman/listinfo/talk
> Subject: RE:  distinct-values in Where Clauses
> 
> Hi,
> 
>   I have found out that the problem why I was having these 
> issues is because I have some markup with different 
> attributes in the <head> section. So that is probably why 
> some markup of
> 
> <div>
> <head type="main>PHP and MySQL</head>
> <head type="sub">Web Design and Database Management</head> 
> <p>So far I have not seen full support of XQuery usage 
> here.</p> </div>
> 
> would be treated as two different elements and called twice.
> If I am assuming this correct, the way to elude from this 
> problem of having two headings that are "exactly the same" 
> not to be displayed twice is to put an additonal "where" 
> clause to eliminate the output of such, right?
> 
> Or, is there another method?
> 
> ======================================================
> Alice Wei
> MIS 2008
> School of Library and Information Science Indiana University 
> Bloomington http://x-query.com/mailman/listinfo/talk ________________________________________
> From: Michael Kay [http://x-query.com/mailman/listinfo/talk]
> Sent: Thursday, January 17, 2008 11:14 AM
> To: Wei, Alice J.; http://x-query.com/mailman/listinfo/talk
> Subject: RE:  distinct-values in Where Clauses
> 
> You replied to me off-list (please don't do that!):
> 
> =================================
> Hi,
> 
>    Actually it is hard to describe the situation I am having here.
>  I am processing some nodes of information using a lot of 
> different "or" in my query structure.
> 
> Here is the XQuery:
> 
> declare boundary-space preserve;
> declare variable $text external;
> <text>{
> for $find in doc("resume.xml")//div,
> $head in $find/head,
> $desc in $find/p
> where
> distinct-values((contains($desc,$text)) or 
> (contains($head,$text))) return <div> 
> <head>{data($head)}</head> <p>{data($desc)}</p> </div> } </text>
> 
> XML:
> 
> <div>
> <head>PHP and MySQL</head>
> <p>So far I have not seen full support of XQuery usage 
> here.</p> </div>
> 
> <note>
> <head>PHP5</head>
> <p>XML nor XQuery does not seem to be even available.</p> </note>
> 
> If I set the $text variable to XQuery, the result  is 
> supposed to be appearing only once for each, but now it gives 
> me two results for each. Can anyone help out?
> 
> Thanks to those who can help.
> ====================
> 
> You've done half of what I asked, which is to show the input. 
> You haven't done the other half, which is to show the desired 
> output (or the output you are actually getting).
> 
> Unfortunately your input isn't well-formed XML (there is no 
> outer wrapper
> element) so I can't try it for myself. Since your input has 
> only one <div> element I find it hard to see why there should 
> be any duplicates. I don't really know what you mean by 
> "appearing only once for each" - each what?
> 
> Anyway, as I already explained, it's obvious why the 
> distinct-values() does no good.
> 
> Michael Kay
> http://www.saxonica.com/
> 
> _______________________________________________
> 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-2007 All Rights Reserved.