Ihe Onwuka
2014-01-01 07:02:51 UTC
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.
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.