1 <?xml version="1.0" encoding="UTF-8"?>
3 <!-- Note the declaration of the namespace for XInclude. -->
4 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
5 xmlns:xi="http://www.w3.org/2001/XInclude">
8 <xsl:variable name="newline">
9 <xsl:text> </xsl:text>
12 <xsl:variable name="carriageReturn">
13 <xsl:text> </xsl:text>
16 <!-- =====================================================
17 Replace one string by another
18 - src: string to do substituion in
19 - from: literal string to replace
20 - to:substitution string.
21 ======================================================-->
22 <xsl:template name="string-replace">
23 <xsl:param name="src"/>
24 <xsl:param name="from"/>
25 <xsl:param name="to"/>
27 <xsl:when test="contains($src, $from)">
28 <xsl:value-of select="substring-before($src, $from)"/>
29 <xsl:value-of select="$to"/>
30 <xsl:call-template name="string-replace">
31 <xsl:with-param name="src" select="substring-after($src, $from)"/>
32 <xsl:with-param name="from" select="$from"/>
33 <xsl:with-param name="to" select="$to"/>
37 <xsl:value-of select="$src"/>
42 <xsl:template name="indent">
43 <xsl:param name="src"/>
44 <xsl:param name="indentString"/>
45 <xsl:value-of select="$indentString"/>
46 <xsl:call-template name="string-replace">
47 <xsl:with-param name="src"><xsl:value-of select="$src"/></xsl:with-param>
48 <xsl:with-param name="from"><xsl:value-of select="$newline"/></xsl:with-param>
49 <xsl:with-param name="to">
50 <xsl:value-of select="$newline"/>
51 <xsl:value-of select="$indentString"/>
56 <xsl:template name="word-wrap">
57 <xsl:param name="src"/>
58 <xsl:param name="width"/>
60 <xsl:call-template name="word-wrap-impl">
61 <xsl:with-param name="src">
62 <xsl:call-template name="string-replace">
63 <xsl:with-param name="src">
64 <xsl:value-of select="$src"/>
66 <xsl:with-param name="from"><xsl:text> </xsl:text></xsl:with-param>
67 <xsl:with-param name="to"><xsl:text> </xsl:text></xsl:with-param>
70 <xsl:with-param name="width"><xsl:value-of select="$width"/></xsl:with-param>
71 <xsl:with-param name="index"><xsl:value-of select="0"/></xsl:with-param>
75 <xsl:template name="word-wrap-impl">
76 <xsl:param name="src"/>
77 <xsl:param name="index"/>
78 <xsl:param name="width"/>
80 <xsl:variable name="word">
81 <xsl:value-of select="substring-before($src, ' ')"></xsl:value-of>
83 <xsl:variable name="wordlength">
84 <xsl:value-of select="string-length($word)"/>
86 <xsl:variable name="remainder">
87 <xsl:value-of select="substring($src, $wordlength+2)"/>
90 <xsl:if test="string-length($remainder) > 0">
92 <!-- xsl:value-of select="$wordlength"></xsl:value-of -->
93 <xsl:value-of select="$word"/><xsl:text> </xsl:text>
94 <!-- xsl:value-of select="$index"/ -->
96 <xsl:when test="$index + $wordlength + 1 > $width">
97 <xsl:value-of select="$newline"/>
98 <xsl:call-template name="word-wrap-impl">
99 <xsl:with-param name="src"><xsl:value-of select="$remainder"></xsl:value-of></xsl:with-param>
100 <xsl:with-param name="index"><xsl:value-of select="0"/></xsl:with-param>
101 <xsl:with-param name="width"><xsl:value-of select="$width"></xsl:value-of></xsl:with-param>
105 <xsl:call-template name="word-wrap-impl">
106 <xsl:with-param name="src"><xsl:value-of select="$remainder"></xsl:value-of></xsl:with-param>
107 <xsl:with-param name="index"><xsl:value-of select="$index + $wordlength+1"/></xsl:with-param>
108 <xsl:with-param name="width"><xsl:value-of select="$width"></xsl:value-of></xsl:with-param>