In here StringBreak template looping over the characters in a given string and look for the last space character within the given length. Here the looping starts from the needed size of the result string, which is CharLimit index of the given text and goes towards start until, find a space character (Actually the first space character from the searching location). Once found, it gets the index of that space character and substring from start to that character.
<!-- String Break Template -->
<xsl:template name="StringBreak">
<xsl:param name="text" />
<xsl:param name="count" />
<xsl:if test="string-length($text) <= $count" >
<xsl:value-of select="$text"/>
</xsl:if>
<xsl:if test="string-length($text) > $count" >
<xsl:if test="not($count < 1)">
<xsl:choose>
<xsl:when test="substring($text, $count + 1, 1) = ' '">
<xsl:value-of select="substring($text, 1, $count)"/> ...
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="StringBreak">
<xsl:with-param name="count" select="$count - 1" />
<xsl:with-param name="text" select="$text" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:if>
</xsl:template>
<!--Define a variable called ‘CharLimit’, which is the size of the output -->
<xsl:variable name="CharLimit" select="'30'"></xsl:variable>
<!-- Call String Break Template -->
<xsl:call-template name="StringBreak">
<xsl:with-param name="text" select="@Title" />
<xsl:with-param name="count" select="$CharLimit" />
</xsl:call-template>
No comments:
Post a Comment