Debian Codegraph @

docs/xsl-generic/html/verbatim.xsl

raw
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'>
9
10 <!-- ********************************************************************
11 $Id: verbatim.xsl 6946 2007-07-04 10:21:57Z xmldoc $
12 ********************************************************************
13
14 This file is part of the XSL DocBook Stylesheet distribution.
15 See ../README or http://docbook.sf.net/release/xsl/current/ for
16 copyright and other information.
17
18 ******************************************************************** -->
19
20 <xsl:include href="../highlighting/common.xsl"/>
21 <xsl:include href="highlight.xsl"/>
22
23 <lxslt:component prefix="xverb"
24 functions="numberLines"/>
25
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>
31
32 <xsl:call-template name="anchor"/>
33
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>
45
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>
69
70 <xsl:template match="literallayout">
71 <xsl:param name="suppress-numbers" select="'0'"/>
72
73 <xsl:variable name="rtf">
74 <xsl:apply-templates/>
75 </xsl:variable>
76
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>
88
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"/>
106 <p>
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"/>
126 <p>
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>
137
138 <xsl:template match="address">
139 <xsl:param name="suppress-numbers" select="'0'"/>
140
141 <xsl:variable name="rtf">
142 <xsl:apply-templates/>
143 </xsl:variable>
144
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"/>
152 <p>
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>
159
160 <xsl:otherwise>
161 <div>
162 <xsl:apply-templates select="." mode="class.attribute"/>
163 <p>
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>
172
173 <xsl:template name="number.rtf.lines">
174 <xsl:param name="rtf" select="''"/>
175 <xsl:param name="pi.context" select="."/>
176
177 <!-- Save the global values -->
178 <xsl:variable name="global.linenumbering.everyNth"
179 select="$linenumbering.everyNth"/>
180
181 <xsl:variable name="global.linenumbering.separator"
182 select="$linenumbering.separator"/>
183
184 <xsl:variable name="global.linenumbering.width"
185 select="$linenumbering.width"/>
186
187 <!-- Extract the <?dbhtml linenumbering.*?> PI values -->
188 <xsl:variable name="pi.linenumbering.everyNth">
189 <xsl:call-template name="pi.dbhtml_linenumbering.everyNth">
190 <xsl:with-param name="node" select="$pi.context"/>
191 </xsl:call-template>
192 </xsl:variable>
193
194 <xsl:variable name="pi.linenumbering.separator">
195 <xsl:call-template name="pi.dbhtml_linenumbering.separator">
196 <xsl:with-param name="node" select="$pi.context"/>
197 </xsl:call-template>
198 </xsl:variable>
199
200 <xsl:variable name="pi.linenumbering.width">
201 <xsl:call-template name="pi.dbhtml_linenumbering.width">
202 <xsl:with-param name="node" select="$pi.context"/>
203 </xsl:call-template>
204 </xsl:variable>
205
206 <!-- Construct the 'in-context' values -->
207 <xsl:variable name="linenumbering.everyNth">
208 <xsl:choose>
209 <xsl:when test="$pi.linenumbering.everyNth != ''">
210 <xsl:value-of select="$pi.linenumbering.everyNth"/>
211 </xsl:when>
212 <xsl:otherwise>
213 <xsl:value-of select="$global.linenumbering.everyNth"/>
214 </xsl:otherwise>
215 </xsl:choose>
216 </xsl:variable>
217
218 <xsl:variable name="linenumbering.separator">
219 <xsl:choose>
220 <xsl:when test="$pi.linenumbering.separator != ''">
221 <xsl:value-of select="$pi.linenumbering.separator"/>
222 </xsl:when>
223 <xsl:otherwise>
224 <xsl:value-of select="$global.linenumbering.separator"/>
225 </xsl:otherwise>
226 </xsl:choose>
227 </xsl:variable>
228
229 <xsl:variable name="linenumbering.width">
230 <xsl:choose>
231 <xsl:when test="$pi.linenumbering.width != ''">
232 <xsl:value-of select="$pi.linenumbering.width"/>
233 </xsl:when>
234 <xsl:otherwise>
235 <xsl:value-of select="$global.linenumbering.width"/>
236 </xsl:otherwise>
237 </xsl:choose>
238 </xsl:variable>
239
240 <xsl:variable name="linenumbering.startinglinenumber">
241 <xsl:choose>
242 <xsl:when test="$pi.context/@startinglinenumber">
243 <xsl:value-of select="$pi.context/@startinglinenumber"/>
244 </xsl:when>
245 <xsl:when test="$pi.context/@continuation='continues'">
246 <xsl:variable name="lastLine">
247 <xsl:choose>
248 <xsl:when test="$pi.context/self::programlisting">
249 <xsl:call-template name="lastLineNumber">
250 <xsl:with-param name="listings"
251 select="preceding::programlisting[@linenumbering='numbered']"/>
252 </xsl:call-template>
253 </xsl:when>
254 <xsl:when test="$pi.context/self::screen">
255 <xsl:call-template name="lastLineNumber">
256 <xsl:with-param name="listings"
257 select="preceding::screen[@linenumbering='numbered']"/>
258 </xsl:call-template>
259 </xsl:when>
260 <xsl:when test="$pi.context/self::literallayout">
261 <xsl:call-template name="lastLineNumber">
262 <xsl:with-param name="listings"
263 select="preceding::literallayout[@linenumbering='numbered']"/>
264 </xsl:call-template>
265 </xsl:when>
266 <xsl:when test="$pi.context/self::address">
267 <xsl:call-template name="lastLineNumber">
268 <xsl:with-param name="listings"
269 select="preceding::address[@linenumbering='numbered']"/>
270 </xsl:call-template>
271 </xsl:when>
272 <xsl:when test="$pi.context/self::synopsis">
273 <xsl:call-template name="lastLineNumber">
274 <xsl:with-param name="listings"
275 select="preceding::synopsis[@linenumbering='numbered']"/>
276 </xsl:call-template>
277 </xsl:when>
278 <xsl:otherwise>
279 <xsl:message>
280 <xsl:text>Unexpected verbatim environment: </xsl:text>
281 <xsl:value-of select="local-name($pi.context)"/>
282 </xsl:message>
283 <xsl:value-of select="0"/>
284 </xsl:otherwise>
285 </xsl:choose>
286 </xsl:variable>
287
288 <xsl:value-of select="$lastLine + 1"/>
289 </xsl:when>
290 <xsl:otherwise>1</xsl:otherwise>
291 </xsl:choose>
292 </xsl:variable>
293
294 <xsl:choose>
295 <xsl:when test="function-available('sverb:numberLines')">
296 <xsl:copy-of select="sverb:numberLines($rtf)"/>
297 </xsl:when>
298 <xsl:when test="function-available('xverb:numberLines')">
299 <xsl:copy-of select="xverb:numberLines($rtf)"/>
300 </xsl:when>
301 <xsl:otherwise>
302 <xsl:message terminate="yes">
303 <xsl:text>No numberLines function available.</xsl:text>
304 </xsl:message>
305 </xsl:otherwise>
306 </xsl:choose>
307 </xsl:template>
308
309 <xsl:template name="make-verbatim">
310 <xsl:param name="rtf"/>
311
312 <!-- I want to make this RTF verbatim. There are two possibilities: either
313 I have access to the exsl:node-set extension function and I can "do it right"
314 or I have to rely on CSS. -->
315
316 <xsl:choose>
317 <xsl:when test="function-available('exsl:node-set')">
318 <xsl:apply-templates select="exsl:node-set($rtf)" mode="make.verbatim.mode"/>
319 </xsl:when>
320 <xsl:otherwise>
321 <span style="white-space: pre;">
322 <xsl:copy-of select="$rtf"/>
323 </span>
324 </xsl:otherwise>
325 </xsl:choose>
326 </xsl:template>
327
328 <!-- ======================================================================== -->
329
330 <xsl:template name="lastLineNumber">
331 <xsl:param name="listings"/>
332 <xsl:param name="number" select="0"/>
333
334 <xsl:variable name="lines">
335 <xsl:call-template name="countLines">
336 <xsl:with-param name="listing" select="string($listings[1])"/>
337 </xsl:call-template>
338 </xsl:variable>
339
340 <xsl:choose>
341 <xsl:when test="not($listings)">
342 <xsl:value-of select="$number"/>
343 </xsl:when>
344 <xsl:when test="$listings[1]/@startinglinenumber">
345 <xsl:value-of select="$number + $listings[1]/@startinglinenumber + $lines - 1"/>
346 </xsl:when>
347 <xsl:when test="$listings[1]/@continuation='continues'">
348 <xsl:call-template name="lastLineNumber">
349 <xsl:with-param name="listings" select="listings[position() &gt; 1]"/>
350 <xsl:with-param name="number" select="$number + $lines"/>
351 </xsl:call-template>
352 </xsl:when>
353 <xsl:otherwise>
354 <xsl:value-of select="$lines"/>
355 </xsl:otherwise>
356 </xsl:choose>
357 </xsl:template>
358
359 <xsl:template name="countLines">
360 <xsl:param name="listing"/>
361 <xsl:param name="count" select="1"/>
362
363 <xsl:choose>
364 <xsl:when test="contains($listing, '&#10;')">
365 <xsl:call-template name="countLines">
366 <xsl:with-param name="listing" select="substring-after($listing, '&#10;')"/>
367 <xsl:with-param name="count" select="$count + 1"/>
368 </xsl:call-template>
369 </xsl:when>
370 <xsl:otherwise>
371 <xsl:value-of select="$count"/>
372 </xsl:otherwise>
373 </xsl:choose>
374 </xsl:template>
375
376 </xsl:stylesheet>