So now my code looks like

xquery version "3.0";

import module namespace sp="urn:sparkpictures.com" at 'common.xqm';

declare function local:getReviews($type as xs:string+) as element(review)* {
  $type ! collection($sp:reviewsColl || '/' || .)/reviews/review
};

<stats date="{current-date()}">{

  <reviewData>{('',$sp:tabs) !
               (let $reviews:=local:getReviews(.)
                  return element {if (.) then . else 'total'}
                                       {count($reviews)})}</reviewData>}
 </stats>

where $sp:tabs just contains a sequence of strings. I have simplified it to
just return count($reviews) but the above code gives me

<?xml version="1.0"
?><exception><path>/db/apps/spark/stats.xq</path><message>err:XPDY0002
Undefined context sequence for 'self::node()' [source:
/db/apps/spark/stats.xq]</message></exception>ihe@ihe-machine:~/film$





On Wed, Jan 1, 2014 at 3:01 PM, David Lee <[email protected]> wrote:

>  You need to put () around FLOWR expressions after a ! like
>
>
>
> (1,2,3) ! ( for $a in . return . )
>
>
>
>
>
> *From:* [email protected] [mailto:[email protected]] *On
> Behalf Of *Ihe Onwuka
> *Sent:* Wednesday, January 01, 2014 2:03 AM
> *To:* [email protected]
> *Subject:* [xquery-talk] A flowering map
>
>
>
> The code below should (it's been edited) use map to create an element for
> A B C D within the parent reviewData.
>
>
>
> The call to local:getReview is expensive though, so to avoid calling it
> twice I am returning a sequence as the content of the element constructor.
>
>
>
> xquery version "3.0";
>
>
>
> declare variable $coll:='/db/apps/spark/';
>
>
>
> declare function local:getReviews($type as xs:string+) as element(review)*
> {
>
>   $type ! collection($coll || .))/descendant::review
>
> };
>
>
>
> <stats date="{current-date()}">
>
>   <reviewData>{('','A','B','C','D') !
>
>               element {if (.) then . else 'total'}
>
>
> {local:getReviews(.)/(count(.),count(distinct-values(thing/@link)))}</reviewData>}
>
>  </stats>
>
>
>
> What I would like to do is cache the result of calling local:getReviews so
> that I am not pushed into returning a sequence just so as to avoid multiple
> expensive calls to local:getReviews.
>
>
>
> From my reading of the spec you should be able to have  a FLOWR expression
> on the right side of the map operator which if I could do it would give me
>
>
>
>   <reviewData>{('','A','B','C','D') !  let $reviews:=local:getReviews(.)
>
>               element {if (.) then . else 'total'}
>
>
> {$reviews/(count(.),count(distinct-values($reviews/thing/@link)))}</reviewData>}
>
>
>
> following which I would dress up the output in the way I want.
>
>
>
> Trying to put the let where I did however gives me
> unexpected token: $ (while expecting closing tag for element construct
>
>
>
> hence I am not sure whether my reading of the spec is wrong or whether
> it's an implementation issue (this happened on eXist) or a general screw up
> due to my rusty XQuery
>
>
>
>
>
_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk

Reply via email to