tag:help-archives.hannonhill.com,2010-02-09:/discussions/xslt-formats/2860-how-to-display-n-articles-using-xsltCascade CMS: Discussion 2013-09-23T17:39:50Ztag:help-archives.hannonhill.com,2010-02-09:Comment/288438652013-09-16T16:56:47Z2013-09-16T16:56:47ZHow to display N articles using XSLT<div><p>Hi Erik,</p>
<p>It looks like you're really close. The value of the
<code>position()</code> attribute is pre-sorted, so instead of
using XPath to filter by the position in your apply-templates, you
can try adding an <code><xsl:if></code> to test the position
after the sort occurs.</p>
<p>When you have a moment, try out the following and let me know
how it works out:</p>
<pre>
<code>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xalan="http://xml.apache.org/xalan">
<xsl:include href="/_Site Support/Formats/storyListing"/>
<xsl:include href="/_Site Support/Formats/xPaths"/>
<xsl:output indent="yes" method="xml"/>
<xsl:variable name="limit">15</xsl:variable>
<xsl:template match="system-index-block">
<ul class="post-list post-list-alt">
<!--
Loop through every <system-page> element categorized as keyword "Student"
-->
<xsl:apply-templates select="//system-page[dynamic-metadata[name='keywords']/value = 'Student'][start-date]">
<xsl:sort data-type="number" order="descending" select="start-date"/>
</xsl:apply-templates>
</ul>
</xsl:template>
<xsl:template match="system-page">
<xsl:if test="position() &lt;= $limit">
<li>
<a class="post-title" href="{link}">
<xsl:value-of select="title"/>
</a>
<br/>
<xsl:value-of select="teaser"/>
</li>
</xsl:if>
</xsl:template>
</xsl:stylesheet></code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/288438652013-09-23T15:47:17Z2013-09-23T15:47:17ZHow to display N articles using XSLT<div><p>Thanks Ryan. I tried it out and it seems to be working now.</p></div>espanaetag:help-archives.hannonhill.com,2010-02-09:Comment/288438652013-09-23T17:39:49Z2013-09-23T17:39:49ZHow to display N articles using XSLT<div><p>Thank you for following up, Erik. I am glad to hear the adjusted
XSLT did the trick.</p>
<p>I'm going to go ahead and close this discussion, please feel
free to comment or reply to re-open if you have any additional
questions.</p>
<p>Have a great day!</p></div>Ryan Griffith