Friday, November 26, 2010

XSLT creation revisited for SharePoint 2010 Search and a small search tip

Search tip

If you search with only a hash “#”, then you will do an empty search and all results are returned.
When modifying the xslt for the Core Search Result Webpart it’s nice to know what data is actually included in the xml.
SharePoint 2010 has a section called “How to: View Search Results XML Data” which also existed for 2007. This time around it has included the important (obsolete for HTML5) XMP tag which makes rendering xml a breeze. Best practice is to use the PRE tag, but then you have to html encode your tags for it to render correctly.

By substituting your xslt with the snippet below, you will get xml output instead in for your web part.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xmp><xsl:copy-of select="*"/></xmp>

Which results in something like this

<title>Your document title</title>
<author>Mikael Svenson</author>
<hithighlightedsummary>This is a summary.</hithighlightedsummary>
<HHTitle>Your document title</HHTitle>
<imageurl imageurldescription="Web Page">/_layouts/images/html16.png</imageurl>
<docvector>[procedure overview, 1][office procedure, 1][links, 0.707107]</docvector>
<escprojname>00 - UNDEFINED</escprojname>
<escdeptname>0000 - UNDEFINED</escdeptname>
<esccategoryname>COMPANY MANAGEMENT SYSTEM</esccategoryname>
<escsubcategoryname>GOVERNING DOCUMENTS</escsubcategoryname>

This is a result using FS4SP which includes the docvector tag which included concepts from the text. The last properties starting with “esc” are custom defined fields which I’ve added to the Display Properties –> Fetched Properties setting on the Core Result Web Part.

With this xml as a reference, it’s easy to create and modify the default xslt. I usually keep two Core Result Web Parts on the page while creating it, one with the rendered output and one with xml for reference. Once I’m done, I’ll remove my debug part from the page and package it all up for deployment.


  1. This was very helpful thank you!

  2. Hi Mickael,
    Nice article. I am trying to create a new webpart overriding the existing core results webpart. If the result that is returned is of type other than page , i want to show them in a separate panel called documents. this.XmlResponsedoc contains the complete XML resultset but when i try to display them using this.XmlResponsedoc.Selectnode("/All_Results/Result"), i expected complete result set but instead it is getting filtered by the Sharepoint core results webpart property "Number of Results per page" . Any idea what should be done??

  3. Hi Ranjani,
    So you are executing a search, and want to filter out some items, showing them in a separate pane right?

    It would be easier to use two Core Results Web Parts, where you add your filter in the "Append Text To Query" property below "Result Query Options" Something like: NOT(fileextension:docx)

    This also saves you from creating a custom web part.

  4. Quick question:

    >>If you search with only a hash “#”, then you will do an >>empty search and all results are returned.

    Does this still work, i couldn't get it to work on my vanilla instal?

  5. It works with FS4SP and with Office365. You can also use % to get the same results.

  6. Hmm that's so weird, it doesn't work for me...?
    I get this: "We did not find any results for #"

    But if i do this: meta.collection:sp i get full results back.

    Same experience on qrserver as-well

  7. Hmm.. weird indeed. And if you do: string("#")
    on the QR server you get no results?

  8. Hi, I can see my content type name in xml result by using above code.
    But i could not able to see that name on my screen in search core result webpart.
    can you please suggest me somthing.

    1. Hi,
      Did you include it in your rendering xslt so that it would display?