Having problems using umbraco.library:DateGreaterThanOrEqualToday in a for-each select statement Options
grmortimer
Posted: Wednesday, January 23, 2008 2:21:12 PM
Rank: Enthusiast

Joined: 1/30/2007
Posts: 22
Hi

Sorry, beginer to XSLT here so forgive the dire code and mistakes :)

I'm having problems using 'umbraco.library:DateGreaterThanOrEqualToday' in a 'for-each select'. Basically I'm populating a list of upcoming seminars and only want to have the ones that are upcoming, not that have gone by. (I don't want to automatically unpublish the seminar details pages as they will go on a seperate page to show what we've already done.)

So the original xslt I tried was something like this but it didn't work
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">


<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:template match="/">
<xsl:variable name="DateNow" select="umbraco.library:CurrentDate()" />

<!-- The fun starts here -->

    <table width="100%" border="1" cellspacing="1" cellpadding="1" summary="Cefas Events">
    <caption align="top">
        Cefas Seminars <xsl:value-of select="$DateNow"/>
    </caption>
    <tr>
        <th scope="col">Seminar</th>
        <th scope="col">Author</th>
        <th scope="col">Seminar Date</th>
        <th scope="col">Location</th>
        <th scope="col">Further Details</th>
    </tr>
    <xsl:for-each select="$currentPage/node string(data[@alias='umbracoNaviHide']) != '0'][string(data [@alias='seminarDateAndtime']) &gt;$DateNow]">
    <xsl:sort select="data [@alias = 'seminarDateAndtime']"/>
    <tr>
        <td><p><xsl:value-of select="data[@alias = 'seminarTitle']"/></p></td>
        <td><p><xsl:value-of select="data [@alias = 'seminarAuthor']"/> </p></td>
        <td><p><xsl:value-of select="umbraco.library:FormatDateTime(data [@alias = 'seminarDateAndtime'],'d MMMM yyyy @

H:mm')"/></p></td>

        <td><p><xsl:value-of select="data [@alias = 'seminarLocation']"/></p></td>
        <td><p><a href="{umbraco.library:NiceUrl(@id)}">Further Details</a></p></td>

    </tr>
    </xsl:for-each>
</table>

</xsl:template>

</xsl:stylesheet>



So I looked into the problem I had and found that umbraco.library:DateGreaterThanOrEqualToday seemed to be the solution to my problems... but is it? I've not managed to get it to work or find any examples of it.

I tried
Code:
<xsl:for-each select="$currentPage/node [umbraco.library:DateGreaterThanOrEqualToday(data[@alias='seminarDateAndtime'])]">
but that didn't work and threw up errors about "System.FormatException: String was not recognized as a valid DateTime. "

Any help would be much appreciated

Thanks

Gavin
grmortimer
Posted: Wednesday, January 23, 2008 2:22:25 PM
Rank: Enthusiast

Joined: 1/30/2007
Posts: 22
that second section of code should have read <xsl:for-each select="$currentPage/node [umbraco.library:DateGreaterThanOrEqualToday(data[@alias='seminarDateAndtime'])]">
tim
Posted: Wednesday, January 23, 2008 2:34:30 PM

Rank: Addict

Joined: 2/19/2007
Posts: 738
Location: Belgium
Try like this:

Code:

umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:FormatDateTime(./data[@alias = 'startDate'], 'dd/MM/yyyy')


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
grmortimer
Posted: Wednesday, January 23, 2008 3:22:50 PM
Rank: Enthusiast

Joined: 1/30/2007
Posts: 22
Code:

umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:FormatDateTime(./data[@alias = 'startDate'], 'dd/MM/yyyy')

[/quote]

Hi Tim

Thanks for the help. I tried as you suggested as [code]<xsl:for-each select="$currentPage/node [umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:FormatDateTime(./data[@alias = 'seminarDateAndtime'], 'dd/MM/yyyy')]">[code] but I received an error for that line.

Any suggestions?

Thanks

Gavin
PeterD
Posted: Wednesday, January 23, 2008 3:24:06 PM

Rank: Fanatic

Joined: 7/20/2006
Posts: 486
Location: NL
Tim Geyssens wrote:

Try like this:

Code:

umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:FormatDateTime(./data[@alias = 'startDate'], 'dd/MM/yyyy')



Yes, Tim is right.
I ran into a similar problem. If the error still keeps popping up, try this (worked in my case):

Code:

