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.
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() > $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.
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?
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.
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.
Hi radmanmm,
You should insert the link after the for loop. Try something like this:
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
Hi Jesper,
can I access the position() value outside the for loop?
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
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
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.
is working on a reply...