Solved

Limit number of Rows returned in XSLT Loop

Posted on 2008-10-10
6
2,671 Views
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"/>
</xsl:for-each>
 
</xsl:template>
</xsl:stylesheet>

Open in new window

0
Comment
Question by:Paulconsulting
  • 3
  • 3
6 Comments
 
LVL 18

Expert Comment

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

select="rss/channel/item[position()<4]"
0
 
LVL 18

Expert Comment

by:zc2
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

select="rss/channel/item[position()&lt;4]"

Open in new window

0
 

Author Comment

by:Paulconsulting
ID: 22689716
That kinda works, but <4 just returns 2 results - I have to do <7 to return 5 rows :~
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 18

Accepted Solution

by:
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

0
 

Author Comment

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

Author Closing Comment

by:Paulconsulting
ID: 31505141
Thanks :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jquery validation by class 12 54
Coova-Chilli can't work with URL using HTTPS! 3 270
Animated .jpg? 13 95
Make Line Items Look Good Over Mobile 2 80
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…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to count occurrences of each item in an array.

789 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