Copied to clipboard

Flag this post as spam?

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


  • Profiterole 232 posts 264 karma points
    Dec 24, 2010 @ 14:00
    Profiterole
    0

    Select certain date

    Hi,

    I have node with an eventDate (datepicker). So it returns 2010-12-24 as date. Now, in an xslt file, I'd like to select only eventDate that occurs, say, in 2009.

    For now,I have something like that :

    <xsl:for-each select="umbraco.library:GetXmlNodeById($albumSource)/node">
    <xsl:sort select="data [@alias = 'eventDate']" order="descending" />
    <xsl:if test="position() &lt;= $numChild and $eventDate = '2009'">
    ...
    </xsl:if>
    </xsl:for-each>

    My code sort the event by date (the newest on top) and shows $numChild maximum number of nodes, but when I try to only have certain year event, it does not work.

    Can you help me!

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 24, 2010 @ 14:26
    Jan Skovgaard
    0

    Hi Profiterole

    What does your event variable look like? Are you formatting it to only output the year? like umbraco.library:FormatDateTime(data [alias = 'eventDate'],'yyyy')

    /Jan

  • Profiterole 232 posts 264 karma points
    Dec 24, 2010 @ 15:51
    Profiterole
    0

    Oh!!! I forgot to set a variable before calling $evenDate!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 24, 2010 @ 15:56
    Jan Skovgaard
    0

    Hmm...you did'nt get an error on the page then? :-)

    But glad you got it solved.

    /Jan

  • Profiterole 232 posts 264 karma points
    Dec 24, 2010 @ 15:56
    Profiterole
    0

    So, ok I set this : 

    <xsl:for-each select="umbraco.library:GetXmlNodeById($albumSource)/node">
    <xsl:sort select="data [@alias = 'eventDate']" order="descending" />

    <xsl:variable name="eventDate" select="umbraco.library:FormatDateTime(data [alias = 'eventDate'],'yyyy')"/>


    <xsl:if test="position() &lt;= $numChild and $eventDate = '2009'">
    ...
    </xsl:if>
    </xsl:for-each>


    but it does not work either

  • Profiterole 232 posts 264 karma points
    Dec 24, 2010 @ 16:00
    Profiterole
    0

    So, ok I set this : 

    <xsl:for-each select="umbraco.library:GetXmlNodeById($albumSource)/node">
    <xsl:sort select="data [@alias = 'eventDate']" order="descending" />

    <xsl:variable name="eventDate" select="umbraco.library:FormatDateTime(data [alias = 'eventDate'],'yyyy')"/>


    <xsl:if test="position() &lt;= $numChild and $eventDate = '2009'">
    ...
    </xsl:if>
    </xsl:for-each>


    but it does not work either

  • Profiterole 232 posts 264 karma points
    Dec 24, 2010 @ 16:01
    Profiterole
    0

    Sorry for the double post!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 24, 2010 @ 16:02
    Jan Skovgaard
    0

    Where is the $numChild varaible defined?

    And do you get any errors when you're saving the XSLT? Or du you get an XSLT error when trying to load the page? Saying it does not work is a broad error description. We need some more specific info to be able to help you out mate :-)

    On the page where you are running the macro...try adding the ?umbDebugShowTrace=true to the end of the url. Do you get any error messages in here?

    /Jan

  • Profiterole 232 posts 264 karma points
    Dec 24, 2010 @ 16:08
    Profiterole
    0

    Ok, the $numChild variable is set in a macro (number). I don't get any error... it just don't display anything if I add "and $eventDate...". My xslt displays the number of node I asked and sort it correctly if I only use the first condition in <xsl:if test="position() &lt;= $numChild>, but I don't want 2010 events, so I add the "and $eventDate" part and it display nothing...

    For the ?umbDebugShowTrace=true, it gives me a blue line with nothing under.

    Is it clearer :)

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Dec 24, 2010 @ 17:11
    Bo Damgaard Mortensen
    0

    Maybe try setting the eventDate variable inside the for loop like this:

    <xsl:variable name="eventDate" select="umbraco.library:FormatDateTime(current()/eventDate,'yyyy')"/>

    or

    <xsl:variable name="eventDate" select="umbraco.library:FormatDateTime(current()//eventDate,'yyyy')"/>

    Can't remember if you need a double slash or not ;)

    Merry xmas!

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 25, 2010 @ 22:12
    Chriztian Steinmeier
    1

    Hi Profiterole,

    You should just apply the eventDate filter already when selecting nodes to display - you want only nodes from 2009, so make sure that your for-each (or apply-templates) selects only those:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($albumSource)/node[starts-with(data[@alias = 'eventDate'], '2009')]">
        <xsl:sort select="data[@alias = 'eventDate']" data-type="text" order="descending" />
    
        <xsl:if test="position() &lt; $numChild">
            <!-- do stuff. -->
        </xsl:if>
    
    </xsl:for-each> 

    /Chriztian 

  • Profiterole 232 posts 264 karma points
    Dec 31, 2010 @ 19:17
    Profiterole
    0

    Wow!! Thank you Chriztian, I was not aware of "starts-with" and now it works perfectly!

Please Sign in or register to post replies

Write your reply to:

Draft