MOSS 2007: Customizing the Search Results Page (XSLT) – Part 2 – Add highlighting
Posted by Tobias Zimmergren
Author: Tobias Zimmergren
In one of my previous blogposts I wrote about how you easily could alter the XSLT of a the Search Core Results Web Part on your Search Results Page in order to achieve a customization to the presentation of the output.
In this article I will scratch on the surface of some more XSLT and show you how you can implement the HitHighligting Template in order to achieve colored/customized display of the search words you entered.
What is the HitHighligting Template?
Well, basically the HitHighligting template offers you the ability to highlight words that are used in your search. It offers you the possibility to highlight words in the following three result sections: Title, Url and Description (And that’s basically all you need, mostly)
Study the following XSLT, as per MSDN:
<c0>SharePoint</c0> <c1>namespace</c1> provides types and members that can be used for working with a <c0>SharePoint</c0> site <ddd /> a top-level <c2>class</c2> that represents a <c0>SharePoint</c0> site and provides access to its collection of subsites <ddd /> <c0>SharePoint</c0> <c1>namespace</c1> and a brief description of each.
You may notice that the sections hithighlightedsummary, HHtitle and HHUrl elements contain childs (<c0>,<c1> etc). This basically means that for each instance of the words entered in your search, you get a set of highlight-tags that encloses that word. This is the default behaviour of the SharePoint Search. First word gets <c0>, second word gets <c1> and so on…
How do I add the Highlighting functionality?
Note: If you do not know how to access the XSLT of the Search Core Results Web Part, view my previous post on the subject.
In order to customize the presentation of the search result and make your words highlighted, you basically only need to add some tags to the XSL-template for each search word you want to highlight as you can see in the screenshot below.
Now locate the following section in your Search Core Results Web Part (It already exist):
And since this template exists from the beginning, all you really have to do is to customize the style attribute and add a color property of the <b> tag (I replaced it with a <strong> tag instead, for sake of standards)
Then you can simply specify the styles for each highlighted word as picted in the following screenshot:
It’s simple as that. I hope this helped some of you to get started on some basic Search Core Results XSLT customizations.