Sort by property A or property B if property A is empty
Hi Guys,
I'm currently sorting a list of reports by createdDate, however I need to be able to override this date so I'm setting up a new property "reportDate". What i need is for the list to use this date if it is set, otherwise resort back to the createdDate.
I am not an XSLT expert so this is just thought out loud, couldn't you set a variable which by default is set to "reportDate" and if this is not set change the variable to "createdDate".
another approach would be to make an eventhandler/action triggered on updates on these types of documents, and then set the reportDate to createDate in the eventhandler in case it is not already set.
You could also consider using multiple sort-statemenets in your xslt - depending on how you want the output presented.
Don't think that'll solve all of your issues, as you'll be sorting the list on either reportDate or createDate, and you don't know upfront whether each of the items in the list will have a value for that property you'll be sorting on.
I agree with tommy and chris, create some event handler that on save of document check whether reportDate is filled in, and if not, copy value of createDate.
Sorting will become a breeze as you don't need to check anymore whether values are existing.
Orindarily I would go the event handler route. The reason I haven't, is that the site is already full of reports, and this feature is being added on.
You are right that I won't know up front whether an item has a ReportDate set, but that is the purpose of the mehtod, if one exists use that to sort with, if not, resort to the createdDate. Or am I missing something?
Hm, didn't know that either, so you're saying that the sort will take either value of createDate or ReportDate, depending on whether value exists (and it does that for each item from the list)? Interesting, need to refresh my xslt knowledge on that specific method.
Sort by property A or property B if property A is empty
Hi Guys,
I'm currently sorting a list of reports by createdDate, however I need to be able to override this date so I'm setting up a new property "reportDate". What i need is for the list to use this date if it is set, otherwise resort back to the createdDate.
Anybody know how to go about this?
Many thanks
Matt
Hi Matt,
I am not an XSLT expert so this is just thought out loud, couldn't you set a variable which by default is set to "reportDate" and if this is not set change the variable to "createdDate".
then pass this variable into the XSLT sort?
Tom
another approach would be to make an eventhandler/action triggered on updates on these types of documents, and then set the reportDate to createDate in the eventhandler in case it is not already set.
You could also consider using multiple sort-statemenets in your xslt - depending on how you want the output presented.
>Tommy
I'd probably take the approach of making the reportDate mandatory or defaulting the field to the createDate if it's left blank.
Although Umbraco doesn't support default values for properties, you could easily implement it with an event handler or make a custom data type.
Not an xslt answer I know, I don't know if what you're trying to do is possible in xslt.
Cheers guys,
I ended up solving it another way.
I created a function inside the XSLT as follows:
Then is used it within the xslt sort attribute as follows:
Many thanks
Matt
Matt,
Don't think that'll solve all of your issues, as you'll be sorting the list on either reportDate or createDate, and you don't know upfront whether each of the items in the list will have a value for that property you'll be sorting on.
I agree with tommy and chris, create some event handler that on save of document check whether reportDate is filled in, and if not, copy value of createDate.
Sorting will become a breeze as you don't need to check anymore whether values are existing.
Cheers,
/Dirk
Orindarily I would go the event handler route. The reason I haven't, is that the site is already full of reports, and this feature is being added on.
You are right that I won't know up front whether an item has a ReportDate set, but that is the purpose of the mehtod, if one exists use that to sort with, if not, resort to the createdDate. Or am I missing something?
Many thanks
Matt
I didn't know you could implement a sort like that. Very Interesting.
if you go down the event handler route you could republish all the pages and the handler would update the field on all the historic pages.
ahhh, cool. I might have a go at that then, as it would obvously be better if i didn't have to do extra processing.
Cheers guys.
Matt
Hm, didn't know that either, so you're saying that the sort will take either value of createDate or ReportDate, depending on whether value exists (and it does that for each item from the list)? Interesting, need to refresh my xslt knowledge on that specific method.
Cheers,
/Dirk
Yup, that's correct. Well, thats how it worked for me at least =)
Matt
is working on a reply...