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"/>
69 <xsl:text> </xsl:text>
71 <xsl:with-param name="from">
72 <xsl:text> </xsl:text>
74 <xsl:with-param name="to">
75 <xsl:text> </xsl:text>
79 <xsl:with-param name="width">
80 <xsl:value-of select="$width"/>
82 <xsl:with-param name="index">
83 <xsl:value-of select="0"/>
88 <xsl:template name="word-wrap-impl">
89 <xsl:param name="src"/>
90 <xsl:param name="index"/>
91 <xsl:param name="width"/>
93 <xsl:variable name="word">
94 <xsl:value-of select="substring-before($src, ' ')"/>
96 <xsl:variable name="wordlength">
97 <xsl:value-of select="string-length($word)"/>
99 <xsl:variable name="remainder">
100 <xsl:value-of select="substring($src, $wordlength+2)"/>
104 <xsl:when test="$index + $wordlength + 1 > $width">
105 <xsl:value-of select="$newline"/>
106 <xsl:value-of select="$word"/>
107 <xsl:text> </xsl:text>
108 <xsl:if test="string-length($remainder) > 0">
109 <xsl:call-template name="word-wrap-impl">
110 <xsl:with-param name="src">
111 <xsl:value-of select="$remainder"/>
113 <xsl:with-param name="index">
114 <xsl:value-of select="$wordlength + 1"/>
116 <xsl:with-param name="width">
117 <xsl:value-of select="$width"/>
123 <xsl:value-of select="$word"/>
124 <xsl:text> </xsl:text>
126 <xsl:if test="string-length($remainder) > 0">
127 <xsl:call-template name="word-wrap-impl">
128 <xsl:with-param name="src">
129 <xsl:value-of select="$remainder"/>
131 <xsl:with-param name="index">
132 <xsl:value-of select="$index + $wordlength+1"/>
134 <xsl:with-param name="width">
135 <xsl:value-of select="$width"/>