Skip to main content

Patrick Tisseghem's Blog [MVP SharePoint]

Go Search
U2U Blog Center
U2U website
  

The Happy SharePoint Traveller

U2U Blog Center > Patrick Tisseghem's Blog [MVP SharePoint] > Posts > Custom XSLT for the Search Core Results Web Part
Custom XSLT for the Search Core Results Web Part

Yesterday, I described the steps to drop the Search Core Results Web Part on a page of a WSS 3.0 team site and have it configured with a fixed query. Let me continue with that example but go a step further and customize the way the results are displayed to the user.

The list of results returned by the search service is in XML format. This XML output can be reviewed in the Search Core Results Web Part itself by replacing the default XSLT (using the toolpane with the properties exposed by the Web Part) with the following:

<?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>

If you run the query now, the output will look like this:

Creating a custom XSLT for this XML can be done in a number of ways. If you are an XSLT geek, open NotePad and start writing your pattern-matching rules. There are however plenty of XSLT editors available that can help you in this and possibly even come up with a nice transformation without writing any line of XSLT.

What I will demonstrate here is how you can make use of the SharePoint Designer 2007 to come up with an XSLT for this XML.

First of all, just copy the XML in a local file since you'll need it in a minute.

Next open the SharePoint Designer 2007 and the site containing the page you are working with. The Search Core Web Part is like many other MOSS 2007 Web Parts (for example the Business Data Web Parts) based on the Data View Web Part. This is a Web Part you can only create in the SharePoint Designer. Before doing this however, you have to create a data source. The data source to create is one that connects to the file containing the raw XML outputted by the search Web Part. There is a menu called Data View in the SharePoint Designer. Use it to open the Data Sources panel. In that panel, you'll see a link to create a new XML data source. Just point to the XML file and import it in the site. You'll not need it anymore later - it is just needed as the sample XML for the generation of the XSLT.

In the Data Sources panel, select to option in the context menu of the XML data source, to show the data. A new panel is activated showing all of the XML nodes available in the XML file. Use all of that information now to insert a Data View Web Part on one of your pages. Again, you do not need that Web Part to stay on the page. We'll simply steal the generated XSLT from this one and use it to replace the XSLT of the Search Core Results Web Part.

The Data View Web Part allows for many customizations. For example, you can configure it to show the results grouped by author. Many other formatting and styling configurations are possible.
Bottom-line is that you can have a peek in the code view and copy all of the XSLT that is generated by the Data View Web Part.

Go back to a page where you have the Search Core Results Web Part (this can also be the search results page in the Search Center) and replace the active XSLT with the copied one.
Here is a possible outcome:

Message to take away from this posting is.. there is a quick way to come up with XSLT or the Search Core Results Web Part by making use of the Data View Web Part in the SharePoint Designer.

Comments

Why is description empty

My <description> tag in the results is always empty.  But it's filled out in the content.  Any ideas?

Thanks!
at 5/03/2007 21:57

Grouping By Area

Is it possible to group the results by area?

If so, how?

Best Regards
at 12/03/2007 15:43

custom properties/metadata

Is it possible to group search-result by custom properties/metadata or list values of custom metadata?
Mine is always empty.

Best Regards
at 21/03/2007 17:02

<description> tag fix?

I believe heather solomon found the solution to the problem you're having. Sometimes the internal name isn't the same as the field name.

Look up her article on the content query web part and read the last paragraph. I believe she switched out "description" to "comments" and it worked fine.
at 30/03/2007 20:31

<description> tag fix?

I believe heather solomon found the solution to the problem you're having. Sometimes the internal name isn't the same as the field name.

Look up her article on the content query web part and read the last paragraph. I believe she switched out "description" to "comments" and it worked fine.
at 30/03/2007 20:31

Paging

If I use the sorting and grouping function, is that it only sort and group the results of each page separately, rather then sorting/grouping the whole searched results?

Thanks.
at 17/05/2007 3:46

Editable doc?

Can the search results be changed so that users get an edit menu (check in/out, etc)?
at 25/05/2007 0:31

Change search stylesheet at runtime

Hi

Is it possible to change the Search Result page at runtime?
I changed the stylesheet to display results grouped by "Author", but it is done with SharePoint Designer.

I like to change the Stylesheet based on some metadata (not necessary in-built), so that end-user can group result page display at runtime.

Thanks,
Avinash
at 7/06/2007 8:23

Change search stylesheet at runtime ?

Hi,

In continuation of my previous questions...
I am able to change the xsl of Web Part by using either of following ways:
1) Create the xsl file from SharePoint designer and paste is in XSL Editor provided when we modify the Web Part in Edit mode.
2) Create the xsl file from SharePoint designer and paste the xsl in Web Part’s .webpart file (by replacing the ‘<’ with &lt; and ‘>’ with &gt; in xsl).


But I want to change the xsl at runtime. So, when I try to change the xsl of Web Part by using either this.XslLink or this.Xsl, I faced following exception.

StackTrace "   at System.IO.StringReader..ctor(String s)\r\n   at Microsoft.SharePoint.WebPartPages.DataFormWebPart.GetXslCompiledTransform()\r\n   at Microsoft.SharePoint.WebPartPages.DataFormWebPart.PrepareAndPerformTransform()"


Any ideas?

Thanks,
Avinash
at 11/06/2007 13:39

Access to current search terms from XSL?

Hi,

The HOL: "Building and Implementing Enterprise Search Solutions (3 day 400 level)" Module 7 - Exercise 4

