Matthew McDermott

Matthew is a principal consultant for Catapult Systems. A Microsoft MVP (SharePoint Server), Matthew blogs about SharePoint and Microsoft technologies related to collaboration, web content management and productivity.
RSS Feed

Building a blog host, Part 4

Fixing the RSS Feed

You may or may not have noticed that the RSS feed for our rollup does not work the way RSS should. The Body and Author fields are missing. Broken RSS Image

This post will address how to fix the RSS feed. All the work in this post is based on the post: How to: Customize RSS for the Content Query Web Part.

Prepare a new RSS definition

  1. Navigate to the Style Library and open the XSL Style Sheets folder. Make a copy of the Rss.xsl file and call it BlogSummaryRss.xsl.
  2. Make a copy of the ContentQueryMain.xsl file and call it BlogContentQueryMain.xsl. (You could edit the ContentQueryMain.xsl file but I prefer to work on a copy.)
  3. Edit the file and locate the line:

    <xsl:variable name="FeedUrl1" select="concat($SiteUrl,$FeedPageUrl,'xsl=1&amp;web=',$WebUrl,'&amp;page='

    And change the 'xsl=1' to 'xsl=2':

    <xsl:variable name="FeedUrl1" select="concat($SiteUrl,$FeedPageUrl,'xsl=2&amp;web=',$WebUrl,'&amp;page='

  4. Save the file and check it in.

Update the web.config file

  1. Open the web.config file for your web application.
  2. Find the lline:

    <add key="FeedXsl1" value="/Style Library/Xsl Style Sheets/Rss.xsl" />

    Insert the following line below:

    <add key="FeedXsl2" value="/Style Library/Xsl Style Sheets/BlogSummaryRss.xsl" />

Update the web part to use the custom BlogContentQueryMain.xsl

  1. Export the web part again.
  2. Open the file in Notepad and locate the line:

    <property name="MainXslLink" type="string" />

    Change the line to this:

    <property name="MainXslLink" type="string">/Style Library/XSL Style Sheets/BlogContentQueryMain.xsl</property>

  3. Save the file. Delete the web part from the page and import the latest version. The web part should not change in appearance. The only change you should notice is that the link for the RSS icon should read:

    http://<blog host>/_layouts/feed.aspx?xsl=2&web=%2F&page=<guid>&wp=<guid>

  4. Clicking the RSS icon should display the same view as before, still missing fields.

Add the Published Date and Author fields to our feed

  1. In SharePoint Designer open the file BlogSummaryRss.xsl.
  2. Locate the lines:

    <description>

    <xsl:if test="string-length(@Description) != 0">

    <xsl:value-of disable-output-escaping="no" select="@Description" />

    </xsl:if>

    </description>

  3. Change the @Description field to @Body so that the code reads:

    <description>

    <xsl:if test="string-length(@Body) != 0">

    <xsl:value-of disable-output-escaping="no" select="@Body" />

    </xsl:if>

    </description>

  4. Locate the lines:

    <pubDate>

    <xsl:value-of disable-output-escaping="no" select="@PubDate" />

    </pubDate>

    Change @PubDate to @PublishedDate so the line reads:

    <xsl:value-of disable-output-escaping="no" select="@PublishedDate" />

  5. Above the <pubDate> node insert the following line to display the author field:

    <dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/"><xsl:value-of select="substring-after(@Author,'#')" /></dc:creator>

  6. When you are done editing the <item> section should look like this:

    <item>

    <title>

    <xsl:if test="string-length(@Title) != 0">

    <xsl:value-of select="@Title" />

    </xsl:if>

    <xsl:if test="string-length(@Title) = 0">

    <xsl:value-of select="$BlankTitle"/>

    </xsl:if>

    </title>

    <xsl:value-of select="'&lt;link&gt;'" disable-output-escaping="yes" />

    <xsl:call-template name="OuterTemplate.GetSafeLink">

    <xsl:with-param name="Url" select="@LinkUrl" />

    </xsl:call-template>

    <xsl:value-of select="'&lt;/link&gt;'" disable-output-escaping="yes" />

    <description>

    <xsl:if test="string-length(@Body) != 0">

    <xsl:value-of disable-output-escaping="no" select="@Body" />

    </xsl:if>

    </description>

    <dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/"><xsl:value-of select="substring-after(@Author,'#')" /></dc:creator>

    <pubDate>

    <xsl:value-of disable-output-escaping="no" select="@PublishedDate" />

    </pubDate>

    </item>

     

  7. Save the file and check it in.
  8. Return to your home page and click the RSS icon. Your page should look like this now:

    Note: Caching may affect how long it takes to see the results of your work. Go walk the dog, get a drink and come back and test it again.

Posted by Matthew McDermott on Saturday, 24 Nov 2007 06:48
4 Comments | Filed under: Community Kit for SharePoint, Web Publishing
Bookmark this post with:        

Comments

On 11 Feb 2008 01:57, Joost Scherners said:

Hi, for displaying the title as a link in the CQWP you also have to add the following to the blogcontentquerymain $SiteUrl, Change this line to (added $SiteUrl) (http://msmvps.com/blogs/obts/archive/2007/03/27/716595.aspx) kind regards, Joost

On 07 Aug 2008 05:20, Clement said:

I just had to say thanks! That was as accurate, concise, and productive a tutorial as I've ever done. Great instructions, and great blog. Went through all 4 of these posts.

On 21 Oct 2009 01:29, Jay said:

We've been attempting to create a custom web part that calls upon a copy of contentquerymain.xsl to get different information than the default file (we're creating a web part to that will generate an rss feed that is different from the default). We've followed directions for doing this from several sites/blogs (they all give the same instructions to do this). In Sharepoint Designer, we copy the contentquerymain.xsl to a different name like contentquerymain2.xsl. We then take a Content Query Web Part that has been configured to set up an rss feed, etc., and export that web part. Here's where the problems start. All the walkthroughs discuss changing the line below as shown. < property name ="MainXslLink" type ="string" > /Style Library/XSL Style Sheets/contentquerymain2.xsl Just following that direction, the web part will import, but the web part is broken (unable to proceed or something like that) Looking around the web part file, we also find a long line that calls the contentquerymain.xsl <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cmswrt="http://schemas.microsoft.com/WebPart/v3/Publishing/runtime" exclude-result-prefixes="xsl cmswrt x" > <xsl:import href="/Style Library/XSL Style Sheets/Header.xsl" /> <xsl:import href="/Style Library/XSL Style Sheets/ItemStyle.xsl" /> <xsl:import href="/Style Library/XSL Style Sheets/ContentQueryMain.xsl " /> </xsl:stylesheet> If we don't change the MainXslLink field, but change that long line to point at the copied file and import the web part, we can tell the web part is not calling the copied file....it's still calling the original xsl file. If we change both the long line and the MainXslLink, the web part will be broken. We've tried multiple variations and methods of changing those two lines to get the desired effect...but to no avail. We can not get anything to point at the right xsl file. Has anyone found any snag/trick/procedure that makes this work as written?

On 26 Oct 2009 10:42, Matthew said:

Jay, I have seen situations where the links fail due to improperly configuring BackConnectionHostNames or not checking in and approving the new file. If you are trying to use RSS I would suggest forgetting about the CQWP and just write a new feed. Unless you need the portability it sounds like you could just write an application page to execute the query and apply the XSLT before rendering the XML. Ping me by e-mail if you still have questions.

Comments are disabled