XSL: for-each with max items

While working with Umbraco and Sitecore I learned some Xsl tricks.

The following example shows how to show the first 10 items in a HTML list.


<ul>

  

    &lt;xsl:if test=&quot;position()

      <li>

 <a href="{@link}">

   

  </a>

      </li>

    

  

</ul>


3 Replies to “XSL: for-each with max items”

  1. In this case (when your just limiting results) it’s probably better to put the position into the for each statement. Something like:

    <xsl:for-each select="position()&lt;=’9’">

    using it in the <if> statement is great for displaying a couple of items differently (for example the first 3)

  2. Hey thanks for this post. It helped me out of a jam today. Any chance you can help with how to do greater than/less than using the above example?

Leave a Reply

Your email address will not be published.