Partilhar via


Enabling HTML Rendering for the Federated Results Web Part

By default, the XSLT of a Federated Results Web Part strips HTML from the display for security reasons. However, you might want to display a field that contains HTML in a Federated Results Web Part from a trusted location source. You can do this by making the following changes to the XSL property of either a federated location or the Federated Results 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 Federated Results 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 Modify Shared Web Part.

  4. In the Federated Results Web Part tool pane, click the Display Properties arrow.

  5. Select Use Location Visualization.

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

Note

The federated search Web Parts on the default results page are configured to use the Internet Search Results and the Internet Search Suggestions locations. The following XSLT code does not work as expected for the default configuration for these locations.

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 view the XML that is returned by a federated location, and to learn how to edit the XSL property of a federated location or Web Part, follow the instructions in How to: View the XML Data Returned by Your Federated Location [Search Server 2008]. For a review of XSLT in Federated Results Web Parts, see Federated Results Web Parts XSLT [Search Server 2008].

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:

<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 only for the description field of a typical RSS or ATOM feed. For information about displaying other metadata, see Displaying Additional MetaData in Federated Results. For information about customizing the title display, see How to: Customize the Title and Branding Icon for Federated Search Results [Search Server 2008].

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 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.

<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 avoid that possibility, 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

Tasks

How to: View the XML Data Returned by Your Federated Location [Search Server 2008]
How to: Customize the Title and Branding Icon for Federated Search Results [Search Server 2008]

Other Resources

<xsl:value-of> Element
How to: Disable Output Escaping in XML Style Sheet Transformations