This usually happens because the property is empty (it's probably empty if an item should not expire, right?)
You may be able to do something like this:
<xsl:param name="currentPage" />
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<xsl:variable name="newsRoot" select="$siteRoot/NewsSection" /><!-- Select the right node here -->
<!-- Grab items with an expire date and make sure it is after today and combine with items that have no expire date -->
<xsl:variable name="newsItems" select="$newsRoot//NewsItem[normalize-space(newsExpireDate)][umbraco.library:DateGreaterThanToday(newsExpireDate)] | $newsRoot//NewsItem[not(normalize-space(newsExpireDate))]" />
<xsl:for-each select="$newsItems">
<xsl:sort select="newsDate" data-type="text" order="descending" />
<!-- Do something -->
</xsl:for-each>
EDIT: Note that I'm assuming your "News" document types are named "NewsSection" (for the container) and "NewsItem" (for the individual items) and that the News section is located as a direct child of your site's Home. All of this can be easily changed...
umbraco.library:DateGreaterThanToday giving this error :
Error occured
System.FormatException: String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at umbraco.library.DateGreaterThanToday(String firstDate)
<xsl:for-eachselect="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and umbraco.library:DateGreaterThanToday(newsExpireDate)] "> <xsl:sortselect="newsDate"order="descending"/>
The reason this fails is exactly what I wrote in the first answer: Some (or even just one) of the children of $currentPage has an empty newsExpireDate and thus, the library call fails (it's called for every node in the selection).
That's why you should make sure the library call is only executed on nodes that have a date in that field, which is what I posted.
News filtering by News Expire date
I have multiple news sorted by new date descending order in xslt to display the latest news at first :
<xsl:sort select="newsDate" order="descending"/>
but i dont want to display the news which has already expired according to 'newsExpireDate'
property
i tried using and umbraco.library:DateGreaterThan it gave date format error
any suggestion some xslt code samples wil be very useful
Hi Max,
This usually happens because the property is empty (it's probably empty if an item should not expire, right?)
You may be able to do something like this:
/Chriztian
umbraco.library:DateGreaterThanToday giving this error :
Error occured
System.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at umbraco.library.DateGreaterThanToday(String firstDate)
Hi Max,
Is the newsExpireDate a "Date" or "DateTime" data type property?
(It needs to be in the '2011-01-03T12:00:00' format)
/Chriztian
i am using Datepicker in teh document types as property ....
hat do you suggest
OK - could you post the relevant XSLT you're using?
Also - which version of Umbraco are you using?
/Chriztian
i ma using umbraco version 4.7
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and umbraco.library:DateGreaterThanToday(newsExpireDate)] ">
<xsl:sort select="newsDate" order="descending"/>
//news items
</xsl:for-each>
http://our.umbraco.org/forum/developers/xslt/16516-SystemFormatException-String-was-not-recognized-as-a-valid-DateTime
similar situation
Hi Max,
The reason this fails is exactly what I wrote in the first answer: Some (or even just one) of the children of $currentPage has an empty newsExpireDate and thus, the library call fails (it's called for every node in the selection).
That's why you should make sure the library call is only executed on nodes that have a date in that field, which is what I posted.
Try this then instead:
/Chriztian
yes thanks
/Chriztian finally it works
now i got it
is working on a reply...