[xquery-talk] Using Union Operator without Duplicate Records
Alice Wei
ajwei at indiana.edu
Sat Dec 29 20:54:30 PST 2007
Alice Wei wrote:
{for $file in doc("resume_2.xml")//author let $author :=
distinct-values($file[./@type='co-author' ] union
$file[./@type='Faculty']) order by $author ascending return
<li>{data($author)}</li> }
Actually the distinct-values() is in the for body. So it is called with
a sequence of 0 or 1 item each time. Try something like the following
instead (the distinct-values() is used here to give the right sequence
to the for):
for $a in <projection> <author type="co-author">Andrew Tawfik</author>
<author type="co-author">Chris Hosler</author> <author
type="co-author">Michelle Scott</author> <author
type="Faculty">Michelle Scott</author> </projection> /
distinct-values(.//author[@type = ('co-author', 'Faculty')]) order by
$a ascending return <li> { data($a) } </li>
Result:
<?xml version="1.0" encoding="UTF-8"?> <li>Andrew Tawfik</li> <li>Chris
Hosler</li> <li>Michelle Scott</li>
Thanks, now it is working a lot better than before. But there is one
little problem, since I have other "children" under project that are
not to be selected in this set of XQuery, is it not possible to just
state some for statements instead of putting in the entire code?
The other thing is, I have placed all the other "sections" within the
original XML file into this code, and now the output from A-R is
running in an orderly fashion. But, somehow the one that has the first
name with an S is at the beginning of the list.
eg. <projection>
<author type="co-author">Stanley</author>
<author type="co-author">Henry</author>
</projection>
<projection>
<author type="co-author">Frances</author>
<author type="co-author">Anna</author>
</projection>
The result I got is supposed to start with Anna, but instead it starts
with Stanley, then skips to Anna. The rest of the list is in orderly
fashion according to the structure of the code. Have I missed something
here?
Alice
Regards,
--drkm
_____________________________________________________________________________
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo!
Mail
http://mail.yahoo.fr
_______________________________________________ ta... at x-query.com
http://x-query.com/mailman/listinfo/talk
Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu
812-856-2659
More information about the talk
mailing list