javascript|xml| Sort | data
How to implement Xml+xsl+javascript data sorting
Data Sort Template
<?xml version= "1.0" encoding= "gb2312"?>
<xsl:stylesheet version= "1.1" xmlns:xsl= Http://www.w3.org/1999/XSL/Transform "xmlns:fo=" http://www.w3.org/ 1999/xsl/format ">
<xsl:output method= "html"/>
<xsl:param name= "Queryparam" select= "" "/>
<xsl:template match= "/guestbook" >
<table border= "0" >
<tbody>
<tr>
<td>
<table width= "border=" 0 ">
<tbody>
<xsl:apply-templates select= "article" >
<xsl:sort select= "datadate" order= "Descending"/>
</xsl:apply-templates>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</xsl:template>
<!--article list template:-->
<xsl:template match= "article" >
<xsl:choose>
<xsl:when test= "position () mod 2 = 1" >
<tr bgcolor= "#cccccc" >
<th align= "left" width= "M" > Author </th>
<th align= "left" width= "M" >
<xsl:value-of select= "Author"/>
</th>
<th align= "left" width= "M" > Publishing Time </th>
<th align= "left" width= "M" >
<xsl:value-of select= "Datadate"/>
</th>
</tr>
<tr bgcolor= "#cccccc" >
<TD colspan= "4" >
<xsl:value-of select= "Content"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise>
<tr>
<th align= "left" width= "M" > Author </th>
<th align= "left" width= "M" >
<xsl:value-of select= "Author"/>
</th>
<th align= "left" width= "M" > Publishing Time </th>
<th align= "left" width= "M" >
<xsl:value-of select= "Datadate"/>
</th>
</tr>
<tr>
<TD colspan= "4" >
<xsl:value-of select= "Content"/>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Data files
<?xml version= "1.0" encoding= "gb2312"?>
<guestbook>
<article id= "73a7a287-aef6-4d35-ac2c-638ca3233be6" >
<author>guest</author>
<datadate>20060812</datadate>
<content>asdfsad</content>
</article>
<article id= "84957008-4CB4-4C96-BAFA-775DD33E10CF" >
<author>guest</author>
<datadate>20060812</datadate>
<content>fffff</content>
</article>
<article id= "91426bb3-3bbf-4176-be66-c92cb79bb171" >
<author>guest</author>
<datadate>20060812</datadate>
<content>fffff</content>
</article>
<article id= "8e3bda3f-7d6e-4ae3-af0a-740a884cbf06" >
<author>guest</author>
<datadate>20060812</datadate>
<content>asdf</content>
</article>
<article id= "D6528172-CD03-4333-BB42-0121EFFCA2FF" >
<author>guest</author>
<datadate>20060812</datadate>
<content>asdf</content>
</article>
<article id= "cd30a893-f0aa-44be-b56b-32a1aa44717a" >
<author>guest</author>
<datadate>20060812</datadate>
<content>asdf</content>
</article>
<article id= "b47ca7e6-93e0-4992-97fa-78ea557b0252" >
<author>guest</author>
<datadate>20060812</datadate>
<content>asdf</content>
</article>
<article id= "2070cb5d-e225-46f5-95ca-3dea33f9d42f" >
<author>guest</author>
<datadate>20060812</datadate>
<content>aa</content>
</article>
</guestbook>
Since we have already described how to convert XML to HTML through js+xsl, this will not be the case here. Readers only need to read and understand the sorting template file.