$Id: truncate-phrase.xsl,v 1.1 2005/09/21 13:46:39 asc Exp $
Copyright © 2005 Aaron Straup Cope
Permission to use, copy, modify and distribute this stylesheet and its accompanying documentation for any purpose and without fee is hereby granted in perpetuity, provided that the above copyright notice and this paragraph appear in all copies. The copyright holders make no representation about the suitability of the stylesheet for any purpose.
The truncate phrase stylesheet defines a single public template that will truncate a phrase at a maximum length, with the option to truncate on a word boundary.
This template is not internationalized and assumes a left-to-right writing orientation. Patches are welcome.
Table of Contents
truncate-phrase — Truncate a phrase at a maximum length, with the option to truncate on a word boundary.
Example 1. Using the truncate-phrase template in your stylesheet
<xsl:include href="/path/to/truncate-phrase.xsl" /> <xsl:call-template name="truncate_phrase"> <xsl:with-param name="phrase"> <xsl:value-of select="/h:html/h:head/h:link[@rel='next']/@title" /> </xsl:with-param> <xsl:with-param name="length" select="25" /> <xsl:with-param name="truncate_to_word_boundary" select="1" /> </xsl:call-template>
The phrase to be truncated.
The number of characters to truncate the phrase to.
A boolean parameter to indicate whether or not the phrase should be truncated on a word boundary. Default is false.
The string to append to the truncated phrase. Default is “...”