1 <?xml version='1.0' encoding="utf-8"?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:fo="http://www.w3.org/1999/XSL/Format"
6 <!-- ********************************************************************
7 $Id: spaces.xsl 9647 2012-10-26 17:42:03Z bobstayton $
8 ********************************************************************
9 XSL-FO specification treats all space characters like ordinary spaces.
10 We need to map them to fo:leader with different widths in order to
11 simulate desired behaviour.
12 ******************************************************************** -->
14 <xsl:template match="text()[namespace-uri(..) = '' or
15 namespace-uri(..) = 'http://docbook.org/ns/docbook']">
16 <xsl:call-template name="space.2000.subst">
17 <xsl:with-param name="string" select="."/>
21 <xsl:param name="space.enquad.width">0.5em</xsl:param> <!-- U+2000 -->
22 <xsl:param name="space.emquad.width">1em</xsl:param> <!-- U+2001 -->
23 <xsl:param name="space.enspace.width">0.5em</xsl:param> <!-- U+2002 -->
24 <xsl:param name="space.emspace.width">1em</xsl:param> <!-- U+2003 -->
25 <xsl:param name="space.3emspace.width">0.33em</xsl:param><!-- U+2004 -->
26 <xsl:param name="space.4emspace.width">0.25em</xsl:param><!-- U+2005 -->
27 <xsl:param name="space.6emspace.width">0.16em</xsl:param><!-- U+2006 -->
28 <xsl:param name="space.figspace.width"></xsl:param> <!-- U+2007 -->
29 <xsl:param name="space.punctspace.width"></xsl:param> <!-- U+2008 -->
30 <xsl:param name="space.thinspace.width">0.2em</xsl:param><!-- U+2009 -->
31 <xsl:param name="space.hairspace.width">0.1em</xsl:param><!-- U+200A -->
33 <xsl:template name="space.2000.subst">
34 <xsl:param name="string"/>
37 <xsl:when test="contains($string, ' ') and $space.enquad.width != ''">
38 <xsl:call-template name="space.2001.subst">
39 <xsl:with-param name="string" select="substring-before($string, ' ')"/>
41 <fo:leader leader-length="{$space.enquad.width}"/>
42 <xsl:call-template name="space.2000.subst">
43 <xsl:with-param name="string" select="substring-after($string, ' ')"/>
47 <xsl:call-template name="space.2001.subst">
48 <xsl:with-param name="string" select="$string"/>
54 <xsl:template name="space.2001.subst">
55 <xsl:param name="string"/>
58 <xsl:when test="contains($string, ' ') and $space.emquad.width != ''">
59 <xsl:call-template name="space.2002.subst">
60 <xsl:with-param name="string" select="substring-before($string, ' ')"/>
62 <fo:leader leader-length="{$space.emquad.width}"/>
63 <xsl:call-template name="space.2001.subst">
64 <xsl:with-param name="string" select="substring-after($string, ' ')"/>
68 <xsl:call-template name="space.2002.subst">
69 <xsl:with-param name="string" select="$string"/>
75 <xsl:template name="space.2002.subst">
76 <xsl:param name="string"/>
79 <xsl:when test="contains($string, ' ') and $space.enspace.width != ''">
80 <xsl:call-template name="space.2003.subst">
81 <xsl:with-param name="string" select="substring-before($string, ' ')"/>
83 <fo:leader leader-length="{$space.enspace.width}"/>
84 <xsl:call-template name="space.2002.subst">
85 <xsl:with-param name="string" select="substring-after($string, ' ')"/>
89 <xsl:call-template name="space.2003.subst">
90 <xsl:with-param name="string" select="$string"/>
96 <xsl:template name="space.2003.subst">
97 <xsl:param name="string"/>
100 <xsl:when test="contains($string, ' ') and $space.emspace.width != ''">
101 <xsl:call-template name="space.2004.subst">
102 <xsl:with-param name="string" select="substring-before($string, ' ')"/>
104 <fo:leader leader-length="{$space.emspace.width}"/>
105 <xsl:call-template name="space.2003.subst">
106 <xsl:with-param name="string" select="substring-after($string, ' ')"/>
110 <xsl:call-template name="space.2004.subst">
111 <xsl:with-param name="string" select="$string"/>
117 <xsl:template name="space.2004.subst">
118 <xsl:param name="string"/>
121 <xsl:when test="contains($string, ' ') and $space.3emspace.width != ''">
122 <xsl:call-template name="space.2005.subst">
123 <xsl:with-param name="string" select="substring-before($string, ' ')"/>
125 <fo:leader leader-length="{$space.3emspace.width}"/>
126 <xsl:call-template name="space.2004.subst">
127 <xsl:with-param name="string" select="substring-after($string, ' ')"/>
131 <xsl:call-template name="space.2005.subst">
132 <xsl:with-param name="string" select="$string"/>
138 <xsl:template name="space.2005.subst">
139 <xsl:param name="string"/>
142 <xsl:when test="contains($string, ' ') and $space.4emspace.width != ''">
143 <xsl:call-template name="space.2006.subst">
144 <xsl:with-param name="string" select="substring-before($string, ' ')"/>
146 <fo:leader leader-length="{$space.4emspace.width}"/>
147 <xsl:call-template name="space.2005.subst">
148 <xsl:with-param name="string" select="substring-after($string, ' ')"/>
152 <xsl:call-template name="space.2006.subst">
153 <xsl:with-param name="string" select="$string"/>
159 <xsl:template name="space.2006.subst">
160 <xsl:param name="string"/>
163 <xsl:when test="contains($string, ' ') and $space.6emspace.width != ''">
164 <xsl:call-template name="space.2007.subst">
165 <xsl:with-param name="string" select="substring-before($string, ' ')"/>
167 <fo:leader leader-length="{$space.6emspace.width}"/>
168 <xsl:call-template name="space.2006.subst">
169 <xsl:with-param name="string" select="substring-after($string, ' ')"/>
173 <xsl:call-template name="space.2007.subst">
174 <xsl:with-param name="string" select="$string"/>
180 <xsl:template name="space.2007.subst">
181 <xsl:param name="string"/>
184 <xsl:when test="contains($string, ' ') and $space.figspace.width != ''">
185 <xsl:call-template name="space.2008.subst">
186 <xsl:with-param name="string" select="substring-before($string, ' ')"/>
188 <fo:leader leader-length="{$space.figspace.width}"/>
189 <xsl:call-template name="space.2007.subst">
190 <xsl:with-param name="string" select="substring-after($string, ' ')"/>
194 <xsl:call-template name="space.2008.subst">
195 <xsl:with-param name="string" select="$string"/>
201 <xsl:template name="space.2008.subst">
202 <xsl:param name="string"/>
205 <xsl:when test="contains($string, ' ') and $space.punctspace.width != ''">
206 <xsl:call-template name="space.2009.subst">
207 <xsl:with-param name="string" select="substring-before($string, ' ')"/>
209 <fo:leader leader-length="{$space.punctspace.width}"/>
210 <xsl:call-template name="space.2008.subst">
211 <xsl:with-param name="string" select="substring-after($string, ' ')"/>
215 <xsl:call-template name="space.2009.subst">
216 <xsl:with-param name="string" select="$string"/>
222 <xsl:template name="space.2009.subst">
223 <xsl:param name="string"/>
226 <xsl:when test="contains($string, ' ') and $space.thinspace.width != ''">
227 <xsl:call-template name="space.200A.subst">
228 <xsl:with-param name="string" select="substring-before($string, ' ')"/>
230 <fo:leader leader-length="{$space.thinspace.width}"/>
231 <xsl:call-template name="space.2009.subst">
232 <xsl:with-param name="string" select="substring-after($string, ' ')"/>
236 <xsl:call-template name="space.200A.subst">
237 <xsl:with-param name="string" select="$string"/>
243 <xsl:template name="space.200A.subst">
244 <xsl:param name="string"/>
247 <xsl:when test="contains($string, ' ') and $space.hairspace.width != ''">
248 <xsl:value-of select="substring-before($string, ' ')"/>
249 <fo:leader leader-length="{$space.hairspace.width}"/>
250 <xsl:call-template name="space.200A.subst">
251 <xsl:with-param name="string" select="substring-after($string, ' ')"/>
255 <xsl:value-of select="$string"/>