Wednesday, June 16, 2010

Custom People Results

I did not like the results format of a People search so I decided to create my own. On the results page I edited the page, edited the XSL and made this:


To do this, you need to know the values for each column of data. Here is mine, yours may be different but the formatting would be the same:

 <xsl:stylesheet version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="no"/>
<xsl:decimal-format NaN=""/>
<xsl:param name="FileName" />
<xsl:param name="dvt_apos">'</xsl:param>
<xsl:variable name="dvt_1_automode">0</xsl:variable>
<xsl:template match="/">
<xsl:call-template name="dvt_1"/>
</xsl:template>
<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="/All_Results/Result"/>
<table border="1" width="100%" cellpadding="4" cellspacing="0">
<tr valign="top">
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<th class="ms-vh" width="1%" nowrap="nowrap"></th>
</xsl:if>
<th class="ms-vh" nowrap="nowrap">Name</th>
<th class="ms-vh" nowrap="nowrap">Nickname</th>
<th class="ms-vh" nowrap="nowrap">Title</th>
<th class="ms-vh" nowrap="nowrap">Company</th>
<th class="ms-vh" nowrap="nowrap">Office</th>
<th class="ms-vh" nowrap="nowrap">Phone</th>
<th class="ms-vh" nowrap="nowrap">Extension</th>
<th class="ms-vh" nowrap="nowrap">E-Mail</th>
</tr>
<xsl:call-template name="dvt_1.body">
<xsl:with-param name="Rows" select="$Rows"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:for-each select="$Rows">
<xsl:call-template name="dvt_1.rowview"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="dvt_1.rowview">
<tr>
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">ms-alternating</xsl:attribute>
</xsl:if>
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<td class="ms-vb" width="1%" nowrap="nowrap">
<span ddwrt:amkeyfield="" ddwrt:amkeyvalue="string($XPath)" ddwrt:ammode="view"></span>
</td>
</xsl:if>
<td class="ms-vb">
<a href="https://mysite.yourdomain.com/Person.aspx?guid={userprofile_guid}">
<xsl:value-of select="preferredname"/>
</a>
</td>
<td class="ms-vb">
<xsl:value-of select="nickname"/>
<script type="text/javascript">
document.write("&amp;nbsp;");
</script>
</td>
<td class="ms-vb">
<xsl:value-of select="jobtitle"/>
<script type="text/javascript">
document.write("&amp;nbsp;");
</script>
</td>
<td class="ms-vb">
<xsl:value-of select="company1"/>
<script type="text/javascript">
document.write("&amp;nbsp;");
</script>
</td>
<td class="ms-vb">
<xsl:value-of select="officenumber"/>
<script type="text/javascript">
document.write("&amp;nbsp;");
</script>
</td>
<td class="ms-vb">
<xsl:value-of select="workphone"/>
<script type="text/javascript">
document.write("&amp;nbsp;");
</script>
</td>
<td class="ms-vb">
<xsl:value-of select="extension1"/>
<script type="text/javascript">
document.write("&amp;nbsp;");
</script>
</td>
<td class="ms-vb">
<a href="mailto:{workemail}">
<xsl:value-of select="workemail"/>
<script type="text/javascript">
document.write("&amp;nbsp;");
</script>
</a>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>

Possible Error
I did initially run into the problem whereas I was getting this error when trying to display the results of a people search:

 System.NullReferenceException:   
Object reference not set to an instance of an object. at
System.Xml.XmlNode.RemoveChild(XmlNode oldChild) at
Microsoft.Office.Server.Search.WebControls.PeopleCoreResultsWebPart.DeleteElementAddToMyColleaguesURL(XmlNode result) at
Microsoft.Office.Server.Search.WebControls.PeopleCoreResultsWebPart.CreateXmlDocument() at
Microsoft.Office.Server.Search.WebControls.PeopleCoreResultsWebPart.SortBySocialDistance() at
Microsoft.Office.Server.Search.WebControls.PeopleCoreResultsWebPart.GetXPathNavigator(String viewPath)

Turns out that the results Web Part needed it's "Default Results View" to be set to "Relevance" instead of "Social Distance" as it had been by default. After that change the error went away.

No comments:

Post a Comment