At the moment I'm using the <xsl:sortselect="@createDate"order="descending"/> in order to have the lastest added first. Now I would like to sort the list for the customCreateDate setting this value the .net DateTime.Now if empty. So I would like to write something like:
Think of how the processor collects all the values to sort - and then take each node and examine what's selected...
The first sort selects the <customCreateDate> if it has a value.
The second sort selects the createDate attribute if its parent (the element it sits on) doesn't have a <customCreateDate> with a value.
So for every node in the selection that's to be sorted, the processor will pick EITHER customCreateDate OR @createDate and sort by that value... as long as they're in the same format it will work.
So yes, it works as if you were allowed to do a normal choose/when/otherwise to select the value for the sort statement's select attribute .
Cool - Thanks for the thourough explanation. Got a feeling this will ease things for many more out there. Have come accross this issue earlier ending up solving it in much more cumbersome ways.
sorting xsl:for-each on different fields
Hi,
my "News Item" page has the default @createDate and a custom date (customCreateDate).
In my News page I've a macro that renders the list of News
At the moment I'm using the <xsl:sort select="@createDate" order="descending"/> in order to have the lastest added first. Now I would like to sort the list for the customCreateDate setting this value the .net DateTime.Now if empty. So I would like to write something like:
any help?
Thanks.
Hi Lorenzo,
You should be able to do this by supplying two mutually exclusive sort statements:
/Chriztian
Hi Chriztian
I was wondering very long about this...this is dead simple. Brilliant! So let's see if I understand it correctly...
I suppose it works like a <xsl:choose> where the first condition that is true skips the rest (roughly speaking), right?
/Jan
Hi Jan,
Think of how the processor collects all the values to sort - and then take each node and examine what's selected...
The first sort selects the <customCreateDate> if it has a value.
The second sort selects the createDate attribute if its parent (the element it sits on) doesn't have a <customCreateDate> with a value.
So for every node in the selection that's to be sorted, the processor will pick EITHER customCreateDate OR @createDate and sort by that value... as long as they're in the same format it will work.
So yes, it works as if you were allowed to do a normal choose/when/otherwise to select the value for the sort statement's select attribute .
/Chriztian
Hi Chriztian
Cool - Thanks for the thourough explanation. Got a feeling this will ease things for many more out there. Have come accross this issue earlier ending up solving it in much more cumbersome ways.
This definately goes in the "bookmarks" :-)
/Jan
is working on a reply...