SharePoint (2003 thru Online): How to display RSS feed using XML Web Part

Wednesday, June 10, 2015

How to display RSS feed using XML Web Part


A good solution to display RSS Feeds using XML Web part, so there was no need for some third-party Web Parts. Also there was no need to write any additional code.
Easy step-by-step guide. 
  1. Go to page you need to add the RSS Feed, Open this page in edit view and add new Web Part called XML Web Part. 
     
  2. If Web Part is added to page then open it’s settings window. 
     
  3. On the field XML Link insert your blog feed URL. Check out if link is correct and content is receivable by clicking the link titled as Test Link. 
     
  4. Push button titled as [XSL Editor]. 
     
  5. XSL editing window is opened and now insert XSL code given below. When inserted click [OK]. 
     
  6. You should see the RSS feed as bulleted list. 
     
  7. Save the edited page.
XSL you need is here. Take it using copy and paste.

With the below code, you will get limited items 5 with Published Date in Green color.
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl"> 
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<!--venugopalreddy.india@gmail.com-->

<xsl:template match="/"> 
<div><xsl:apply-templates select="rss/channel"/></div> 
</xsl:template> <xsl:template match="rss/channel"> 
<xsl:variable name="link" select="link"/> 
<xsl:variable name="description" select="description"/> 
<xsl:variable name="pubDate" select="pubDate"/> 

<ul> 
<!--<xsl:apply-templates select="item"/>--><!--For All Items--> 
<xsl:apply-templates select="item[position() &lt;= 5]"/><!--Limit 5 Items--> 
<xsl:apply-templates select="pubDate"/><!-- Published Date of the Items--> 
</ul>
</xsl:template> 

<xsl:template match="item"> 
<xsl:variable name="item_link" select="link"/> 
<xsl:variable name="item_title" select="description"/> 
<xsl:variable name="item_pubDate" select="pubDate"/>

<li> 
<a href="{$item_link}" title="{$item_title}" target="_blank"> 
<b><xsl:value-of select="title"/>&#160;</b> 
<!-- <font color="green"><xsl:value-of select="pubDate"/></font>--><!-- Date and Time --> 
<font color="green"><xsl:value-of select="substring(pubDate,1,16)"/></font> <!-- Date Only --> 
</a>
</li>
<li></li>
</xsl:template> </xsl:stylesheet>




No comments:

Post a Comment