<xsl:for-each select="$currentPage/node [(data [@alias = 'seminarDateAndtime'] != '') and (umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:FormatDateTime(./data[@alias = 'seminarDateAndtime'], 'dd/MM/yyyy'))]">


PeterD

Working on an events-calendar with recursion. Post requests on my blog!
grmortimer
Posted: Wednesday, January 23, 2008 3:39:45 PM
Rank: Enthusiast

Joined: 1/30/2007
Posts: 22
Yes, Tim is right.
I ran into a similar problem. If the error still keeps popping up, try this (worked in my case):

Code:

<xsl:for-each select="$currentPage/node [(data [@alias = 'seminarDateAndtime'] != '') and (umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:FormatDateTime(./data[@alias = 'seminarDateAndtime'], 'dd/MM/yyyy'))]">


PeterD
[/quote]
Hi Peter

Thanks for that. Works like a charm :) I had to add another closing bracket as in
Code:
<xsl:for-each select="$currentPage/node [(data [@alias = 'seminarDateAndtime'] != '') and (umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:FormatDateTime(./data[@alias = 'seminarDateAndtime'], 'dd/MM/yyyy')))]">
but apart from that it's great. Helps a lot...wouldn't have tried anything like that myself(not good enough) now I just need to find something that will 'showDateLessThanOrEqualToday'

Thanks again

Gavin
PeterD
Posted: Wednesday, January 23, 2008 3:47:38 PM

Rank: Fanatic

Joined: 7/20/2006
Posts: 486
Location: NL
For that you can use the function:
umbraco.library:DateGreaterThanOrEqual(date1, date2)

At least that one worked for me also :D

example:

Code:

<xsl:variable name="datenow" select="umbraco.library:CurrentDate()" />

<xsl:variable name="straten" select="$currentPage//node [((data[@alias='enddate'] !='') and umbraco.library:DateGreaterThanToday(data[@alias='enddate']) = 'true') and ((data[@alias='startdate'] !='') and umbraco.library:DateGreaterThanOrEqual($datenow, data[@alias='startdate']) = 'true')]" />


Should probably get you on the way.

PeterD

Working on an events-calendar with recursion. Post requests on my blog!
grmortimer
Posted: Thursday, January 24, 2008 9:58:40 AM
Rank: Enthusiast

Joined: 1/30/2007
Posts: 22
Peter Dijksterhuis wrote:

For that you can use the function:
umbraco.library:DateGreaterThanOrEqual(date1, date2)
...Should probably get you on the way.

PeterD

Hi Peter

After a bit of confusion on my part(hey I am very new to this! :innocent: ) I got it to work :w00t:

Thanks for all the help, very much appreciated.

For anyone who's interested this is the finished stylesheet for displaying the seminars past their date.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">


<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:template match="/">
    <xsl:variable name="datenow" select="umbraco.library:CurrentDate()" />   

<!-- The fun starts here -->

    <table width="100%" border="1" cellspacing="1" cellpadding="1" summary="Cefas Events">
    <caption align="top">
        Cefas Seminars
    </caption>
    <tr>
        <th scope="col">Seminar</th>
        <th scope="col">Author</th>
        <th scope="col">Seminar Date</th>
        <th scope="col">Location</th>
        <th scope="col">Further Details</th>
    </tr>

    <xsl:for-each select="$currentPage/preceding-sibling::node [((data[@alias='seminarDateAndtime'] !='') and umbraco.library:DateGreaterThanOrEqual($datenow, data[@alias='seminarDateAndtime']))]">


    <xsl:sort select="data [@alias = 'seminarDateAndtime']"/>
    <tr>
        <td><p><xsl:value-of select="data[@alias = 'seminarTitle']"/></p></td>
        <td><p><xsl:value-of select="data [@alias = 'seminarAuthor']"/> </p></td>
        <td><p><xsl:value-of select="umbraco.library:FormatDateTime(data [@alias = 'seminarDateAndtime'],'d MMMM yyyy @ H:mm')"/></p></td>

        <td><p><xsl:value-of select="data [@alias = 'seminarLocation']"/></p></td>
        <td><p><a href="{umbraco.library:NiceUrl(@id)}">Further Details</a></p></td>

    </tr>
    </xsl:for-each>
</table>

</xsl:template>

</xsl:stylesheet>
PeterD
Posted: Thursday, January 24, 2008 10:05:31 AM

Rank: Fanatic

Joined: 7/20/2006
Posts: 486
Location: NL
Glad we could be of help and good to see it worked out :D


Working on an events-calendar with recursion. Post requests on my blog!
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.