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

RE: FLOR or FLWOR

Hans-Juergen Rennau hrennau at yahoo.de
Mon Sep 15 05:54:42 PDT 2008


  RE: FLOR or FLWOR
Hello, Rob,

it seems to me important to remember two facts about FLWOR expressions:
a) they may not only create loops but procure intermediate results (via let clause)
b) to remove a tuple from the tuple stream, a predicate has to be placed in a for clause

If the filter condition refers to such an intermediate result, it is very convenient that we have the where, because otherwise we would have to create the intermediary twice: once to procure the predicate (as part of a for loop), and once to be used later on (as a let clause).

As an illustration consider this query:

(:---------------------------------------------------------------------------------------:) 
  string-join(
   for $owner in distinct-values(//ContainerDataList/@EIGT)
   let $nrs := distinct-values(//ContainerDataList[@EIGT eq $owner]/@CONR)
   where count($nrs) le 2
   order by $owner 
   return (
     concat($owner, "  (", count($nrs), ")"),
     for $n in $nrs return concat("            ", $n)
   )
, "
")
(:---------------------------------------------------------------------------------------:) 


 The intermediate ($nrs) is definitely needed later on, and the filter condition refers to it. To replace the where by a predicate, one would end up with something like this:

 (:---------------------------------------------------------------------------------------:) 
 string-join(
   let $in := .
   for $owner in distinct-values(//ContainerDataList/@EIGT)
      [let $o := . return count(distinct-values($in//ContainerDataList[@EIGT eq $o]/@CONR)) le 2]
   let $nrs := distinct-values(//ContainerDataList[@EIGT eq $owner]/@CONR)
   order by $owner 
   return (
     concat($owner, "  (", count($nrs), ")"),
     for $n in $nrs return concat("       ", $n)
   )
, "
")
(:---------------------------------------------------------------------------------------:) 

which is horrible, isn't it? The alternative would be to introduce an artificial for clause:

(:---------------------------------------------------------------------------------------:) 
  string-join(
   for $owner in distinct-values(//ContainerDataList/@EIGT)
   let $nrs := distinct-values(//ContainerDataList[@EIGT eq $owner]/@CONR)
   for $dummy in 1[count($nrs) le 1]
   return (
     concat($owner, "  (", count($nrs), ")"),
     for $n in $nrs return concat("       ", $n)
   )
, "
")
(:---------------------------------------------------------------------------------------:) 


If anyone considers this an acceptable alternative to a where clause, I give up.

With kind regards -
Hans-Juergen Rennau

> Message: 2
>Date: Tue, 9 Sep 2008 21:01:36 -0400
>  From: Robert Koberg <http://x-query.com/mailman/listinfo/talk>
> Subject:  FLOR or FLWOR
> To: http://x-query.com/mailman/listinfo/talk
> Message-ID: <http://x-query.com/mailman/listinfo/talk>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>
> Hi,
> 
> Where would you use 'where' that couldn't be handled by XPath? In  
> other words, why is there a where?
>
> best,
> -Rob
***********************************


__________________________________________________
Do You Yahoo!?
Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails. 
http://mail.yahoo.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.