Limit number of Rows returned in XSLT Loop

Posted on 2008-10-10
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="" xmlns:feedburner="" xmlns:atom10="">
<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
  • 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 :~
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

LVL 18

Accepted Solution

zc2 earned 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Forbidden errors 5 142
CSS (line height?) issue 2 65
Form submit issue 11 85
What language/protocol is the Angular Chat? 2 77
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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…

777 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