title: Limit sorted conditional xsl:for-each results to n values
body: <p>I looked around on the site but wasn't able to locate a solution to a particular XSL problem. If you recognize this as a duplicate post I apologize and would be thankful to be pointed in the right direction.</p>
  
  <p>Based on the relatively simple XML data set below I want to create a table by project but also limit the entries to something more 'digestible' like the 'newest' 10 for that project.</p>
  
  <pre><code>+---------------------------------------------------+  
  | Alpha                   | Beta                    |  
  +---------------------------------------------------+  
  | Log_20091014_0900PM.xml | Log_20091015_0900PM.xml |  
  | Log_20091013_0900PM.xml | ...                     |  
  | ...                     |                         |  
  +---------------------------------------------------+  
  | Gamma                   | Delta                   |  
  +---------------------------------------------------+  
  | ...                     | ...                     |  
  +---------------------------------------------------+  
  </code></pre>
  
  <p>XML source data of the form:</p>
  
  <pre><code>&lt;LogResults&gt;
    &lt;Result&gt;
      &lt;Project&gt;Alpha&lt;/Project&gt;
      &lt;Data&gt;Log_20091013_0900PM.xml&lt;/Data&gt;
      &lt;Name&gt;Log_20091013_0900PM.xml&lt;/Name&gt;
    &lt;/Result&gt;
    &lt;Result&gt;
      &lt;Project&gt;Alpha&lt;/Project&gt;
      &lt;Data&gt;Log_20091014_0900PM.xml&lt;/Data&gt;
      &lt;Name&gt;Log_20091014_0900PM.xml&lt;/Name&gt;
    &lt;/Result&gt;
    &lt;Result&gt;
      &lt;Project&gt;Beta&lt;/Project&gt;
      &lt;Data&gt;Log_20091015_0900PM.xml&lt;/Data&gt;
      &lt;Name&gt;Log_20091015_0900PM.xml&lt;/Name&gt;
    &lt;/Result&gt;
    &lt;Result&gt;
      &lt;Project&gt;Gamma&lt;/Project&gt;
      &lt;Data&gt;Log_20091016_0900PM.xml&lt;/Data&gt;
      &lt;Name&gt;Log_20091016_0900PM.xml&lt;/Name&gt;
    &lt;/Result&gt;
    &lt;Result&gt;
      &lt;Project&gt;Delta&lt;/Project&gt;
      &lt;Data&gt;Log_20091019_0900PM.xml&lt;/Data&gt;
      &lt;Name&gt;Log_20091019_0900PM.xml&lt;/Name&gt;
    &lt;/Result&gt;
    &lt;Result&gt;
      &lt;Project&gt;Delta&lt;/Project&gt;
      &lt;Data&gt;Log_20091020_0900PM.xml&lt;/Data&gt;
      &lt;Name&gt;Log_20091020_0900PM.xml&lt;/Name&gt;
    &lt;/Result&gt;
    ...
  &lt;/LogResults&gt;
  </code></pre>
  
  <p>I am able to show <em>ALL</em> results for each project with appropriate variations of the following XSL:</p>
  
  <pre><code>&lt;xsl:for-each select="LogResults/Result"&gt;
    &lt;xsl:sort select="Data" order="descending" /&gt;
    &lt;xsl:if test="(Project='Alpha')"&gt;
      &lt;li&gt;
        &lt;a style="font-size:11pt;"&gt;
          &lt;xsl:attribute name="href"&gt;
            Alpha/&lt;xsl:value-of select="Data" /&gt;
          &lt;/xsl:attribute&gt;
          &lt;xsl:value-of select="Name" /&gt;
        &lt;/a&gt;
      &lt;/li&gt;
    &lt;/xsl:if&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p>Is it possible to limit the results to the 'newest' 10 (or 20 ...)? And if so how would you suggest this to be done?</p>
  
  <p>I tried to use <code>position()</code> in the following way for example</p>
  
  <pre><code>&lt;xsl:for-each select="(LogResults/Result) [position &amp;lt; 11]"&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>&lt;xsl:if test="(Project='Alpha')"&gt;
    &lt;xsl:for-each select=". [position &amp;lt; 11]"&gt;
      &lt;li&gt;
        &lt;a style="font-size:11pt;"&gt;
          &lt;xsl:attribute name="href"&gt;
            Alpha/&lt;xsl:value-of select="Data" /&gt;
          &lt;/xsl:attribute&gt;
          &lt;xsl:value-of select="Name" /&gt;
        &lt;/a&gt;
      &lt;/li&gt;
    &lt;/xsl:for-each&gt;
  &lt;/xsl:if&gt;
  </code></pre>
  
  <p>But so far I couldn't get it to work. Certainly because it's more trail and error right now.</p>
  
  <p>Thanks a lot for even reading this and any potential advice.
  -T</p>