title: Sorting with getElementsByTagName
body: <p>I would like to parse an xml file and list the elements in a different order than they appears  in the xml. Each child elements have a name and a number value, i would like to list the names but in the order of the number values. The xml file looks similar to this:</p>
  
  <pre><code> &lt;stories&gt;
      &lt;story&gt;
        &lt;name&gt;fast&lt;/name&gt;
        &lt;number&gt;1000&lt;/number&gt;
      &lt;/story&gt;
      &lt;story&gt;
        &lt;name&gt;bomb&lt;/name&gt;
        &lt;number&gt;2&lt;/number&gt;
      &lt;/story&gt;
      &lt;story&gt;
        &lt;name&gt;descend&lt;/name&gt;
        &lt;number&gt;500&lt;/number&gt;
      &lt;/story&gt;
      &lt;story&gt;
        &lt;name&gt;A&lt;/name&gt;
        &lt;number&gt;1&lt;/number&gt;
      &lt;/story&gt;
      &lt;story&gt;
        &lt;name&gt;can&lt;/name&gt;
        &lt;number&gt;40&lt;/number&gt;
      &lt;/story&gt;
      &lt;story&gt;
        &lt;name&gt;extremely&lt;/name&gt;
        &lt;number&gt;10000&lt;/number&gt;
      &lt;/story&gt;
   &lt;/stories&gt;
  </code></pre>
  
  <p>update:
  and my script looks something like this atm:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var xmlhttp = new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari
  testOpen = xmlhttp;
  testOpen.open("GET", "test.xml", false);
  xmlhttp.send();
  testDoc = testOpen.responseXML;
  stories = testDoc.getElementsByTagName("story");
  function display(){
      var arrayStory = Array.prototype.slice.call(stories, 0);
      arrayStory.sort(function(a, b){
          return a.getElementsByTagName("number")[0].firstChild.nodeValue - b.getElementsByTagName("number")[0].firstChild.nodeValue;
      });
      document.getElementById("show").innerHTML = arrayStory.map(function(story){
          return story.getElementsByTagName("name")[0].firstChild.nodeValue;
      }).join("&lt;br&gt;");
  };
  &lt;/script&gt;
  </code></pre>
  
  <p>i've got my listorder working this way. my question would be that, how can i list the numbers(or any additional nodevalue) next to the names (without using tables) and how can i setup conditions/creating sublists in a list like this(if i cannot, please help me create a list where i can), I would appreciate your help! Thanks in advance!</p>