title: xslt: matching position of filtered and sorted result set
body: <p>this is a follow up <a href="https://stackoverflow.com/questions/5067791/xslt-matching-first-x-items-of-filtered-result-set">to this post</a>. Basically I need to get the <code>position()</code> of items within a filtered <em>and sorted</em> collection. Any advice on how to proceed with this?</p>
  
  <p>Thanks!</p>
  
  <p><strong>XML:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;news&gt;
      &lt;newsItem id="1"&gt;
          &lt;title&gt;Title 1&lt;/title&gt;
      &lt;/newsItem&gt;
      &lt;newsItem id="2"&gt;
          &lt;title&gt;Title 2&lt;/title&gt;
      &lt;/newsItem&gt;
      &lt;newsItem id="3"&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/newsItem&gt;
      &lt;newsItem id="4"&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/newsItem&gt;
      &lt;newsItem id="5"&gt;
          &lt;title&gt;Title 5&lt;/title&gt;
      &lt;/newsItem&gt;
  &lt;/news&gt;
  </code></pre>
  
  <p><strong>XSL:</strong></p>
  
  <p>
  
      </p>
  
  <pre><code>&lt;xsl:template match="/"&gt;
      &lt;ol&gt;
          &lt;xsl:apply-templates select="/news/newsItem [string(title)][3 &gt; position()]"&gt;
              &lt;xsl:sort order="descending" data-type="number" select="@id"/&gt;
          &lt;/xsl:apply-templates&gt;
      &lt;/ol&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="newsItem"&gt;
      &lt;li&gt;
          &lt;xsl:value-of select="title"/&gt;
      &lt;/li&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="*" /&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Desired Result:</strong></p>
  
  <ol>
  <li>Title 5</li>
  <li>Title 2</li>
  </ol>
  
  <p><strong>Actual Result:</strong></p>
  
  <ol>
  <li>Title 2</li>
  <li>Title 1</li>
  </ol>