Sunday, May 31, 2009

RSS Aggregator webpart using DataView webpart

Scenario:
RSS Aggregator web part


Points( +/- ):

+ Full XSLT support
+ Data caching support

- Need to edit every time you want to add a new RSS url
- Untested for maximum limit

RSSAggregator.webpart:

<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="Microsoft.SharePoint.WebPartPages.DataFormWebPart, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="DataSourcesString" type="string">
&lt;%@ Register TagPrefix="sharepoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt;&lt;sharepoint:AggregateDataSource runat="server" SeparateRoot="" RootName="" RowsName="" ID="merged1"&gt;&lt;Sources&gt;
&lt;sharepoint:XmlUrlDataSource runat="server" HttpMethod="GET" SelectCommand="http://feeds.feedburner.com/sandeepnahta" AuthType="None" XPath=""&gt;&lt;/sharepoint:XmlUrlDataSource&gt;
&lt;sharepoint:XmlUrlDataSource runat="server" HttpMethod="GET" SelectCommand="http://codename-srini.blogspot.com/feeds/posts/default?alt=rss" AuthType="None" XPath=""&gt;&lt;/sharepoint:XmlUrlDataSource&gt;
&lt;/Sources&gt;
&lt;Aggregate&gt;
&lt;concat name="data source"&gt;&lt;datasource name="sandeepnahta" id="0" Type="SPXml"/&gt;&lt;datasource name="default" id="1" Type="SPXml"/&gt;&lt;/concat&gt;&lt;/Aggregate&gt;
&lt;/sharepoint:AggregateDataSource&gt;
</property>
<property name="ParameterBindings" type="string">
&lt;ParameterBinding Name="dvt_apos" Location="Postback;Connection"/&gt;
&lt;ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/&gt;
&lt;ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/&gt;
</property>
<property name="Xsl" type="string">
&lt;xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:agg="http://schemas.microsoft.com/sharepoint/aggregatesource" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:atom10="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xmlns:media="http://search.yahoo.com/mrss/" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal"&gt;
&lt;xsl:output method="html" indent="no"/&gt;
&lt;xsl:decimal-format NaN=""/&gt;
&lt;xsl:param name="dvt_apos"&gt;'&lt;/xsl:param&gt;
&lt;xsl:variable name="dvt_1_automode"&gt;0&lt;/xsl:variable&gt;
&lt;xsl:template match="/"&gt;
&lt;xsl:call-template name="dvt_1"/&gt;
&lt;/xsl:template&gt;
&lt;xsl:template name="dvt_1"&gt;
&lt;xsl:variable name="dvt_StyleName"&gt;Table&lt;/xsl:variable&gt;
&lt;xsl:variable name="Rows" select="/dsQueryResponse/rss/channel"/&gt;
&lt;table border="0" width="100%" cellpadding="2" cellspacing="0"&gt;
&lt;tr valign="top"&gt;
&lt;xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1"&gt;
&lt;th class="ms-vh" width="1%" nowrap="nowrap"&gt;&lt;/th&gt;
&lt;/xsl:if&gt;

&lt;/tr&gt;
&lt;xsl:call-template name="dvt_1.body"&gt;
&lt;xsl:with-param name="Rows" select="$Rows"/&gt;
&lt;/xsl:call-template&gt;
&lt;/table&gt;
&lt;/xsl:template&gt;
&lt;xsl:template name="dvt_1.body"&gt;
&lt;xsl:param name="Rows"/&gt;
&lt;xsl:for-each select="$Rows"&gt;

&lt;xsl:call-template name="dvt_1.rowview"/&gt;

&lt;/xsl:for-each&gt;
&lt;/xsl:template&gt;
&lt;xsl:template name="dvt_1.rowview"&gt;

&lt;tr&gt;

