title: Xquery 1.0 - query to get the average of some elements, and put that average back in the same place
body: <p>So I have an XML file like this:</p>
  
  <pre><code>&lt;data&gt;
      &lt;person name="john" lastname="doe" &gt;
          &lt;grades&gt;
              &lt;math&gt;90&lt;/math&gt;
              &lt;biology&gt;23&lt;/biology&gt;
          &lt;/grades&gt;
      &lt;/person&gt;
      .
      .
  </code></pre>
  
  <p></p>
  
  <p>I know how to query this to get the average of all the grades, but I want to take that average and put it in the exact same place that grades are in for the original xml file, replacing grades. So I would have something like:</p>
  
  <pre><code>&lt;data&gt;
      &lt;person name="john" lastname="doe" &gt;
          &lt;average&gt;56.5&lt;/average&gt; 
      &lt;/person&gt;
      .
      .
  </code></pre>
  
  <p></p>
  
  <p>edit: I actually figured out a way to get the needed results internally, thanks for the suggestion to this problem though, it may help me in the future. </p>