Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
how can i display just the first two records in an xslt loop? Im wanting to display just the latest 2 news stories on my homepage.
<xsl:for-each select="$currentPage/descendant-or-self::node[(@nodeTypeAlias = 'NewsStory')]">
<h2><xsl:value-of select="@nodeName"/></h2>
<p><xsl:value-of select="data[@alias='IntroPara']" disable-output-escaping="yes"/></p>
</xsl:for-each>
Hi Phil,
There are 2 ways to do it, first by limiting the number of nodes that are used in the for-each loop:
<xsl:for-each select="$currentPage/descendant-or-self::node[@nodeTypeAlias = 'NewsStory' and position() <= 2]">
But the problem with that is they aren't sorted, it will only take the first 2 nodes - which "might" not be in the correct date order.
So your best bet is to go with an IF condition within the loop...
<xsl:for-each select="$currentPage/descendant-or-self::node[(@nodeTypeAlias = 'NewsStory')]"> <xsl:sort select="@createDate" order="descending" /> <xsl:if test="position() <= 2"> <h2> <xsl:value-of select="@nodeName"/> </h2> <p> <xsl:value-of select="data[@alias='IntroPara']" disable-output-escaping="yes"/> </p> </xsl:if> </xsl:for-each>
Cheers, Lee.
Thanks a lot Lee
This is a perfect example of the limitations of XSLT :P
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Show just the top 2
how can i display just the first two records in an xslt loop? Im wanting to display just the latest 2 news stories on my homepage.
<xsl:for-each select="$currentPage/descendant-or-self::node[(@nodeTypeAlias = 'NewsStory')]">
<h2><xsl:value-of select="@nodeName"/></h2>
<p><xsl:value-of select="data[@alias='IntroPara']" disable-output-escaping="yes"/></p>
</xsl:for-each>
Hi Phil,
There are 2 ways to do it, first by limiting the number of nodes that are used in the for-each loop:
But the problem with that is they aren't sorted, it will only take the first 2 nodes - which "might" not be in the correct date order.
So your best bet is to go with an IF condition within the loop...
Cheers, Lee.
Thanks a lot Lee
This is a perfect example of the limitations of XSLT :P
is working on a reply...