rss

Sharepointology

Sharepointology is the study and handling of Microsoft Office SharePoint Server

Customize the People Search Results – Part 1

Posted 30Aug08 by Erwin in Development

Out of the box:

First of all let’s start off with showing how the default People Search Results look like:

People Search Default Results

In my opinion not really something you can give to your users to work with. No labels, no design, no clear layout.

This article will try to show you how you can beautify these results a bit.

Preparation:

Let’s try and get ourselfs something to work with for starters. The list of results returned by the search service is in XML format and get’s transformed by using an XSLT. If we can get the XML before it gets translated by the XSLT we can use that XML as input for our custom XSLT.

How do we do this?

  • First you go to your People Search Page and execute a search on a certain name for wich you know you will find results.
  • On the results page you click on Site Actions / Edit page.
  • For the People Search Core Results web part you choose Modify Shared Web Part.

People Search Core Results Edit Web Part

  • Edit the XSL by pressing the XSL Editor button.
  • Save the existing source into a backup XSL file, you can use it later on.
  • Replace the existing XSL by the folowing code:
<?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>
  • Save, press OK button on Properties of web part, choose Save and stop editing from the menu.
  • Retry your search and the results will look something like this:
<All_Results>
    <DummyResult>
      <Everyone />
    </DummyResult>
    <Result>
      <id>1</id>
      <accountname>MOSS\Sharepoint-Test</accountname>
      <userprofile_guid>07BEF018-AE22-495E-B8B5-0EF167B46C90</userprofile_guid>
      <preferredname>Sharepoint Test</preferredname>
      <jobtitle>Sharepoint Tester</jobtitle>
      <department>ICT</department>
      <workphone>+32 14 76 78 90</workphone>
      <officenumber>+32 14 76 45 67</officenumber>
      <aboutme></aboutme>
      <pictureurl></pictureurl>
      <workemail>Sharepoint-Test@moss.com</workemail>
      <website></website>
      <url>http://moss2007:17212/Person.aspx?guid=07BEF018-AE22-495E-B8B5-0EF167B46C90</url>
      <urlEncoded>http%3A%2F%2Fmoss2007%3A17212%2FPerson%2Easpx%3Fguid%3D07BEF018%2DAE22%2D495E%2DB8B5%2D0EF167B46C90</urlEncoded>
      <hithighlightedsummary>moss\<c0>Sharepoint</c0>-<c1>Test</c1>  <ddd /> <c0>Sharepoint</c0> <c1>Test</c1>  <ddd /> <c0>Sharepoint</c0>-<c1>Test</c1> </hithighlightedsummary>
      <hithighlightedproperties>
        <HHTitle />
        <HHUrl>http://moss2007:17212/Person.aspx?guid=07BEF018-AE22-495E-B8B5-0EF167B46C90</HHUrl>
      </hithighlightedproperties>
      <responsibility>Testing Sharepoint</responsibility>

      <skills>sharepoint;C#</skills>
      <sipaddress></sipaddress>
      <imageurl imageurldescription="File with extension: aspx">/_layouts/images/html16.gif</imageurl>
      <addtomycolleaguesurl>javascript:AddToColleagues('moss\\sharepoint-test')</addtomycolleaguesurl>
      <EveryOne />
    </Result>
  </All_Results>
  • Copy the XML and save it in a file.

Create the XSL:

Now that we have the XML, we can this data as input for our XSL. I will explain how to create a simple XSL with Sharepoint Designer 2007. If you have experience with making XSL using another tool, be my guest.

  • Open up your Sharepoint Designer 2007 and open the site (File, Open Site) you are working with.
  • Make a new ASPX page (File, New, ASPX).
  • Insert a Data View on the page (Data View, Insert Data View).
  • After you add the Data View, the Data Source Library window opens.

Data Source Library

  • Expand the node that says XML Files, as seen above, and choose Add an XML file. Browse to your XML file that contains the XML data we saved before and hit ok. Hit Yes on the question about importing the XML.
  • Click the dropdown of your file, and choose Show Data.
  • A nice way to get you started is by using the default XSL that Sharepoint uses to display the People Search Results. We saved it earlier on in this article into a backup XSL file. Open this backup file in Notepad or some other text editor, copy the XSL source code, go to your ASPX file in Sharepoint Designer and copy the XSL source code between the <XSL> and </XSL> tags.
  • Go to the Split view in Sharepoint Designer, this will show you the code and the resulting page.
  • Now you can edit the result, you can add labels to your data. Make stuff bold, italic, use tables to design the results.

Testing the new XSL:

  • When you are satisfied with the result copy everything between the <XSL> and </XSL> tags and paste it into your Sharepoint site. Where exactly? Look at the “Preparation” part of this article and search for “pressing the XSL Editor button” that will explain where to paste the XSL source.
  • Save, press OK button on Properties of web part, choose Save and stop editing from the menu.
  • Retry your search and the results will look something like this:

People Search New Results

It’s not much, but it’s a start. I’ll show you what i changed to the Default XSL source, search for DisplayOfficeProfile and compare it with the next source, the differences are the things I changed.

