afizzyweb

XSL to truncate word at space instead of middle of it

Posted on: November 12, 2010

Code:

<xsl:value-of select=”substring($bodyContent, 1, 200 + string-length(substring-before(substring($bodyContent, 201), ” “))))” disable-output-escaping=”yes”/>

Explanation
substring($bodyContent, 201) returns a substring from 201th character to the end.
– substring-before(substring($bodyContent, 201), ” “) returns substring from 201th character till next blank space, that’s the “remaining characters in last word”.
200 + string-length(substring-before(substring($bodyContent, 201), ” “) returns the actual number of characters you need to select.

Example:

In-complete word

Complete word

Complete word

Leave a comment

Categories