Monday, May 19, 2014

Customise 'XSL Editor' Search Core Result WebPart in SharePoint 2010

------------------------------------------------------------------------------
Step 1: Deselect Check Box
------------------------------------------------------------------------------
Step 2: Add Custom column below formate with 2 spaceses.

<Columns>  <Column Name="WorkId"/>  <Column Name="Rank"/>  <Column Name="Title"/>  <Column Name="Author"/>  <Column Name="Size"/>  <Column Name="Path"/>  <Column Name="Description"/>  <Column Name="Write"/>  <Column Name="SiteName"/>  <Column Name="CollapsingStatus"/>  <Column Name="HitHighlightedSummary"/>  <Column Name="HitHighlightedProperties"/>  <Column Name="ContentClass"/>  <Column Name="IsDocument"/>  <Column Name="PictureThumbnailURL"/>  <Column Name="PopularSocialTags"/>  <Column Name="PictureWidth"/>  <Column Name="PictureHeight"/>  <Column Name="DatePictureTaken"/>  <Column Name="ServerRedirectedURL"/>  </Columns>
------------------------------------------------------------------------------
Step 2: Click 'XSL Edit' to add below code. remember 'fieldname' always should be in small letters.

<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:param name="dvt_adhocmode">sort</xsl:param>
  <xsl:decimal-format NaN=""/>

  <xsl:param name="FileName" />
  <xsl:param name="dvt_apos">'</xsl:param>
  <xsl:param name="dvt_fieldsort" />
  <xsl:param name="dvt_filterfield" />
  <xsl:param name="dvt_sortdir">ascending</xsl:param>
  <xsl:param name="dvt_sortfield" />
  <xsl:param name="dvt_sorttype">text</xsl:param>
  <xsl:param name="dvt_filterfields" />
  <xsl:param name="dvt_partguid" />

  <xsl:variable name="dvt_1_automode">0</xsl:variable>

  <xsl:template match="/">
    <xsl:call-template name="dvt_1"/>
    <style type="text/css">
      .ms-alternatingstrong
      {
      background-color:#e3efff;
      }
    </style>
  </xsl:template>
  <xsl:template name="dvt_1">
    <xsl:variable name="dvt_StyleName">Table</xsl:variable>
    <xsl:variable name="Rows" select="/All_Results/Result"/>
    <table border="0" width="93%" cellpadding="4" cellspacing="2" id="ResultsTable" align="right">
      <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="">

        </th>
        <th class="ms-vh" nowrap="" style="width: 257px" align="left">
          <xsl:call-template name="dvt.headerfield" ddwrt:atomic="1">
            <xsl:with-param name="fieldname">title</xsl:with-param>
            <xsl:with-param name="fieldtitle">TITLE</xsl:with-param>
            <xsl:with-param name="displayname">TITLE</xsl:with-param>
            <xsl:with-param name="sortable">1</xsl:with-param>
            <xsl:with-param name="fieldtype">Text</xsl:with-param>
          </xsl:call-template>
        </th>
        <th class="ms-vh" nowrap="" align="left">
          DESCRIPTION
        </th>
        <th class="ms-vh" nowrap="" align="left">
          <xsl:call-template name="dvt.headerfield" ddwrt:atomic="1">
            <xsl:with-param name="fieldname">write</xsl:with-param>
            <xsl:with-param name="fieldtitle">PUBLISHED</xsl:with-param>
            <xsl:with-param name="displayname">PUBLISHED</xsl:with-param>
            <xsl:with-param name="sortable">1</xsl:with-param>
            <xsl:with-param name="fieldtype">Text</xsl:with-param>
          </xsl:call-template>
        </th>
      </tr>
      <xsl:call-template name="dvt_1.body">
        <xsl:with-param name="Rows" select="$Rows"/>
      </xsl:call-template>
    </table>
  </xsl:template>
  <xsl:template name="dvt_1.body">
    <xsl:param name="Rows"/>
    <xsl:for-each select="$Rows">
      <xsl:sort select="*[name() = $dvt_sortfield] | @*[name() = $dvt_sortfield] | text()[name(ancestor::*[1]) = $dvt_sortfield]" order="{$dvt_sortdir}" data-type="{$dvt_sorttype}" />
      <xsl:sort select="title" order="ascending" />
      <xsl:sort select="write" order="ascending" />
      <xsl:call-template name="dvt_1.rowview"/>

    </xsl:for-each>
  </xsl:template>
  <xsl:template name="dvt_1.rowview">
    <tr>
      <xsl:if test="position() mod 2 = 1">
        <xsl:attribute name="class">ms-alternatingstrong</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">
        <img border="0" src="{imageurl/text()}" />
      </td>
      <td class="ms-vb" style="width: 257px">
        <a href="{url}">
          <xsl:value-of select="title" />
        </a>
      </td>
      <td class="ms-vb">

        <xsl:choose>
          <xsl:when test="string-length(hithighlightedsummary/text()) &lt; 80">
            <div>
              <xsl:value-of select="hithighlightedsummary/text()" />
            </div>
          </xsl:when>
          <xsl:otherwise>
            <div>
              <xsl:value-of select="substring(hithighlightedsummary/text(),1,75)" />
            </div>
            <a href="#" onclick="javascript:moreless(this,'{hithighlightedsummary}')">more&gt;&gt;</a>
          </xsl:otherwise>
        </xsl:choose>

        <script type="text/javascript">
          function moreless(abc,fullText)
          {
          if(abc.innerText == "more&gt;&gt;")
          {
          div = abc.parentNode.getElementsByTagName('div');
          div[0].innerText = fullText;
          abc.innerText = "&lt;&lt;less";
          }
          else if(abc.innerText == "&lt;&lt;less")
          {
          div = abc.parentNode.getElementsByTagName('div');
          div[0].innerText = fullText.substring(0,75);
          abc.innerText = "more&gt;&gt;";
          }

          }
        </script>
      </td>


      <td class="ms-vb">
        <xsl:value-of select="write"/>
      </td>
    </tr>
  </xsl:template>
  <xsl:template name="dvt.headerfield">
    <xsl:param name="fieldname" />
    <xsl:param name="fieldtitle" />
    <xsl:param name="displayname" />
    <xsl:param name="sortable">1</xsl:param>
    <xsl:param name="fieldtype">0</xsl:param>
    <xsl:choose>
      <xsl:when test="($dvt_adhocmode = 'sort' or $dvt_fieldsort = '1')and $sortable='1'">
        <xsl:variable name="sortfield">
          <xsl:choose>
            <xsl:when test="substring($fieldname, string-length($fieldname) - 5) = '(text)'">
              <xsl:value-of select="substring($fieldname, 1, string-length($fieldname) - 6)" />
            </xsl:when>
            <xsl:when test="substring($fieldname, 1, 1) = '@'">
              <xsl:value-of select="substring($fieldname, 2)" />
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="$fieldname" />
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:variable name="linkdir">
          <xsl:choose>
            <xsl:when test="$dvt_sortfield = $sortfield and $dvt_sortdir = 'ascending'">descending</xsl:when>
            <xsl:otherwise>ascending</xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:variable name="sortText">
          <xsl:choose>
            <xsl:when test="$linkdir='descending'">&apos; + &apos;descending&apos; + &apos;</xsl:when>
            <xsl:otherwise>&apos; + &apos;ascending&apos; + &apos;</xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:variable name="separator" select="' '" />
        <xsl:variable name="connector" select="';'" />
        <table CtxNum="1" cellspacing="0" class="ms-unselectedtitle" onmouseover="OnMouseOverAdHocFilter(this, '{concat($displayname,$separator,$fieldname, $separator,$fieldtype, $connector, 1033, $separator, $dvt_partguid)}')">
          <tr>
            <td width="100%" class="ms-vb" nowrap="">
              <a>
                <xsl:attribute name="href">
                  javascript: <xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_sortfield={',$sortfield,'};dvt_sortdir={',$sortText,'}'))" />;
                </xsl:attribute>
                <xsl:attribute name="onclick">
                  javascript: <xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_sortfield={',$sortfield,'};dvt_sortdir={',$sortText,'}'))" />;
                </xsl:attribute>
                <xsl:choose>
                  <xsl:when test="$fieldtype = 'Attachments'">
                    <xsl:value-of select="$fieldtitle" disable-output-escaping="yes" />
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="$fieldtitle" />
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:if test="$dvt_sortfield = $sortfield">
                  <xsl:choose>
                    <xsl:when test="$dvt_sortdir = 'ascending'">
                      <img border="0" alt="Ascending" src="{ddwrt:FieldSortImageUrl('Desc')}" />
                    </xsl:when>
                    <xsl:when test="$dvt_sortdir = 'descending'">
                      <img border="0" alt="Descending" src="{ddwrt:FieldSortImageUrl('Asc')}" />
                    </xsl:when>
                  </xsl:choose>
                </xsl:if>
              </a>
              <xsl:if test="contains($dvt_filterfields, concat($fieldname, ';' ))">
                <IMG SRC="/_layouts/images/filter.gif" BORDER="0" ALT="" />
              </xsl:if>
            </td>
            <td>
              <img src="/_layouts/images/blank.gif" width="13" style="visibility: hidden" alt="" />
            </td>
          </tr>
        </table>

      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$fieldtype = 'Attachments'">
            <xsl:value-of select="$fieldtitle" disable-output-escaping="yes" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$fieldtitle" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="$dvt_filterfield=$fieldname" ddwrt:cf_ignore="1">
      <img alt="Filter" src="{ddwrt:FieldFilterImageUrl('')}" />
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
------------------------------------------------------------------------------

2 comments:

  1. Thanks for sharing this information.
    RR technosoft offering DevOps training in hyderabad .RR Technosoft offers DevOps training in Hyderabad. Get trained by 15+ years of real-time IT experience, 4+ years of DevOps & AWS experience. RR Technosoft is one of the trusted institutes for DevOps Online training in Hyderabad.

    ReplyDelete

Featured Post

Mention a Channel or Team – Power Automate

Mention a Channel or Team – Power Automate graph.microsoft.com/v1.0/teams/{teamId}/channels/{channelId}/messages Channel: ---------- {   ...

Popular posts