Monday, May 12, 2008

Sharepoint XSLT Tips

Customize search result

  • When you reach a search result page which contains the core search web part, if you want to get rid of the auther, date as well as the file size, you can edit the web part and in the XSL editor, get rid of the following:
    • Under the template <xsl:template match="Result"> Get rid of
      • <xsl:call-template name="DisplaySize"> <xsl:with-param name="size" select="size" /> </xsl:call-template>
      • <xsl:call-template name="DisplayString"> <xsl:with-param name="str" select="author" /> </xsl:call-template>
      • <xsl:call-template name="DisplayString"> <xsl:with-param name="str" select="write" /> </xsl:call-template>
    • Get rid of the following templates:
      • DisplaySize
      • DisplayString

Customize DataView

  • If you want to hide an image that its image file name parameter of the dataview is empty, you can use:
    • <xsl:if test="contains(@ImageFileName,'.')"><img src="../Pictures/{@ImageFileName}"></img></xsl:if>
  • Say if you want to show a extract of a long description, you could just show the first sentence of the description by getting all the words before the first full stop, if there is no full stop in the description, then you can just show the first 200 letters:
    • <xsl:choose>
    • <xsl:when test="contains(@Profile,'.')">
    • <xsl:value-of select="concat(substring-before(@Profile,'.'), ' ...')" disable-output-escaping="yes"/>
    • </xsl:when>
    • <xsl:otherwise>
    • <xsl:value-of select="concat(substring(@Profile,0,200), ' ...')" disable-output-escaping="yes"/>
    • </xsl:otherwise>
    • </xsl:choose>
  • If you want to formate a date to be for example "Tuesday, 6 May 2008", here is how:
    • <xsl:value-of select="ddwrt:FormatDate(string(@Date), 3081, 3)"/>
blog comments powered by Disqus