truncate-phrase.xsl

Aaron Straup Cope

$Id: truncate-phrase.xsl,v 1.1 2005/09/21 13:46:39 asc Exp $

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.


Introduction

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.

Name

truncate-phrase — Truncate a phrase at a maximum length, with the option to truncate on a word boundary.

Synopsis

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>
        

Parameters

phrase

The phrase to be truncated.

length

The number of characters to truncate the phrase to.

truncate_to_word_boundary

A boolean parameter to indicate whether or not the phrase should be truncated on a word boundary. Default is false.

trailing_string

The string to append to the truncated phrase. Default is “...”