title: xquery "last" function with other selectors
body: <p>I am curious how to use the <code>last()</code> function in Xquery along with other "selectors" (not sure of the correct lingo). Here is what I have (and this works):</p>
  
  <pre><code>for $lastscoreplay in //bbgame/plays/period[last()]/play[@action="GOOD"]
  
  return &lt;datarow&gt;
  
  &lt;lastscoreplay&gt;{data($lastscoreplay/@uni)}&lt;/lastscoreplay&gt;
  
  &lt;/datarow&gt;
  </code></pre>
  
  <p>But, I want to select the last <code>play</code> where the <code>@action</code> equals <code>GOOD</code>. If that makes sense. I would think I could do this but it does not work:</p>
  
  <pre><code>for $lastscoreplay in //bbgame/plays/period[last()]/play[last()][@action="GOOD"]
  
  return &lt;datarow&gt;
  
  &lt;lastscoreplay&gt;{data($lastscoreplay/@uni)}&lt;/lastscoreplay&gt;
  
  &lt;/datarow&gt;
  </code></pre>
  
  <p>Sorry I am still rather new to Xquery and coding in general so sorry if this is easy and I just don't see the problem. Thanks for any help!</p>