W3C home > Mailing lists > Public > www-ql@w3.org > January to March 2005

RE: how to prune subtrees in an XQuery result

From: Michael Kay <mhk@mhk.me.uk>
Date: Mon, 21 Mar 2005 14:22:12 -0000
To: "'Mukul Gandhi'" <mukul_gandhi@yahoo.com>, "'Sergio Andreozzi'" <sergio.andreozzi@cnaf.infn.it>
Cc: <www-ql@w3.org>
Message-ID: <E1DDNns-0004kE-UO@frink.w3.org>

> 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 ()


   for ... where X return Y

Michael Kay
Received on Monday, 21 March 2005 14:22:48 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:43:43 UTC