Custom styling and transformation for your search results are a great way of fitting the results into the general look & feel of the application and adding relevant metadata in one big swoop. Unfortunately, debugging the XSLT is rather limited. A quick overview:
- if your XSLT contains a syntax error, SharePoint will load the previous version of the XSLT
- in order to get the popup in which you can paste your XSLT, you’ll need a number of page reloads which is a hassle in itself and might be cumbersome depending on your system specs
- XSLT error messages are hidden, only a generic error with the mapped properties might be displayed (related to the columns)
If you need to do a complete rework of the style, there’s a simple trick that I noticed many SharePoint developers don’t know about that will potentially save you a lot of time and effort.
Test your XSLT outside of the CoreResultsWebPart!
By extracting the XML for search results from the CoreResultsWebPart and linking the XSLT stylesheet to it, you have access to error details from the XSLT parser and can avoid many often slow loading SharePoint page reloads. Two simple steps will allow you to do this.
1. Extract the XML from the CoreResultsWebPart
Using the following XSLT snippet (which every other SharePoint blogger has posted at some point; I got from MSDN this time around) to style the search results, the webpart dumps the generated XML on th screen. Simply copy and paste the XML code into a file on your local machine and step 1 is finished.
<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>
The XML results should look similar to this:
<All_Results>
<Result>
<id>1</id>
<workid>5015</workid>
<rank>87098240</rank>
<title>TEST</title>
<author>Frans</author>
<size>0</size>
<url>http://server:2002/default.aspx</url>
<urlEncoded>http%3A%2F%2Fserver%3A2002%2Fdefault%2Easpx</urlEncoded>
<description></description>
<write>29-9-2011</write>
<sitename></sitename>
<collapsingstatus>0</collapsingstatus>
<hithighlightedsummary><ddd /> </hithighlightedsummary>
<contentclass>ContentClass</contentclass>
<isdocument>False</isdocument>
<picturethumbnailurl></picturethumbnailurl>
<serverredirectedurl></serverredirectedurl>
<Result>
<All_Results>
2. Link your XSLT to the XML
Paste your XSLT code into a file and store it in the same folder as the XML file. Now all we need to do is link the stylesheet file to the XML file. The snippet to accomplish this looks like this:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="searchresults_styling.xslt"?>
More info about this on w3schools. And that’s it. Now just open the XML file in a browser and start styling and transforming the search results using real data!
Note: since the XSLT most likely won’t be generating a full HTML document styling you’ll most likely be lacking CSS and such. The structure however will be just fine.
Reageren Lees verder
Frans
Sharepoint Developer


