Limiting the output of a SharePoint field in a dataview to [x] words.

This solution was created by a guy named Marc, the XSL templates he created are just, well, freaking fantastic! View his blog entry here: Displaying the First N Words of a Long Rich Text Column with XSL

I have been looking for a solution to cleanly limit the output of a SharePoint list field. Most of the time I find solutions that I piece together to make my desired outcome. However, with FirstNWords and the StripHTML templates that Marc shared, there was nothing left to be desired.

For my implementation of his solution: at the beginning of my row template I added the xsl:variable tag, effectively stripping the HTML from the @SRDetails field and placing into $BodyText. Then where I wanted to display the output, I added the xsl:call-template tag for FirstNWords with the appropriate xsl:with-param values. The actual template code was placed directly below the row template, with the only changes being:

1. StripHTML: replace the < sign in the xsl:when to &lt; .
2. StripHTML: replace the other two signs (< and >) as Marc stated.
3. FirstNWords: replace the > signs in the first and second xsl:when to &gt; .

Awesome solution…thanks Marc.

-Aaron Gilbert

Tags: ,

About aaron

IT is not just a job but also a passion. Everything I have accomplished, both personally and professionally, has been generally entertaining, bordering on fun. Some of my projects, such as working with SharePoint Services workflow actions in Visual Studio or building a custom iSCSI SAN using the OpenSolaris, ZFS and COMSTAR, has been quite rewarding. You may think nerd...I think developing a new trend!