Limit number of Rows returned in XSLT Loop

Posted on 2008-10-10
Medium Priority
Last Modified: 2013-11-18
I'm using XSLT to style the data in an RSS Feed and I want to limit the number of rows returned:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xmlns:atom10="http://www.w3.org/2005/Atom">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="/">
<img src="{rss/channel/image/url}" />
<br />
<xsl:for-each select="rss/channel/item">
  <a href="{rss/channel/item/feedburner:origLink}"><xsl:value-of select="title"/></a> <br />
  <xsl:value-of select="description" disable-output-escaping="yes"/>

Open in new window

Question by:Paulconsulting
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 18

Expert Comment

ID: 22689654
try to use the position() function like in follows:

LVL 18

Expert Comment

ID: 22689689
I'm sorry, the experts-exchange's text editor replaced a '& lt;' with a '<',
see the code snippet below, hope it will remain as is


Open in new window


Author Comment

ID: 22689716
That kinda works, but <4 just returns 2 results - I have to do <7 to return 5 rows :~
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

LVL 18

Accepted Solution

zc2 earned 2000 total points
ID: 22689911
Ok, I agree, position() < 4 return 3, but you said it returns only 2? Weird...

Should select the first 4 items:
<xsl:for-each select="rss/channel/item[position() &lt;= 4]">

Open in new window


Author Comment

ID: 22690028
Your right, I missed one of the rows

Author Closing Comment

ID: 31505141
Thanks :)

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question