Discussion:
unknown
1970-01-01 00:00:00 UTC
Permalink
--001a11c30780ecd66c04eef8a2c4
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable <div dir="ltr"><div>So now my code looks like <br></div><div><br>xquery version &quot;3.0&quot;;<br><br>import module namespace sp=&quot;urn:<a href="http://sparkpictures.com">sparkpictures.com</a>&quot; at &#39;common.xqm&#39;;<br> <br>declare function local:getReviews($type as xs:string+) as element(review)* {<br>  $type ! collection($sp:reviewsColl || &#39;/&#39; || .)/reviews/review<br>};<br><br>&lt;stats date=&quot;{current-date()}&quot;&gt;{<br>
  <br>  &lt;reviewData&gt;{(&#39;&#39;,$sp:tabs) ! <br>               (let $reviews:=local:getReviews(.) <br>                  return element {if (.) then . else &#39;total&#39;}<br>                                       {count($reviews)})}&lt;/reviewData&gt;}<br>
 &lt;/stats&gt;<br><br></div>where $sp:tabs just contains a sequence of strings. I have simplified it to just return count($reviews) but the above code gives me<br><br>&lt;?xml version=&quot;1.0&quot; ?&gt;&lt;exception&gt;&lt;path&gt;/db/apps/spark/stats.xq&lt;/path&gt;&lt;message&gt;err:XPDY0002 Undefined context sequence for &#39;self::node()&#39; [source: /db/apps/spark/stats.xq]&lt;/message&gt;&lt;/exception&gt;***@ihe-machine:~/film$ <br>
?<br><div><br><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 1, 2014 at 3:01 PM, David Lee <span dir="ltr">&lt;<a href="mailto:***@calldei.com" target="_blank">***@calldei.com</a>&gt;</span> wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div link="blue" vlink="purple" lang="EN-US"> <div> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">You need to put () around FLOWR expressions after a ! like<u></u><u></u></span></p> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u>?<u></u></span></p> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">(1,2,3) ! ( for $a in . return . )<u></u><u></u></span></p> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u>?<u></u></span></p> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u>?<u></u></span></p> <p class="MsoNormal" style="margin-left:.5in"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:talk-***@x-query.com" target="_blank">talk-***@x-query.com</a> [mailto:<a href="mailto:talk-***@x-query.com" target="_blank">talk-***@x-query.com</a>] <b>On Behalf Of </b>Ihe Onwuka<br> <b>Sent:</b> Wednesday, January 01, 2014 2:03 AM<br> <b>To:</b> <a href="mailto:***@x-query.com" target="_blank">***@x-query.com</a><br> <b>Subject:</b> [xquery-talk] A flowering map<u></u><u></u></span></p><div><div class="h5"> <p class="MsoNormal" style="margin-left:.5in"><u></u>?<u></u></p> <div> <div> <p class="MsoNormal" style="margin-left:.5in">The code below should (it&#39;s been edited) use map to create an element for A B C D within the parent reviewData.<u></u><u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in"><u></u>?<u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in">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.<u></u><u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in"><u></u>?<u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in">xquery version &quot;3.0&quot;;<u></u><u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in"><u></u>?<u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in">declare variable $coll:=&#39;/db/apps/spark/&#39;;<u></u><u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in"><u></u>?<u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in">declare function local:getReviews($type as xs:string+) as element(review)* {<u></u><u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in">? $type ! collection($coll || .))/descendant::review<u></u><u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in">};<u></u><u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in"><u></u>?<u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in">&lt;stats date=&quot;{current-date()}&quot;&gt;<u></u><u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in">? &lt;reviewData&gt;{(&#39;&#39;,&#39;A&#39;,&#39;B&#39;,&#39;C&#39;,&#39;D&#39;) ! ?<u></u><u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in">? ? ? ? ? ? ? element {if (.) then . else &#39;total&#39;}<u></u><u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in">� � � � � � � � � � � {local:getReviews(.)/(count(.),count(distinct-values(thing/@link)))}&lt;/reviewData&gt;}<u></u><u></u></p> </div> <div> <p class="MsoNormal" style="margin-left:.5in"> &lt;/stats&gt;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">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.<u></u><u></u></p>

</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">

Loading...