SharePoint Blogs / SharePoint University
SharePoint Blogs and SharePoint University - all in one place!
Need SharePoint Training? Attend a SharePoint Bootcamp!

Please delete cookies related to sharepointblogs.com and sharepointu.com to resolve login issues!

MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007

Author: Tobias Zimmergren
Url:
http://www.sharepointblogs.com/zimmer

After being rather busy the last couple of weeks due to taking the SharePoint Certifications as well as tutoring some MOSS 2007 Development around the country it has finally begun to lighten up again. Being the geeky nerd that I am (Yeah, like you aint?), of course the first thing that comes to my mind is to complete the two articles about customizing the Search Results Page with a third post on the subject which will show you a trick to use SharePoint Designer to generate your custom XSLT. These posts are by no means any in-depth articles on the subject, but rather a pointer to get you started on the journey. If there's interest to create a more in-depth article series about the subject, don't hesitate to contact me using the contactlink from my blog or leave a comment to this post.

Please refer to the previous articles if you have any questions about editing the xslt for your Search Result. They can be found here:
MOSS 2007: Customize the Search Result using XSLT
MOSS 2007: Customizing the Search Results Page (XSLT) - Part 2 - Add highlighting

Step by step

First of all, take a look at this picture to understand how it looks before the changes are done (this picture illustrates a standard-layout of the Search Core Results WebPart that is shown when you perform a search in the Search Center)

Modify the XSLT of the Search Core Results Web Part to get the raw XML

The search results are actually based on plain XML (which is why we can use XSLT to customize the appearance of the results to a high extent) so what we will do here is to basically use standard XSLT to get ALL the XML elements displayed in the search results as raw XML. This is done because we will use this raw XML in SharePoint Designer to generate some good looking XSLT markup for our Search Core Results Web Part.

Replace the existing XSLT markup from the Search Core Results Web Part with the following snippet (which basically just give us the raw XML output when searching):

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
 <xsl:template match="/">
  <xmp><xsl:copy-of select="*"/></xmp>
 </xsl:template>
</xsl:stylesheet>

Now if you publish the page, you will see a result like the result in the following picure, which illustrates how the raw XML could look:

Make use of the raw XML that SharePoint generated for us in the Search Core Results Web Part

