Created
March 11, 2014 18:27
-
-
Save michmy/9491957 to your computer and use it in GitHub Desktop.
This template will truncate a phrase at a maximum length, with the option to truncate on a word boundary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- http://aaronland.info/xsl/string/truncate-phrase --> | |
<!-- This template will truncate a phrase at a maximum length, with the option to truncate on a word boundary --> | |
<xsl:template name="globalReplace"> | |
<xsl:param name="outputString"/> | |
<xsl:param name="target"/> | |
<xsl:param name="replacement"/> | |
<xsl:choose> | |
<xsl:when test="contains($outputString,$target)"> | |
<xsl:value-of select="concat(substring-before($outputString,$target),$replacement)"/> | |
<xsl:call-template name="globalReplace"> | |
<xsl:with-param name="outputString" select="substring-after($outputString,$target)"/> | |
<xsl:with-param name="target" select="$target"/> | |
<xsl:with-param name="replacement" select="$replacement"/> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$outputString"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment