Jitterbug no more.
[fvwm.git] / doc / docbook-xsl / html / verbatim.xsl
blob6c8fed8656090df51581180f6fa4fef7f9b21070
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:sverb="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Verbatim"
4 xmlns:xverb="xalan://com.nwalsh.xalan.Verbatim"
5 xmlns:lxslt="http://xml.apache.org/xslt"
6 xmlns:exsl="http://exslt.org/common"
7 exclude-result-prefixes="sverb xverb lxslt exsl"
8 version='1.0'>
10 <!-- ********************************************************************
11 $Id: verbatim.xsl,v 1.1 2007/03/10 05:15:13 scott Exp $
12 ********************************************************************
14 This file is part of the XSL DocBook Stylesheet distribution.
15 See ../README or http://nwalsh.com/docbook/xsl/ for copyright
16 and other information.
18 ******************************************************************** -->
20 <xsl:include href="../highlighting/common.xsl"/>
21 <xsl:include href="highlight.xsl"/>
23 <lxslt:component prefix="xverb"
24 functions="numberLines"/>
26 <xsl:template match="programlisting|screen|synopsis">
27 <xsl:param name="suppress-numbers" select="'0'"/>
28 <xsl:variable name="id">
29 <xsl:call-template name="object.id"/>
30 </xsl:variable>
32 <xsl:call-template name="anchor"/>
34 <xsl:if test="$shade.verbatim != 0">
35 <xsl:message>
36 <xsl:text>The shade.verbatim parameter is deprecated. </xsl:text>
37 <xsl:text>Use CSS instead,</xsl:text>
38 </xsl:message>
39 <xsl:message>
40 <xsl:text>for example: pre.</xsl:text>
41 <xsl:value-of select="local-name(.)"/>
42 <xsl:text> { background-color: #E0E0E0; }</xsl:text>
43 </xsl:message>
44 </xsl:if>
46 <xsl:choose>
47 <xsl:when test="$suppress-numbers = '0'
48 and @linenumbering = 'numbered'
49 and $use.extensions != '0'
50 and $linenumbering.extension != '0'">
51 <xsl:variable name="rtf">
52 <xsl:call-template name="apply-highlighting"/>
53 </xsl:variable>
54 <pre>
55 <xsl:apply-templates select="." mode="class.attribute"/>
56 <xsl:call-template name="number.rtf.lines">
57 <xsl:with-param name="rtf" select="$rtf"/>
58 </xsl:call-template>
59 </pre>
60 </xsl:when>
61 <xsl:otherwise>
62 <pre>
63 <xsl:apply-templates select="." mode="class.attribute"/>
64 <xsl:call-template name="apply-highlighting"/>
65 </pre>
66 </xsl:otherwise>
67 </xsl:choose>
68 </xsl:template>
70 <xsl:template match="literallayout">
71 <xsl:param name="suppress-numbers" select="'0'"/>
73 <xsl:variable name="rtf">
74 <xsl:apply-templates/>
75 </xsl:variable>
77 <xsl:if test="$shade.verbatim != 0 and @class='monospaced'">
78 <xsl:message>
79 <xsl:text>The shade.verbatim parameter is deprecated. </xsl:text>
80 <xsl:text>Use CSS instead,</xsl:text>
81 </xsl:message>
82 <xsl:message>
83 <xsl:text>for example: pre.</xsl:text>
84 <xsl:value-of select="local-name(.)"/>
85 <xsl:text> { background-color: #E0E0E0; }</xsl:text>
86 </xsl:message>
87 </xsl:if>
89 <xsl:choose>
90 <xsl:when test="$suppress-numbers = '0'
91 and @linenumbering = 'numbered'
92 and $use.extensions != '0'
93 and $linenumbering.extension != '0'">
94 <xsl:choose>
95 <xsl:when test="@class='monospaced'">
96 <pre>
97 <xsl:apply-templates select="." mode="class.attribute"/>
98 <xsl:call-template name="number.rtf.lines">
99 <xsl:with-param name="rtf" select="$rtf"/>
100 </xsl:call-template>
101 </pre>
102 </xsl:when>
103 <xsl:otherwise>
104 <div>
105 <xsl:apply-templates select="." mode="class.attribute"/>
107 <xsl:call-template name="number.rtf.lines">
108 <xsl:with-param name="rtf" select="$rtf"/>
109 </xsl:call-template>
110 </p>
111 </div>
112 </xsl:otherwise>
113 </xsl:choose>
114 </xsl:when>
115 <xsl:otherwise>
116 <xsl:choose>
117 <xsl:when test="@class='monospaced'">
118 <pre>
119 <xsl:apply-templates select="." mode="class.attribute"/>
120 <xsl:copy-of select="$rtf"/>
121 </pre>
122 </xsl:when>
123 <xsl:otherwise>
124 <div>
125 <xsl:apply-templates select="." mode="class.attribute"/>
127 <xsl:call-template name="make-verbatim">
128 <xsl:with-param name="rtf" select="$rtf"/>
129 </xsl:call-template>
130 </p>
131 </div>
132 </xsl:otherwise>
133 </xsl:choose>
134 </xsl:otherwise>
135 </xsl:choose>
136 </xsl:template>
138 <xsl:template match="address">
139 <xsl:param name="suppress-numbers" select="'0'"/>
141 <xsl:variable name="rtf">
142 <xsl:apply-templates/>
143 </xsl:variable>
145 <xsl:choose>
146 <xsl:when test="$suppress-numbers = '0'
147 and @linenumbering = 'numbered'
148 and $use.extensions != '0'
149 and $linenumbering.extension != '0'">
150 <div>
151 <xsl:apply-templates select="." mode="class.attribute"/>
153 <xsl:call-template name="number.rtf.lines">
154 <xsl:with-param name="rtf" select="$rtf"/>
155 </xsl:call-template>
156 </p>
157 </div>
158 </xsl:when>
160 <xsl:otherwise>
161 <div>
162 <xsl:apply-templates select="." mode="class.attribute"/>
164 <xsl:call-template name="make-verbatim">
165 <xsl:with-param name="rtf" select="$rtf"/>
166 </xsl:call-template>
167 </p>
168 </div>
169 </xsl:otherwise>
170 </xsl:choose>
171 </xsl:template>
173 <xsl:template name="number.rtf.lines">
174 <xsl:param name="rtf" select="''"/>
175 <xsl:param name="pi.context" select="."/>
177 <!-- Save the global values -->
178 <xsl:variable name="global.linenumbering.everyNth"
179 select="$linenumbering.everyNth"/>
181 <xsl:variable name="global.linenumbering.separator"
182 select="$linenumbering.separator"/>
184 <xsl:variable name="global.linenumbering.width"
185 select="$linenumbering.width"/>
187 <!-- Extract the <?dbhtml linenumbering.*?> PI values -->
188 <xsl:variable name="pi.linenumbering.everyNth">
189 <xsl:call-template name="dbhtml-attribute">
190 <xsl:with-param name="pis"
191 select="$pi.context/processing-instruction('dbhtml')"/>
192 <xsl:with-param name="attribute" select="'linenumbering.everyNth'"/>
193 </xsl:call-template>
194 </xsl:variable>
196 <xsl:variable name="pi.linenumbering.separator">
197 <xsl:call-template name="dbhtml-attribute">
198 <xsl:with-param name="pis"
199 select="$pi.context/processing-instruction('dbhtml')"/>
200 <xsl:with-param name="attribute" select="'linenumbering.separator'"/>
201 </xsl:call-template>
202 </xsl:variable>
204 <xsl:variable name="pi.linenumbering.width">
205 <xsl:call-template name="dbhtml-attribute">
206 <xsl:with-param name="pis"
207 select="$pi.context/processing-instruction('dbhtml')"/>
208 <xsl:with-param name="attribute" select="'linenumbering.width'"/>
209 </xsl:call-template>
210 </xsl:variable>
212 <!-- Construct the 'in-context' values -->
213 <xsl:variable name="linenumbering.everyNth">
214 <xsl:choose>
215 <xsl:when test="$pi.linenumbering.everyNth != ''">
216 <xsl:value-of select="$pi.linenumbering.everyNth"/>
217 </xsl:when>
218 <xsl:otherwise>
219 <xsl:value-of select="$global.linenumbering.everyNth"/>
220 </xsl:otherwise>
221 </xsl:choose>
222 </xsl:variable>
224 <xsl:variable name="linenumbering.separator">
225 <xsl:choose>
226 <xsl:when test="$pi.linenumbering.separator != ''">
227 <xsl:value-of select="$pi.linenumbering.separator"/>
228 </xsl:when>
229 <xsl:otherwise>
230 <xsl:value-of select="$global.linenumbering.separator"/>
231 </xsl:otherwise>
232 </xsl:choose>
233 </xsl:variable>
235 <xsl:variable name="linenumbering.width">
236 <xsl:choose>
237 <xsl:when test="$pi.linenumbering.width != ''">
238 <xsl:value-of select="$pi.linenumbering.width"/>
239 </xsl:when>
240 <xsl:otherwise>
241 <xsl:value-of select="$global.linenumbering.width"/>
242 </xsl:otherwise>
243 </xsl:choose>
244 </xsl:variable>
246 <xsl:variable name="linenumbering.startinglinenumber">
247 <xsl:choose>
248 <xsl:when test="$pi.context/@startinglinenumber">
249 <xsl:value-of select="$pi.context/@startinglinenumber"/>
250 </xsl:when>
251 <xsl:when test="$pi.context/@continuation='continues'">
252 <xsl:variable name="lastLine">
253 <xsl:choose>
254 <xsl:when test="$pi.context/self::programlisting">
255 <xsl:call-template name="lastLineNumber">
256 <xsl:with-param name="listings"
257 select="preceding::programlisting[@linenumbering='numbered']"/>
258 </xsl:call-template>
259 </xsl:when>
260 <xsl:when test="$pi.context/self::screen">
261 <xsl:call-template name="lastLineNumber">
262 <xsl:with-param name="listings"
263 select="preceding::screen[@linenumbering='numbered']"/>
264 </xsl:call-template>
265 </xsl:when>
266 <xsl:when test="$pi.context/self::literallayout">
267 <xsl:call-template name="lastLineNumber">
268 <xsl:with-param name="listings"
269 select="preceding::literallayout[@linenumbering='numbered']"/>
270 </xsl:call-template>
271 </xsl:when>
272 <xsl:when test="$pi.context/self::address">
273 <xsl:call-template name="lastLineNumber">
274 <xsl:with-param name="listings"
275 select="preceding::address[@linenumbering='numbered']"/>
276 </xsl:call-template>
277 </xsl:when>
278 <xsl:when test="$pi.context/self::synopsis">
279 <xsl:call-template name="lastLineNumber">
280 <xsl:with-param name="listings"
281 select="preceding::synopsis[@linenumbering='numbered']"/>
282 </xsl:call-template>
283 </xsl:when>
284 <xsl:otherwise>
285 <xsl:message>
286 <xsl:text>Unexpected verbatim environment: </xsl:text>
287 <xsl:value-of select="local-name($pi.context)"/>
288 </xsl:message>
289 <xsl:value-of select="0"/>
290 </xsl:otherwise>
291 </xsl:choose>
292 </xsl:variable>
294 <xsl:value-of select="$lastLine + 1"/>
295 </xsl:when>
296 <xsl:otherwise>1</xsl:otherwise>
297 </xsl:choose>
298 </xsl:variable>
300 <xsl:choose>
301 <xsl:when test="function-available('sverb:numberLines')">
302 <xsl:copy-of select="sverb:numberLines($rtf)"/>
303 </xsl:when>
304 <xsl:when test="function-available('xverb:numberLines')">
305 <xsl:copy-of select="xverb:numberLines($rtf)"/>
306 </xsl:when>
307 <xsl:otherwise>
308 <xsl:message terminate="yes">
309 <xsl:text>No numberLines function available.</xsl:text>
310 </xsl:message>
311 </xsl:otherwise>
312 </xsl:choose>
313 </xsl:template>
315 <xsl:template name="make-verbatim">
316 <xsl:param name="rtf"/>
318 <!-- I want to make this RTF verbatim. There are two possibilities: either
319 I have access to the exsl:node-set extension function and I can "do it right"
320 or I have to rely on CSS. -->
322 <xsl:choose>
323 <xsl:when test="function-available('exsl:node-set')">
324 <xsl:apply-templates select="exsl:node-set($rtf)" mode="make.verbatim.mode"/>
325 </xsl:when>
326 <xsl:otherwise>
327 <span style="white-space: pre;">
328 <xsl:copy-of select="$rtf"/>
329 </span>
330 </xsl:otherwise>
331 </xsl:choose>
332 </xsl:template>
334 <!-- ======================================================================== -->
336 <xsl:template name="lastLineNumber">
337 <xsl:param name="listings"/>
338 <xsl:param name="number" select="0"/>
340 <xsl:variable name="lines">
341 <xsl:call-template name="countLines">
342 <xsl:with-param name="listing" select="string($listings[1])"/>
343 </xsl:call-template>
344 </xsl:variable>
346 <xsl:choose>
347 <xsl:when test="not($listings)">
348 <xsl:value-of select="$number"/>
349 </xsl:when>
350 <xsl:when test="$listings[1]/@startinglinenumber">
351 <xsl:value-of select="$number + $listings[1]/@startinglinenumber + $lines - 1"/>
352 </xsl:when>
353 <xsl:when test="$listings[1]/@continuation='continues'">
354 <xsl:call-template name="lastLineNumber">
355 <xsl:with-param name="listings" select="listings[position() &gt; 1]"/>
356 <xsl:with-param name="number" select="$number + $lines"/>
357 </xsl:call-template>
358 </xsl:when>
359 <xsl:otherwise>
360 <xsl:value-of select="$lines"/>
361 </xsl:otherwise>
362 </xsl:choose>
363 </xsl:template>
365 <xsl:template name="countLines">
366 <xsl:param name="listing"/>
367 <xsl:param name="count" select="1"/>
369 <xsl:choose>
370 <xsl:when test="contains($listing, '&#10;')">
371 <xsl:call-template name="countLines">
372 <xsl:with-param name="listing" select="substring-after($listing, '&#10;')"/>
373 <xsl:with-param name="count" select="$count + 1"/>
374 </xsl:call-template>
375 </xsl:when>
376 <xsl:otherwise>
377 <xsl:value-of select="$count"/>
378 </xsl:otherwise>
379 </xsl:choose>
380 </xsl:template>
382 </xsl:stylesheet>