Copied to clipboard

Flag this post as spam?

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


  • bob baty-barr 1180 posts 1294 karma points MVP
    Feb 07, 2011 @ 16:42
    bob baty-barr
    0

    how to grap first 3 nodes when position() not starting at 1?

    Hey umbraco GURUS :) i am grabbing all events in the tree that are happenign AFTER today... but i want to only show the first 3... I usually use a test based on position(), but my position ids start at 4 in this particular case...

    how do i count those?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 07, 2011 @ 16:45
    Dirk De Grave
    0

    Can't you include the AFTER clause in the for-each to filter out these that shouldn't be in the list and then start from 1 using position()?

     

    Cheers,

    /Dirk

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Feb 07, 2011 @ 16:46
    Matt Brailsford
    1

    Do you know what the offset position is? Can you get it into a variable? If so, just do some simple math?

    position() - $positionOffset < 3

    Matt

  • bob baty-barr 1180 posts 1294 karma points MVP
    Feb 07, 2011 @ 16:51
    bob baty-barr
    0

    yeah, but i don't really know the postition offset... i really need a way to re-seed the position() i think nodeset is what i want, but not sure how to implement...

    here is my code snippet

    <xsl:variable name="numToShow"
     select="number($currentPage/howManyEventItemsToList)"/>
     
      <xsl:variable name="nodes" select="umbraco.library:GetXmlAll()//* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']"/>
      
     
    <ul id="newsNewsList">
      <xsl:for-each select="position()&lt;= $numToShow and umbraco.library:GetXmlAll()//* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">
        <xsl:sort select="eventStartDate" order="ascending"/>

    i am basically letting the client specify how many events they want to show... then grabbing all events... then showing the top 3... but the postition is based on the entire list... not the ones that are past the date of today... do i just need to move my date logic into my for-each?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 07, 2011 @ 16:54
    Dirk De Grave
    1

    It can be done your way, but you'd need to iterate your events first, build up a string containing events which should be shown (ie after today) and then use split to iterate the list again (think of how xslt search is doing it...)

    But, anyway, I'd move the logic into the variable 'nodes'

     

    Cheers,

    /Dirk

  • bob baty-barr 1180 posts 1294 karma points MVP
    Feb 07, 2011 @ 16:54
    bob baty-barr
    0

    um, disregard that code above... that was some bad copy and paste - DOH! total blonde moment there...

    anyway, this appears to work better now...

    <!-- Input the documenttype you want here 
    -->
    <xsl:variable name="documentTypeAlias" select="string('EventItem')"/>
    <xsl:variable name="today" select="Exslt.ExsltDatesAndTimes:date()"/>

    <xsl:template match="/">
      <h3>Upcoming Events</h3>
    <!-- The fun starts here -->
      <xsl:variable name="numToShow" select="number($currentPage/howManyEventItemsToList)"/>
     
      <xsl:variable name="nodes" select="umbraco.library:GetXmlAll()//* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']"/>
      
     
    <ul id="newsNewsList">
      <xsl:for-each select="umbraco.library:GetXmlAll()//* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1'][umbraco.library:DateGreaterThan(eventStartDate, $today)]">
        <xsl:sort select="eventStartDate" order="ascending"/>
       

      <xsl:if test="position()&lt;= $numToShow">
      <li>
        <p class="newsDate"><xsl:value-of select="umbraco.library:FormatDateTime(eventStartDate, 'MMMM dd, yyyy')"/><xsl:if test = "eventEndDate !=''">&nbsp;-&nbsp;<xsl:value-of select="umbraco.library:FormatDateTime(eventEndDate, 'MMMM dd, yyyy')"/></xsl:if></p>
        <p class="newsHeadline"><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="pageHeading"/></a>
          <xsl:if test="eventLocation !=''"><br/>Location:&nbsp;<xsl:value-of select="eventLocation"/></xsl:if></p>
       </li>
      </xsl:if>
    </xsl:for-each>
      <xsl:if test="count(umbraco.library:GetXmlAll()//* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1'])&gt; $numToShow">
        <li><a href="{umbraco.library:NiceUrl($currentPage/@id)}/events" class="allNewsLink">See all Events Here</a></li>
        </xsl:if>
    </ul>
  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Feb 07, 2011 @ 17:01
    Douglas Robar
    0

    The key is to return only events that have dates that haven't yet expired. Umbraco provides a really handy "umbraco.library:DateGreaterThanOrEqualToday". Include that in the predicate for your variable.

    Something like (I typed in the forum, watch for silly errors)...

    <xsl:variable name="nodes" select="umbraco.library:GetXmlAll()//* [
                   name() = $documentTypeAlias 
                   and string(umbracoNaviHide) != '1' 
                   and umbraco.library:DateGreaterThanOrEqualToday($eventStartDate)
                              ]" />

     

     

    Then you use position() <= $numToShow in your for-each and you're done.

     

    cheers,
    doug.

     

  • bob baty-barr 1180 posts 1294 karma points MVP
    Feb 07, 2011 @ 17:11
    bob baty-barr
    0

    ah, i was using dategreater than, but i had NO IDEA there was a built in greater than today - BRILLIANT!

    Thanks for all the help guys! H5YR!

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Feb 07, 2011 @ 17:12
    Douglas Robar
    0

    To complete the picture, 

    <xsl:for-each select="$nodes">
    <xsl:sort select="eventStartDate" order="ascending" />
    ... do stuff here ..
    </xsl:for-each>

    cheers,
    doug.

Please Sign in or register to post replies

Write your reply to:

Draft