Copied to clipboard

Flag this post as spam?

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


  • radmanmm 117 posts 108 karma points
    Apr 04, 2011 @ 23:41
    radmanmm
    0

    Show optional link if count is higher than display value

    Hi All,

    I wasn't sure how to actually search for this to see if there was a solution already.  So I will state what I need and then someone may be able to direct me.

    I have a list of comments, I need to limit the list to 5 and then provide a "read more" link if the number of comments are over the limit.  I started with the UCommentsListComments macro (great package by the way!!!).  I am able to successfully limit the number showing in the list, but I cannot figure out how to tell the xslt parser that I need to show a link if position() > $numberToDisplay.  At the time I know what "position()" is, I am inside the for loop but I don't the link to show until after the for loop is complete and the closing OL tag.

    Anyone done this before? Not having a "variable" that can be set is very difficult here.

    Thanks for your time.

  • Jesper Hauge 298 posts 487 karma points c-trib
    Apr 05, 2011 @ 00:03
    Jesper Hauge
    2

    Hi radmanmm,

    You should insert the link after the for loop. Try something like this:

    <xsl:for-each select="...">
     <!-- Loop code here -->
    </xsl:for-each>
    <xsl:if test="$currentPage/node[position() &gt; $numberToDisplay]">
     <a href="#">Read more ...</a>
    </xsl:if>

    In xslt any xpath statement that result in a non-empty node set is considered true, so the above statement will be true if there is one or more nodes at a position greater than $numberToDisplay.

    Regards
    Jesper Hauge

  • radmanmm 117 posts 108 karma points
    Apr 12, 2011 @ 02:55
    radmanmm
    1

    Hi Jesper,

    can I access the position() value outside the for loop?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 12, 2011 @ 03:08
    Tom Fulton
    0

    Hi,

    No, I don't think you'll be able to access position() outside the loop, but I'm not sure why you'd need to.  Jesper's solution should work.  Are you having an issue with it?

    -Tom

  • Jesper Hauge 298 posts 487 karma points c-trib
    Apr 12, 2011 @ 09:00
    Jesper Hauge
    1

    Hi radmanmm,

    The position() method is not linked to a for-each loop, actually I almost never use the for-each structure in my xlst, but that's another story.

    You should think of what's going on in the test and select attributes as queries not variable and values. XPath is a query language, not a programming language. The test attribute contains a query saying something like: If there exists a node below $currentpage with a position() in the node set greater than $numberToDisplay then write out the contents of the xls:if tag.

    Regards
    Jesper Hauge

  • Ove Andersen 435 posts 1541 karma points c-trib
    Apr 12, 2011 @ 09:24
    Ove Andersen
    0

    Tim Geyssens has an example of how to put a link after a specified number of nodes here:
    http://www.nibble.be/?p=44

    It's original purpose is for pagination, but you should be able to adapt it to your needs.

Please Sign in or register to post replies

Write your reply to:

Draft