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 8421 2009-05-04 07:49:49Z bobstayton $
|
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
|
<!-- XSLTHL highlighting is turned off by default. See highlighting/README
|
21
|
for instructions on how to turn on XSLTHL -->
|
22
|
<xsl:template name="apply-highlighting">
|
23
|
<xsl:apply-templates/>
|
24
|
</xsl:template>
|
25
|
|
26
|
<lxslt:component prefix="xverb"
|
27
|
functions="numberLines"/>
|
28
|
|
29
|
<xsl:template match="programlisting|screen|synopsis">
|
30
|
<xsl:param name="suppress-numbers" select="'0'"/>
|
31
|
<xsl:variable name="id">
|
32
|
<xsl:call-template name="object.id"/>
|
33
|
</xsl:variable>
|
34
|
|
35
|
<xsl:call-template name="anchor"/>
|
36
|
|
37
|
<xsl:if test="$shade.verbatim != 0">
|
38
|
<xsl:message>
|
39
|
<xsl:text>The shade.verbatim parameter is deprecated. </xsl:text>
|
40
|
<xsl:text>Use CSS instead,</xsl:text>
|
41
|
</xsl:message>
|
42
|
<xsl:message>
|
43
|
<xsl:text>for example: pre.</xsl:text>
|
44
|
<xsl:value-of select="local-name(.)"/>
|
45
|
<xsl:text> { background-color: #E0E0E0; }</xsl:text>
|
46
|
</xsl:message>
|
47
|
</xsl:if>
|
48
|
|
49
|
<xsl:choose>
|
50
|
<xsl:when test="$suppress-numbers = '0'
|
51
|
and @linenumbering = 'numbered'
|
52
|
and $use.extensions != '0'
|
53
|
and $linenumbering.extension != '0'">
|
54
|
<xsl:variable name="rtf">
|
55
|
<xsl:choose>
|
56
|
<xsl:when test="$highlight.source != 0">
|
57
|
<xsl:call-template name="apply-highlighting"/>
|
58
|
</xsl:when>
|
59
|
<xsl:otherwise>
|
60
|
<xsl:apply-templates/>
|
61
|
</xsl:otherwise>
|
62
|
</xsl:choose>
|
63
|
</xsl:variable>
|
64
|
<pre>
|
65
|
<xsl:apply-templates select="." mode="common.html.attributes"/>
|
66
|
<xsl:if test="@width != ''">
|
67
|
<xsl:attribute name="width">
|
68
|
<xsl:value-of select="@width"/>
|
69
|
</xsl:attribute>
|
70
|
</xsl:if>
|
71
|
<xsl:call-template name="number.rtf.lines">
|
72
|
<xsl:with-param name="rtf" select="$rtf"/>
|
73
|
</xsl:call-template>
|
74
|
</pre>
|
75
|
</xsl:when>
|
76
|
<xsl:otherwise>
|
77
|
<pre>
|
78
|
<xsl:apply-templates select="." mode="common.html.attributes"/>
|
79
|
<xsl:if test="@width != ''">
|
80
|
<xsl:attribute name="width">
|
81
|
<xsl:value-of select="@width"/>
|
82
|
</xsl:attribute>
|
83
|
</xsl:if>
|
84
|
<xsl:choose>
|
85
|
<xsl:when test="$highlight.source != 0">
|
86
|
<xsl:call-template name="apply-highlighting"/>
|
87
|
</xsl:when>
|
88
|
<xsl:otherwise>
|
89
|
<xsl:apply-templates/>
|
90
|
</xsl:otherwise>
|
91
|
</xsl:choose>
|
92
|
</pre>
|
93
|
</xsl:otherwise>
|
94
|
</xsl:choose>
|
95
|
</xsl:template>
|
96
|
|
97
|
<xsl:template match="literallayout">
|
98
|
<xsl:param name="suppress-numbers" select="'0'"/>
|
99
|
|
100
|
<xsl:variable name="rtf">
|
101
|
<xsl:apply-templates/>
|
102
|
</xsl:variable>
|
103
|
|
104
|
<xsl:if test="$shade.verbatim != 0 and @class='monospaced'">
|
105
|
<xsl:message>
|
106
|
<xsl:text>The shade.verbatim parameter is deprecated. </xsl:text>
|
107
|
<xsl:text>Use CSS instead,</xsl:text>
|
108
|
</xsl:message>
|
109
|
<xsl:message>
|
110
|
<xsl:text>for example: pre.</xsl:text>
|
111
|
<xsl:value-of select="local-name(.)"/>
|
112
|
<xsl:text> { background-color: #E0E0E0; }</xsl:text>
|
113
|
</xsl:message>
|
114
|
</xsl:if>
|
115
|
|
116
|
<xsl:choose>
|
117
|
<xsl:when test="$suppress-numbers = '0'
|
118
|
and @linenumbering = 'numbered'
|
119
|
and $use.extensions != '0'
|
120
|
and $linenumbering.extension != '0'">
|
121
|
<xsl:choose>
|
122
|
<xsl:when test="@class='monospaced'">
|
123
|
<pre>
|
124
|
<xsl:apply-templates select="." mode="common.html.attributes"/>
|
125
|
<xsl:call-template name="number.rtf.lines">
|
126
|
<xsl:with-param name="rtf" select="$rtf"/>
|
127
|
</xsl:call-template>
|
128
|
</pre>
|
129
|
</xsl:when>
|
130
|
<xsl:otherwise>
|
131
|
<div>
|
132
|
<xsl:apply-templates select="." mode="common.html.attributes"/>
|
133
|
<p>
|
134
|
<xsl:call-template name="number.rtf.lines">
|
135
|
<xsl:with-param name="rtf" select="$rtf"/>
|
136
|
</xsl:call-template>
|
137
|
</p>
|
138
|
</div>
|
139
|
</xsl:otherwise>
|
140
|
</xsl:choose>
|
141
|
</xsl:when>
|
142
|
<xsl:otherwise>
|
143
|
<xsl:choose>
|
144
|
<xsl:when test="@class='monospaced'">
|
145
|
<pre>
|
146
|
<xsl:apply-templates select="." mode="common.html.attributes"/>
|
147
|
<xsl:copy-of select="$rtf"/>
|
148
|
</pre>
|
149
|
</xsl:when>
|
150
|
<xsl:otherwise>
|
151
|
<div>
|
152
|
<xsl:apply-templates select="." mode="common.html.attributes"/>
|
153
|
<p>
|
154
|
<xsl:call-template name="make-verbatim">
|
155
|
<xsl:with-param name="rtf" select="$rtf"/>
|
156
|
</xsl:call-template>
|
157
|
</p>
|
158
|
</div>
|
159
|
</xsl:otherwise>
|
160
|
</xsl:choose>
|
161
|
</xsl:otherwise>
|
162
|
</xsl:choose>
|
163
|
</xsl:template>
|
164
|
|
165
|
<xsl:template match="address">
|
166
|
<xsl:param name="suppress-numbers" select="'0'"/>
|
167
|
|
168
|
<xsl:variable name="rtf">
|
169
|
<xsl:apply-templates/>
|
170
|
</xsl:variable>
|
171
|
|
172
|
<xsl:choose>
|
173
|
<xsl:when test="$suppress-numbers = '0'
|
174
|
and @linenumbering = 'numbered'
|
175
|
and $use.extensions != '0'
|
176
|
and $linenumbering.extension != '0'">
|
177
|
<div>
|
178
|
<xsl:apply-templates select="." mode="common.html.attributes"/>
|
179
|
<p>
|
180
|
<xsl:call-template name="number.rtf.lines">
|
181
|
<xsl:with-param name="rtf" select="$rtf"/>
|
182
|
</xsl:call-template>
|
183
|
</p>
|
184
|
</div>
|
185
|
</xsl:when>
|
186
|
|
187
|
<xsl:otherwise>
|
188
|
<div>
|
189
|
<xsl:apply-templates select="." mode="common.html.attributes"/>
|
190
|
<p>
|
191
|
<xsl:call-template name="make-verbatim">
|
192
|
<xsl:with-param name="rtf" select="$rtf"/>
|
193
|
</xsl:call-template>
|
194
|
</p>
|
195
|
</div>
|
196
|
</xsl:otherwise>
|
197
|
</xsl:choose>
|
198
|
</xsl:template>
|
199
|
|
200
|
<xsl:template name="number.rtf.lines">
|
201
|
<xsl:param name="rtf" select="''"/>
|
202
|
<xsl:param name="pi.context" select="."/>
|
203
|
|
204
|
<!-- Save the global values -->
|
205
|
<xsl:variable name="global.linenumbering.everyNth"
|
206
|
select="$linenumbering.everyNth"/>
|
207
|
|
208
|
<xsl:variable name="global.linenumbering.separator"
|
209
|
select="$linenumbering.separator"/>
|
210
|
|
211
|
<xsl:variable name="global.linenumbering.width"
|
212
|
select="$linenumbering.width"/>
|
213
|
|
214
|
<!-- Extract the <?dbhtml linenumbering.*?> PI values -->
|
215
|
<xsl:variable name="pi.linenumbering.everyNth">
|
216
|
<xsl:call-template name="pi.dbhtml_linenumbering.everyNth">
|
217
|
<xsl:with-param name="node" select="$pi.context"/>
|
218
|
</xsl:call-template>
|
219
|
</xsl:variable>
|
220
|
|
221
|
<xsl:variable name="pi.linenumbering.separator">
|
222
|
<xsl:call-template name="pi.dbhtml_linenumbering.separator">
|
223
|
<xsl:with-param name="node" select="$pi.context"/>
|
224
|
</xsl:call-template>
|
225
|
</xsl:variable>
|
226
|
|
227
|
<xsl:variable name="pi.linenumbering.width">
|
228
|
<xsl:call-template name="pi.dbhtml_linenumbering.width">
|
229
|
<xsl:with-param name="node" select="$pi.context"/>
|
230
|
</xsl:call-template>
|
231
|
</xsl:variable>
|
232
|
|
233
|
<!-- Construct the 'in-context' values -->
|
234
|
<xsl:variable name="linenumbering.everyNth">
|
235
|
<xsl:choose>
|
236
|
<xsl:when test="$pi.linenumbering.everyNth != ''">
|
237
|
<xsl:value-of select="$pi.linenumbering.everyNth"/>
|
238
|
</xsl:when>
|
239
|
<xsl:otherwise>
|
240
|
<xsl:value-of select="$global.linenumbering.everyNth"/>
|
241
|
</xsl:otherwise>
|
242
|
</xsl:choose>
|
243
|
</xsl:variable>
|
244
|
|
245
|
<xsl:variable name="linenumbering.separator">
|
246
|
<xsl:choose>
|
247
|
<xsl:when test="$pi.linenumbering.separator != ''">
|
248
|
<xsl:value-of select="$pi.linenumbering.separator"/>
|
249
|
</xsl:when>
|
250
|
<xsl:otherwise>
|
251
|
<xsl:value-of select="$global.linenumbering.separator"/>
|
252
|
</xsl:otherwise>
|
253
|
</xsl:choose>
|
254
|
</xsl:variable>
|
255
|
|
256
|
<xsl:variable name="linenumbering.width">
|
257
|
<xsl:choose>
|
258
|
<xsl:when test="$pi.linenumbering.width != ''">
|
259
|
<xsl:value-of select="$pi.linenumbering.width"/>
|
260
|
</xsl:when>
|
261
|
<xsl:otherwise>
|
262
|
<xsl:value-of select="$global.linenumbering.width"/>
|
263
|
</xsl:otherwise>
|
264
|
</xsl:choose>
|
265
|
</xsl:variable>
|
266
|
|
267
|
<xsl:variable name="linenumbering.startinglinenumber">
|
268
|
<xsl:choose>
|
269
|
<xsl:when test="$pi.context/@startinglinenumber">
|
270
|
<xsl:value-of select="$pi.context/@startinglinenumber"/>
|
271
|
</xsl:when>
|
272
|
<xsl:when test="$pi.context/@continuation='continues'">
|
273
|
<xsl:variable name="lastLine">
|
274
|
<xsl:choose>
|
275
|
<xsl:when test="$pi.context/self::programlisting">
|
276
|
<xsl:call-template name="lastLineNumber">
|
277
|
<xsl:with-param name="listings"
|
278
|
select="preceding::programlisting[@linenumbering='numbered']"/>
|
279
|
</xsl:call-template>
|
280
|
</xsl:when>
|
281
|
<xsl:when test="$pi.context/self::screen">
|
282
|
<xsl:call-template name="lastLineNumber">
|
283
|
<xsl:with-param name="listings"
|
284
|
select="preceding::screen[@linenumbering='numbered']"/>
|
285
|
</xsl:call-template>
|
286
|
</xsl:when>
|
287
|
<xsl:when test="$pi.context/self::literallayout">
|
288
|
<xsl:call-template name="lastLineNumber">
|
289
|
<xsl:with-param name="listings"
|
290
|
select="preceding::literallayout[@linenumbering='numbered']"/>
|
291
|
</xsl:call-template>
|
292
|
</xsl:when>
|
293
|
<xsl:when test="$pi.context/self::address">
|
294
|
<xsl:call-template name="lastLineNumber">
|
295
|
<xsl:with-param name="listings"
|
296
|
select="preceding::address[@linenumbering='numbered']"/>
|
297
|
</xsl:call-template>
|
298
|
</xsl:when>
|
299
|
<xsl:when test="$pi.context/self::synopsis">
|
300
|
<xsl:call-template name="lastLineNumber">
|
301
|
<xsl:with-param name="listings"
|
302
|
select="preceding::synopsis[@linenumbering='numbered']"/>
|
303
|
</xsl:call-template>
|
304
|
</xsl:when>
|
305
|
<xsl:otherwise>
|
306
|
<xsl:message>
|
307
|
<xsl:text>Unexpected verbatim environment: </xsl:text>
|
308
|
<xsl:value-of select="local-name($pi.context)"/>
|
309
|
</xsl:message>
|
310
|
<xsl:value-of select="0"/>
|
311
|
</xsl:otherwise>
|
312
|
</xsl:choose>
|
313
|
</xsl:variable>
|
314
|
|
315
|
<xsl:value-of select="$lastLine + 1"/>
|
316
|
</xsl:when>
|
317
|
<xsl:otherwise>1</xsl:otherwise>
|
318
|
</xsl:choose>
|
319
|
</xsl:variable>
|
320
|
|
321
|
<xsl:choose>
|
322
|
<xsl:when test="function-available('sverb:numberLines')">
|
323
|
<xsl:copy-of select="sverb:numberLines($rtf)"/>
|
324
|
</xsl:when>
|
325
|
<xsl:when test="function-available('xverb:numberLines')">
|
326
|
<xsl:copy-of select="xverb:numberLines($rtf)"/>
|
327
|
</xsl:when>
|
328
|
<xsl:otherwise>
|
329
|
<xsl:message terminate="yes">
|
330
|
<xsl:text>No numberLines function available.</xsl:text>
|
331
|
</xsl:message>
|
332
|
</xsl:otherwise>
|
333
|
</xsl:choose>
|
334
|
</xsl:template>
|
335
|
|
336
|
<xsl:template name="make-verbatim">
|
337
|
<xsl:param name="rtf"/>
|
338
|
|
339
|
<!-- I want to make this RTF verbatim. There are two possibilities: either
|
340
|
I have access to the exsl:node-set extension function and I can "do it right"
|
341
|
or I have to rely on CSS. -->
|
342
|
|
343
|
<xsl:choose>
|
344
|
<xsl:when test="$exsl.node.set.available != 0">
|
345
|
<xsl:apply-templates select="exsl:node-set($rtf)" mode="make.verbatim.mode"/>
|
346
|
</xsl:when>
|
347
|
<xsl:otherwise>
|
348
|
<span style="white-space: pre;">
|
349
|
<xsl:copy-of select="$rtf"/>
|
350
|
</span>
|
351
|
</xsl:otherwise>
|
352
|
</xsl:choose>
|
353
|
</xsl:template>
|
354
|
|
355
|
<!-- ======================================================================== -->
|
356
|
|
357
|
<xsl:template name="lastLineNumber">
|
358
|
<xsl:param name="listings"/>
|
359
|
<xsl:param name="number" select="0"/>
|
360
|
|
361
|
<xsl:variable name="lines">
|
362
|
<xsl:call-template name="countLines">
|
363
|
<xsl:with-param name="listing" select="string($listings[1])"/>
|
364
|
</xsl:call-template>
|
365
|
</xsl:variable>
|
366
|
|
367
|
<xsl:choose>
|
368
|
<xsl:when test="not($listings)">
|
369
|
<xsl:value-of select="$number"/>
|
370
|
</xsl:when>
|
371
|
<xsl:when test="$listings[1]/@startinglinenumber">
|
372
|
<xsl:value-of select="$number + $listings[1]/@startinglinenumber + $lines - 1"/>
|
373
|
</xsl:when>
|
374
|
<xsl:when test="$listings[1]/@continuation='continues'">
|
375
|
<xsl:call-template name="lastLineNumber">
|
376
|
<xsl:with-param name="listings" select="listings[position() > 1]"/>
|
377
|
<xsl:with-param name="number" select="$number + $lines"/>
|
378
|
</xsl:call-template>
|
379
|
</xsl:when>
|
380
|
<xsl:otherwise>
|
381
|
<xsl:value-of select="$lines"/>
|
382
|
</xsl:otherwise>
|
383
|
</xsl:choose>
|
384
|
</xsl:template>
|
385
|
|
386
|
<xsl:template name="countLines">
|
387
|
<xsl:param name="listing"/>
|
388
|
<xsl:param name="count" select="1"/>
|
389
|
|
390
|
<xsl:choose>
|
391
|
<xsl:when test="contains($listing, ' ')">
|
392
|
<xsl:call-template name="countLines">
|
393
|
<xsl:with-param name="listing" select="substring-after($listing, ' ')"/>
|
394
|
<xsl:with-param name="count" select="$count + 1"/>
|
395
|
</xsl:call-template>
|
396
|
</xsl:when>
|
397
|
<xsl:otherwise>
|
398
|
<xsl:value-of select="$count"/>
|
399
|
</xsl:otherwise>
|
400
|
</xsl:choose>
|
401
|
</xsl:template>
|
402
|
|
403
|
</xsl:stylesheet>
|