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

by

   for ... where X return Y

Michael Kay
http://www.saxonica.com/
Received on Monday, 21 March 2005 14:22:48 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:17:17 UTC