DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

Limit items in a SharePoint RSS Feed XSLT

Posted by PANVEGA on January 29, 2008

If you want to show only, say, the first 5 items of the RSS feed then you can modify the for-each element. For instance, you can pass to the stylesheet a couple of parameters, namely the limit and amount of items as follows.

Otherwise if you do not pass the paramters and you wanna check the position when calling the template you allways “1” in the positin function and your xslt template lists all items.

  1. catch the limitation parameter when calling the xslt here rss_FeedLimit
  2. Store the Items in a variable here Rows
  3. Count the items in the channel here RowCount
  4. Pass the parameters and call a template
  5. compare the current positoin with the rss_FeedLimit

<xsl:param name=”rss_FeedLimit“>5</xsl:param>
<xsl:variable name=”Rows” select=”channel/item”/>
<xsl:variable name=”RowCount” select=”count($Rows)”/>
<xsl:call-template name=”rssItems”>
<xsl:with-param name=”Rows” select=”$Rows”/>
<xsl:with-param name=”RowCount” select=”count($Rows)”/>

The only thing you need to know is how to pass these parameters to your XSLT engine. This will allow you to generate “dynamically” the table to be shown (probably depending on some user choice like a “next” link or similar). Probably there are many other (more efficient and smarter) ways to do this. I hope this helps anyway (partiallyat least!)

<xsl:template name=”rssItems”>
<xsl:param name=”Rows”/>
<xsl:param name=”RowCount”/>
<xsl:for-each select=”$Rows”>

<xsl:variable name=”CurPosition” select=”position()” />
<xsl:if test=”($CurPosition &lt;= $rss_FeedLimit)”>
<xsl:value-of select=”substring(pubDate,18,8)” />
<a href=”{link}” title=”{title}” target=”_blank” class=”ArticleHead”>
<xsl:when test=”(string-length(title) &gt; 50)”>
<xsl:value-of select=”concat(substring(title,0,50),’ …’)”/>
<xsl:value-of select=”title”/>

In order to tramsform the Date and Time you should apply the SP Webpart namespace:



<xsl:value-of select=”ddwrt:FormatDateTime(string(pubDate),1033,’yyyy-MM-dd’)”/>

or <xsl:value-of select=”ddwrt:FormatDateTime(string(pubDate),1033,’hh:mm’)”/>
One last thing:

When you wannt to use the SharePoint RSS Feed Webpart (CQWP) you can insert a path to your custom XSLT file.

  1. Open your SP Designer
  2. Go to Style Library/XSL Style Sheets
  3. Create a new XSL file
  4. copy the path to your new file like Style Library/XSL Style Sheets/Feed.xsl
  5. Copy the path into the Webpart properties new XSLT file and add a slash ti the beginning of the path
  6. e.g. /Style Library/XSL Style Sheets/Feed.xsl thats it

More Information:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: