[xquery-talk] Recursion problem

Michael Kay mike at saxonica.com
Fri Sep 7 11:42:55 PDT 2007


How do you know it is making n calls?

In principle the processor can call the function as often as it likes. It
might be inefficient, but it's not disallowed, so long as the results are
the same as calling it once.

You mention recursion in your title, but I don't see any recursion here.

It would be useful to give a sample input and your desired output, and show
how your actual output differs; also to give the whole query not just an
extract.

What product are you using?

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: talk-bounces at x-query.com 
> [mailto:talk-bounces at x-query.com] On Behalf Of Jens-Martin Groenne
> Sent: 07 September 2007 09:55
> To: talk at x-query.com
> Subject: [xquery-talk] Recursion problem
> 
> I have a problem with the following code.
> When I call this function it actually makes n calls to the 
> functions getCustomer and getAddress, where n is the number 
> of customerIds and addressIds in the Criteria.
> 
> Can anyone point out to me what I have done wrong?
> 
> Here is the code:
> declare function tns:getCustomer($Criteria as 
> element(ns30:Criteria)) as element(ns28:Customer)*{
> 
>             let $CustCustomers := ns32:getCustomer(
>                     <ns33:CustCriteria>
>                         {
>                         for $customerId in
> fn:distinct-values($Criteria/ns30:customerId)
>                         return
>                         
> <ns33:custId>{fn:data($customerId)}</ns33:custId>
>                         }
>                     </ns33:CustCriteria>
>                 )
> 
>               let $AddAddresses := ns7:getAddress(
>                     <ns8:AddressGetCriteria>
>                     {
>                     for $addressId in
> fn:distinct-values($Criteria/ns30:addressId)
>                     return
>                     <ns8:farId>{fn:data($addressId)}</ns8:farId>
>                     }
>                     </ns8:AddressGetCriteria>
>                 )
> 
> 
>               for   $searchCustomer in $Criteria
>               return
>                 for  $resultCustomer in $CustCustomers/ns28:Customer
>                 where $searchCustomer/ns30:customerId = 
> $resultCustomer/ns28:customerId
>                 return
>                 <ns28:Customer>
>                 {
>                 for $Person in $resultCustomer/ns28:Person
>                 return $Person
>                 }
>                 {
>                 for $Organization in $resultCustomer/ns28:Organization
>                 return $Organization
>                 }
> 
>                 {
>                 for $resultAddress in $AddAddresses
>                     where $resultAddress/ns29:addressId = 
> $searchCustomer/ns30:addressId
>                     return
>                     $resultAddress
>                 }
>             </ns28:Customer>
> 
> };
> 
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk



More information about the talk mailing list