Copied to clipboard

Flag this post as spam?

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


  • Darryl Godden 145 posts 197 karma points
    Feb 18, 2010 @ 10:56
    Darryl Godden
    0

    Help with loop

    Hi guys,

    We have this code which find events on our website within certain date parameters and we only want to display 10 events. The problem is if an event doesn't meet the date parameters the position counter still increments.

    Therefore we only get 4 or so events displaying as the position reaches 10 irrespective of the if tests.

    Can you help with a way to achieve this?

    <xsl:for-each select="$currentPage/ancestor-or-self::root/node/node [@nodeName='whatson']/node [string(data [@alias='Highlight']) = '1']">
        <xsl:sort select="concat(substring(data [@alias = 'eventcreation'],1,4),substring(data [@alias = 'eventcreation'],6,2),substring(data [@alias = 'eventcreation'],9,2))" order="descending"/>
        <xsl:sort select="concat(substring(data [@alias='startDate'],1,4),substring(data [@alias='startDate'],6,2),substring(data [@alias='startDate'],9,2))" order="ascending"/>
        <xsl:if test="position() &lt; 10">
        <xsl:if test="data [@alias = 'endDate'] != ''">
        <xsl:if test="umbraco.library:DateGreaterThanOrEqual(umbraco.library:FormatDateTime(data [@alias = 'endDate'],'yyyy/MM/dd'),umbraco.library:FormatDateTime(umbraco.library:CurrentDate(),'yyyy/MM/dd')) = 'true'">
            <dd>
                <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:value-of select="data [@alias = 'ShortTitle']" />
                    <!--<xsl:value-of select="concat(substring(data [@alias='startDate'],1,4),substring(data [@alias='startDate'],6,2),substring(data [@alias='startDate'],9,2))" />-->
                </a>
            </dd>
        </xsl:if>
        </xsl:if>
        </xsl:if>
    </xsl:for-each>

    Thanks

  • dandrayne 1138 posts 2262 karma points
    Feb 18, 2010 @ 10:59
    dandrayne
    0

    I think you'd need to move more of your conditions into the for-each in order to use position() in this way. Something like (totally untested!)

    <xsl:for-each select="$currentPage/ancestor-or-self::root/node/node [@nodeName='whatson']/node [string(data [@alias='Highlight']) = '1' and string(./data[@alias = 'endDate']) != '' and umbraco.library:DateGreaterThanOrEqual(umbraco.library:FormatDateTime(data [@alias = 'endDate'],'yyyy/MM/dd'),umbraco.library:FormatDateTime(umbraco.library:CurrentDate(),'yyyy/MM/dd')) = 'true']">
    <xsl:sort select="concat(substring(data [@alias = 'eventcreation'],1,4),substring(data [@alias = 'eventcreation'],6,2),substring(data [@alias = 'eventcreation'],9,2))" order="descending"/>
    <xsl:sort select="concat(substring(data [@alias='startDate'],1,4),substring(data [@alias='startDate'],6,2),substring(data [@alias='startDate'],9,2))" order="ascending"/>
    <xsl:if test="position() &lt; 10">
    <dd>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="data [@alias = 'ShortTitle']" />
    <!--<xsl:value-of select="concat(substring(data [@alias='startDate'],1,4),substring(data [@alias='startDate'],6,2),substring(data [@alias='startDate'],9,2))" />-->
    </a>
    </dd>
    </xsl:if>
    </xsl:for-each>

    Dan

  • Darryl Godden 145 posts 197 karma points
    Feb 18, 2010 @ 11:10
    Darryl Godden
    0

    Perfect - thank you!

Please Sign in or register to post replies

Write your reply to:

Draft