SharePoint 2010 Search show default DispForm.aspx instead of custom display form

I had a problem where SharePoint Foundation 2010 Search was returning the DispForm.aspx in the search results instead of the CustomForm.aspx that was configured as the default display form.

Solution:

  1. Follow article http://blog.larslynch.com/2013/12/sharepoint-2010-search-show-default.html

Use the following JavaScript redirect in a content editor webpart in the DispForm.aspx:

<script type="text/javascript">
function redirectForm() {
var pagemode = GetUrlKeyValue('DisplayMode', false);
if(pagemode == null || pagemode == "")
{
var hrefCurrent = window.location.href;
var hrefNew = hrefCurrent.replace("DispForm.aspx","CustomForm.aspx");
window.location.href = hrefNew;
}
}
ExecuteOrDelayUntilScriptLoaded(redirectForm, "sp.js");
</script>

2. Custom xsl Search Core Result

At the page using webpart Search core results edit this webpart by IE browser (it need installed Silverlight)

in Webpart edit box, select Display Properties click XSL Editor… (the popup xsl content required IE & SilverLight)

You will see in

<xsl:template match=”Result”>

<xsl:variable name=”url” select=”url”/>

<xsl:template/>

Some postion inside <xsl:template match=”Result”><xsl:template/> using url or $url to bind Link with DispForm.aspx

We need replace DispForm.aspx to custom form

Because xsl 1.0 does not support replace method, so we have to add function replace in this xsl.

<xsl:template name=”string-replace-all”>
 <xsl:param name=”text” />
 <xsl:param name=”replace” />
 <xsl:param name=”by” />
 <xsl:choose>
 <xsl:when test=”$text = ‘’ or $replace = ‘’or not($replace)” >
 <! — Prevent this routine from hanging →
 <xsl:value-of select=”$text” />
 </xsl:when>
 <xsl:when test=”contains($text, $replace)”>
 <xsl:value-of select=”substring-before($text,$replace)” />
 <xsl:value-of select=”$by” />
 <xsl:call-template name=”string-replace-all”>
 <xsl:with-param name=”text” select=”substring-after($text,$replace)” />
 <xsl:with-param name=”replace” select=”$replace” />
 <xsl:with-param name=”by” select=”$by” />
 </xsl:call-template>
 </xsl:when>
 <xsl:otherwise>
 <xsl:value-of select=”$text” />
 </xsl:otherwise>
 </xsl:choose>
</xsl:template>

Add this above

</xsl:stylesheet>

Now, we add new variable with value is called by method replace and input is $url

<xsl:variable name=”newUrl”>
 <xsl:call-template name=”string-replace-all”>
 <xsl:with-param name=”text” select=”$url” />
 <xsl:with-param name=”replace” select=” ’DispForm.aspx’ ” />
 <xsl:with-param name=”by” select=” ’CustomForm.aspx’” />
 </xsl:call-template>
</xsl:variable>

Add it bellow <xsl:variable name=”url” select=”url”/>

Now, we just replace url or $url by newUrl in

<xsl:template match=”Result”>

<xsl:variable name=”url” select=”url”/>

<xsl:variable name=”newUrl”>
 <xsl:call-template name=”string-replace-all”>
 <xsl:with-param name=”text” select=”$url” />
 <xsl:with-param name=”replace” select=” ’DispForm.aspx’ ” />
 <xsl:with-param name=”by” select=” ’CustomForm.aspx’” />
 </xsl:call-template>
</xsl:variable>

replace url by newUrl

<xsl:template/>

Enjoy it :)