Copied to clipboard

Flag this post as spam?

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


  • John C Scott 473 posts 1183 karma points
    Sep 08, 2010 @ 16:30
    John C Scott
    0

    xslt selection for next item by date

    i'm faily clear how to do this as an xslt extension in c# but i am sure this should be simple in xslt only

    this is in 4.5.2 so with the new schema

    i have some content which relates to an event with a datetimeStart property, and i need to construct a link that links to the next event from the home page, so essentially the events will be ordered by this datetimeStart property anyway so then select the first item that is greater than now

    i imagine writing something like the following

    <xsl:variable name="futureRaces" select="2010season/races [datetimeStart > ?todayDateFromServer?]"/>
    <xsl:variable name="nextRace" select="$futureRaces [position() =1]"/>
    <a>
      <xsl:attribute name="href">
        <xsl:value-of select="umbraco.library:NiceUrl($nextRace/@id )"/>
      </xsl:attribute>
    </a>

    what i am not sure about is

    1) it would be better to add something to explicitly order the $futureRaces by the datetimeStart property
    2) will $nextRace get only the first result 
    3) what's the right way to do the date comparison

    thanks for taking the time to look at this :)

  • Sascha Wolter 615 posts 1101 karma points
    Sep 08, 2010 @ 17:47
    Sascha Wolter
    0

    Hi John,

    you could put this in a for-each loop, so something like:

    <xsl:for-each select="2010season/races[comparison here]">
    <xsl:sort select="dateTimeStart" order="descending" />
    <xsl:if test="position() = 1">
    <!-- show the link -->
    </xsl:if>
    </xsl:for-each>

    That should take care of 1) and 2). The right way to do the date comparison is probably via the Exslt.ExsltDates extension. That's where you get the current date from as well (I think it's just :Date() ). Afraid I don't know the exact syntax by heart, however should point you in the right direction.

    Cheers,

    Sascha

  • John C Scott 473 posts 1183 karma points
    Sep 08, 2010 @ 18:25
    John C Scott
    0

    thanks Sascha - that's very helpful - i'll follow that through 

    i did like the idea of trying to do it without a loop 

    if i get it to work i'll post it back here

Please Sign in or register to post replies

Write your reply to:

Draft