Sharepoint Search XSL

There is a possiblity to show a link to the corresponding Document Library or Explorer Directory in Sharepoint Search. You have to change the XSL which defines the Visual Search in the Core Search Webpart.

This is the XSL Template:

 <!-- Display a folder for opening the Document Library or Folder -->
  <xsl:template name="DisplaySite">
    <xsl:param name="title"/>
    <xsl:param name="url" />
    <xsl:param name="isdocument" />
    <xsl:if test='$isdocument = 1'>
      <xsl:variable name="siteUrl" select="foo"/>
      <xsl:if test='string-length($url) &gt; 0'>
        <xsl:choose>
          <xsl:when test="starts-with($url, 'file://')">
            - <xsl:element name="a">
              <xsl:attribute name="href">
                <xsl:call-template name="strip">
                  <xsl:with-param name="relfile">
                    <xsl:value-of select="url"/>
                  </xsl:with-param>
                </xsl:call-template>
              </xsl:attribute>
              <img src="/_layouts/images/folder.gif" alt="Dokumentenbibliothek öffnen" style="border:none; vertical-align:bottom;"/>
                Ordner im Explorer öffnen
            </xsl:element>
          </xsl:when>
          <xsl:when test="starts-with($url, 'http://')">
            - <xsl:element name="a">
              <xsl:attribute name="href">
                <xsl:call-template name="strip">
                  <xsl:with-param name="relfile">
                    <xsl:value-of select="url"/>
                  </xsl:with-param>
                </xsl:call-template>
              </xsl:attribute>
              <xsl:attribute name="target">blank</xsl:attribute>
              <img src="/_layouts/images/itdl.gif" alt="Dokumentenbibliothek öffnen" style="border:none; vertical-align:bottom;"/>
                Zugehörige Dokumentbibliothek öffnen
            </xsl:element>
          </xsl:when>
        </xsl:choose>
        <br/>
        <xsl:value-of select="$siteUrl"/>
      </xsl:if>

    </xsl:if>
  </xsl:template>
  <!-- Utility function to remove the document from the URL -->
  <xsl:template name="strip">
    <xsl:param name="reldir"/>
    <xsl:param name="relfile"/>
    <xsl:choose>
      <xsl:when test="contains($relfile, '/')">
        <xsl:call-template name="strip">
          <xsl:with-param name="relfile">
            <xsl:value-of select="substring-after($relfile,'/')"/>
          </xsl:with-param>
          <xsl:with-param name="reldir">
            <xsl:value-of select="concat($reldir, substring-before($relfile,'/'), '/')"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$reldir"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
To call this template in the location where every search result is processed, use this snippet:

 <xsl:call-template name="DisplaySite">
        <xsl:with-param name="title" select="title"/>
        <xsl:with-param name="url" select="sitename" />
        <xsl:with-param name="isdocument" select="isdocument"/>
      </xsl:call-template>

Credits for this useful extension goes to the Sharepoint XSL  Samples Project on Codeplex. Thx!
http://sctxsl.codeplex.com/
http://sctxsl.codeplex.com/releases/view/12070 (look there for the Open Document Library File under Downloads)


Schreibe einen Kommentar

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s