Posts

Showing posts from October, 2007

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">
<xsl:text>...</xsl:text>
</xsl:if>
</xsl:value-of></xsl:param></xsl:param></xsl:template>


To use it,

just

<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--> </x…