[xquery-talk] Grouping without Duplicates Issues

Wei, Alice J. ajwei at indiana.edu
Mon Jan 28 15:27:18 PST 2008


Hi,

  I am trying to parse through a group of files through fn:collection, but I am not sure if grouped results would display wrong numbers of results after using distinct-values() because white space is taken into consideration.
  Here is my XQuery:

<booklist>
{
for $book in fn:collection("xmldb:exist://db/library")//book,
$title in $book/title,
$para in $book/p,
$note in $book/note
let $sorted_result:=
for $doc in distinct-values($book)
where distinct-values(contains($para,'hey') or contains($note,'hey'))
order by $title ascending, $para ascending
return $doc
for $r at $count in $sorted_result
let $nodes := $book[. = $r]
return
<book>
<statistics>
Showing Result: {$count} / {count($sorted_result)}
</statistics>
{$title}
{$para}
{$note}
</book>
}
</booklist>

  The odd thing is that when I run the search, it appears that it still gives me back 2 of every single result that match the query, and it also gives me 1 for every number no matter how many the total is.
  For example:

<booklist>
<book>
<statistics> Showing Result: 1 / 1</statistics>
<title type ="main"> Xquery from the Experts: <emph rend="bold">A Guide to the W3c XML Query Language</emph></head>
<p>The individual perspectives on the concepts behind the XQuery language offered by "XQuery from the Experts "will be of great value to those who
are seeking to understand the implications, opportunities, and challenges of XQuery as they design future information systems based on XML.</p>
<note>Published 2004 by Addison-Wesley</note>
</book>
<book>
<statistics> Showing Result: 1 / 1</statistics>
<title type ="main"> Xquery from the Experts: <emph rend="bold">A Guide to the W3c XML Query Language</emph></head>
<p>The individual perspectives on the concepts behind the XQuery language offered by "XQuery from the Experts "will be of great value to those who
are seeking to understand the implications, opportunities, and challenges of XQuery as they design future information systems based on XML.</p>
<note>Published 2004 by Addison-Wesley</note>
</book>
</booklist>

My desired output:

<booklist>
<book>
<statistics> Showing Result: 1 / 1</statistics>
<title type ="main"> Xquery from the Experts: <emph rend="bold">A Guide to the W3c XML Query Language</emph></head>
<p>The individual perspectives on the concepts behind the XQuery language offered by "XQuery from the Experts "will be of great value to those who
are seeking to understand the implications, opportunities, and challenges of XQuery as they design future information systems based on XML.</p>
<note>Published 2004 by Addison-Wesley</note>
</book>
</booklist>

Does the distinct-values() supposed to be doing something else here?
Another question is, if I did were not mistaken, does not the structure of the XQuery be similar to both doc() and collection() according to XPath 2.0?

Thanks to those who can help.
======================================================
Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu



More information about the talk mailing list