Archive for April, 2013

April 3, 2013

SharePoint 2010 – Search Core Results XSLT Transformation

Suddenly your manger says to you, man, we just wanted to modify the core search results of the SharePoint 2010. So the first step is to add a Search core results web part to your search results page and open the same page in a browser. After that put the page in edit mode and choose edit web part from the Search Core Results Web Part menu.

In the Search Core Results Tool Pane open the Display Properties section and then uncheck “Use Location Visualization” and you can notice that the XSL Editor… button should become active.

image001

Click the “XSL Editor…” button to open the Text Editor dialog.

image002

Replace all the above XSL with the below (or just copy to the clipboard hence you will need the data in future):

<?xml version="1.0" encoding="UTF-8"?>
<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 reason why I did substituted the existing XSLT is to know how the SharePoint renders the output of the search results.

So the core results search of the SharePoint will give you the results in a format as below:

<All_Results>
    <Result>
      <id>1</id>
      <workid></workid>
      <rank>1006</rank>
      <title>Your document title</title>
      <author>Mikael Svenson</author>
      <size>79872</size>
      <path>http://server/path/test.html</path>
      <description></description>
      <write>11/1/2010</write>
      <sitename>Procedures</sitename>
      <collapsingstatus></collapsingstatus>
      <hithighlightedsummary>This is a summary.</hithighlightedsummary>
      <hithighlightedproperties>
        <HHTitle>Your document title</HHTitle>
        <HHUrl>http://server/path/test.html</HHUrl>
      </hithighlightedproperties>
      <imageurl imageurldescription="Web Page">/_layouts/images/html16.png</imageurl>
      <contentclass></contentclass>
      <isdocument>True</isdocument>
      <picturethumbnailurl></picturethumbnailurl>
      <url>http://server/path/test.html</url>
      <serverredirectedurl></serverredirectedurl>
      <fileextension>ASPX</fileextension>
      <spsiteurl></spsiteurl>
      <docvector>[procedure overview, 1][links, 0.707107]</docvector>
      <fcocount>1</fcocount>
      <fcoid>336059505871761914</fcoid>
      <pictureheight></pictureheight>
      <picturewidth></picturewidth>
      <escbaseextension>xls</escbaseextension>
      <escprojname>00 - UNDEFINED</escprojname>
      <escdeptname>0000 - UNDEFINED</escdeptname>
      <escprocnumber></escprocnumber>
      <esccategoryname>COMPANY MANAGEMENT SYSTEM</esccategoryname>
      <escsubcategoryname>GOVERNING DOCUMENTS</escsubcategoryname>
      <eschistdocnum></eschistdocnum>
    </Result>
</All_Results>

When you wanted to modify the search results, then what you have to do is to modify the XSLT part that we copied in one of the steps above. I usually used to do is to copy all those XSLT in to Visual Studio and then modifying the same as needed.

image004

By default the search results would be as below with icons, etc.

image006

After modifying the XSLT the search results would like below:

image008

I was using the OOB search paging web part to get the paging for the search results.

image010

please refer the following links for more detail:

Enterprise Search Core Results XSLT Transformation
http://msdn.microsoft.com/en-us/library/ms584121%28v=office.12%29.aspx

How to: View Search Results XML Data
http://msdn.microsoft.com/en-us/library/ms546985.aspx

Take Control of Search XSL
http://www.ableblue.com/blog/archive/2011/09/30/take-control-of-search-xsl/

Advertisements