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.
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?
Here are the 3 files
THIS IS THE HTML FILE WITH A SCRIPT I'M USING TO VISUALIZE IT
<html>
<body>
<script>
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("<table border='1'>");
var x=xmlDoc.getElementsByTagName("TERM");for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("WORD")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write("</td><td>");
document.write(x[i].getElementsByTagName("LANGUAGE")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("DESCRIPTION")[0].childNodes[0].nodeValue);
document.write("</td></td>");
document.write("</td><td>");
document.write(x[i].getElementsByTagName("EDITBY")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
</body>
</html>
//------------------------------ THIS IS THE XML FILE res.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<?xml-stylesheet type="text/xsl" href="tt.xsl"?>
<LIBRARY>
<TERM>
<EDITBY>giovanni</EDITBY>
<WORD>ciao</WORD>
<LANGUAGE>Italian</LANGUAGE>
<DESCRIPTION>
it means hi
</DESCRIPTION>
</TERM>
<TERM>
<EDITBY>giacomo</EDITBY>
<WORD>all</WORD>
<LANGUAGE>italian</LANGUAGE>
<DESCRIPTION>
significa tutto
</DESCRIPTION>
</TERM>
</LIBRARY>
//----------------------------------
THIS IS THE XSL tt.xsl
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="LIBRARY/TERM">
<xsl:sort select="WORD"/>
<tr>
<td><xsl:value-of select="LANGUAGE"/></td>
<td><xsl:value-of select="WORD"/></td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
RESULT, IT SHOWS THE DATA BUT NOT IN ALPHABETICAL ORDER
ANY HELP WOULD BE GREATLY APPRECIATED