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