[
Lists Home |
Date Index |
Thread Index
]
I think the where clause is indeed redundant. "where X return Y" can always
be replaced by "return if (X) then Y else ()".
The let clause is also redundant - not because it can be replaced by a "for"
clause, which is what you are suggesting, but because references to the
variable can be replaced by the expression to which the variable is bound.
(A "let" can only be replaced by a "for" in the case where the expression
after ":=" returns a singleton).
However, the fact that constructs are redundant doesn't stop them being very
convenient.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Roger L. Costello [mailto:costello@mitre.org]
> Sent: 05 December 2004 14:43
> To: xml-dev@lists.xml.org
> Subject: [xml-dev] [XQuery] FLWOR
> (for-let-where-order-return) equivalent to FOR (for-order-return)?
>
> Hi Folks,
>
> I am wondering about the value of the "let" and "where"
> clause in the XQuery
> FLWOR expression. I believe that the same capability is
> possible simply by
> using a for-order-return expression. If that is true, then I
> wonder about
> the value of FLWOR (recent discussions seem to imply that
> FLWOR is one of
> the "key advantages" of XQuery).
>
> Let me give a couple of examples.
>
> Example 1. Let's start with a simple example. Consider this
> XML document:
>
> <?xml version="1.0"?>
> <Numbers>
> <Number>0</Number>
> <Number>8</Number>
> <Number>23</Number>
> <Number>17</Number>
> <Number>5</Number>
> <Number>19</Number>
> <Number>44</Number>
> <Number>13</Number>
> <Number>78</Number>
> <Number>21</Number>
> <Number>2</Number>
> <Number>1</Number>
> <Number>15</Number>
> <Number>67</Number>
> <Number>99</Number>
> <Number>14</Number>
> <Number>8</Number>
> <Number>33</Number>
> <Number>50</Number>
> </Numbers>
>
> Problem: output all the numbers less than 20, in ascending
> sorted order.
>
> Here's how to do it using for-where-order-return:
>
> for $i in //Number
> where number($i) <= 20
> order by number($i) ascending
> return $i/text()
>
> However, it could just as easily be accomplished with simply
> for-order-return:
>
> for $i in //Number[number(text()) <= 20]
> order by number($i) ascending
> return $i/text()
>
> Thus, we see that for-order-return has the same capability as
> for-where-order-return.
>
> Example 2. Consider these two XML documents which contain
> information about
> Fitness Center members:
>
> <?xml version="1.0"?>
> <MemberNames>
> <Member id="1">
> <Name>Jeff</Name>
> </Member>
> <Member id="2">
> <Name>David</Name>
> </Member>
> .
> </MemberNames>
>
> <?xml version="1.0"?>
> <MemberAges>
> ...
> <Member id="1">
> <Age>35</Age>
> </Member>
> <Member id="2">
> <Age>39</Age>
> </Member>
> ...
> </MemberAges>
>
> Problem: Join each Member's Name with their Age.
>
> Here's how to do it using for-let-where-order-return:
>
> for $i in //Member
> let $j := doc("MemberAges.xml")//Member[@id eq $i/@id]/Age
> where number($i/@id) <= 5
> order by $i/Name/text() ascending
> return
> $i/Name/text(),
> $j/text()
>
> However, it could just as easily be accomplished with simply
> for-order-return:
>
> for $i in //Member[number(@id) <= 5], $j in
> doc("MemberAges.xml")//Member[@id eq $i/@id]/Age
> order by $i/Name/text() ascending
> return
> $i/Name/text(),
> $j/text()
>
> Thus, we see that for-order-return has the same capability as
> for-let-where-order-return.
>
> Is there something that can be done with
> for-let-where-order-return which
> simply cannot be done with for-order-return? If not, then
> what value is
> for-let-where-order-return? Is it simply "syntactic sugar"? /Roger
>
>
>
>
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
>
> The list archives are at http://lists.xml.org/archives/xml-dev/
>
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://www.oasis-open.org/mlmanage/index.php>
>
>
|