&lt;xsl:if test="position() mod 2 = 1"&gt;
&lt;xsl:attribute name="class"&gt;ms-alternating&lt;/xsl:attribute&gt;
&lt;/xsl:if&gt;
&lt;xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1"&gt;
&lt;td class="ms-vb" width="1%" nowrap="nowrap"&gt;
&lt;span ddwrt:amkeyfield="" ddwrt:amkeyvalue="string($XPath)" ddwrt:ammode="view"&gt;&lt;/span&gt;
&lt;/td&gt;
&lt;/xsl:if&gt;
&lt;td class="ms-vb"&gt;
&lt;strong&gt;&lt;xsl:value-of select="title" /&gt;&lt;/strong&gt;
&lt;xsl:call-template name="dvt_2" /&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/xsl:template&gt;
&lt;xsl:variable name="dvt_2_automode"&gt;0&lt;/xsl:variable&gt;
&lt;xsl:template name="dvt_2"&gt;
&lt;xsl:variable name="dvt_StyleName"&gt;RepForm3&lt;/xsl:variable&gt;
&lt;xsl:variable name="Rows" select="item" /&gt;
&lt;table border="0" width="100%"&gt;
&lt;xsl:call-template name="dvt_2.body"&gt;
&lt;xsl:with-param name="Rows" select="$Rows" /&gt;
&lt;/xsl:call-template&gt;
&lt;/table&gt;
&lt;/xsl:template&gt;
&lt;xsl:template name="dvt_2.body"&gt;
&lt;xsl:param name="Rows" /&gt;
&lt;xsl:for-each select="$Rows"&gt;
&lt;xsl:call-template name="dvt_2.rowview" /&gt;
&lt;/xsl:for-each&gt;
&lt;/xsl:template&gt;
&lt;xsl:template name="dvt_2.rowview"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;table border="0" cellspacing="0" width="100%"&gt;
&lt;tr&gt;
&lt;td width="2%" class="ms-vb"&gt;
&lt;img alt="rect" src="http://spvm/_layouts/images/rect.gif" /&gt;
&lt;/td&gt;
&lt;td width="95%" class="ms-vb"&gt;
&lt;a href="{link}"&gt;&lt;xsl:value-of select="title" /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;xsl:if test="$dvt_2_automode = '1'" ddwrt:cf_ignore="1"&gt;
&lt;tr&gt;
&lt;td colspan="99" class="ms-vb"&gt;
&lt;span ddwrt:amkeyfield="" ddwrt:amkeyvalue="string($XPath)" ddwrt:ammode="view"&gt;&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/xsl:if&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</property>

<property name="DataFields" type="string">atom:id;lastBuildDate;title;description;link;managingEditor;generator;openSearch:totalResults;openSearch:startIndex;openSearch:itemsPerPage;atom10:link/@rel,atom10:link/rel;atom10:link/@href,atom10:link/href;atom10:link/@type,atom10:link/type;</property>
<property name="Title" type="string">RSS Aggregator</property>
</properties>
</data>
</webPart>
</webParts>
DataSource section in above it
This is the section need to be modified to add more RSS Urls. Below you can see i have used two RSS Urls, replace them with the ones you need.
 <property name="DataSourcesString" type="string" >  
<%@ Register TagPrefix="sharepoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><sharepoint:AggregateDataSource runat="server" SeparateRoot="" RootName="" RowsName="" ID="merged1"><Sources>
<sharepoint:XmlUrlDataSource runat="server" HttpMethod="GET" SelectCommand="http://feeds.feedburner.com/sandeepnahta" AuthType="None" XPath=""></sharepoint:XmlUrlDataSource>
<sharepoint:XmlUrlDataSource runat="server" HttpMethod="GET" SelectCommand="http://codename-srini.blogspot.com/feeds/posts/default?alt=rss" AuthType="None" XPath=""></sharepoint:XmlUrlDataSource>
</Sources>
<Aggregate>
<concat name="data source"><datasource name="sandeepnahta" id="0" Type="SPXml"/><datasource name="default" id="1" Type="SPXml"/></concat></Aggregate>
</sharepoint:AggregateDataSource>
</property >

0 comments: