title: Updating counter in XQuery
body: <p>I want to create a counter in xquery. My initial attempt looked like the following:</p>
  
  <pre class="lang-xquery prettyprint-override"><code>let $count := 0
  for $prod in $collection
  let $count := $count + 1
  return 
  &lt;counter&gt;{$count }&lt;/counter&gt;
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;counter&gt;1&lt;/counter&gt;
  &lt;counter&gt;2&lt;/counter&gt;  
  &lt;counter&gt;3&lt;/counter&gt;
  </code></pre>
  
  <p>Actual result:  </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;counter&gt;1&lt;/counter&gt;
  &lt;counter&gt;1&lt;/counter&gt;  
  &lt;counter&gt;1&lt;/counter&gt;
  </code></pre>
  
  <p>The <code>$count</code> variable either failing to update or being reset. Why can't I reassign an existing variable? What would be a better way to get the desired result?</p>