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

Using Union Operator without Duplicate Records

Michael Kay mike at saxonica.com
Sun Dec 30 10:04:00 PST 2007


  Using Union Operator without Duplicate Records
> 
>   This is what I have now:
> 
> {
> 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>
> }
> 

I wonder why you chose to call your variable $file when its value is an
<author> element? This poor choice of name may have led to your subsequent
mistakes. Because $file is declared in a "for" expression, its value is
always a single item, in this case a single author element. Applying a
predicate to $file (as in $file[...]) will either return that author element
(if the predicate is true), or an empty sequence (if it is false). Applying
the union operator ($file[C1] union $file[C2]) is equivalent to writing
($file[C1 or C2]), which again selects either the author element or nothing.
Applying distinct-values to a singleton author element achieves nothing.

I hope this helps you to understand why your code cannot possibly be right.
I'm afraid I haven't tried to understand the problem you are trying to
solve, so I can't tell you how to correct it.

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




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.