none
Search core results webpart - Group by and display top 3 results using XSLT RRS feed

  • Question

  • I have fetch list data from all the blog sites having post list, using search core results webpart

    Below is the XML generated for the output of search core results

    <?xml version="1.0" encoding="utf-8"?>
    <All_Results>
      <Result>
        <id>1</id>
        <workid>1113</workid>
        <sitetitle>Process Improvement Around New Culture Site</sitetitle>
        <sitename>ProcessImprovementAroundNewCultureSite/Lists/Posts</sitename>
      </Result>
      <Result>
        <id>2</id>
        <workid>1113</workid>
        <title>Process Improvement for ACL Process</title>
         <sitetitle>Process Improvement Around New Culture Site</sitetitle>
        <sitename>ProcessImprovementAroundNewCultureSite/Lists/Posts</sitename>
      </Result>
      <Result>
        <id>3</id>
        <workid>1113</workid>
        <title>Process Improvement Test</title>
        <sitetitle>Process Improvement Test</sitetitle>
        <sitename>ProcessImprovementAroundNewCultureSite/Lists/Posts</sitename>
      </Result>
      <Result>
        <id>4</id>
        <workid>1113</workid>
        <title>Process Improvement Test</title>
        <sitetitle>Process Improvement Test</sitetitle>
        <sitename>ProcessImprovementAroundNewCultureSite/Lists/Posts</sitename>
      </Result>
    </All_Results>
    

     I need to group the results based on sitetitle and display top 3 results from each site.

    1)The approach followed was providing the  in fixed query as sitename: "url" contentType:"post"
    2)Read the xml above using xml services in sharepoint designer generate the group by with site title, All the results are respective of site title are displaying appropriately

    Following is the generated xslt from sharepoint designer to group the items by site title. I need to know how we can display only top 3 using xslt for the generated results. Tried using priority property i.e ID,  but will only get first group values...

    Any help on this would be appreciated of how to get the top 3 results using xslt for each group.

    <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="dvt_apos">'</xsl:param>
    
    <xsl:param name="FileName" />
    
    <xsl:param name="FinalCount" select="1" />
    
    <xsl:param name="dvt_groupfield" />
    
    <xsl:variable name="dvt_1_automode">0</xsl:variable>
    
    <xsl:template match="/" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
    
    <xsl:call-template name="dvt_1">
    
    </xsl:call-template>
    
    </xsl:template>
    
    <xsl:template name="dvt_1">
    
    <xsl:variable name="dvt_StyleName">Table</xsl:variable>
    
    <xsl:variable name="Rows" select="/All_Results/Result"/>
    
    <xsl:variable name="dvt_RowCount" select="count($Rows)" />
    
    <xsl:variable name="IsEmpty" select="$dvt_RowCount = 0" />
    
    <table border="0" width="100%" cellpadding="2" 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="">title</th>
    
    <th class="ms-vh" nowrap="">Rating</th>
    
    <th class="ms-vh" nowrap="">No:ofComments</th>
    
    </tr>
    
    <xsl:call-template name="dvt_1.body">
    
    <xsl:with-param name="Rows" select="$Rows"/>
    
    <xsl:with-param name="FirstRow" select="1" />
    
    <xsl:with-param name="LastRow" select="$dvt_RowCount" />
    
    
    </xsl:call-template>
    
    </table>
    
    </xsl:template>
    
    <xsl:template name="dvt_1.body">
    
    <xsl:param name="Rows"/>
    
    <xsl:param name="FirstRow" />
    
    <xsl:param name="LastRow" />
    
    <xsl:param name="count123" select="1"/>
    
    <xsl:variable name="dvt_Rows">
    
    <root>
    
    <xsl:for-each select="$Rows">
    
    <xsl:sort select="sitetitle" order="ascending" />
    
    <xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow)">
    
    <xsl:copy-of select="." />
    
    </xsl:if>
    
    </xsl:for-each>
    
    </root>
    
    </xsl:variable>
    
    <xsl:for-each select="$Rows">
    
    <xsl:sort select="sitetitle" order="ascending" />
    
    <!--<xsl:value-of select="$count123"/>-->
    
    <xsl:variable name="NewGroup_0">
    
    <xsl:choose>
    
    <xsl:when test="not ($dvt_groupfield)">
    
    <xsl:value-of select="ddwrt:NameChanged(string(sitetitle), 0)" />
    
    </xsl:when>
    
    <xsl:otherwise></xsl:otherwise>
    
    </xsl:choose>
    
    </xsl:variable>
    
    <xsl:value-of select="$dvt_groupfield"/>
    
    <xsl:choose>
    
    <xsl:when test="0" />
    
    <xsl:when test="not($dvt_groupfield) and (not($NewGroup_0='') and position() &gt;= $FirstRow and position() &lt;= $LastRow or ($FirstRow = position()))">
    
    <xsl:variable name="groupheader0">
    
    <xsl:choose>
    
    <xsl:when test="not (sitetitle) and (sitetitle) != false()">
    
    <xsl:value-of select="' '" />
    
    </xsl:when>
    
    <xsl:otherwise>
    
    <xsl:value-of select="sitetitle" />
    
    </xsl:otherwise>
    
    </xsl:choose>
    
    </xsl:variable>
    
    <xsl:call-template name="dvt_1.groupheader0">
    
    <xsl:with-param name="fieldtitle">sitetitle</xsl:with-param>
    
    <xsl:with-param name="fieldname">sitetitle</xsl:with-param>
    
    <xsl:with-param name="fieldvalue" select="$groupheader0" />
    
    <xsl:with-param name="fieldtype" select="'text'" />
    
    <xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Result[((sitetitle)=$groupheader0 or ((not(sitetitle) or sitetitle='') and $groupheader0=' '))]" />
    
    <xsl:with-param name="groupid" select="'0'" />
    
    <xsl:with-param name="displaystyle" select="'auto'" />
    
    <xsl:with-param name="imagesrc" select="'/_layouts/images/minus.gif'" />
    
    <xsl:with-param name="alttext" select="'collapse'" />
    
    <xsl:with-param name="altname" select="'expand'" />
    
    <xsl:with-param name="hidedetail" select="false()" />
    
    <xsl:with-param name="showheader" select="true()" />
    
    <xsl:with-param name="showheadercolumn" select="false()" />
    
    </xsl:call-template>
    
    </xsl:when>
    
    </xsl:choose>
    
    <xsl:variable name="BreakOut">
    
    <xsl:choose>
    
    <xsl:when test="not($dvt_groupfield) and position()=$LastRow+1">
    
    <xsl:value-of select="ddwrt:NameChanged('', -1)" />
    
    </xsl:when>
    
    <xsl:otherwise>BreakOut</xsl:otherwise>
    
    </xsl:choose>
    
    </xsl:variable>
    
    <xsl:variable name="dvt_KeepItemsTogether" select="false()" />
    
    <xsl:variable name="dvt_HideGroupDetail" select="false()" />
    
    <xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow) or $dvt_KeepItemsTogether " >
    
    <xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">
    
    <!--<xsl:if test="$count123 &lt; 4">-->
    
    <xsl:call-template name="dvt_2.rowview" >
    
    <xsl:with-param name="count" select="$count123"></xsl:with-param>
    
    </xsl:call-template>
    
    <!--<xsl:variable name="count1234" select="$count123 +1"/>-->
    
    <!--</xsl:if>-->
    
    </xsl:if>
    
    </xsl:if>
    
    <xsl:choose>
    
    <xsl:when test="0" />
    
    </xsl:choose>
    
    </xsl:for-each>
    
    </xsl:template>
    
    <xsl:template name="dvt_2.rowview">
    
    <xsl:param name="count"/>
    
    <xsl:if test="$FinalCount &lt; 4">
    
    <xsl:call-template name="dvt_1.rowview" >
    
    <xsl:with-param name="FinalCount" select="$FinalCount+1"></xsl:with-param>
    
    </xsl:call-template>
    
    <xsl:value-of select="$FinalCount+1"></xsl:value-of>
    
    </xsl:if>
    
    </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="{url}">
    
    <xsl:value-of select="title"/>
    
    </a>
    
    </td>
    
    <td class="ms-vb">
    
    Rating: <xsl:value-of select="rating"/>
    
    </td>
    
    <td class="ms-vb">
    
    Number Of Comments:<xsl:value-of select="numberofcomments"/>
    
    </td>
    
    </tr>
    
    </xsl:template>
    
    <xsl:template name="dvt_1.groupheader0">
    
    <xsl:param name="fieldtitle" />
    
    <xsl:param name="fieldname" />
    
    <xsl:param name="fieldvalue" />
    
    <xsl:param name="fieldtype" />
    
    <xsl:param name="nodeset" />
    
    <xsl:param name="groupid" />
    
    <xsl:param name="displaystyle" />
    
    <xsl:param name="imagesrc" />
    
    <xsl:param name="alttext" />
    
    <xsl:param name="altname" />
    
    <xsl:param name="hidedetail" />
    
    <xsl:param name="showheader" />
    
    <xsl:param name="showheadercolumn" />
    
    <xsl:if test="$showheader" ddwrt:cf_ignore="1">
    
    <tr id="group{$groupid}" style="display:{$displaystyle}">
    
    <td class="ms-gb" style="background:#cccccc;" colspan="99">
    
    header:
    
    <xsl:choose>
    
    <xsl:when test="$fieldtype='url'">
    
    <a href="{$fieldvalue}">
    
    <xsl:value-of select="$fieldvalue" />
    
    </a>
    
    </xsl:when>
    
    <xsl:when test="$fieldtype='user'">
    
    <xsl:value-of select="$fieldvalue" disable-output-escaping="yes" />
    
    </xsl:when>
    
    <xsl:otherwise>
    
    <a href="{sitename}">
    
    <xsl:value-of select="sitetitle" />
    
    </a>
    
    </xsl:otherwise>
    
    </xsl:choose>
    
    </td>
    
    </tr>
    
    </xsl:if>
    
    </xsl:template>
    
    </xsl:stylesheet>
    
    

     

     


    suneelchinni
    Friday, April 9, 2010 3:31 PM