다음을 통해 공유


How to: Customize RSS for the SharePoint Content By Query Web Part (ECM)

Applies to: SharePoint Server 2010

After you customize the Content By 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 By Query Web Part content:

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

  • How an RSS feed URL works

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

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

Enabling an RSS Feed for Content Query Web Part Content

To enable an RSS feed that emits Content By 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.

Understanding How an RSS Feed URL Works

One key to understanding how to customize RSS for the Content By Query Web Part is understanding the parts of an RSS feed URL and how they interact. Following is the format of an RSS feed URL: **http://servername/_layouts/feed.aspx?xsl=registeredXSL 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 the server running Microsoft SharePoint Server 2010. 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 SharePoint Server 2010 requires to emit an RSS feed.

Parameter

Description

Valid Values

xsl

Pointer to the key used to identify the Rss.xsl file that the 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 By Query Web Part that is emitting the RSS feed.

Server-relative URL

Page

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

GUID

Wp

Content By Query Web Part ID.

GUID

Additional XSL Parameter Information

The design of the Content By Query Web Part makes RSS feeds easy to administer; SharePoint Server 2010 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 that is found at the following 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 SharePoint Server 2010 includes by default.

To enable an RSS feed for a Content Query Web Part

  1. Edit the Content By 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 By Query Web Part RSS Feeds

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

  • Editing the default Rss.xsl file that is included with SharePoint Server 2010; this ensures that all Content By 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 By Query Web Parts in the site collection. Use this approach if you own the site collection but you do not own the server running SharePoint Server 2010.

  • 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 By Query Web Part. Use this option if you need local admininstrator rights on the server running SharePoint Server 2010 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 that 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 By Query Web Part by editing the ItemXslLink.xsl file that is 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 By 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. Delete this code:

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

    And replace it with this code:

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

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

    2. Edit the MainXslLink property. Delete this code:

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

      And replace it with this code:

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

Resolving Caching Issues with Content By Query Web Part RSS Feeds

When using Content By Query Web Part RSS feeds, the RSS feed for the Content By 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 By 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 By Query Web Part reuses the cached feed data from the first page load.

To resolve caching issues with the Content By 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\14\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 SharePoint Content By Query Web Part by Using Custom Properties (ECM)

How to: Display Custom Fields in a SharePoint Content By Query Web Part (ECM)

How to: Customize RSS for the SharePoint Content By Query Web Part (ECM)