I'm pretty sure the date in the xml isn't a number, but a string, so the question is whether or not you can do a sort on that string and expect it to come out in the right order. Unless the date always looks like this: yyyy-mm-dd you really can't sort it in the correct order.
Dates in the Umbraco XML are indeed strings, not numbers, but they are sortable because of the format (believe it's called 'xmlDate' or similar), so this will work:
<xsl:sort select="newsDate" order="descending" />
(The data-type attribute defaults to "text" so it isn't necessary)
You are using "Date Picker" or "Date Picker with time" as the Type for the newsDate property, right?
I can't help but notice that while you say you want the newest items at the top, all the examples (save for Kim's) are using "ascending" as the order???
Did you try using @nodeName as Sascha suggested, just to be sure that you're actually selecting the right nodes?
Unfortunately due to my stupidity, I was putting on the wrong macro!! No wonder it didn't work.|I had two macro's one showing only the latest item, and one showing all the news items.
@Sascha & @Steen Thanks for all your help your solutions worked.
@Chriztian Thanks for the explanation, it much clearer in my head whats happening now then before. Yes I did know the order was ascending, I changed it to descending in my code.
correct way of sorting in xslt
I'm trying to sort a news section by date order but its not working, I want the latest entry at the top. Is this the correct way of sorting an item?
or this way?
I'm pretty sure the date in the xml isn't a number, but a string, so the question is whether or not you can do a sort on that string and expect it to come out in the right order. Unless the date always looks like this: yyyy-mm-dd you really can't sort it in the correct order.
So this is the way:
I think you have to use: <xsl:sort select="data[@alias='newsDate']" order="ascending" />
Well, that really depends on which version he's using, but yes, that might be with correct if it's not Umbraco 4.5.x
@Bas I'm using 4.5 so it woudln't work on the old schema.
@Steen I'm using
But it doesn't work, no matter what date I set to an item, it always appends the list last.
What will happen if you try this one:
Using text as the data type.
/Kim A
Couple of ideas:
- Have you tried just sorting by @nodeName for instance to see if it has any effect?
- I tend to convert the dates explicitly to dates for comparison like so (have never used the data-type parameter though):
Hi ivorthedesigner,
To clarify a couple of things:
Dates in the Umbraco XML are indeed strings, not numbers, but they are sortable because of the format (believe it's called 'xmlDate' or similar), so this will work:
(The data-type attribute defaults to "text" so it isn't necessary)
You are using "Date Picker" or "Date Picker with time" as the Type for the newsDate property, right?
I can't help but notice that while you say you want the newest items at the top, all the examples (save for Kim's) are using "ascending" as the order???
Did you try using @nodeName as Sascha suggested, just to be sure that you're actually selecting the right nodes?
/Chriztian
Hi All thanks for the replies.
Unfortunately due to my stupidity, I was putting on the wrong macro!! No wonder it didn't work.|I had two macro's one showing only the latest item, and one showing all the news items.
@Sascha & @Steen Thanks for all your help your solutions worked.
@Chriztian Thanks for the explanation, it much clearer in my head whats happening now then before. Yes I did know the order was ascending, I changed it to descending in my code.
is working on a reply...