Ordering a table with XSL

Hello,

I have an XML and a XSL to display my XML file as a HMTL table. But this table must be ordered by one of the columns.

I tried to use <xsl:sort>, but my stylesheet "http://www.w3.org/TR/WD-xsl" does not accept it. When I change to "http://www.w3.org/TR/2001/REC-xsl-20011015/", it accepts the <xsl:sort>, but the HMTL table is always empty!!!

Does anyone know what could be the problem?

Thanks for the help,
Wagner
[481 byte] By [wschalch] at [2007-11-19 8:35:58]
# 1 Re: Ordering a table with XSL
Any particular reason you are not using the proper " http://www.w3.org/1999/XSL/Transform" namespace instead of that working draft or XSL-FO namespace ?.

If you continue to have problems you should probably post your xsl code.
khp at 2007-11-10 3:27:35 >
# 2 Re: Ordering a table with XSL
Hello,

Thanks for help...

When I change to "http://www.w3.org/1999/XSL/Transform" the following part of the code stop working:

<TD>
<xsl:choose>
<xsl:when test=".[OriginIndicator='0']">TIMETABLE</xsl:when>
<xsl:when test=".[OriginIndicator='1']">NOT_PLANNED</xsl:when>
<xsl:otherwise>INVALID</xsl:otherwise>
</xsl:choose>
</TD>

Where "OriginIndicator" is an element of my XML that assumes only 0 or 1. The error is related to the usage of ".[" or something like this...

Another point is that even if I comment the part of the code that prevents the HTML table to be built, the <xsl:sort> seems to cause no effect... The element that will be the source of the ordering is a string containing a date, e.g. 11:34:00, and I want to order the table by this string element.

Thanks again for the help,
Wagner
wschalch at 2007-11-10 3:28:35 >
# 3 Re: Ordering a table with XSL
.[OriginIndicator='0']

Is illegal syntax, you should probably use something like
self::node()[OriginIndicator='0']
Instead.
Or more simply
OriginIndicator[text()='0']

Another point is that even if I comment the part of the code that prevents the HTML table to be built, the <xsl:sort> seems to cause no effect...

I really really hate having to repeat myself. But here goes...

If you continue to have problems you should probably post your xsl code.
khp at 2007-11-10 3:29:38 >
# 4 Re: Ordering a table with XSL
Ok for the first problem (syntax error)...

Here goes the XSL code:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<HTML>
<BODY>
<H2>Stabling Services</H2>
<TABLE BORDER="1">
<TR BGCOLOR="#CCCCCC">
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>Name</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>StartTime</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>FirstTrack</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>EndTime</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>LastTrack</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>OriginIndicator</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>ExpectedDepotEntryTime</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>ExpectedTransferTrack</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>HMITrainID</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>Kind</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>ActualDepotEntryTime</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>ActualTransferTrack</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>State</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>StablingLocation</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>WashPlant</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>MaintenanceTrack</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>MaintenanceHour</B></FONT></TD>
<TD vAlign="center" align="middle" bgColor="#0a4d96"><FONT color="#ffffff"><B>Pattern</B></FONT></TD>
</TR>
<xsl:for-each select="StablingServices/Service">
<xsl:sort select="ExpectedDepotEntryTime"/>
<TR>
<TD><xsl:value-of select="@name"/></TD>
<TD><xsl:value-of select="StartTime"/></TD>
<TD><xsl:value-of select="FirstTrack"/></TD>
<TD><xsl:value-of select="EndTime"/></TD>
<TD><xsl:value-of select="LastTrack"/></TD>
<TD>
<xsl:choose>
<xsl:when test="OriginIndicator[text()='0']">TIMETABLE</xsl:when>
<xsl:when test="OriginIndicator[text()='1']">NOT_PLANNED</xsl:when>
<xsl:otherwise>INVALID</xsl:otherwise>
</xsl:choose>
</TD>
<TD><xsl:value-of select="ExpectedDepotEntryTime"/></TD>
<TD><xsl:value-of select="ExpectedTransferTrack"/></TD>
<TD><xsl:value-of select="HMITrainID"/></TD>
<TD>
<xsl:choose>
<xsl:when test="Kind[text()='0']">DIRECT</xsl:when>
<xsl:when test="Kind[text()='1']">WITHOUT_ORDER</xsl:when>
<xsl:when test="Kind[text()='2']">WITH_WASH_ORDER</xsl:when>
<xsl:when test="Kind[text()='3']">WITH_WORK_ORDER</xsl:when>
<xsl:when test="Kind[text()='4']">WITH_WASH_WORK_ORDER</xsl:when>
<xsl:otherwise>INVALID</xsl:otherwise>
</xsl:choose>
</TD>
<TD><xsl:value-of select="ActualDepotEntryTime"/></TD>
<TD><xsl:value-of select="ActualTransferTrack"/></TD>
<TD>
<xsl:choose>
<xsl:when test="State[text()='0']">NOT_ANNOUNCED</xsl:when>
<xsl:when test="State[text()='2']">ANNOUNCED</xsl:when>
<xsl:when test="State[text()='6']">IN_PROGRESS</xsl:when>
<xsl:when test="State[text()='7']">PERFORMED</xsl:when>
<xsl:when test="State[text()='8']">CANCELLED</xsl:when>
<xsl:when test="State[text()='9']">LOST</xsl:when>
<xsl:otherwise>INVALID</xsl:otherwise>
</xsl:choose>
</TD>
<TD><xsl:value-of select="StablingLocation"/></TD>
<TD><xsl:value-of select="WashPlant"/></TD>
<TD><xsl:value-of select="MaintenanceTrack"/></TD>
<TD><xsl:value-of select="MaintenanceHour"/></TD>
<TD><xsl:value-of select="Pattern"/></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
The problem I am facing is that I would like my table to be sorted by the text of the "ExpectedDepotEntryTime" element. It is a string containing a date "11:32:40"... I don't know if it is possible, maybe I will have to change the type of the data in the element...

Thanks
wschalch at 2007-11-10 3:30:33 >
# 5 Re: Ordering a table with XSL
Works perfectly for me, of course not having a sample XML file to work with, I wrote one to fit the XSL, so that doesn't really prove anything.

And ofcourse you might want to be a bit more explicit with the sort decleration. Something like
<xsl:sort select="ExpectedDepotEntryTime/text()" data-type="text"/>

If that doesn't work you will have to show us a sample of the XML file.
khp at 2007-11-10 3:31:37 >
# 6 Re: Ordering a table with XSL
Hello,

In fact I was making some mistakes in the XML file... Now everything seems to be ok!

Thanks a lot for your help.
wschalch at 2007-11-10 3:32:36 >