Copied to clipboard

Flag this post as spam?

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


  • Frederik T 241 posts 372 karma points
    Aug 29, 2011 @ 16:29
    Frederik T
    0

    "Advanced" usage of position() in a list of items? Start at one number end at another.

    Ok, this is hopefully quick but i couldnt find anything about it.

    I have a list of articles, and that works and all, there was two things that needed to be done with it:

    1: Specific styling for the first item in the list
    2: Specific styling for the rest
    3: And limit the number.

    Ive finally begun to get my head around position() and i suceeded in the first and second point.

    But! the way ive done it, i dont know how to limit the number of items then, can position have two statements? Like "start from number 2 stop at 4" or something.

    <xsl:variable name="level" select="4"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul class="list green">
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <xsl:sort select="articleDate[normalize-space()]" order="descending" />
      <xsl:sort select="@updateDate[not(normalize-space(../articleDate))]" order="descending" />
      <xsl:choose>
        <xsl:when test="position() = 1">
          <li class="feature">
            <a href="{umbraco.library:NiceUrl(@id)}">
            
              <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
              <!-- we're under the item - you can do your own styling here -->
              <xsl:attribute name="class">selected</xsl:attribute>
              </xsl:if>
              
             <xsl:if test="count(current()/outputPictures) > 0">
              <img src="/ImageGen.ashx?image={current()/outputPictures[position()=1]/DAMP[@fullMedia]/mediaItem/Image/umbracoFile}&amp;width=300&amp;height=135" width="300" height="135"/>
             </xsl:if>
            
              <h5><xsl:value-of select="articleHeading"/></h5>
              <p class="teaser"><xsl:value-of select="umbraco.library:TruncateString(artikel-Teasertekst,70,'...')"/></p>
             </a>
            </li>
        </xsl:when>
        <xsl:when test="position() &gt;= 2">
          <li>
          <a href="{umbraco.library:NiceUrl(@id)}">
          
            <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
            <!-- we're under the item - you can do your own styling here -->
            <xsl:attribute name="class">selected</xsl:attribute>
            </xsl:if>
            
           <xsl:if test="count(current()/outputPictures) > 0">
            <img src="/ImageGen.ashx?image={current()/outputPictures[position()=1]/DAMP[@fullMedia]/mediaItem/Image/umbracoFile}&amp;width=125&amp;height=70" width="125" height="70"/>
           </xsl:if>
          
            <h5><xsl:value-of select="articleHeading"/></h5>
            <p class="teaser"><xsl:value-of select="umbraco.library:TruncateString(artikel-Teasertekst,70,'...')"/></p>
           </a>
          </li>
        </xsl:when>
      </xsl:choose>
    </xsl:for-each>
    </ul>

    </xsl:template>

    Ive highlighted the lines where i use position.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 29, 2011 @ 16:34
    Dirk De Grave
    1

    Hi,

    How about 

    <xsl:whentest="position() &gt;= 2 and position() &lt;= 4">

     

    Hope this helps.

    Regards,

    /Dirk

  • Frederik T 241 posts 372 karma points
    Sep 01, 2011 @ 09:35
    Frederik T
    0

    Okay this is wierd indeed, i did the exact same solution you did, before making this thread, and it didnt work, thats why i came here. And now it does, this is so confusing sometimes. But thank you for your time, its much appreciated :)

Please Sign in or register to post replies

Write your reply to:

Draft