<xsl:template name="DisplayOfficeProfile">
  <xsl:param name="title" />
  <xsl:param name="dep" />
  <xsl:param name="phone" />
  <xsl:param name="skills" />
  <xsl:param name="responsibility" />

  <table>
  <span class="psrch-Metadata">
  <xsl:if test='string-length($title) > 0'>
  <tr>
   <td><b>Functie: </b></td>
   <td><xsl:value-of select="$title" /></td>
  </tr>
  </xsl:if>
  <xsl:if test='string-length($dep) > 0'>
  <tr>
   <td><b>Afdeling: </b></td>
   <td><xsl:value-of select="$dep" />  </td>
  </tr>
  </xsl:if>
  <xsl:if test='string-length($phone) > 0'>
  <tr>
   <td><b>Telefoon nr: </b></td>
   <td><xsl:value-of select="$phone" />  </td>
  </tr>
  </xsl:if>
   <xsl:if test='string-length($skills) > 0'>
  <tr>
   <td><b>Skills: </b></td>
   <td><xsl:value-of select="$skills" />  </td>
  </tr>
  </xsl:if>
  <xsl:if test='string-length($responsibility) > 0'>
  <tr>
   <td><b>Responsibility: </b></td>
   <td><xsl:value-of select="$responsibility" />  </td>
  </tr>
  </xsl:if>
  </span>
  </table>
  <br/>
</xsl:template>

I also removed the following part of the XSL:

<div class="psrch-Description">
          <xsl:choose>
            <xsl:when test="hithighlightedsummary[. != '']">
              <xsl:apply-templates select="hithighlightedsummary" />
              <br/>
            </xsl:when>
            <xsl:when test="aboutme[. != '']">
              <xsl:value-of disable-output-escaping="yes" select="aboutme"/>
              <br/>
            </xsl:when>
          </xsl:choose>
           <xsl:choose>
            <xsl:when test="responsibility[. != ''] or skills[. != '']">
              <xsl:choose>
                <xsl:when test="responsibility[. != '']">
                  <span class="psrch-PropLabel">
                    <xsl:text>Responsibilities: </xsl:text>
                  </span>
                  <span class="psrch-PropValue">
                    <xsl:value-of select="translate(responsibility,';',',')"/>
                    <xsl:text> </xsl:text>
                  </span>
                </xsl:when>
              </xsl:choose>
              <xsl:choose>
                <xsl:when test="skills[. != '']">
                  <xsl:if test="responsibility[. != ''] and skills[. != '']">
                    <br/>
                  </xsl:if>
                  <span class="psrch-PropLabel">
                    <xsl:text>Skills: </xsl:text>
                  </span>
                  <span class="psrch-PropValue">
                    <xsl:value-of select="translate(skills,';',',')"/>
                  </span>
                </xsl:when>
              </xsl:choose>
              <br/>
            </xsl:when>
            <xsl:otherwise><span /></xsl:otherwise>
          </xsl:choose>
        </div>

RSSIf you like this post then please consider subscribing to my full feed RSS. You can also subscribe by Email and have new posts sent directly to your inbox.

11 Responses

  1. Adrian

    I made the same thing a few months ago:look here

    Because I already made a few experiences with XSLT as Microsoft BizTalk Developer I wrote/modified the XSLT directly in a Text-Editor.

    …and now: until now I havn’t wrote about this (or similar things). My blog contains till now just private things. But I think about to add content about SharePoint, BizTalk and generic C# experiences ;-)

  2. Links (9/1/2008) « Steve Pietrek - Everything SharePoint

    [...] Customize the People Search Results – Part 1 [...]

  3. Customize the People Search Results - Part 2 | Sharepointology

    [...] Customize the People Search Results – Part 1 we learned how to pimp the search results from looking something like [...]

  4. Anthony

    Nice post. You really helped me out here.

  5. Tom

    Great information! Very timely information for me.

  6. Sharepoint tips and tricks « Kevin's Blog

    [...] http://www.sharepointology.com/development/customize-the-people-search-results-part-1/ [...]

  7. Customizing People Search « Michaels Technology Soapbox

    [...] http://www.sharepointology.com/development/customize-the-people-search-results-part-1 [...]

  8. Kişi Arama (People Search) Sonuç Özelleştirmesi | Evren Ayan - Blog

    [...] http://www.sharepointology.com/development/customize-the-people-search-results-part-1/ [...]

  9. James

    The preperation part does not explain to me clearly where I should be adding my end result so I can test it?

  10. Khushi

    Hi there, I tried to do this in SharePoint 2010. I couldn’t do it. I did able to add New ASPX page but was not able to bind DataView with XML file.
    Is there any other way to do it in SP2010
    Thanks
    Khushi

  11. Lerma

    Great article, easy to follow and worked great. Thanks!

Leave a Comment

About

My name is Erwin Bastiaensen and I am a Software Architect from Belgium, with a huge interest in technology. Lately I have been involved in some Java projects and implementing, interfacing and extending a Sharepoint portal.

You can contact me at sharepointology[@]gmail.com.

View Erwin Bastiaensen's profile on LinkedIn