Compartilhar via


How to: Enable HTML Rendering for the Federated Results Web Part

Applies to: SharePoint Server 2010

In this article
Step 1. Ensure That HTML Is Not Removed from the Display
Step 2. Disable Output Escaping
Step 3 (optional). Disable Truncating

By default, the XSLT transformation (XSLT) of the Federated Results Web Part removes HTML from the display for security reasons. However, you might want to display a field that contains HTML in a Federated Results Web Part that displays results from a trusted location source. You can do this by making the following changes to the XSL property of a federated location or the Web Part:

  • Ensure that the HTML is not removed from the display.

  • Disable output caching.

  • Disable truncating (optional).

This topic describes these changes.

Note

If you update the federated location's XSL property, you must ensure that the Web Part is configured to use the location's display information.

To configure the Federated Results Web Part to use the location's display information

  1. In your browser, navigate to the results page URL. For example, http:// ServerName/results.aspx.

  2. Click the Site Actions link, and then click Edit Page.

  3. In the Federated Results Web Part instance you want to modify, click the edit arrow to display the Web Part menu, and then click Edit Web Part.

  4. In the Federated Results Web Part tool pane, expand the Display Properties section.

  5. Select Use Location Visualization.

  6. Click OK to update the Federated Results Web Part instance.

Step 1. Ensure That HTML Is Not Removed from the Display

Before you can enable HTML rendering, you must understand the structure of both the XML that is returned to the Federated Results Web Part and the XSLT that transforms the XML. To learn how to edit the XSL property of a federated location or Web Part, see How to: View and Edit the Search Results XSLT Transformation. To view the search results XML that is returned by a federated location, follow the instructions in How to: View Search Results XML Data.

Verify that the XML node whose data you want to display contains HTML. Next, notice that this HTML is not displayed on the page because the XSLT is removing HTML. For example, the following tag inside the GetPlainTextFromHtml template removes HTML tags from the description field of an RSS feed, as follows.

<xsl:value-of select="srwrt:GetPlainTextFromHtml($Html)"/>

Modify the <xsl:value-of> tag to output the $Html value without calling the GetPlainTextFromHtml template.

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

Note

The default XSLT for an OpenSearch location displays the title, link, and description fields of an OpenSearch RSS feed. Make this change for only the description field of a typical RSS or ATOM feed. For information about customizing the title display, see How to: Customize the Title and Branding Icon for Federated Search Results.

After you save this change to the federated location or Federated Results Web Part, HTML tags are displayed as escaped characters on the page. For example, you will see angle brackets (<>) instead of the rendered HTML. The next step explains how to change this behavior.

Step 2. Disable Output Escaping

Find the <xsl:value-of> tag whose output you want to display. For example, to display HTML from the description field of an RSS or ATOM feed, find the following tag.

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

Add the disable-output-escaping attribute, as follows.

<xsl:value-of select="$DescText" disable-output-escaping="yes"/>

Note

The disable-output-escaping attribute causes the <xsl:value-of> tag to output HTML without any escaping of characters. This could result in HTML output that is not well-formed. Therefore, use this attribute with caution and to display only valid HTML from trusted sources.

Step 3 (optional). Disable Truncating

Because the $DescText value in the tag you edited earlier is a truncated value, the HTML code in the description field might be truncated before the tagging is complete. This would cause the HTML to render incorrectly.

To ensure that the HTML renders correctly, modify the select value for the tag so that it uses the value that is not truncated.

<xsl:value-of select="$DescLongText" disable-output-escaping="yes"/>

See Also

Other Resources

How to: Disable Output Escaping in XML Style Sheet Transformations

<xsl:value-of> Element