source: clfs-embedded/BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/xhtml/verbatim.xsl@ eb56776

Last change on this file since eb56776 was 9882b55, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Added the new lfs-xsl stylesheets.

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