You need to put () around FLOWR expressions after a ! like (1,2,3) ! ( for $a in . return . )
From: talk-boun...@x-query.com [mailto:talk-boun...@x-query.com] On Behalf Of Ihe Onwuka Sent: Wednesday, January 01, 2014 2:03 AM To: talk@x-query.com 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
_______________________________________________ talk@x-query.com http://x-query.com/mailman/listinfo/talk