Skip to main content

Custom Search Result using XSLT

 XSLT for Display search result in box format. Copy this xslt in to Search Core Results webpart's  XSL Editors Properties.







<xsl:stylesheet version="1.0"
xmlns:wxsl="http://www.w3schools.com/w3style.xsl"  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="xml" indent="yes"/>
  <!--this tamplate is main tamplate wich calls dvt_1 and main root template of this xslt.-->
  <xsl:template match="/">
    <style type="text/css">
      <!--
      .subDiv{width:308px; height:150px; border:1px solid Green; padding:5px; float:left;margin-left:5px;margin-top:5px;}
      .clearDiv{clear:both;}-->
      *{padding:0px; margin:0px;}
      body, html{font:normal 12px Arial, Helvetica, sans-serif; color:#000000;}
      .float_l{float:left;}
      .mainDiv{width:655px;}
      .contentBox{width:308px; min-height:122px; background-color:#f4f4f4; padding:5px; margin:0 0 5px 5px;}
       .contentBox h1{font:bold 14px Arial, Helvetica,  sans-serif;color:#FFFFFF !important; padding-bottom:10px;  padding-left:2px !important; }
      .Title{font:bold;background-color:#EEAA09;vertical-align:middle; padding-top:5px;}
      .Title a{color:#FFFFFF !important; text-decoration:none;}
      .contentBox a{text-decoration:none;}
       .contentBox .flotBox{overflow:hidden; color:#666666; font-size:12px;  padding-bottom:5px; padding-left:2px !important; padding-top:5px; }
      .contentBox .flotBox .left{float:left;}
      .contentBox .flotBox .right{float:right;}
      .contentBox .norText{font:normal 12px Arial, Helvetica, sans-serif; color:#000000;}
      .contentBox .norText a{float:right; color:#0072bc; text-decoration:none; padding-left:2px !important;}
      .contentBox .clearDiv{clear:both;}
    </style>
    <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;";
      }

      }

      function onDisplayItem(urlTest)
      {
      var options = {
      url: urlTest,
      autoSize:true,
      };
      SP.UI.ModalDialog.showModalDialog(options);
      }
    </script>
    <xsl:call-template name="dvt_1"/>
  </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="95%" cellpadding="4" cellspacing="2" id="ResultsTable" align="right">
      <tr>
        <td>
          <xsl:call-template name="dvt_1.body">
            <xsl:with-param name="Rows" select="$Rows"/>
          </xsl:call-template>
        </td>
      </tr>
    </table>
  </xsl:template>
  
  <!--this tamplate is used is body template which displys all recods it calles dvt1.rowview temp and dispalys all rows-->
  <xsl:template name="dvt_1.body">
    <xsl:param name="Rows"/>
    <xsl:param name="count" select="2"/>
    <div class="mainDiv">
      <xsl:for-each select="$Rows">
        <xsl:variable name="Position"  select="position() mod 2"></xsl:variable>
        <xsl:call-template name="dvt_1.rowview"/>
        <xsl:choose>
          <xsl:when test="$Position &lt; 1">
            <div class="clearDiv"></div>
          </xsl:when>
          <xsl:otherwise>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
      <div class="clearDiv"></div>
    </div>
  </xsl:template>
  
  <!--this tamplate is used to get site, sub site, site collection urls. from related links.-->
  <xsl:template name="SPWebUrl">
    <xsl:param name="siteUrl" />
    <xsl:param name="contentclass" />
    <xsl:choose>
      <!--<!–- Check the content class to see if it is a document -–>-->
      <xsl:when test="$contentclass='STS_ListItem_DocumentLibrary'">
        <!--<!– Get Document Library Url Name –>-->
        <xsl:variable name="DocLib">
          <xsl:call-template name="StripSlash">
            <xsl:with-param name="text" select="$siteUrl"/>
          </xsl:call-template>
        </xsl:variable>
        <!--<!– Remove the document library from the url –>-->
         <xsl:variable name="SPWebURLString"  select="substring-before(concat($siteUrl, '/'), concat('/',  concat($DocLib, '/')))" />
        <xsl:value-of select="$SPWebURLString"/>
      </xsl:when>
      <xsl:otherwise>
        <!--<!– Get List Url Name –>-->
        <xsl:variable name="ListUrl">
          <xsl:call-template name="StripSlash">
            <xsl:with-param name="text" select="$siteUrl"/>
          </xsl:call-template>
        </xsl:variable>
        <!--<!– Remove the list name from the url –>-->
         <xsl:variable name="urlLists"  select="substring-before(concat($siteUrl, '/'), concat('/',  concat($ListUrl, '/')))" />
        <!--<!– Remove Lists from the url –>-->
        <xsl:variable name="Lists">
          <xsl:call-template name="StripSlash">
            <xsl:with-param name="text" select="$urlLists"/>
          </xsl:call-template>
        </xsl:variable>
         <xsl:variable name="SPWebURLString"  select="substring-before(concat($urlLists, '/'), concat('/',  concat($Lists, '/')))" />

        <xsl:value-of select="$SPWebURLString"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!--<!– this template Removes Lists from the url and used in SPWebUrl template –>-->
  <xsl:template name="StripSlash">
    <xsl:param name="text"/>
    <xsl:choose>
      <xsl:when test="contains($text, '/')">
        <xsl:call-template name="StripSlash">
          <xsl:with-param name="text" select="substring-after($text, '/')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!--this template for Strip HTML and used in dvt_1.rowview -->
  <xsl:template name="StripHTML">
    <xsl:param name="HTMLText"/>
    <xsl:choose>
      <xsl:when test="contains($HTMLText, '&lt;')">
        <xsl:call-template name="StripHTML">
           <xsl:with-param name="HTMLText"  select="concat(substring-before($HTMLText, '&lt;'),  substring-after($HTMLText, '&gt;'))"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$HTMLText"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

   <!--this template for for displaying data in row view. it fatches  data from results of search and displying in box format. -->
  
  <xsl:template name="dvt_1.rowview">
    <xsl:variable name="dvt_StyleName">Table</xsl:variable>
    <xsl:variable name="Rows" select="/All_Results/Result"/>
    <div class="contentBox float_l">
      <div class="Title">
        <h1>
          <a>
            <xsl:attribute name="href">
              <xsl:call-template name="SPWebUrl">
                <xsl:with-param name="siteUrl" select="sitename" />
                <xsl:with-param name="contentclass" select="contentclass" />
              </xsl:call-template>
            </xsl:attribute>
            <xsl:value-of select="title" />
          </a>
        </h1>
      </div>
      <div class="flotBox">
        <p class="left">
          <xsl:value-of select="author"/>
        </p>
        <p class="right">
          <xsl:value-of select="write"/>
        </p>
      </div>
      <div class="norText">
        <xsl:choose>
          <xsl:when test="string-length(description) &lt; 175">
            <div>
              <xsl:call-template name="StripHTML">
                <xsl:with-param name="HTMLText" select="description"></xsl:with-param>
              </xsl:call-template>
            </div>
          </xsl:when>
          <xsl:otherwise>
            <div>
              <xsl:call-template name="StripHTML">
                <xsl:with-param name="HTMLText" select="substring(description,1,135)"></xsl:with-param>
              </xsl:call-template>
            </div>
          </xsl:otherwise>
        </xsl:choose>
      
        <div>
          <xsl:choose>
            <xsl:when test="string-length(description) &lt; 175">
            </xsl:when>
            <xsl:otherwise>
              <a onclick="javascript:moreless(this,'{description}')">
                <xsl:attribute name="href">
                  <xsl:call-template name="SPWebUrl">
                    <xsl:with-param name="siteUrl" select="sitename" />
                    <xsl:with-param name="contentclass" select="contentclass" />
                  </xsl:call-template>
                </xsl:attribute>
                More...
              </a>
            </xsl:otherwise>
          </xsl:choose>
        </div>
      </div>
    </div>
  </xsl:template>
  <xsl:include href="/_layouts/xsl/main.xsl"/>
  <xsl:include href="/_layouts/xsl/internal.xsl"/>
   <xsl:template name="FieldRef_Computed_DocIcon_body.DocIcon"  ddwrt:dvt_mode="body" match ="FieldRef[@Name='DocIcon']"  mode="Computed_DocIcon_body" ddwrt:ghost=""  xmlns:ddwrt2="urn:frontpage:internal">
    <xsl:param name="thisNode" select="."/>
    <xsl:param name="folderUrlAdditionalQueryString" select="''"/>
    <xsl:choose>
      <xsl:when test="$thisNode/@FSObjType='1'">
        <xsl:variable name="alttext">
          <xsl:choose>
            <xsl:when test="starts-with($thisNode/@ContentTypeId, &quot;0x0120D5&quot;)">
               <xsl:value-of select="$thisNode/../@itemname_documentset"/>:  <xsl:value-of select="$thisNode/@FileLeafRef"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:value-of select="$thisNode/../@listformtitle_folder"/>:  <xsl:value-of select="$thisNode/@FileLeafRef"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:variable name="mapico" select="$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapico"/>
        <xsl:variable name="folderIconPath">
          <xsl:call-template name="GetFolderIconSourcePath">
            <xsl:with-param name="thisNode" select="$thisNode"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:choose>
          <xsl:when test="$RecursiveView='1'">
            <img border="0" alt="{$alttext}" src="{$folderIconPath}" />
            <xsl:choose>
              <xsl:when test="$thisNode/@IconOverlay != ''">
                <img src="/_layouts/images/{$thisNode/@IconOverlay.mapoly}" class="ms-vb-icon-overlay" alt="" title="" />
              </xsl:when>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <xsl:variable name="FolderCTID">
               <xsl:value-of select="$PagePathFinal"  />RootFolder=<xsl:value-of select="$thisNode/@FileRef.urlencode"  /><xsl:value-of  select="$ShowWebPart"/>&amp;FolderCTID=<xsl:value-of  select="$thisNode/@ContentTypeId" />&amp;View=<xsl:value-of  select="$View"/><xsl:value-of  select="$folderUrlAdditionalQueryString"/>
            </xsl:variable>
             <a href="{$FolderCTID}" onmousedown ="VerifyFolderHref(this, event,  '{$thisNode/@File_x0020_Type.url}','{$thisNode/@File_x0020_Type.progid}','{$XmlDefinition/List/@DefaultItemOpen}',  '{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon}',  '{$thisNode/@HTML_x0020_File_x0020_Type}',  '{$thisNode/@serverurl.progid}')"
               onclick="return  HandleFolder(this,event,&quot;{$PagePathFinal}RootFolder=&quot; +  escapeProperly(&quot;{$thisNode/@FileRef}&quot;) +  '{$ShowWebPart}&amp;FolderCTID={$thisNode/@ContentTypeId}&amp;View={$View}{$folderUrlAdditionalQueryString}','TRUE','FALSE','{$thisNode/@File_x0020_Type.url}','{$thisNode/@File_x0020_Type.progid}','{$XmlDefinition/List/@DefaultItemOpen}','{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon}','{$thisNode/@HTML_x0020_File_x0020_Type}','{$thisNode/@serverurl.progid}','{$thisNode/@CheckoutUser.id}','{$Userid}','{$XmlDefinition/List/@ForceCheckout}','{$thisNode/@IsCheckedoutToLocal}','{$thisNode/@PermMask}');">
              <img border="0" alt="{$alttext}" title="{$alttext}" src="{$folderIconPath}" />
              <xsl:choose>
                <xsl:when test="$thisNode/@IconOverlay != ''">
                   <img src="/_layouts/images/{$thisNode/@IconOverlay.mapoly}"  class="ms-vb-icon-overlay" alt="" title="" />
                </xsl:when>
              </xsl:choose>
            </a>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$IsDocLib">
            <xsl:choose>
              <xsl:when test="not ($thisNode/@IconOverlay) or $thisNode/@IconOverlay =''">
                <xsl:choose>
                  <xsl:when test="not ($thisNode/@CheckoutUser.id) or $thisNode/@CheckoutUser.id =''">
                     <img border="0" alt="{$thisNode/@FileLeafRef}"  title="{$thisNode/@FileLeafRef}"  src="/_layouts/images/{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapico}"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:variable name="alttext">
                       <xsl:value-of select="$thisNode/@FileLeafRef"/><xsl:text  disable-output-escaping="yes"  ddwrt:nbsp-preserve="yes">&#10;</xsl:text><xsl:value-of  select="$thisNode/../@managecheckedoutfiles_header_checkedoutby"/>:  <xsl:value-of select="$thisNode/@CheckoutUser.title"/>
                    </xsl:variable>
                     <img border="0" alt="{$alttext}" title="{$alttext}"  src="/_layouts/images/{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapico}"  />
                    <img  src="/_layouts/images/checkoutoverlay.gif" class="ms-vb-icon-overlay"  alt="{$alttext}" title="{$alttext}" />
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:when>
              <xsl:otherwise >
                 <img border="0" alt="{$thisNode/@FileLeafRef}"  title="{$thisNode/@FileLeafRef}"  src="/_layouts/images/{$thisNode/@IconOverlay.mapico}" />
                <img src="/_layouts/images/{$thisNode/@IconOverlay.mapoly}" class="ms-vb-icon-overlay" alt="" title="" />
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <img border="0" src="/_layouts/images/{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapico}">
              <xsl:attribute name="title">
                <xsl:value-of select="$thisNode/@Title"/>
              </xsl:attribute>
              <xsl:attribute name="alt">
                <xsl:value-of select="$thisNode/@Title"/>
              </xsl:attribute>
            </img>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

Search Result  :


Comments

Popular posts from this blog

How to deal with SharePoint 2010 exception "An exception occurred when trying to issue security token: The server was unable to process the request due to an internal error"

Scenario: You receive the below exception when you try to logon to a site that has been configured to use Claims Based Authentication with a custom membership provider using FBA credentials: Event ID from Event Log  - 8306 An exception occurred when trying to issue security token: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.. Explanation: This error started to appear in our QA environment which does not have Visual Studio installed. I have tried starting the service "Claims to Windows Token Service" but that did not help either. I have made sure that all configuration c

Custom Form Base Login Web Part With Sharepoint 2010

In my  Last Post , I talked about creating a Form based authentication web application with Active Directory LDAP. After implementing that you have surely noticed that, when you try to sign in after creating a site collection from FBA web application, you get the following sign in page: Surely, it does not look pretty at all. So, you might want to change this default login page. In order to do this, first let us create an empty SharePoint project in Visual Studio 2010. After that, add an application page by right click-selecting “Add New Item” and you will get like the following window in Solution Explorer: Notice that, when you add any application page to your project, Visual Studio automatically creates a Layouts  folder. To keep things simple enough for your understanding, you may keep your application page under a folder where you might name it as same as your project like the figure above. Now, add a reference for  Microsoft.SharePoint.IdentityModel  in your project.

Migrating from Skype for Business to Microsoft Teams: A Step-by-Step Guide

Do you still use Skype for Business to meet the communication and collaboration needs of your business? If so, now is the perfect time to think about switching to Microsoft Teams, a cutting-edge platform with cutting-edge capabilities and seamless connectivity with other Microsoft services. But if you're unfamiliar with the procedure, switching to a new platform can seem like a difficult task. I'll walk you through the process of switching from Skype for Business to Microsoft Teams in this article. Plan the migration in Step 1 You must make a plan before you start the relocation procedure. Set a deadline, make a list of all the Skype for Business capabilities you presently use, and choose whether to migrate gradually or all at once. Step 2: Set up your surroundings. Make sure your network and infrastructure fulfil Microsoft Teams' standards. Upgrades to your hardware, software, and licences might be necessary. Additionally, confirm that you have the right permissions to ca