[xquery-talk] A flowering map

William Candillon wcandillon at gmail.com
Wed Jan 1 10:52:20 PST 2014


Hello,

I think that you are missing a return clause after the let clause.

William

On Wed, Jan 1, 2014 at 8:02 AM, Ihe Onwuka <ihe.onwuka at gmail.com> wrote:
> 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
>
>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk


More information about the talk mailing list