[xquery-talk] distinct-values in Where Clauses

Wei, Alice J. ajwei at indiana.edu
Thu Jan 17 11:17:53 PST 2008


_______________________________________
From: Michael Kay [mike at saxonica.com]
Sent: Thursday, January 17, 2008 11:14 AM
To: Wei, Alice J.; talk at x-query.com
Subject: RE: [xquery-talk] distinct-values in Where Clauses

You replied to me off-list (please don't do that!):
Oops, looks like a pushed (Reply to) instead of (Reply all)

=================================
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>

It appears that my XML is well-formed. What I really want to see from the result is:

<div>
<head>PHP and MySQL</head>
<p>So far I have not seen full support of XQuery usage here.</p>
</div>

<div>
<head>PHP5</head>
<p>XML nor XQuery does not seem to be even available.</p>
</div>

This is, as a matter of fact, only a small portion of the output. Since I am calling this from an external variable, some of the files that generate a longer result jeopardizes the output.

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/



More information about the talk mailing list