aims to implement a drill down on the filetype for the current search. (but doesn't succeed...)

The code provided only replaces the current search terms by ?k={$fieldname}%3a{$value}

Which are:
     <xsl:call-template name="DisplayDrillDown">
        <xsl:with-param name="value" select="fileextension"/>
        <xsl:with-param name="fieldname">FileExtension</xsl:with-param>
        <xsl:with-param name="label">File</xsl:with-param>
     </xsl:call-template>    

To successfully implement the planned drill down one should have access to the current search terms. Could you give me a hint, where to look for? Is there a reference list of the valid
external parameters to use inside the XSL.

Thanks for any hint!

kh

PS: Any idea why <xsl:param name="MoreResultsLink" /> breaks the whole thing (but <xsl:param name="foo_MoreResultsLink" /> doesn't...

at 29/06/2007 14:41

Using this technique with content query webpart

Hi,
This is a very imaginative way of using SPD and I really like it. I tried to use you xsl-code to get some raw xml from the content query webpart, but when I tried adding it in inside the <xsl> tag in the html-view in SPD and saving it, I got no result what so ever.

Have you got this to work with the content query webpart? If so how?

Gustaf Westerlund,
Humandata AB
at 18/09/2007 16:44

Parameters

I want to show different types of result which I choose on search page. How can I send this parameter or maybe read it.
at 4/03/2008 9:59

MOSS 2007 search results to open in native application instead of Browser Window

This a nice article. But my requirement is, clicking on the document link in Search Result page should open documents in respective application(like MS Word) instead of Browser Window. So that user can edit the doc and save it to document source. Just like what it happenes in Document library.

Please help me.

Thanks
at 20/03/2008 12:03

XSTL

any other resources to speed up learning on XSTL?
at 30/05/2008 4:34

Good questions, but no answers?

Hi, there are some good questions posted here, but you don't seem to respond to them.  Just wondering why that is?

Kind regards
Tiffany
at 3/06/2008 8:49

customizing search paging info

Hi,

Can any one give any sort of example to customize the paging info of search results?

I am able to modify the search result using xslt but not able to modify my own style for paging.

Thanks.
at 12/06/2008 3:29

Change Title in XSLT with a IF- or WHEN-statement ??

Hi,

Can anyone help me with a problem that I have.
I have a webpart returning the latest result from a Forum - the problem is that when people replies to a message - the Title is "DispForm.aspx". I want to change the title to "ANSWER" instead of "DispForm.aspx". How do I change this in the XSL?? I still want the title for the first message be the title that the author wrote.

I need a "if Title == DispForm.aspx then Title = "ANSWER" ELSE ... <span class="srch-Title"> and so on"-statement. Something like that.


It is in this part of the code where I want to make a change:

  <span class="srch-Icon">
   <a href="{$url}" id="{concat('CSR_IMG_',$id)}" title="{$url}">
   <img align="absmiddle" src="{imageurl}" border="0" alt="{imageurl/@imageurldescription}" />
   </a>
  </span>
  <span class="srch-Title">
   <a href="{$url}" id="{concat('CSR_',$id)}" title="{$url}">
    <xsl:choose>
     <xsl:when test="hithighlightedproperties/HHTitle[. != '']">
         <xsl:call-template name="HitHighlighting">
          <xsl:with-param name="hh" select="hithighlightedproperties/HHTitle" />
         </xsl:call-template>  
     </xsl:when>
     <xsl:otherwise><xsl:value-of select="title"/></xsl:otherwise>
    </xsl:choose>
   </a>
    <br/>
   </span>
 

I really hope you can help me with this issue
Thanks
at 11/09/2008 15:00

Update search

Hi!
It seems that this data view works static, because when I change a detail like phone or mail from a user in sharepoint it won t give me the up to date result.

Any hint?

thx!
at 29/10/2008 11:19

Funny, Lotsa Q no A !!!

I see lots of good questions but no answers.
at 31/10/2008 0:05

People Search Core Results & Search Core Results

Hi,

I have a requirement like, I need to show the people details in left pane and the content in right pane. To achieve this, I used People Search Core Results & Search Core Results web parts.
Condition:
1. No of records in Search Core Results & People Search Core Results should be equal.
2. If there is no record corresponding to Search Core Results in People Search Core Results available, it should show blank row in People Search Core Results
3. In People Search Core Results, I should show only the People details not other contents

If I use each web part alone it is showing result properly. But, if I use both the web parts it isn't showing people details but showing contents.

Your comments in this regard will be highly helpful.

Thanks.
at 5/11/2008 5:17

GroupBy results according to custom property

Hi,
    I am new to this world of XSLT.... Can anyone help me with the problem i m facing?

I have to group results according to the custom property defined. I achieved this in designer. I copied the xslt to search core result webpart but it is giving error as "Cannot find the script or external object that implements prefix 'ddwrt'.  I have added the xmlns of ddwrt also but still problem is not solved....

Can this groupby be dynamic means right now i have grouped results according to one of my custom property but this has to be implemented as per the user enter property .Is this possible?

Your comments in this regard will be highly helpful.
Thanks
at 3/12/2008 13:51

Re: Custom XSLT for the Search Core Results Web Part

It seems that this data view works static, because when I change a detail like phone or mail from a user in sharepoint it won t give me the up to date result.<a href=http://cobroweb.com/>cobro</a>
at 6/03/2009 10:22
Captcha

Enter the code shown above: *

(Note: If you cannot read the numbers in the above
image, reload the page to generate a new one.)