Sorting data in a HTML file using XML and XSLT


This example is working fine without sorting. But now I want to sort the data by clicking on the heading of each column.
For example if I click on "days" heading, all the data should be sorted accordingly. If I click on "letter" heading, all the data should be sorted accordingly. How do I do that in my XSLT.
I am using a simple java class to transform into a HTML file. I am pasting my XML, XSLT & JAVA class for applying XSLT.  What do I have to do to sort the data.

<?xml version="1.0" encoding="utf-8"?>
<Messages_Report category="XSLT">
          <message>I agree </message>
Here is my XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
     <xsl:output method="html" />
     <xsl:template match="/">
                    <title>Message Report Details</title>
     font-family: "Tahoma", Sans-Serif;
     font-size: 9pt;
     color: #333333;

     background-color: White;
     margin: 1em;

A:hover {
     color: #0099CC;

.bookTable {
     padding: 2pt;
     width: 100%;
     border: solid 1px #999999;

     padding: 2pt;
     text-align: left;
     border: none;

H1 {
    color: White;
    background-color: #0F3063;
    font-family: "Arial", Sans-Serif;
    font-size: 16pt;
    font-weight: bold;
    height: 22px;
    padding-left: 1pt;

H2 {
    color: gray;
    background-color: #FFFFFF;
    font-family: "Arial", Sans-Serif;
    font-size: 14pt;
    font-weight: bold;
    height: 18px;
    padding-left: 1pt;

.tblHeader {
    background-color: #DADADA;
    font-weight: bold;

.tblFooter {
    background-color: #CACACA;
    font-weight: bold;

<h1>Message Report Detail</h1>
<table class="bookTable" cellspacing="0" cellpadding="0">
<thead class="tblHeader">
<xsl:for-each select="/Messages_Report/messageDetails">
<tr class="bookCell">
     <td><xsl:value-of select="days"/></td>
     <td><xsl:value-of select="msgid"/></td>
     <td><xsl:value-of select="letter"/></td>
     <td><xsl:value-of select="message"/></td>
     <td><xsl:value-of select="status"/></td>

 * Apply XSLT stylesheets
 * Input parameters are names of local XML and XSLT files
 * Output is sent to the console  
 * XSLT Parameters are not supported.

import javax.xml.transform.*;

public class ApplyXSLT {

   public static void main(String[] args) {
      int argsCount=0;
         argsCount = args.length;
         if(argsCount != 2)
            System.err.println("Usage java ApplyXSLT <localXMLFile> " +

            System.err.println("\tjava ApplyXSLT BestBooks.xml BestBooks.xsl ");
            System.err.println("\tjava ApplyXSLT lowercase.xml ToUpper.xsl ");
      catch(Exception exp)

         //   Source XML File
         StreamSource xmlFile = new StreamSource(new File(args[0]));
         //   Source XSLT Stylesheet
         StreamSource xsltFile = new StreamSource(new File(args[1]));
         TransformerFactory xsltFactory = TransformerFactory.newInstance();
         Transformer transformer = xsltFactory.newTransformer(xsltFile);

         //   Send transformed output to the console
         StreamResult resultStream = new StreamResult(System.out);

         //   Apply the transformation
         transformer.transform(xmlFile, resultStream);
      catch(Exception exp)
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.