Copy all the raw XML data (including the <All_Results> tags and save to a new XML-file (I named mine rawsearchresult.xml)

When you've copied down the raw XML and saved the file, launch SharePoint Designer 2007 - Let the magic begin!

Use SharePoint Designer 2007 to customize the XSLT for your Search Result Page in SharePoint 2007

Launch Microsoft SharePoint Designer 2007 and open up your SharePoint site (by going to "File" - "Open Site.." and enter the url to your SharePoint site (in my case, it's "http://zimmergren" and hit open)

Next, choose File - New - "ASPX" to create a new ASP.NET page. Note that you do not need to save this page because we will only use the page as a base when we customize our XSLT using SharePoint Designer. Later, when we are satisfied with the presentation of our search results, we will simply copy the generated XSLT and close the new .aspx page and ignore the changes.

Now from the File-meny choose "Data View" - "Insert Data View" to insert a standard DataFormWebPart.

Note, when inserting the aforementioned Data View, the Data Source Library is opened/displayed in the top right pane (if you havn't customized the appearance of SPD) as seen here:

In this newly opened Data Source Library we will expand the node that says "XML Files" and choose "Add an XML file...". Browse to your XML file that contains the raw XML and hit okay.

You will be confronted with a question asking you to import the file into SharePoint, press Ok. When you've hit OK until you're back on the aspx-page, you will see your newly added XML file under the "XML Files" node in the tree in the Data Source Library and in my case it's called "rawsearchresults.xml".

Click the dropdown of your file, and choose "Show Data". Next, choose the tags/entities that you want to include in the presentation of your Search Result by holding down Ctrl + clicking the ones you'd like to insert.

Simply drag and drop those items onto the DataFormWebPart on your ASPX-page and it will automatically render the XSLT for you, like so:

Now, either manually edit the presentation of your search results - or choose the quick edit for your DataFormWebPart and click "Change layout...".

On dialog, choose your desired layout to base the presentation of your search results on.

When we've done this, SharePoint Designer automatically renders the XSLT for us (based on the XML File we chose, that contains our raw XML for the Search Results (which is also why we get the nice preview in SharePoint Designer))

Now, that might not be the best layout to use for displaying the search results on a page.. So we will have to do some manual tweaking in order to get the presentation of this XSLT to fully fit our needs and demands.

Something that is important to note is how we can e.g. change the title to become a hyperlink that links to the acutal object by choosing the title-element and using the Quick Edit to change some properties. Note that I changed the title to a Hyperlink, which links to {url} that is part of the Search Result and also setting the title to {title} which also is an element in the Search Result.

Do all your manual tweaking (either by customizing the XSLT from the source view, or as the previous picture illustrated) and continue to the next step.

Tip: You can of course add Sorting, Filtering and Grouping aswell by simply choosing it in the same dialog that we chose to change the layout..

Use the XSLT that was rendered by SharePoint Designer 2007 in the Search Core Results Web Part

Switch to Split View or Source View, and copy the entire <xsl:stylesheet> tag and all content.

Now simply paste the generated XSLT into your Search Core Results WebPart's XML-section.

NOTE: If you can't see the entire Web Part and thereby not being able to access the edit-button, you can simply enter the querystring: ?contents=1 which will take you to the Web Part Maintenence Page for your site, where you can delete the webpart, and then add a new one as usual, and edit the XSLT of the new Search Core Results Web Part instead.

Publish the page, and behold your new presentation of the Search Results. Please note that I didn't make any heavy customizations to my XSLT and therefore it's rather steril, but you can make some major changes in the XSLT and in SharePoint Designer if you really want to customize the display of your Search Results.

This is how my presentation of the Search Results look like:

I love feedback and comments :)

If you liked this article please leave a comment with feedback so I know that people read it, otherwise it's boring to write these step by step illustrated articles.

Cheers, and good weekend.


Posted 10-28-2007 7:10 PM by Tobias Zimmergren

Comments

MOSS Jr. wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 10-29-2007 2:13 AM

hey zimmer. love the blogpost. never thought you could do this with spd.. then again i never used it very much. been playing around with it all night long and got a very cool searchresult displayed now hehe. you can also implement images/icons of the searchresults so you know what type it is. just as simple as you changed to hyperlink. peace

Satheesh wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 10-29-2007 7:00 AM

Nice article, i know we can edit the XSLT to alter the display, but this article showed me, how to use sharepoint designer for that

Satheesh Palaniswamy

Tobias Zimmergren wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 10-29-2007 8:09 AM

Hi Sateesh,

Thanks for the feedback. Yes, SPD is rather nifty at generating XSLT. Foremost I like it because it generates the XSLT and then shows a preview of how it will look when applied, which means that we don't have to apply, test, change, apply, test, change and so on :)

SharePoint, SharePoint and stuff wrote SharePoint Kaffeetasse 27
on 10-29-2007 11:22 AM

The latest news and gossip from SharePoint-Land :-) OT aber eigentlich doch nicht Microsoft kauft sich

Merill wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 10-29-2007 9:05 PM

I'm just getting started off on SP and this blog post just introduced me to 10 different things I didn't know about SP and SPD.

layout » MOSS 2007: Customize the Search Result (using XSLT) - Part 3 … wrote layout &raquo; MOSS 2007: Customize the Search Result (using XSLT) - Part 3 &#8230;
on 10-30-2007 7:30 AM

Pingback from  layout &raquo; MOSS 2007: Customize the Search Result (using XSLT) - Part 3 &#8230;

ca domain name » MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007 wrote ca domain name &raquo; MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 10-30-2007 11:52 AM

Pingback from  ca domain name &raquo; MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007

SharePoint, SharePoint and stuff wrote SPPD079 SharePointPodcast
on 11-01-2007 8:38 AM

Direkter Download: SPPD-079-2007-11-01 Aktuell Linkssammlung Zielgruppen SharePoint Backup und Restore

SharePointPodcast.de wrote SPPD079 SharePointPodcast
on 11-01-2007 8:39 AM

Direkter Download: SPPD-079-2007-11-01 Aktuell Linkssammlung Zielgruppen SharePoint Backup und Restore

Amber wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 11-05-2007 9:40 AM

Ok, so I have a question.  I am extremely new to this software.  I am new to web design in general.  I was making a mock web page and could not figure out for the life of me how to view the page in a browser.  Also, I could not figure out how to link two or more pages together.  Do you happen to know what I am doing wrong?

The Mit's Blog wrote MSS(X) 2008 : Microsoft Search Server
on 11-13-2007 9:13 AM

Ca y est c'est officiel, voici enfin le dernier produit MS (à base de SharePoint soit dit en passant)

Andrej wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 11-16-2007 3:08 AM

Thank you for this extremely useful article. It saved us a lot of time!

Fred wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 11-18-2007 4:30 AM

awesome blogpost.

keep up the good work zimmergren.

Gabriel wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 11-28-2007 1:03 PM

Thanks fro the blog , i lost two days fighting agains the xslt that comes with the webpart , very good tutorial.

Thanks

Daniel Berg wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 11-30-2007 6:35 AM

Es muy bueno! Gracias!

Angel wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 11-30-2007 9:12 AM

Hi Tobias,

Thank you very much. I've learned a lot so far. And I think I'll visit your site a lot when I needto figure something out :)

I'm looking for a way to present my search results as thumbnails. I know this is the way to do it, but I still get an error when I place the code back in de xsl editor. Something about it already exits or something.

Any ideas somebody ?

ramyasharepoint wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 12-20-2007 12:04 AM

Thanx For giving me an opportunity to join his blog!!!

Hope all are Fine.

i face problems while converting to XSLT..Can you please tell me the method how to perform in share point designer.

I want to implement search in our intranet portral,Can you please suggest some methods for it.

Mirrored Blogs wrote SPPD079 SharePointPodcast
on 01-09-2008 6:59 PM

Direkter Download: SPPD-079-2007-11-01 Aktuell Linkssammlung Zielgruppen SharePoint Backup und Restore

Toby wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 01-14-2008 9:59 PM

Nice post, thank you. Can see that it will save me a fair bit of effort manually writing XSL-Ts for my MOSS Search Results.

Petu wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 01-15-2008 11:06 AM

If (and when) you want to add your own site columns into the search, you have to make your columns so called "Managed Properties".

First create your columns normally, then add them as Managed Properties. You can do this from the site administration site -> Shared Services1 -> Search Settings -> Metadata Property Mappings. Lastly add your newly added managed properties to Results Query Options -> Selected Columns.

After this just follow mr. Zimmergren's brilliant instructions on this blog post.

Petu wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 01-15-2008 11:08 AM

..and to correct myself..

The Results Query Options -> Selected Columns can be found in the search results web part.

Tobias Zimmergren wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 01-15-2008 11:56 AM

Cheers for the input Petu. Good tip!

Gilda wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 01-23-2008 4:47 AM

Hi, Tobias! Thank's for this article. I could customize my search results in a record time!

Fred wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 01-31-2008 2:17 PM

How can I save the XSLT to a file and add it so that the XSLT is available across my site and sub sites?

Chander wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 02-05-2008 7:25 PM

Folks,

I followed the steps mentioned in this article carefully and the search core results works like charm.

Just wondering,Is it possible to make the Hyperlinked field open in a new window instead of opening it in the same window?

Is it by editing the hyperlink properties and setting the Target to a new window?I did this though,still doesn't work for some reason.

Any ideas?

Thanks

Chander

Chander wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 02-05-2008 9:27 PM

Sorted out!

No Worries

target="_blank"

Thanks

Chander wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 02-06-2008 11:29 PM

Folks,

Is it possible to display a field such as a "Body" in the search core results.

Any Ideas

Thanks

Chander

kohwee wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 03-19-2008 9:03 AM

Hi,

Is there a way to change the width of people picker and multiple-line text box? I tried to stretch them like I did for single text box, but these boxes remained unchanged. I tried applying a custom style to them but it did not work also.

Vinny wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 03-26-2008 3:27 PM

Is it possible to have two Search Core Results connect to each other?

The first one will display the unique list of authors from search results, when clicked, the second search results will filter by selected author.  

Thanks, this is a big help....

Tobias Zimmergren wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 03-27-2008 4:57 PM

Hi, my blog has moved to http://www.zimmergren.net - please locate the post there and post your comments instead!

Thanks a bunch!

John Ross wrote Creating a custom advanced search by building strings with JavaScript
on 04-02-2008 10:44 AM

A little more than a month ago a client called and wanted to customize the MOSS search to allow users

Balaji wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 04-24-2008 10:09 AM

Wonderful ....... there's no other word to congragulate you  zimmig....I have been struggling for more than 1 month for customizing my search results..... you .... you have really pulled off the knife from my head... Thanks a Lot....  

My search regarding sharepoint will definitely start from your blog.... from now onwards....

Keep going and rocking.....

Thanks...... U have really made the presence of Sharepoint Designer and its power to the world..... Still lot people dont know abt the features of SD.... If possible try to maintain a series of posts regarding the powerful usage of SD which could save a lot of valuable time.....

Tobias Zimmergren wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 04-24-2008 10:33 AM

Thanks for the kind words!

You can follow the progess of my blog on http://www.zimmergren.net from now on. it's not getting updated here anymore.

Thanks,

Tobias.

sharepoint 2007 import xml wrote sharepoint 2007 import xml
on 05-09-2008 3:02 AM

Pingback from  sharepoint 2007 import xml

Dhanyatha wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 05-30-2008 7:23 AM

Hi,

I have customised my People search result  in just the way you have mentioned! but now i want to display error messages through the XSLT (just like the default results page) when a query returns no result...

can any one please suggest a way for doing so?

Thanks in advance....

Marc P wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 06-13-2008 9:39 AM

Tobias you truly are the man.

Thanks so much for this post. All is now clear.

Rahul wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 07-16-2008 6:48 AM

Hi Zimmer,

I followed all the steps those are described above. However I am getting error as

"Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator"

Can you guide me what I am missing ??

Rahul wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 07-17-2008 12:11 AM

Hey,

It's resovled. Instead of copying only the XSL tags, I copied the whole code.

Thanks Zimmer, it's really a very very nice article.

Really helped me in gaining the complete knowledge of the topic.

decatec wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 09-14-2008 6:52 AM

Excellent post, very useful for customizing a search page

MOSS2007: Everything Search… « rinonu writes… wrote MOSS2007: Everything Search&#8230; &laquo; rinonu writes&#8230;
on 09-22-2008 9:26 PM

Pingback from  MOSS2007: Everything Search&#8230; &laquo; rinonu writes&#8230;

Adeel wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 10-20-2008 5:20 PM

Hi and thanks alot for the post. Saved me alot of time. I have one question. How can I remove the site name. In example, I always get hit on the titles I have on the left nav of a site, and thus the site is given in the search result. Is there a way to exlude site name in the search results?

on 02-21-2009 8:33 AM

Nice site.

Look here:

<a href= orvandils-ta.com/.../index.html >business</a>   [url=orvandils-ta.com/.../index.html]business[/url]   <a href= orvandils-ta.com/.../domain-name-registration.html >domain name registration</a>   [url=orvandils-ta.com/.../domain-name-registration.html]domain name registration[/url]   <a href= orvandils-ta.com/.../buying-a-franchise.html >buying a franchise</a>   [url=orvandils-ta.com/.../buying-a-franchise.html]buying a franchise[/url]   <a href= orvandils-ta.com/.../homeowners-insurance.html >homeowners insurance</a>   [url=orvandils-ta.com/.../homeowners-insurance.html]homeowners insurance[/url]   <a href= orvandils-ta.com/.../apply-for-a-credit-card.html >apply for a credit card</a>   [url=orvandils-ta.com/.../apply-for-a-credit-card.html]apply for a credit card[/url]   <a href= orvandils-ta.com/.../fast-food-franchise.html >fast food franchise</a>   [url=orvandils-ta.com/.../fast-food-franchise.html]fast food franchise[/url]   <a href= orvandils-ta.com/.../management.html >management</a>   [url=orvandils-ta.com/.../management.html]management[/url]  

... wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 03-03-2009 10:55 AM

Interessante Informationen.

... wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 03-03-2009 2:04 PM

Gute Arbeit hier! Gute Inhalte.

chinni wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 05-13-2009 9:40 AM

Hi Zimmer,

"Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator"

Can you guide me what I am missing ??

James wrote re: MOSS 2007: Customize the Search Result (using XSLT) - Part 3 - Customize using SharePoint Designer 2007
on 06-08-2009 2:10 PM

Okay I have completed this a couple times and have this down.  I want to take it a step further.  I want to return the String the user searched for at the top of the page either in the same web part for Search core results or a different web part that displays the search text.  

Example:  user Searches one column called Product Type

and picks Product Document.  I want the search results page to say Text Searched: Product Document.  I have multiple columns and I am wondering how I get this into my code?

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Need SharePoint Training? Attend a SharePoint Bootcamp!
Posts (c) their respective authors. Everything else (c) 2009 SharePoint Experts, Inc.