Update 14 December 2009: Improved slightly, first the tags are stripped, then content shortened. 

Displaying a textual preview of an wiki’s article in SharePoint is quite easy. All one needs to do is create a data view web part with SharePoint Designer (free since April 1) and have it display the field ‘Wiki Contents’ from the wiki’s pages library. Now the contents of this field contain all the HTML markup of the article, which we now need to strip of the tags and also reduce in size.

In order to strip the ‘Wiki Contents’ of the HTML markup, we need to apply XSLT. In the xsl:stylesheet section of the data view web part, add the following template:

<xsl:template name="strip-tags">
  <xsl:param name="text"/>
    <xsl:when test="contains($text, ‘&lt;’)">
     <xsl:value-of select="substring-before($text, ‘&lt;’)"/>
     <xsl:call-template name="strip-tags">
      <xsl:with-param name="text" select="substring-after($text, ‘&gt;’)"/>
     <xsl:value-of select="$text"/>

Afterwards, find <xsl:value-of select="@WikiField" /> and replace it with the following

<xsl:variable name="strippedWiki">
  <xsl:call-template name="strip-tags">
     <xsl:with-param name="text" select="string(@WikiField)"/>
<xsl:value-of select="concat(substring($strippedWiki,1,800),
        substring-before(substring($strippedWiki,801,850),’ ‘))"/>
<a href="{@LinkFilenameNoMenu}" mce_href="{@LinkFilenameNoMenu}">….(more)</a>

This calls the template above with a part of the wiki article’s content (replace 800, 801, and 850 accordingly if you want to show more/less) and adds a link to it add the end. The concetanation here is to avoid having a word cut off by adding text add the end of the first substring until the first space is encountered.

The result looks like this:

sharepoint wiki preview

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.