@Rodion: They're sortable yes, but unfortunately in XSLT 1.0, you can't compare them to see if a date is between two values. The < and > operators are simply not defined for strings...
It works perfectly with a few tweaks for my nodetree.
Thank you so much :)
$newsList//NewsItem[@isDoc][umbraco.library:DateGreaterThan(@createDate, $inputDateStart) and umbraco.library:DateGreaterThan($inputDateEnd, @createDate)]
Just want to clarify that using the alias of the Document Type ("NewsItem" in this case), you actually don't need the @isDoc filter any longer, because they do the same thing in this context - but using the alias is the best solution and will have the processor looking through the least amount of nodes for matches.
Uhmm... My fault. I looked into the spec and understood that I said complete baloney. In fact XPath doesn't know anything about datetimes and treats them as strings, meanwile relatoinal expressions besides "=" and "!=" aren't defined for strings at all (the latter is the very one that I was not aware of).
Select nodes between two dates
Hi guys
I need some help from you to make a xslt statement.
I need to loop through a tree containing news items, and i want to get the news items between two create dates.
Can anybody please help me with that?
<xsl:call-template name="search">
<xsl:with-param name="items" select="$newsList/descendant::*[xxxxxxxxxxxxxx]"/>
</xsl:call-template>
Thanks
Kim
Hi Kim,
Because everything's effectively a string in XSLT, you'll need to use some of the Date* -extensions from umbraco.library, e.g.:
Check them out, there's quite a few, so there's probably one you can use.
/Chriztian
AFAIK, actually Umbraco stores all dates inside XML in sortable date format, so you don't have to bother about date-string conversion for comparing.
@Rodion: They're sortable yes, but unfortunately in XSLT 1.0, you can't compare them to see if a date is between two values. The < and > operators are simply not defined for strings...
/Chriztian
Hi
Maybe i didnt explain it right.
Ive got a news search page, where i have two date selector fields, on my result page, i want the news items that is between these two dates.
As far as i know, i cant use DateGreaterThanOrEqualToday(@createDate) as it gives me a true/false on a given date.
What i need is something like @createDate > $inputDateStart and @createDate < $inputDateEnd
Thanks
Kim
Hi Kim,
You should be able to do that in a single XPath selection:
/Chriztian
Thanks, but im getting an error.
String was not recognized as a valid DateTime.
<xsl:variablename="inputDateStart">2010-11-21T01:00:00</xsl:variable>
<xsl:variablename="inputDateEnd">2012-11-21T01:00:00</xsl:variable>
<xsl:copy-ofselect="$newsList//*[umbraco.library:DateGreaterThan(@createDate, $inputDateStart) and umbraco.library:DateGreaterThan($inputDateEnd, @createDate)]" />
Hi Kim,
My bad - we need to slap the @isDoc filter on there first, to make sure it's not trying to find @createDate on the various property nodes;
/Chriztian
It works perfectly with a few tweaks for my nodetree.
Thank you so much :)
$newsList//NewsItem[@isDoc][umbraco.library:DateGreaterThan(@createDate, $inputDateStart) and umbraco.library:DateGreaterThan($inputDateEnd, @createDate)]
Cool Kim,
Just want to clarify that using the alias of the Document Type ("NewsItem" in this case), you actually don't need the @isDoc filter any longer, because they do the same thing in this context - but using the alias is the best solution and will have the processor looking through the least amount of nodes for matches.
/Chriztian
Uhmm... My fault. I looked into the spec and understood that I said complete baloney. In fact XPath doesn't know anything about datetimes and treats them as strings, meanwile relatoinal expressions besides "=" and "!=" aren't defined for strings at all (the latter is the very one that I was not aware of).
is working on a reply...