title: very simple but i got lost, sorting alphabetically xml using xsl and visualize output in html
body: <p>I'm creating something like a dictionary online where users can add their words using a simple form and then they can see all the words in a page, in alphabetical order of the words, the problem is that it doesn't show it alphabetically but in the order of insertion.</p>
  
  <p>I got 3 files, res.xml, which is the file with the data, tt.xsl which is supposed to sort res.xml in alphabetical order, and index.html which shows the data to the user, i would like to sort the data contained in the xml file alphabetically using the attribute 'WORD', but when i run index.html it doesn't sort it , it just shows it in the order of reading data, what's the easiest way to make it work?</p>
  
  <p>Here are the 3 files</p>
  
  <p>THIS IS THE HTML FILE WITH A SCRIPT I'M USING TO VISUALIZE IT</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;script&gt;
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
   }
  else
   {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  xmlhttp.open("GET","res.xml",false);
  
  xmlhttp.send();
  xmlDoc=xmlhttp.responseXML; 
  
  document.write("&lt;table border='1'&gt;");
  var x=xmlDoc.getElementsByTagName("TERM");for (i=0;i&lt;x.length;i++)
  { 
  document.write("&lt;tr&gt;&lt;td&gt;");
  document.write(x[i].getElementsByTagName("WORD")[0].childNodes[0].nodeValue);
  document.write("&lt;/td&gt;&lt;td&gt;");
  
  document.write("&lt;/td&gt;&lt;td&gt;");
  document.write(x[i].getElementsByTagName("LANGUAGE")[0].childNodes[0].nodeValue);
  document.write("&lt;/td&gt;&lt;td&gt;");
  
  document.write(x[i].getElementsByTagName("DESCRIPTION")[0].childNodes[0].nodeValue);
  document.write("&lt;/td&gt;&lt;/td&gt;");
  
  document.write("&lt;/td&gt;&lt;td&gt;");
  document.write(x[i].getElementsByTagName("EDITBY")[0].childNodes[0].nodeValue);
  document.write("&lt;/td&gt;&lt;/tr&gt;");
  }
  document.write("&lt;/table&gt;");
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>//------------------------------
  THIS IS THE XML FILE res.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;!-- Edited by XMLSpy® --&gt;
  
  
  &lt;?xml-stylesheet type="text/xsl" href="tt.xsl"?&gt;
  
  &lt;LIBRARY&gt;
  &lt;TERM&gt;
  &lt;EDITBY&gt;giovanni&lt;/EDITBY&gt;
  &lt;WORD&gt;ciao&lt;/WORD&gt;
  &lt;LANGUAGE&gt;Italian&lt;/LANGUAGE&gt;
  &lt;DESCRIPTION&gt;
  it means hi
  &lt;/DESCRIPTION&gt;  
  &lt;/TERM&gt;
  
  
  &lt;TERM&gt;
  &lt;EDITBY&gt;giacomo&lt;/EDITBY&gt;
  &lt;WORD&gt;all&lt;/WORD&gt;
  &lt;LANGUAGE&gt;italian&lt;/LANGUAGE&gt;
  &lt;DESCRIPTION&gt;
  significa tutto
  &lt;/DESCRIPTION&gt;  
  &lt;/TERM&gt;
  
  &lt;/LIBRARY&gt;
  </code></pre>
  
  <p>//----------------------------------</p>
  
  <p>THIS IS THE XSL tt.xsl</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt; 
  &lt;xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
  &lt;xsl:template match="/"&gt;
  
  
  
  &lt;xsl:for-each select="LIBRARY/TERM"&gt;
    &lt;xsl:sort select="WORD"/&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;xsl:value-of select="LANGUAGE"/&gt;&lt;/td&gt;
      &lt;td&gt;&lt;xsl:value-of select="WORD"/&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/xsl:for-each&gt;
  
  
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>RESULT, IT SHOWS THE DATA BUT NOT IN ALPHABETICAL ORDER</p>
  
  <p>ANY HELP WOULD BE GREATLY APPRECIATED </p>