RE: how to prune subtrees in an XQuery result

Thanks a lot Mike. Therefore this XQuery seems good..
Hope Sergio likes it!

<Results> {
   for $A in doc("data.xml")/ASet/A
   let $matches := $A[B = ("red","yellow")][C
=("chair","table")]/((B[.=("red","yellow")] |
C[.=("chair","table")]))      
   where $A/$matches
     return
      <A> 
       {$A/@*}
       {$matches}
      </A>        
}</Results>

Regards,
Mukul

--- Michael Kay <mhk@mhk.me.uk> wrote:
> > I have one question.. Can we write if without else
> in
> > XQuery?
> 
> No, you can't.
> > 
> > The XQuery grammer says:
> > IfExpr    ::=    "if" "(" Expr ")" "then"
> ExprSingle
> > "else" ExprSingle 
> > 
> > 
> > If else is mandatory, then is'nt it a
> inconvenience..?
> 
> XQuery is an expression language. In most expression
> languages, both
> branches of a conditional are mandatory. The WG
> decided to do it that way
> (a) so the else branch is explicit, (b) to avoid
> dangling-else ambiguities
> in the grammar (the alternative would have been an
> "end-if" keyword). You
> can always write "else ()". And in most cases, like
> this, you can replace
> 
>    for ... return if X then Y else ()
> 
> by
> 
>    for ... where X return Y
> 
> Michael Kay
> http://www.saxonica.com/



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 

Received on Monday, 21 March 2005 14:58:54 UTC