This may be quite an xslt noob question and I don't know if this is possible but I'd like to sort a list of conted by date created but then have an optional 'DatePosted' field that will override the date created.
So you want to sort your items by DatePosted if this one is present otherwise use the @createDate, is that correct?
I found this WIKI entry that shows you how this can be achieved. The below piece of code is taken from that entry with some changes to your alias-names:
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' ]"> <xsl:sortselect="./DatePosted [string(current()/DatePosted)!=''] | ./@createDate [string(current()/DatePosted)='']"order="descending"/> <!-- Do stuff --> </xsl:for-each>
Thanks, that looks like what I'm trying to achieve but unfortunately it doesn't seem to work, it just ignores the DatePosted even if a value is present. Any ideas?
Are you sure "DatePosted" is the right property alias and correct casing? Usually Umbraco doesn't let you use a capital letter to start a property alias
Did you change the alias name in all of the three places in the snippet above?
Could you maybe try to print out the nodes in your for-each loop to check if the datePosted property is properly set. You can do this by printing out the nodes in a textarea like this:
Sorting by a function to ignore empty field
Hi,
This may be quite an xslt noob question and I don't know if this is possible but I'd like to sort a list of conted by date created but then have an optional 'DatePosted' field that will override the date created.
So at the moment we use
<xsl:sort select="@createDate" order="descending" />
but I want something like
obviously that won't work (being psudo-javascript and not xslt) but is there a way I could do that sort of thing? and if so how?
Thanks for your help
Ben
Hi Ben
So you want to sort your items by DatePosted if this one is present otherwise use the @createDate, is that correct?
I found this WIKI entry that shows you how this can be achieved. The below piece of code is taken from that entry with some changes to your alias-names:
I hope this can help you out.
/Kim A
Thanks, that looks like what I'm trying to achieve but unfortunately it doesn't seem to work, it just ignores the DatePosted even if a value is present. Any ideas?
Thanks
Are you sure "DatePosted" is the right property alias and correct casing? Usually Umbraco doesn't let you use a capital letter to start a property alias
Well it is actually datePosted, but I changed taht in the code already. still doesn't word :-(
Did you change the alias name in all of the three places in the snippet above?
Could you maybe try to print out the nodes in your for-each loop to check if the datePosted property is properly set. You can do this by printing out the nodes in a textarea like this:
/Kim A
Hi Ben - this should work (I know, we all say that :-) :
(Builds a set of either both dates or only the datePosted date - then selects the first in the set)
/Chriztian
Uhh, that was a new one Chriztian! Haven't seen something like that before, but I sure like that snippet :)
/Kim A
is working on a reply...