Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2866
  • Last Modified:

Limit number of Rows returned in XSLT Loop

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
Paulconsulting
Asked:
Paulconsulting
  • 3
  • 3
1 Solution
 
zc2Commented:
try to use the position() function like in follows:

select="rss/channel/item[position()<4]"
0
 
zc2Commented:
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
 
PaulconsultingAuthor Commented:
That kinda works, but <4 just returns 2 results - I have to do <7 to return 5 rows :~
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
zc2Commented:
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
 
PaulconsultingAuthor Commented:
Your right, I missed one of the rows
0
 
PaulconsultingAuthor Commented:
Thanks :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now