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

Query Through Multiple Files

Wei, Alice J. ajwei at indiana.edu
Mon Jan 21 14:58:30 PST 2008


  Query Through Multiple Files
Hi,


   I am wondering if there is a secondary "alternative" to outputting results that may be duplicates. I tried using distinct-values(doc("1.xml"), doc("3.xml"), doc("4.xml"),  doc("2.xml"))//title, but I got the error that there should be only 2 arguments. or less. Is there some way of which I could avoid duplicate values in my query performance as my results shown below:

My XQuery:

  declare boundary-space preserve;
declare variable $text external;

<project>
{
let $sorted_result:= for $book in
(doc("1.xml"), doc("3.xml"), doc("4.xml"),  doc("2.xml"))//title,
$note in $book/note,
$head in $book/head
where
distinct-values(contains($desc,$text) or contains($head,$text))
return $book
for $sorted_results at $count in $sorted_result
return
<book>
<statistics>Showing Result: {$count} / {count($sorted_result)}
</statistics>
{$sorted_result/head}
{$sorted_result/p}
</book>
}
</project>

Current output:

<book>
    <statistics>Showing Result: 1 / 4</statistics>
     <head>XQuery</head>
    <p>This book provides: A high-level overview and quick tour of XQuery Information to write sophisticated queries, without being bogged down by the details of types, namespaces, and schemas.</p>
</book>
<book>
    <statistics>Showing Result: 2 / 4</statistics>
     <head>XQuery</head>
    <p>This book provides: A high-level overview and quick tour of XQuery Information to write sophisticated queries, without being bogged down by the details of types, namespaces, and schemas.</p>
</book>
<book>
    <statistics>Showing Result: 3 / 4</statistics>
     <head>XQuery</head>
    <p>This book provides: A high-level overview and quick tour of XQuery Information to write sophisticated queries, without being bogged down by the details of types, namespaces, and schemas.</p>
</book>
<book>
    <statistics>Showing Result: 4 / 4</statistics>
     <head>XQuery</head>
    <p>This book provides: A high-level overview and quick tour of XQuery Information to write sophisticated queries, without being bogged down by the details of types, namespaces, and schemas.</p>
</book>

Intended Output:
<book>
    <statistics>Showing Result: 1/1</statistics>
     <head>XQuery</head>
    <p>This book provides: A high-level overview and quick tour of XQuery Information to write sophisticated queries, without being bogged down by the details of types, namespaces, and schemas.</p>
</book>

Thanks to those who can help.
======================================================
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: Sunday, January 20, 2008 8:07 PM
To: 'Liam Quin'; Wei, Alice J.
Cc: http://x-query.com/mailman/listinfo/talk
Subject: RE:  Query Through Multiple Files

> >Alice: I did use Liam's suggestions,
> >
> > for $ad in (
> >        doc("1.xml"),
> >        doc("2.xml"),
> >        doc("3.xml"),
> >        doc("4.xml"))//ad
> >
> Liam:That wasn't exactly what I suggested... :-)
>
> XQuery is not a good language in which to make random guesses
> and hope things will work.
>
> You can try,
> for $doc in (
>        doc("1.xml"),
>        doc("2.xml"),
>        doc("3.xml"),
>        doc("4.xml"))
>     return $doc//ad
>

or more simply,

( doc("1.xml"),
  doc("2.xml"),
  doc("3.xml"),
  doc("4.xml"))//ad

or if you want to eliminate duplicates,

distinct-values(( doc("1.xml"),
  doc("2.xml"),
  doc("3.xml"),
  doc("4.xml"))//ad)

I've found when teaching XQuery that there are two important
misunderstandings that students easily make:

(a) the idea that every query has a FLWOR expression as its outermost
construct

(b) the idea that a FLWOR expression can only be used at the outermost level
of a query

Michael Kay




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.