Latest comments navigation issue resolved

Fixed another issue on PardonMyReach this morning.  The latest comments navigation on the right was showing an unexpected order for the comments and wasn't getting the latest ones.  It turns out that the XSLT that generates this content had a sort bug in it.  Here's the original code:

image

If you click on it to make it actually visible, you might spot the bug.  The key for the sort, @created, is actually a datetime, but the sort is treating it as a string and sorting it alphabetically.  Here's my fixed XSLT:

image

It turns out that each comment also has a sequential id, so I used that for my sort key, marked it as a number, and it works.

Some other possible solutions:

  • Parse the string into substrings (year, month, day, hour, minutes…)and sort appropriately.  I didn't do this because it looks like the string that represents the datetime created is not using fixed-width fields ("9/5/2010 11:35:23 PM" and "10/26/2010 10:08:09 PM" were demonstrate this), so it looked more challenging to do this.
  • Use XSLT 2.0 and specify these values as dates.  I didn't do this because I wasn't able to easily confirm Umbraco support for XSLT 2.0.  (A quick search on the forum indicated that it supports 1.0, but this may have changed.)

Post a comment