title: Parsing a fixed number of XML children ordered by last using PHP
body: <p>I am attempting to return a fixed number of XML nodes ordered by last so that I can display a "Recently added" filter.  I am not storing the date. How do I filter on the last 10 nodes using PHP?</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;trackList&gt;
    &lt;track&gt;
      &lt;title&gt;Lost in the Star&lt;/title&gt;
      &lt;creator&gt;Toshiki Hayashi&lt;/creator&gt;
      &lt;cover&gt;images/thinlines.jpg&lt;/cover&gt;
      &lt;location&gt;mp3/toshiki hayashi - lost in the star.mp3&lt;/location&gt;
      &lt;genre&gt;hip-hop&lt;/genre&gt;
      &lt;playlist&gt;2&lt;/playlist&gt;
    &lt;/track&gt;
    &lt;track&gt;
      &lt;title&gt;Black Orpheusr&lt;/title&gt;
      &lt;creator&gt;Ouska&lt;/creator&gt;
      &lt;cover&gt;images/ouska.jpg&lt;/cover&gt;
      &lt;location&gt;mp3/ouska - Black Orpheus.mp3&lt;/location&gt;
      &lt;genre&gt;rock&lt;/genre&gt;
      &lt;playlist&gt;2&lt;/playlist&gt;
    &lt;/track&gt;
    &lt;track&gt;
      &lt;title&gt;Soul Below&lt;/title&gt;
      &lt;creator&gt;Ljones&lt;/creator&gt;
      &lt;cover&gt;images/Ljones.jpg&lt;/cover&gt;
      &lt;location&gt;mp3/Ljones - Soul Below.mp3&lt;/location&gt;
      &lt;genre&gt;hip-hop&lt;/genre&gt;
      &lt;playlist&gt;2&lt;/playlist&gt;
    &lt;/track&gt;
  &lt;/trackList&gt;
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php
  $xml = new SimpleXMLElement('playlist100.xml', NULL, TRUE);
  
  foreach($xml-&gt;xpath('//track[playlist="1"]') as $child)
      {
      echo '&lt;div class="song"&gt;&lt;a href="' . $child-&gt;location . '"&gt;';
      echo '&lt;img src="' . $child-&gt;cover . '" alt="cover" /&gt;';
      echo '&lt;span class="artist"&gt;' . $child-&gt;creator . '&lt;/span&gt;';
      echo '&lt;span class="songTitle"&gt;' . $child-&gt;title . '&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;';
      }
  
  ?&gt;
  </code></pre>