Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort Time

Status
Not open for further replies.

kyern

Programmer
Mar 30, 2006
36
US
I am having a small issues sorting in my xslt file. I have a date like so: 06/28 05:50 PM. This is what I use to sort it:

Code:
<xsl:sort select="substring(date,1,2)" order="descending" data-type="number" /> <!-- month -->
				<xsl:sort select="substring(date,4,2)" order="descending" data-type="number" /> <!-- day  -->
				<xsl:sort select="substring(date,7,2)" order="descending" data-type="number" /> <!-- hour -->
				<xsl:sort select="substring(date,10,2)" order="descending" data-type="number" /> <!-- min -->
				<xsl:sort select="substring(date,13,2)" order="descending" data-type="text" /> <!-- am/pm -->

The only time things seem to become a problem is at the 12 hour 12 AM should be before 10 AM of course. There doesn't seem to be a way to put logic into the sort function, but is there any way I can make it so this will work properly?

Another way i guess would be to store it in military time and then convert to 12 hr clock later, but it seems like a lot of trouble for something that should be simple.

Anyhow, if anyone can help thank you very much.

David
 
why don't you test for 12AM with something like

<xsl:if test="substring(date,7,2) = 12">
<xsl:if test="substring(date,13,2) = 'am'">
<xsl:sort select="substring(date,10,2)" order="descending" data-type="number" /> <!-- min -->
<xsl:sort select="substring(date,13,2)" order="descending" data-type="text" /> <!-- am/pm -->
</xsl:if>
</xsl:if>

So it goes in first, then test for !12AM and sort the rest

<xsl:if test="substring(date,7,2) != 12">
<xsl:if test="substring(date,13,2) != 'am'">
<xsl:sort select="substring(date,10,2)" order="descending" data-type="number" /> <!-- min -->
<xsl:sort select="substring(date,13,2)" order="descending" data-type="text" /> <!-- am/pm -->
</xsl:if>
</xsl:if>

I'm sure there's some syntax errors in here but the logic could work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top