Clinton's profileCherry BytesBlogListsGuestbookMore Tools Help
    October 08

    Display content type in SharePoint search results

    A query that came through to me this week was could we display the content type for an item in the search results? …and the answer of course was yes. I wrote a little function to drop into the XSL to do this, which isn’t that pretty, but does work. Basically this query works by referencing each of the known SharePoint Content Types and giving them a friendly name.

    This can easily be implemented into the search results web part in MOSS.

    As such my (not so short) template is:

    <xsl:template name="GetContentType">
        <xsl:param name="SharePointContentType"></xsl:param>
        <xsl:choose>
            <xsl:when test="contains($SharePointContentType,'STS_Web')">Site</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_850')">Page Library</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_850')">Page</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_DocumentLibrary')">Document Library</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_DocumentLibrary')">Document Library Items</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_Links')">Links List</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_Links')">Links List Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_Tasks')">Tasks List</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_Tasks')">Tasks List Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_Events')">Events List</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_Events')">Events List Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_Announcements')">Announcements List</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_Announcements')">Announcements List Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_Contacts')">Contacts List</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_Contacts')">Contacts List Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_DiscussionBoard')">Discussion List</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_DiscussionBoard')">Discussion List Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_IssueTracking')">Issue Tracking List</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_IssueTracking')">Issue Tracking List Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_GanttTasks')">Project Tasks List</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_GanttTasks')">Project Tasks List Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_Survey')">Survey List</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_Survey')">Survey List Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_PictureLibrary')">Picture Library</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_PictureLibrary')">Picture Library Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_WebPageLibrary')">Web Page Library</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_WebPageLibrary')">Web Page Library Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List_XMLForm')">Form Library</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem_XMLForm')">Form Library Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_ListItem')">Custom List Item</xsl:when>
            <xsl:when test="contains($SharePointContentType,'STS_List')">Custom List</xsl:when>            
            <xsl:when test="contains($SharePointContentType,'urn:content-class:SPSSearchQuery')">Search Query</xsl:when>
            <xsl:when test="contains($SharePointContentType,'urn:content-class:SPSListing:News')">News Listing</xsl:when>
            <xsl:when test="contains($SharePointContentType,'urn:content-class:SPSPeople')">People</xsl:when>
            <xsl:when test="contains($SharePointContentType,'urn:content-class:SPSCategory')">Category</xsl:when>
            <xsl:when test="contains($SharePointContentType,'urn:content-class:SPSListing')">Listing</xsl:when>
            <xsl:when test="contains($SharePointContentType,'urn:content-class:SPSPersonListing')">Person Listing</xsl:when>
            <xsl:when test="contains($SharePointContentType,'urn:content-class:SPSTextListing')">Text Listing</xsl:when>
            <xsl:when test="contains($SharePointContentType,'urn:content-class:SPSSiteListing')">Site Listing</xsl:when>
            <xsl:when test="contains($SharePointContentType,'urn:content-class:SPSSiteRegistry')">Site Registry Listing</xsl:when>
            <xsl:otherwise>
                Webpage (<xsl:value-of select="$SharePointContentType"/>)
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    Then to reference this in your search results simply call this template and pass in the variable ‘contentclass’ which appears on all search result pages:

    <xsl:call-template name="GetContentType">
         <xsl:with-param name="SharePointContentType" select="contentclass"/>
    </xsl:call-template>