Skip to content

Instantly share code, notes, and snippets.

@michmy
Created March 11, 2014 18:27
Show Gist options
  • Save michmy/9491957 to your computer and use it in GitHub Desktop.
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
<!-- 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