I have some existing XSLT code that I need to change due to a change in the way the page handles/displays "Recent Events". Tis particular page has been displaying upcoming events in a left column, based off the eventDate field. For multiple day events (ex. week long) it was requested that I implement an added field for content posting call endDate where they could use it as an expiration and the eventDate would remain in use for the display of an event date.
That code works to display a list of events that have not yet passed the event date. Having added a new CustomEventItem called endDate, there are old event postings that do not have dates. changing the first line to read:
throws the error: "System.FormatException: String was not recognized as a valid DateTime." so I assume you have to cast for this in some way so that anything null/blank is ignored. Am I missing anything here and can someone help with tweaking this to compare on the newly added field to postings?
You can add a predicate (filter) before the one that calls the library function, to make sure that only nodes that have a value in the endDate property are sent to the function:
Help with date comparison
I have some existing XSLT code that I need to change due to a change in the way the page handles/displays "Recent Events". Tis particular page has been displaying upcoming events in a left column, based off the eventDate field. For multiple day events (ex. week long) it was requested that I implement an added field for content posting call endDate where they could use it as an expiration and the eventDate would remain in use for the display of an event date.
Example of the existing code:
<xsl:for-each select="umbraco.library:GetXmlNodeById(1078)/*/*/CustomEventItem [customfunctionlib:includeItem($url, eventItemFilter)] [umbraco.library:DateGreaterThanToday(eventDate)]">
<xsl:sort select="umbraco.library:FormatDateTime(eventDate, 'yyyyMMddhhmmss')" order="ascending"/>
<xsl:if test="position() <= $numberOfItems">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<span class="smallDate"><xsl:value-of select="umbraco.library:ShortDate(eventDate)"/>
<xsl:if test="string(locationSummary) != ''">
<xsl:text> - </xsl:text><xsl:value-of select="locationSummary"/>
</xsl:if>
</span>
<br/>
<xsl:value-of select="Title/text()"/>
</a>
<br />
<br />
</li>
</xsl:if>
</xsl:for-each>
That code works to display a list of events that have not yet passed the event date. Having added a new CustomEventItem called endDate, there are old event postings that do not have dates. changing the first line to read:
<xsl:for-each select="umbraco.library:GetXmlNodeById(1078)/*/*/CustomEventItem [customfunctionlib:includeItem($url, eventItemFilter)] [umbraco.library:DateGreaterThanToday(endDate)]">
throws the error: "System.FormatException: String was not recognized as a valid DateTime." so I assume you have to cast for this in some way so that anything null/blank is ignored. Am I missing anything here and can someone help with tweaking this to compare on the newly added field to postings?
Hi Chris,
You can add a predicate (filter) before the one that calls the library function, to make sure that only nodes that have a value in the endDate property are sent to the function:
/Chriztian
Chriztian,
That's exactly what I needed. I kept trying to write xsl:if statements to handle this, but this is much nicer.
I appreciate the help and thank you very much!
is working on a reply...