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">
48 <xsl:value-of select="$src"/>
50 <xsl:with-param name="from">
51 <xsl:value-of select="$newline"/>
53 <xsl:with-param name="to">
54 <xsl:value-of select="$newline"/>
55 <xsl:value-of select="$indentString"/>
60 <xsl:template name="word-wrap">
61 <xsl:param name="src"/>
62 <xsl:param name="width"/>
64 <xsl:call-template name="word-wrap-impl">
65 <xsl:with-param name="src">
66 <xsl:call-template name="string-replace">
67 <xsl:with-param name="src">
68 <xsl:value-of select="$src"/>
70 <xsl:with-param name="from">
71 <xsl:text> </xsl:text>
73 <xsl:with-param name="to">
74 <xsl:text> </xsl:text>
78 <xsl:with-param name="width">
79 <xsl:value-of select="$width"/>
81 <xsl:with-param name="index">
82 <xsl:value-of select="0"/>
87 <xsl:template name="word-wrap-impl">
88 <xsl:param name="src"/>
89 <xsl:param name="index"/>
90 <xsl:param name="width"/>
92 <xsl:variable name="word">
93 <xsl:value-of select="substring-before($src, ' ')"/>
95 <xsl:variable name="wordlength">
96 <xsl:value-of select="string-length($word)"/>
98 <xsl:variable name="remainder">
99 <xsl:value-of select="substring($src, $wordlength+2)"/>
103 <xsl:when test="$index + $wordlength + 1 > $width">
104 <xsl:value-of select="$newline"/>
105 <xsl:value-of select="$word"/>
106 <xsl:text> </xsl:text>
107 <xsl:if test="string-length($remainder) > 0">
108 <xsl:call-template name="word-wrap-impl">
109 <xsl:with-param name="src">
110 <xsl:value-of select="$remainder"/>
112 <xsl:with-param name="index">
113 <xsl:value-of select="$wordlength + 1"/>
115 <xsl:with-param name="width">
116 <xsl:value-of select="$width"/>
122 <xsl:value-of select="$word"/>
123 <xsl:text> </xsl:text>
125 <xsl:if test="string-length($remainder) > 0">
126 <xsl:call-template name="word-wrap-impl">
127 <xsl:with-param name="src">
128 <xsl:value-of select="$remainder"/>
130 <xsl:with-param name="index">
131 <xsl:value-of select="$index + $wordlength+1"/>
133 <xsl:with-param name="width">
134 <xsl:value-of select="$width"/>