Truncate String in XSL call-template

The purpose is to just prune the string and add ... at the end when certain size of the string in xsl output exceeded.
This method do not burden CPU much. (as some using recursive ways do)

<!-- include this into XSL stylesheet -->

<xsl:template name="fixed-string">
<xsl:param name="targetVar">
<xsl:param name="allowable-length">
<xsl:value-of select="substring($targetVar, 1, $allowable-length)">
<xsl:if test="string-length($targetVar) & gt ; $allowable-length">

To use it,


<xsl:call-template name="fixed-string">
<xsl:with-param name="targetVar">'<xsl:value-of select="MyContent">'</xsl:value-of>
<xsl:with-param name="allowable-length" select="15"> <!-- say, limited to 15 chars--> </xsl:call-template-->

Original script located at
I just tidy up to ease reuse.


Popular posts from this blog

Clearcase check in/uncheck out all the checked out files script

Duplicating a local copy of project from TFS and making web software client factory to work