removing RCS tags
[Samba.git] / docs / docbook / xslt / db2latex / normalize-scape.mod.xsl
blob058695d71dacf7c8ad7ae61a72599ab98c465aad
1 <?xml version='1.0'?>
2 <!--#############################################################################
3 |- #############################################################################
4 |
5 | PURPOSE:
6 | Escape LaTeX and normalize-space templates.
7 | < > # $ % & ~ _ ^ \ { }
8 + ############################################################################## -->
10 <xsl:stylesheet
11 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
12 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
13 exclude-result-prefixes="doc" version='1.0'>
16 <!--############################################################################# -->
17 <!-- DOCUMENTATION -->
18 <doc:reference id="normalize-scape" xmlns="">
19 <referenceinfo>
20 <releaseinfo role="meta">
21 </releaseinfo>
22 <authorgroup>
23 <author> <firstname>Ramon</firstname> <surname>Casellas</surname> </author>
24 <author> <firstname>James</firstname> <surname>Devenish</surname> </author>
25 </authorgroup>
26 <copyright><year>2000</year><year>2001</year><year>2002</year><year>2003</year>
27 <holder>Ramon Casellas</holder>
28 </copyright>
29 </referenceinfo>
30 <title>Normalize and Scape strings.</title>
31 <partintro>
32 <section><title>Introduction</title>
33 <para></para>
34 </section>
35 </partintro>
36 </doc:reference>
37 <!--############################################################################# -->
39 <!--############################################################################# -->
40 <!-- DOCUMENTATION -->
41 <doc:template name="normalize-scape" xmlns="">
42 <refpurpose> Abstract XSL template. </refpurpose>
43 <refdescription>
44 </refdescription>
45 </doc:template>
46 <!--############################################################################# -->
48 <xsl:template match="text()">
49 <xsl:call-template name="trim-outer">
50 <xsl:with-param name="string">
51 <xsl:choose>
52 <xsl:when test="ancestor::literal|ancestor::email|ancestor::sgmltag">
53 <xsl:call-template name="scape-verbatim">
54 <xsl:with-param name="string" select="."/>
55 </xsl:call-template>
56 </xsl:when>
57 <xsl:otherwise>
58 <xsl:call-template name="scape">
59 <xsl:with-param name="string" select="."/>
60 </xsl:call-template>
61 </xsl:otherwise>
62 </xsl:choose>
63 </xsl:with-param>
64 </xsl:call-template>
65 </xsl:template>
67 <xsl:template match="text()" mode="xref.text">
68 <xsl:call-template name="trim-outer">
69 <xsl:with-param name="string">
70 <xsl:call-template name="scape">
71 <xsl:with-param name="string" select="."/>
72 </xsl:call-template>
73 </xsl:with-param>
74 </xsl:call-template>
75 </xsl:template>
77 <xsl:template match="text()" mode="xref-to">
78 <xsl:call-template name="trim-outer">
79 <xsl:with-param name="string">
80 <xsl:call-template name="scape">
81 <xsl:with-param name="string" select="."/>
82 </xsl:call-template>
83 </xsl:with-param>
84 </xsl:call-template>
85 </xsl:template>
87 <xsl:template match="text()" mode="latex.verbatim">
88 <!--
89 <xsl:call-template name="trim-outer">
90 <xsl:with-param name="string">
91 -->
92 <xsl:value-of select="."/>
93 <!--
94 </xsl:with-param>
95 </xsl:call-template>
96 -->
97 </xsl:template>
99 <!-- this template is noly used by xref.mod.xsl and only when
100 $latex.hyphenation.tttricks != 1. -->
101 <xsl:template match="text()" mode="slash.hyphen">
102 <xsl:call-template name="trim-outer">
103 <xsl:with-param name="string">
104 <xsl:call-template name="scape.slash.hyphen">
105 <xsl:with-param name="string" select="." />
106 </xsl:call-template>
107 </xsl:with-param>
108 </xsl:call-template>
109 </xsl:template>
111 <xsl:template name="trim-outer">
112 <xsl:param name="string"/>
113 <xsl:variable name="trimleft" select="position()=1"/>
114 <xsl:variable name="trimright" select="position()=last()"/>
115 <xsl:choose>
116 <xsl:when test="$trimleft and not($trimright)">
117 <xsl:value-of select="substring-before(normalize-space(concat($string,'$$')),'$$')"/>
118 </xsl:when>
119 <xsl:when test="$trimright and not($trimleft)">
120 <xsl:value-of select="substring-after(normalize-space(concat('$$',$string)),'$$')"/>
121 </xsl:when>
122 <xsl:when test="$trimleft and $trimright">
123 <xsl:value-of select="normalize-space($string)"/>
124 </xsl:when>
125 <xsl:otherwise>
126 <xsl:value-of select="$string"/>
127 </xsl:otherwise>
128 </xsl:choose>
129 </xsl:template>
131 <xsl:template name="scape.slash.hyphen">
132 <xsl:param name="string" />
133 <xsl:choose>
134 <xsl:when test="contains($string,'://')">
135 <xsl:call-template name="string-replace">
136 <xsl:with-param name="to">/\-</xsl:with-param>
137 <xsl:with-param name="from">/</xsl:with-param>
138 <xsl:with-param name="string">
139 <xsl:value-of select="substring-before($string,'://')"/>
140 <xsl:value-of select="'://'"/>
141 <xsl:call-template name="scape">
142 <xsl:with-param name="string" select="substring-after($string,'://')"/>
143 </xsl:call-template></xsl:with-param>
144 </xsl:call-template>
145 </xsl:when>
146 <xsl:otherwise>
147 <xsl:call-template name="string-replace">
148 <xsl:with-param name="to">/\-</xsl:with-param>
149 <xsl:with-param name="from">/</xsl:with-param>
150 <xsl:with-param name="string">
151 <xsl:call-template name="scape">
152 <xsl:with-param name="string" select="$string"/>
153 </xsl:call-template></xsl:with-param>
154 </xsl:call-template>
155 </xsl:otherwise>
156 </xsl:choose>
157 </xsl:template>
159 <xsl:template name="normalize-scape" >
160 <xsl:param name="string"/>
161 <xsl:variable name="result">
162 <xsl:call-template name="scape"><xsl:with-param name="string" select="$string"/></xsl:call-template>
163 </xsl:variable>
164 <xsl:value-of select="normalize-space($result)"/>
165 </xsl:template>
168 <xsl:template name="scape" >
169 <xsl:param name="string"/>
170 <xsl:call-template name="string-replace">
171 <xsl:with-param name="to">\textless{}</xsl:with-param>
172 <xsl:with-param name="from">&lt;</xsl:with-param>
173 <xsl:with-param name="string">
174 <xsl:call-template name="string-replace">
175 <xsl:with-param name="to">\textgreater{}</xsl:with-param>
176 <xsl:with-param name="from">&gt;</xsl:with-param>
177 <xsl:with-param name="string">
178 <xsl:call-template name="string-replace">
179 <xsl:with-param name="to">\textasciitilde{}</xsl:with-param>
180 <xsl:with-param name="from">~</xsl:with-param>
181 <xsl:with-param name="string">
182 <xsl:call-template name="string-replace">
183 <xsl:with-param name="to">\^{}</xsl:with-param>
184 <xsl:with-param name="from">^</xsl:with-param>
185 <xsl:with-param name="string">
186 <xsl:call-template name="string-replace">
187 <xsl:with-param name="to">\&amp;</xsl:with-param>
188 <xsl:with-param name="from">&amp;</xsl:with-param>
189 <xsl:with-param name="string">
190 <xsl:call-template name="string-replace">
191 <xsl:with-param name="to">\#</xsl:with-param>
192 <xsl:with-param name="from">#</xsl:with-param>
193 <xsl:with-param name="string">
194 <xsl:call-template name="string-replace">
195 <xsl:with-param name="to">\_</xsl:with-param>
196 <xsl:with-param name="from">_</xsl:with-param>
197 <xsl:with-param name="string">
198 <xsl:call-template name="string-replace">
199 <xsl:with-param name="to">\$</xsl:with-param>
200 <xsl:with-param name="from">$</xsl:with-param>
201 <xsl:with-param name="string">
202 <xsl:call-template name="string-replace">
203 <xsl:with-param name="to">\%</xsl:with-param>
204 <xsl:with-param name="from">%</xsl:with-param>
205 <xsl:with-param name="string">
206 <xsl:call-template name="string-replace">
207 <xsl:with-param name="to">\{</xsl:with-param>
208 <xsl:with-param name="from">{</xsl:with-param>
209 <xsl:with-param name="string">
210 <xsl:call-template name="string-replace">
211 <xsl:with-param name="to">\}</xsl:with-param>
212 <xsl:with-param name="from">}</xsl:with-param>
213 <xsl:with-param name="string">
214 <xsl:call-template name="string-replace">
215 <xsl:with-param name="to">\textbackslash \ </xsl:with-param>
216 <xsl:with-param name="from">\textbackslash </xsl:with-param>
217 <xsl:with-param name="string">
218 <xsl:call-template name="string-replace">
219 <xsl:with-param name="to">\textbackslash </xsl:with-param>
220 <xsl:with-param name="from">\</xsl:with-param>
221 <xsl:with-param name="string" select="$string"></xsl:with-param>
222 </xsl:call-template>
223 </xsl:with-param>
224 </xsl:call-template></xsl:with-param>
225 </xsl:call-template></xsl:with-param>
226 </xsl:call-template></xsl:with-param>
227 </xsl:call-template></xsl:with-param>
228 </xsl:call-template></xsl:with-param>
229 </xsl:call-template></xsl:with-param>
230 </xsl:call-template></xsl:with-param>
231 </xsl:call-template></xsl:with-param>
232 </xsl:call-template></xsl:with-param>
233 </xsl:call-template></xsl:with-param>
234 </xsl:call-template></xsl:with-param>
235 </xsl:call-template>
236 </xsl:template>
238 <xsl:template name="scape-verbatim" >
239 <xsl:param name="string"/>
240 <xsl:call-template name="string-replace">
241 <xsl:with-param name="to">\textasciitilde{}</xsl:with-param>
242 <xsl:with-param name="from">~</xsl:with-param>
243 <xsl:with-param name="string">
244 <xsl:call-template name="string-replace">
245 <xsl:with-param name="to">\^{}</xsl:with-param>
246 <xsl:with-param name="from">^</xsl:with-param>
247 <xsl:with-param name="string">
248 <xsl:call-template name="string-replace">
249 <xsl:with-param name="to">\&amp;</xsl:with-param>
250 <xsl:with-param name="from">&amp;</xsl:with-param>
251 <xsl:with-param name="string">
252 <xsl:call-template name="string-replace">
253 <xsl:with-param name="to">\#</xsl:with-param>
254 <xsl:with-param name="from">#</xsl:with-param>
255 <xsl:with-param name="string">
256 <xsl:call-template name="string-replace">
257 <xsl:with-param name="to">\_</xsl:with-param>
258 <xsl:with-param name="from">_</xsl:with-param>
259 <xsl:with-param name="string">
260 <xsl:call-template name="string-replace">
261 <xsl:with-param name="to">\$</xsl:with-param>
262 <xsl:with-param name="from">$</xsl:with-param>
263 <xsl:with-param name="string">
264 <xsl:call-template name="string-replace">
265 <xsl:with-param name="to">\%</xsl:with-param>
266 <xsl:with-param name="from">%</xsl:with-param>
267 <xsl:with-param name="string">
268 <xsl:call-template name="string-replace">
269 <xsl:with-param name="to">\docbooktolatexgobble\string\{</xsl:with-param>
270 <xsl:with-param name="from">{</xsl:with-param>
271 <xsl:with-param name="string">
272 <xsl:call-template name="string-replace">
273 <xsl:with-param name="to">\docbooktolatexgobble\string\}</xsl:with-param>
274 <xsl:with-param name="from">}</xsl:with-param>
275 <xsl:with-param name="string">
276 <xsl:call-template name="string-replace">
277 <xsl:with-param name="to">\docbooktolatexgobble\string\\</xsl:with-param>
278 <xsl:with-param name="from">\</xsl:with-param>
279 <xsl:with-param name="string" select="$string"/>
280 </xsl:call-template>
281 </xsl:with-param>
282 </xsl:call-template></xsl:with-param>
283 </xsl:call-template></xsl:with-param>
284 </xsl:call-template></xsl:with-param>
285 </xsl:call-template></xsl:with-param>
286 </xsl:call-template></xsl:with-param>
287 </xsl:call-template></xsl:with-param>
288 </xsl:call-template></xsl:with-param>
289 </xsl:call-template></xsl:with-param>
290 </xsl:call-template>
291 </xsl:template>
293 <xsl:template name="scape-href" >
294 <xsl:param name="string"/>
295 <!-- maybe we should warn when there are invalid characters -->
296 <xsl:call-template name="string-replace">
297 <xsl:with-param name="to">\&amp;</xsl:with-param>
298 <xsl:with-param name="from">&amp;</xsl:with-param>
299 <xsl:with-param name="string">
300 <xsl:call-template name="string-replace">
301 <xsl:with-param name="to">\%</xsl:with-param>
302 <xsl:with-param name="from">%</xsl:with-param>
303 <xsl:with-param name="string">
304 <xsl:call-template name="string-replace">
305 <xsl:with-param name="to">\{</xsl:with-param>
306 <xsl:with-param name="from">{</xsl:with-param>
307 <xsl:with-param name="string">
308 <xsl:call-template name="string-replace">
309 <xsl:with-param name="to">\{</xsl:with-param>
310 <xsl:with-param name="from">{</xsl:with-param>
311 <xsl:with-param name="string">
312 <xsl:call-template name="string-replace">
313 <xsl:with-param name="to">\docbooktolatexgobble\string\\</xsl:with-param>
314 <xsl:with-param name="from">\</xsl:with-param>
315 <xsl:with-param name="string" select="$string"/>
316 </xsl:call-template>
317 </xsl:with-param>
318 </xsl:call-template>
319 </xsl:with-param>
320 </xsl:call-template>
321 </xsl:with-param>
322 </xsl:call-template>
323 </xsl:with-param>
324 </xsl:call-template>
325 </xsl:template>
327 <doc:template name="scape-optionalarg" xmlns="">
328 <refpurpose> Escape the ] character in LaTeX optional arguments (experimental) </refpurpose>
329 <refdescription>
330 </refdescription>
331 </doc:template>
332 <xsl:template name="scape-optionalarg" >
333 <xsl:param name="string"/>
334 <xsl:call-template name="string-replace">
335 <xsl:with-param name="to">{\rbrack}</xsl:with-param>
336 <xsl:with-param name="from">]</xsl:with-param>
337 <xsl:with-param name="string" select="$string"/>
338 </xsl:call-template>
339 </xsl:template>
344 <xsl:template name="string-replace">
345 <xsl:param name="string"/>
346 <xsl:param name="from"/>
347 <xsl:param name="to"/>
349 <xsl:choose>
350 <xsl:when test="contains($string, $from)">
352 <xsl:variable name="before" select="substring-before($string, $from)"/>
353 <xsl:variable name="after" select="substring-after($string, $from)"/>
354 <xsl:variable name="prefix" select="concat($before, $to)"/>
356 <xsl:value-of select="$before"/>
357 <xsl:value-of select="$to"/>
358 <xsl:call-template name="string-replace">
359 <xsl:with-param name="string" select="$after"/>
360 <xsl:with-param name="from" select="$from"/>
361 <xsl:with-param name="to" select="$to"/>
362 </xsl:call-template>
363 </xsl:when>
364 <xsl:otherwise>
365 <xsl:value-of select="$string"/>
366 </xsl:otherwise>
367 </xsl:choose>
368 </xsl:template>
373 <!--
374 (c) David Carlisle
375 replace all occurences of the character(s) `from'
376 by the string `to' in the string `string'.
377 <xsl:template name="string-replace" >
378 <xsl:param name="string"/>
379 <xsl:param name="from"/>
380 <xsl:param name="to"/>
381 <xsl:choose>
382 <xsl:when test="contains($string,$from)">
383 <xsl:value-of select="substring-before($string,$from)"/>
384 <xsl:value-of select="$to"/>
385 <xsl:call-template name="string-replace">
386 <xsl:with-param name="string" select="substring-after($string,$from)"/>
387 <xsl:with-param name="from" select="$from"/>
388 <xsl:with-param name="to" select="$to"/>
389 </xsl:call-template>
390 </xsl:when>
391 <xsl:otherwise>
392 <xsl:value-of select="$string"/>
393 </xsl:otherwise>
394 </xsl:choose>
395 </xsl:template>
398 </xsl:stylesheet>