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--> </xsl:call-template-->
</xsl:with-param></xsl:with-param></xsl:call-template>
Original script located at http://www.stylusstudio.com/xsllist/200104/post20940.html
I just tidy up to ease reuse.
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--> </xsl:call-template-->
</xsl:with-param></xsl:with-param></xsl:call-template>
Original script located at http://www.stylusstudio.com/xsllist/200104/post20940.html
I just tidy up to ease reuse.
Comments