title: XSL Fetch All Items From Child Nodes and Get the First 2 Data with the Nearest Date
body: <p>What I am trying to achieve is to fetch all matches (participant) from  nodes and sort them according to the date and get the 2 oldest matches. What I have achieved so far fetching 2 matches from each fixtures nodes separately.</p>
  
  <pre><code>&lt;spocosy version="1.0"&gt;
  &lt;fixtures id="820745" ut="2011-03-01" sport="Football" template="England Premier League" tournament="2010/2011" league="Premier League"&gt;
  &lt;fixture id="839993" name="Chelsea-Manchester United" date="2011-03-01 20:45:00" round="18" status="Not started"&gt;
  &lt;participants&gt;
  &lt;participant participantid="8455" participantname="Chelsea"/&gt;
  &lt;participant participantid="10260" participantname="Manchester United"/&gt;
  &lt;/participants&gt;
  &lt;/fixture&gt;
  &lt;fixture id="840142" name="Birmingham-West Bromwich" date="2011-03-05 13:45:00" round="29" status="Not started"&gt;
  &lt;participants&gt;
  &lt;participant participantid="8658" participantname="Birmingham"/&gt;
  &lt;participant participantid="8659" participantname="West Bromwich"/&gt;
  &lt;/participants&gt;
  &lt;/fixture&gt;
  &lt;fixture id="840143" name="Bolton-Aston Villa" date="2011-03-05 16:00:00" round="29" status="Not started"&gt;
  &lt;participants&gt;
  &lt;participant participantid="8559" participantname="Bolton"/&gt;
  &lt;participant participantid="10252" participantname="Aston Villa"/&gt;
  &lt;/participants&gt;
  &lt;/fixture&gt;
  &lt;/fixtures&gt;
  
  &lt;fixtures id="821290" ut="2011-03-01" sport="Football" template="Spain LIGA BBVA" tournament="2010/2011" league="LIGA BBVA"&gt;
  &lt;fixture id="875757" name="Espanyol-Mallorca" date="2011-03-01 20:00:00" round="26" status="Not started"&gt;
  &lt;participants&gt;
  &lt;participant participantid="8558" participantname="Espanyol"/&gt;
  &lt;participant participantid="8661" participantname="Mallorca"/&gt;
  &lt;/participants&gt;
  &lt;/fixture&gt;
  &lt;fixture id="875739" name="Sevilla-Gijon" date="2011-03-01 22:00:00" round="26" status="Not started"&gt;
  &lt;participants&gt;
  &lt;participant participantid="8302" participantname="Sevilla"/&gt;
  &lt;participant participantid="9869" participantname="Gijon"/&gt;
  &lt;/participants&gt;
  &lt;/fixture&gt;
  &lt;fixture id="875737" name="Zaragoza-Athletic Bilbao" date="2011-03-02 20:00:00" round="26" status="Not started"&gt;
  &lt;participants&gt;
  &lt;participant participantid="8394" participantname="Zaragoza"/&gt;
  &lt;participant participantid="8315" participantname="Athletic Bilbao"/&gt;
  &lt;/participants&gt;
  &lt;/fixture&gt;
  &lt;fixture id="875743" name="Getafe-Atletico Madrid" date="2011-03-02 20:00:00" round="26" status="Not started"&gt;
  &lt;participants&gt;
  &lt;participant participantid="8305" participantname="Getafe"/&gt;
  &lt;participant participantid="9906" participantname="Atletico Madrid"/&gt;
  &lt;/participants&gt;
  &lt;/fixture&gt;
  &lt;fixture id="875746" name="Villarreal-Hercules" date="2011-03-02 20:00:00" round="26" status="Not started"&gt;
  &lt;participants&gt;
  &lt;participant participantid="10205" participantname="Villarreal"/&gt;
  &lt;participant participantid="10278" participantname="Hercules"/&gt;
  &lt;/participants&gt;
  &lt;/fixture&gt;
  &lt;/fixtures&gt;
  
  there are 5 fixtures
  &lt;xsl:template match="fixtures"&gt;
  
   &lt;xsl:for-each select="//fixture"&gt;
      &lt;xsl:sort select="@date" data-type="text" order="ascending"/&gt;
      &lt;xsl:if test="position() &amp;lt; 3"&gt;
  
         &lt;xsl:variable name="eventid" select="@id"/&gt;
      &lt;table class="default soccer"&gt;
          &lt;tbody&gt;
              &lt;tr class="finished livestats event_row"&gt;
                  &lt;td class="status tz_field" data-format="short_datetime"&gt;&lt;xsl:value-of select="@date"&gt;&lt;/xsl:value-of&gt;&lt;/td&gt;
                  &lt;td class="team_1"&gt;
                      &lt;div class="of_wrapper"&gt;
                      &lt;span /&gt;
                      &lt;xsl:value-of select="//participant[position()=1]/@participantname"&gt;&lt;/xsl:value-of&gt;
                      &lt;/div&gt;
                  &lt;/td&gt;
                  &lt;td id="res_{$eventid}" class="result bold link popup"&gt;
                       - 
                  &lt;/td&gt;
                  &lt;td class="team_2"&gt;
                      &lt;div class="of_wrapper"&gt;
                      &lt;span /&gt;
                      &lt;xsl:value-of select="//participant[position()=2]/@participantname"&gt;&lt;/xsl:value-of&gt;                 
                      &lt;/div&gt;
                  &lt;/td&gt;               
              &lt;/tr&gt;
          &lt;/tbody&gt;
          &lt;/table&gt;
  
  
      &lt;/xsl:if&gt;
    &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p></p>
  
  <p>And here is the output of it</p>
  
  <p><img src="https://i.stack.imgur.com/iTmzL.jpg" alt="enter image description here"></p>
  
  <p>In that output, dates are the oldest 2 which is what I want to achieve but they are displayed for each fixtures again and again (there are 5 fixtures and the dates are displayed totally 10 times instead of 2) and the teams are not related to the dates, teams are displayed from the first participants node.</p>
  
  <p>I don't necessarily want exact code, any approaches would be also appreciated. So briefly I want to fetch all matches then sort them according to the date and display the oldest 2 machtes with the exact dates.</p>