Solved

Limit number of Rows returned in XSLT Loop

Posted on 2008-10-10
6
2,628 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now