Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom Allen 50 posts 71 karma points
    Oct 07, 2011 @ 12:37
    Tom Allen
    0

    Pattern for each date between two dates

    Hi,

    Hope someone can help - I'm a relative newcomer to XSLT and I haven't fully grasped the best practice for dealing with a requirement like this:

    I have an Event node with two dates and some other info; let's simply to a start date, an end date and a title.

    What I need in my XSLT is a loop which will output the title and the date for each date between and including the start and end date.

    E.g. for the following node:

    <Event>
        <title>My Event</title>
        <startDate>2011-10-07T00:00:00</startDate>
        <endDate>2011-10-09T00:00:00</endDate>
    </Event>

    I need the following output:

    My Event
    07 October 2011
    
    My Event
    08 October 2011
    
    My Event
    09 October 2011

    Any help would be most appreciated.

    TIA

  • Tom Allen 50 posts 71 karma points
    Oct 07, 2011 @ 12:38
    Tom Allen
    0

    P.S. I need this to be able to span calendar months; e.g. startDate: 2011-10-31, endDate 2011-11-02

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Oct 07, 2011 @ 14:57
    Lee Kelleher
    2

    Hi Tom,

    In uComponents we have an XSLT extension for Dates, there is a method called "ListDates", which can be used like this:

     <xsl:for-each select="Event">
            <xsl:value-of select="title" />
            <xsl:for-each select="ucomponents.dates:ListDates(startDate, endDate)/value">
                    <xsl:value-of select="ucomponents.dates:FormatDateTime(text(), 'ddS MMMM yyyy')" />
            </xsl:for-each>
    </xsl:for-each>

    Cheers, Lee.

  • Tom Allen 50 posts 71 karma points
    Oct 10, 2011 @ 13:20
    Tom Allen
    0

    Nice one Lee - already had uComponents installed, so I'll get stuck in.

    Umbraco is by far the best CMS I've ever used for the kind of sites I develop - everything I need seems to be so easily achievable, as opposed to hours digging through standard .NET's bloated and idiosyncratic codebase...

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Oct 10, 2011 @ 13:55
    Lee Kelleher
    0

    Cool, happy to be of help.

    PS. Don't forget to mark the post as solution ;-)

  • Tom Allen 50 posts 71 karma points
    Oct 11, 2011 @ 10:30
    Tom Allen
    0

    Sorry Lee, I can't seem to get this working. I have no idea what's going wrong, but the XSLT file can't be parsed and it's down to the for-each statement involving ListDates(). The FormatDateTime() function works fine. The dates being supplied are in the format I mentioned in my OP. I even tried hardcoding dates into the function call, but I still get a parser error. Umbraco's XSLT editor pane doesn't show any errors and I'm not sure how else to debug.

    My precise code is:

    <xsl:when test="not(string(endDate)='')">
                        <xsl:variable name="url" select="umbraco.library:NiceUrl(@id)" />
                        <xsl:for-each select="ucomponents.dates:ListDates(startDate, endDate)/values/value">
                            <xsl:text>{"y":"</xsl:text>
                            <xsl:value-of select="ucomponents.dates:FormatDateTime(text(), 'yyyy')" />
                            <xsl:text>","m":"</xsl:text>
                            <xsl:value-of select="ucomponents.dates:FormatDateTime(text(), 'MM')" />
                            <xsl:text>","d":"</xsl:text>
                            <xsl:value-of select="ucomponents.dates:FormatDateTime(text(), 'dd')" />
                            <xsl:text>","link":"</xsl:text>
                            <xsl:value-of select="$url" />
                            <xsl:text>"}</xsl:text>
                        </xsl:for-each>
                    </xsl:when>

    It's outputting for JSON.

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Oct 11, 2011 @ 10:33
    Dirk De Grave
    0

    Add a ?umbdebugshowtrace=true to the url to find out the exact parser error on the frontend, should give you a clue at least of what is wrong.

     

    Cheers,

    /Dirk

  • Tom Allen 50 posts 71 karma points
    Oct 11, 2011 @ 10:37
    Tom Allen
    0

    Just done that - here's the issue:

    Extension object 'urn:ucomponents.dates' does not contain a matching 'ListDates' method that has 2 parameter(s).

    I'm guessing this means I need to update to 2.2 Beta 3. If so, do I need to uninstall the current version, and will this affect the content that uses uComponents datatypes?

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Oct 11, 2011 @ 10:52
    Lee Kelleher
    0

    Hi Tom,

    We've been adding so much stuff to uComponents recently, I can't remember when that XSLT extension was introduced. :-$

    As for upgrading uComponents - it's literally replacing the "uComponents.Core.dll" (make a back-up of your current one).  The DLL will have a Guid name in the package download ZIP ... just rename that to "uComponents.Core.dll".

    Cheers, Lee.

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Oct 11, 2011 @ 10:54
    Dirk De Grave
    1

    Seems to be in the v2.2 branch (not in trunk)...

     

    Cheers,

    /Dirk

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Oct 11, 2011 @ 10:55
    Lee Kelleher
    0

    Yup, we're working from /branches/v2.0/ :-)

  • Tom Allen 50 posts 71 karma points
    Oct 11, 2011 @ 10:59
    Tom Allen
    0

    Thanks again guys, all working now.

    I had to make a slight tweak to your code; here it is for the next person who wants to list dates using this method:

    <xsl:for-each select="ucomponents.dates:ListDates(startDate, endDate)/value">
    <xsl:value-of select="ucomponents.dates:FormatDateTime(., 'dd MM yyyy')" />
    </xsl:for-each>
  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Oct 11, 2011 @ 11:01
    Lee Kelleher
    0

    Cool, glad it's working... that's what I get for writing the XSLT/XPath off the top of my head! ;-)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies