Share via


How to: Customize RSS for the Content Query Web Part

After you customize the Content Query Web Part to display the fields and content you want, you can set up the Web Part to emit a Really Simple Syndication (RSS) feed of that content.

This topic explains how to add and customize RSS feeds that emit Content Query Web Part content:

  • How to enable an RSS feed for a Content Query Web Part

  • How an RSS feed URL works

  • How to use a custom .xsl file for Content Query Web Part RSS feeds

  • How to resolve caching issues with a Content Query Web Part RSS feed

Enable an RSS Feed for Content Query Web Part Content

To enable an RSS feed that emits Content Query Web Part content, edit the Web Part and select the Enable Feed check box. After you enable the feed, click the RSS feed icon to preview the feed's contents in your browser.

Understand How an RSS Feed URL Works

One key to understanding how to customize RSS for the Content Query Web Part is understanding the parts of an RSS feed URL and how they interact. Let's look at the format of an RSS feed URL: http://servername/_layouts/feed.aspx?xsl=registered .xsl files in the Web.config file&web=webaddress&page=guid&wp=guid.

The feed's URL includes a path to the Feed.aspx file, which is generated from the Feed.xsl file in the _layouts folder on your Microsoft Office SharePoint Server 2007 server. The Feed.aspx file looks up the Content Query Web Part that is emitting the RSS feed, determines which query the Web Part runs, and uses the Feed.xsl file in the _layouts folder to produce RSS feed XML.

The values specified for each parameter provide information that Office SharePoint Server 2007 requires to emit an RSS feed.

Parameter Description Valid Values

xsl

Pointer to the key used to identify the Rss.xsl file the Web Part uses to produce the RSS feed

.xsl files that are registered in the web.config file

Web

Web site containing the Content Query Web Part that is emitting the RSS feed

Server-relative URL

Page

Page containing the Content Query Web Part that is emitting the RSS feed

GUID

Wp

Content Query Web Part ID

GUID

Additional XSL Parameter Information

The design of the Content Query Web Part makes RSS feeds easy to administer; Office SharePoint Server 2007 registers each .xsl file in the web.config file. The xsl parameter in the RSS feed URL represents the registered .xsl file in the web.config file found in the path \Inetpub\wwwroot\wss\VirtualDirectories\portnumber\wpresources. Registering an .xsl file in the <appsettings> section of the web.config file enables the Feed.aspx file to use that .xsl file.

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

The key value of FeedXsl1 maps to the xsl parameter value of 1 in the RSS feed URL.

The value value in the /Style Library/Xsl Style Sheets/Rss.xsl path points to the Rss.xsl file in the Style Library, which Office SharePoint Server 2007 includes by default.

To enable an RSS feed for a Content Query Web Part

  1. Edit the Content Query Web Part.

  2. Expand the Presentation section, and then select the Enable Feed check box.

  3. Click through the RSS feed to see a preview in Internet Explorer and verify that the feed is working as expected.

Using a Custom XSL file for Content Query Web Part RSS Feeds

You can use a custom .xsl file for Content Query Web Part RSS feeds by doing either of the following:

  • Editing the default Rss.xsl file that is included with Office SharePoint Server 2007; this ensures that all Content Query Web Parts use the same updated Rss.xsl file to render feeds. For example, do this to use an Rss.xsl file that uses the Atom schema instead of the RSS 2.0 schema, and to use Atom for all Content Query Web Parts in the site collection. Use this approach if you own the site collection but you don't own the server computer where Office SharePoint Server 2007 is installed.

  • Adding a custom Rss.xsl file to the Style Library and registering it in the web.config file. Use this approach to generate a custom RSS feed that applies to a specific Content Query Web Part. Use this option if you need local admininstrator rights on the Office SharePoint Server 2007 server computer to register the .xsl file, if you need to support multiple ways to edit your Web Part, or if you need to edit the web.config file.

To edit the default RSS.xsl file

  1. Navigate to the Style Library.

  2. Edit the Rss.xsl file to emit the RSS feed data you want.

  3. Save changes.

To add a custom RSS .xsl file to the Style Library and modify files for its use

  1. Navigate to the Style Library.

  2. Click Upload, and then upload the custom .xsl file to the Style Library. You can upload the file to the same folder that contains the default Rss.xsl file.

    Note

    If you do not have access to the .xsl file in the Style Library, you can customize the Content Query Web Part by editing the ItemXslLink.xsl file associated with the Web Part Definition (.wpd) file.

  3. Edit the web.config file, add a new <appSettings> entry for the file that you added in Step 2, and then save changes.

    <appSettings>
    ...
       <add key="FeedXsl2" value="/Style Library/Xsl Style Sheets/Rss-custom.xsl" />
    ...
    </appSettings>
    
  4. Modify the .xsl file that emits the RSS feed for the Content Query Web Part by copying the ContentQueryMain.xsl file and uploading the copy to the Style Library.

  5. Edit the copy of the ContentQueryMain.xsl file and change the following code from:

    <xsl:variable name="FeedUrl1" select="concat($SiteUrl,$FeedPageUrl,'xsl=1&amp;web=',$WebUrl,'&amp;page=',$PageId,'&amp;wp=',$WebPartId)" />
    

    to:

    <xsl:variable name="FeedUrl1" select="concat($SiteUrl,$FeedPageUrl,'xsl=2&amp;web=',$WebUrl,'&amp;page=',$PageId,'&amp;wp=',$WebPartId)" />
    
  6. Verify that your Content Query Web Part is using the copy of the ContentQueryMain.xsl file by editing the Content Query Web Part property that determines which Main.xsl file is used.

    1. Find the Content Query Web Part on a page and export it.

    2. Edit the MainXslLink property. Change the following code from:

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

      to:

      <property name="MainXslLink" type="string">/Style Library/XSL Style Sheets/ContentQueryMain-custom.xsl</property>
      
    3. Save changes and import the Content Query Web Part.

Resolving Caching Issues with Content Query Web Part RSS Feeds

When using Content Query Web Part RSS feeds, the RSS feed for the Content Query Web Part that you click first might persist unexpectedly, preventing you from subscribing to and viewing new or updated feeds.

This happens because the Data Form Web Part cache, which the Content Query Web Part inherits, generates the same cache key that is generated for a dynamically created Web Part, even though the xsl property is different. As a result, the Content Query Web Part reuses the cached feed data from the first page load.

To resolve caching issues with the Content Query Web Part RSS feed

  1. Create copies of the Feed.aspx files in the path Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS, and then rename them to Feed1.aspx, Feed2.aspx, and so on.

  2. Edit your Rss.xsl file, and then change the xsl parameter to point to the respective feed number. For example, set xsl=1 for Feed1.aspx, and xsl=2 for Feed2.aspx.

See Also

Tasks

How to: Customize the Content Query Web Part by using Custom Properties
How to: Display Custom Fields in a Content Query Web Part
How to: Customize RSS for the Content Query Web Part