source: BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/xhtml/verbatim.xsl@ cb0b206

clfs-3.0.0-systemd systemd
Last change on this file since cb0b206 was f8c4e94, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Added LFS XSL Stylesheets.

  • Property mode set to 100644
File size: 12.0 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="pi.dbhtml_linenumbering.everyNth">
173 <xsl:with-param name="node" select="$pi.context"/>
174 </xsl:call-template>
175 </xsl:variable>
176
177 <xsl:variable name="pi.linenumbering.separator">
178 <xsl:call-template name="pi.dbhtml_linenumbering.separator">
179 <xsl:with-param name="node" select="$pi.context"/>
180 </xsl:call-template>
181 </xsl:variable>
182
183 <xsl:variable name="pi.linenumbering.width">
184 <xsl:call-template name="pi.dbhtml_linenumbering.width">
185 <xsl:with-param name="node" select="$pi.context"/>
186 </xsl:call-template>
187 </xsl:variable>
188
189 <!-- Construct the 'in-context' values -->
190 <xsl:variable name="linenumbering.everyNth">
191 <xsl:choose>
192 <xsl:when test="$pi.linenumbering.everyNth != ''">
193 <xsl:value-of select="$pi.linenumbering.everyNth"/>
194 </xsl:when>
195 <xsl:otherwise>
196 <xsl:value-of select="$global.linenumbering.everyNth"/>
197 </xsl:otherwise>
198 </xsl:choose>
199 </xsl:variable>
200
201 <xsl:variable name="linenumbering.separator">
202 <xsl:choose>
203 <xsl:when test="$pi.linenumbering.separator != ''">
204 <xsl:value-of select="$pi.linenumbering.separator"/>
205 </xsl:when>
206 <xsl:otherwise>
207 <xsl:value-of select="$global.linenumbering.separator"/>
208 </xsl:otherwise>
209 </xsl:choose>
210 </xsl:variable>
211
212 <xsl:variable name="linenumbering.width">
213 <xsl:choose>
214 <xsl:when test="$pi.linenumbering.width != ''">
215 <xsl:value-of select="$pi.linenumbering.width"/>
216 </xsl:when>
217 <xsl:otherwise>
218 <xsl:value-of select="$global.linenumbering.width"/>
219 </xsl:otherwise>
220 </xsl:choose>
221 </xsl:variable>
222
223 <xsl:variable name="linenumbering.startinglinenumber">
224 <xsl:choose>
225 <xsl:when test="$pi.context/@startinglinenumber">
226 <xsl:value-of select="$pi.context/@startinglinenumber"/>
227 </xsl:when>
228 <xsl:when test="$pi.context/@continuation='continues'">
229 <xsl:variable name="lastLine">
230 <xsl:choose>
231 <xsl:when test="$pi.context/self::programlisting">
232 <xsl:call-template name="lastLineNumber">
233 <xsl:with-param name="listings" select="preceding::programlisting[@linenumbering='numbered']"/>
234 </xsl:call-template>
235 </xsl:when>
236 <xsl:when test="$pi.context/self::screen">
237 <xsl:call-template name="lastLineNumber">
238 <xsl:with-param name="listings" select="preceding::screen[@linenumbering='numbered']"/>
239 </xsl:call-template>
240 </xsl:when>
241 <xsl:when test="$pi.context/self::literallayout">
242 <xsl:call-template name="lastLineNumber">
243 <xsl:with-param name="listings" select="preceding::literallayout[@linenumbering='numbered']"/>
244 </xsl:call-template>
245 </xsl:when>
246 <xsl:when test="$pi.context/self::address">
247 <xsl:call-template name="lastLineNumber">
248 <xsl:with-param name="listings" select="preceding::address[@linenumbering='numbered']"/>
249 </xsl:call-template>
250 </xsl:when>
251 <xsl:when test="$pi.context/self::synopsis">
252 <xsl:call-template name="lastLineNumber">
253 <xsl:with-param name="listings" select="preceding::synopsis[@linenumbering='numbered']"/>
254 </xsl:call-template>
255 </xsl:when>
256 <xsl:otherwise>
257 <xsl:message>
258 <xsl:text>Unexpected verbatim environment: </xsl:text>
259 <xsl:value-of select="local-name($pi.context)"/>
260 </xsl:message>
261 <xsl:value-of select="0"/>
262 </xsl:otherwise>
263 </xsl:choose>
264 </xsl:variable>
265
266 <xsl:value-of select="$lastLine + 1"/>
267 </xsl:when>
268 <xsl:otherwise>1</xsl:otherwise>
269 </xsl:choose>
270 </xsl:variable>
271
272 <xsl:choose>
273 <xsl:when test="function-available('sverb:numberLines')">
274 <xsl:copy-of select="sverb:numberLines($rtf)"/>
275 </xsl:when>
276 <xsl:when test="function-available('xverb:numberLines')">
277 <xsl:copy-of select="xverb:numberLines($rtf)"/>
278 </xsl:when>
279 <xsl:otherwise>
280 <xsl:message terminate="yes">
281 <xsl:text>No numberLines function available.</xsl:text>
282 </xsl:message>
283 </xsl:otherwise>
284 </xsl:choose>
285</xsl:template>
286
287<xsl:template name="make-verbatim">
288 <xsl:param name="rtf"/>
289
290 <!-- I want to make this RTF verbatim. There are two possibilities: either
291 I have access to the exsl:node-set extension function and I can "do it right"
292 or I have to rely on CSS. -->
293
294 <xsl:choose>
295 <xsl:when test="function-available('exsl:node-set')">
296 <xsl:apply-templates select="exsl:node-set($rtf)" mode="make.verbatim.mode"/>
297 </xsl:when>
298 <xsl:otherwise>
299 <span style="white-space: pre;">
300 <xsl:copy-of select="$rtf"/>
301 </span>
302 </xsl:otherwise>
303 </xsl:choose>
304</xsl:template>
305
306<!-- ======================================================================== -->
307
308<xsl:template name="lastLineNumber">
309 <xsl:param name="listings"/>
310 <xsl:param name="number" select="0"/>
311
312 <xsl:variable name="lines">
313 <xsl:call-template name="countLines">
314 <xsl:with-param name="listing" select="string($listings[1])"/>
315 </xsl:call-template>
316 </xsl:variable>
317
318 <xsl:choose>
319 <xsl:when test="not($listings)">
320 <xsl:value-of select="$number"/>
321 </xsl:when>
322 <xsl:when test="$listings[1]/@startinglinenumber">
323 <xsl:value-of select="$number + $listings[1]/@startinglinenumber + $lines - 1"/>
324 </xsl:when>
325 <xsl:when test="$listings[1]/@continuation='continues'">
326 <xsl:call-template name="lastLineNumber">
327 <xsl:with-param name="listings" select="listings[position() &gt; 1]"/>
328 <xsl:with-param name="number" select="$number + $lines"/>
329 </xsl:call-template>
330 </xsl:when>
331 <xsl:otherwise>
332 <xsl:value-of select="$lines"/>
333 </xsl:otherwise>
334 </xsl:choose>
335</xsl:template>
336
337<xsl:template name="countLines">
338 <xsl:param name="listing"/>
339 <xsl:param name="count" select="1"/>
340
341 <xsl:choose>
342 <xsl:when test="contains($listing, '&#10;')">
343 <xsl:call-template name="countLines">
344 <xsl:with-param name="listing" select="substring-after($listing, '&#10;')"/>
345 <xsl:with-param name="count" select="$count + 1"/>
346 </xsl:call-template>
347 </xsl:when>
348 <xsl:otherwise>
349 <xsl:value-of select="$count"/>
350 </xsl:otherwise>
351 </xsl:choose>
352</xsl:template>
353
354</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.