title: How do I select the last N elements with XPath?
body: <p>I support a web site which generates content XML that is then translated into web pages using XSLT.  I have been asked to create a new stylesheet which will transform the output of the "archive" page into Atom for syndication.  The problem I'm running into is that the archive page contains a rather large number of items — 142 and counting — and the feed should never have more than thirty items.</p>
  
  <p>Currently, the output from the archive page looks something like this:</p>
  
  <pre><code>&lt;archive&gt;
      &lt;year&gt;
          &lt;month&gt;
              &lt;day&gt;
              &lt;day&gt;
              ...
          &lt;/month&gt;
  
          ...
      &lt;/year&gt;
  
      ...
  &lt;/archive&gt;
  </code></pre>
  
  <p>The <code>year</code> and <code>month</code> tags are used by the HTML transform but are completely irrelevant for an Atom feed.  I had hoped that using the <code>position()</code> function with the descendant axis would work (<code>//day[position()&gt;last()-30]</code>), but this selects the last 30 days <em>of each month</em>, which isn't at all what I need.  :-)</p>
  
  <p>Is there a way to do this with XSLT or XPath?  Having to modify the XML generator to add, say, a <code>feed="true"</code> attribute to the last thirty days seems like a pretty nasty kludge.</p>