source: BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/fo/verbatim.xsl@ 986e898d

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

Added LFS XSL Stylesheets.

  • Property mode set to 100644
File size: 14.4 KB
RevLine 
[f8c4e94]1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:fo="http://www.w3.org/1999/XSL/Format"
4 xmlns:sverb="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Verbatim"
5 xmlns:xverb="com.nwalsh.xalan.Verbatim"
6 xmlns:lxslt="http://xml.apache.org/xslt"
7 xmlns:exsl="http://exslt.org/common"
8 exclude-result-prefixes="sverb xverb lxslt exsl"
9 version='1.0'>
10
11<!-- ********************************************************************
12 $Id$
13 ********************************************************************
14
15 This file is part of the XSL DocBook Stylesheet distribution.
16 See ../README or http://docbook.sf.net/release/xsl/current/ for
17 copyright and other information.
18
19 ******************************************************************** -->
20
21<xsl:include href="../highlighting/common.xsl"/>
22<xsl:include href="highlight.xsl"/>
23
24<lxslt:component prefix="xverb"
25 functions="numberLines"/>
26
27<xsl:template match="programlisting|screen|synopsis">
28 <xsl:param name="suppress-numbers" select="'0'"/>
29 <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
30
31 <xsl:variable name="content">
32 <xsl:choose>
33 <xsl:when test="$suppress-numbers = '0'
34 and @linenumbering = 'numbered'
35 and $use.extensions != '0'
36 and $linenumbering.extension != '0'">
37 <xsl:call-template name="number.rtf.lines">
38 <xsl:with-param name="rtf">
39 <xsl:call-template name="apply-highlighting"/>
40 </xsl:with-param>
41 </xsl:call-template>
42 </xsl:when>
43 <xsl:otherwise>
44 <xsl:call-template name="apply-highlighting"/>
45 </xsl:otherwise>
46 </xsl:choose>
47 </xsl:variable>
48
49 <xsl:choose>
50 <xsl:when test="$shade.verbatim != 0">
51 <fo:block id="{$id}"
52 xsl:use-attribute-sets="monospace.verbatim.properties shade.verbatim.style">
53 <xsl:choose>
54 <xsl:when test="$hyphenate.verbatim != 0 and function-available('exsl:node-set')">
55 <xsl:apply-templates select="exsl:node-set($content)" mode="hyphenate.verbatim"/>
56 </xsl:when>
57 <xsl:otherwise>
58 <xsl:copy-of select="$content"/>
59 </xsl:otherwise>
60 </xsl:choose>
61 </fo:block>
62 </xsl:when>
63 <xsl:otherwise>
64 <fo:block id="{$id}"
65 xsl:use-attribute-sets="monospace.verbatim.properties">
66 <xsl:choose>
67 <xsl:when test="$hyphenate.verbatim != 0 and function-available('exsl:node-set')">
68 <xsl:apply-templates select="exsl:node-set($content)" mode="hyphenate.verbatim"/>
69 </xsl:when>
70 <xsl:otherwise>
71 <xsl:copy-of select="$content"/>
72 </xsl:otherwise>
73 </xsl:choose>
74 </fo:block>
75 </xsl:otherwise>
76 </xsl:choose>
77</xsl:template>
78
79<xsl:template match="literallayout">
80 <xsl:param name="suppress-numbers" select="'0'"/>
81
82 <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
83
84 <xsl:variable name="content">
85 <xsl:choose>
86 <xsl:when test="$suppress-numbers = '0'
87 and @linenumbering = 'numbered'
88 and $use.extensions != '0'
89 and $linenumbering.extension != '0'">
90 <xsl:call-template name="number.rtf.lines">
91 <xsl:with-param name="rtf">
92 <xsl:apply-templates/>
93 </xsl:with-param>
94 </xsl:call-template>
95 </xsl:when>
96 <xsl:otherwise>
97 <xsl:apply-templates/>
98 </xsl:otherwise>
99 </xsl:choose>
100 </xsl:variable>
101
102 <xsl:choose>
103 <xsl:when test="@class='monospaced'">
104 <xsl:choose>
105 <xsl:when test="$shade.verbatim != 0">
106 <fo:block id="{$id}"
107 xsl:use-attribute-sets="monospace.verbatim.properties shade.verbatim.style">
108
109 <xsl:copy-of select="$content"/>
110 </fo:block>
111 </xsl:when>
112 <xsl:otherwise>
113 <fo:block id="{$id}"
114 xsl:use-attribute-sets="monospace.verbatim.properties">
115 <xsl:copy-of select="$content"/>
116 </fo:block>
117 </xsl:otherwise>
118 </xsl:choose>
119 </xsl:when>
120 <xsl:otherwise>
121 <xsl:choose>
122 <xsl:when test="$shade.verbatim != 0">
123 <fo:block id="{$id}"
124 xsl:use-attribute-sets="verbatim.properties shade.verbatim.style">
125 <xsl:copy-of select="$content"/>
126 </fo:block>
127 </xsl:when>
128 <xsl:otherwise>
129 <fo:block id="{$id}"
130 xsl:use-attribute-sets="verbatim.properties">
131 <xsl:copy-of select="$content"/>
132 </fo:block>
133 </xsl:otherwise>
134 </xsl:choose>
135 </xsl:otherwise>
136 </xsl:choose>
137</xsl:template>
138
139<xsl:template match="address">
140 <xsl:param name="suppress-numbers" select="'0'"/>
141
142 <xsl:variable name="content">
143 <xsl:choose>
144 <xsl:when test="$suppress-numbers = '0'
145 and @linenumbering = 'numbered'
146 and $use.extensions != '0'
147 and $linenumbering.extension != '0'">
148 <xsl:call-template name="number.rtf.lines">
149 <xsl:with-param name="rtf">
150 <xsl:apply-templates/>
151 </xsl:with-param>
152 </xsl:call-template>
153 </xsl:when>
154 <xsl:otherwise>
155 <xsl:apply-templates/>
156 </xsl:otherwise>
157 </xsl:choose>
158 </xsl:variable>
159
160 <fo:block xsl:use-attribute-sets="verbatim.properties">
161 <xsl:copy-of select="$content"/>
162 </fo:block>
163</xsl:template>
164
165<xsl:template name="number.rtf.lines">
166 <xsl:param name="rtf" select="''"/>
167 <xsl:param name="pi.context" select="."/>
168
169 <!-- Save the global values -->
170 <xsl:variable name="global.linenumbering.everyNth"
171 select="$linenumbering.everyNth"/>
172
173 <xsl:variable name="global.linenumbering.separator"
174 select="$linenumbering.separator"/>
175
176 <xsl:variable name="global.linenumbering.width"
177 select="$linenumbering.width"/>
178
179 <!-- Extract the <?dbfo linenumbering.*?> PI values -->
180 <xsl:variable name="pi.linenumbering.everyNth">
181 <xsl:call-template name="pi.dbfo_linenumbering.everyNth">
182 <xsl:with-param name="node" select="$pi.context"/>
183 </xsl:call-template>
184 </xsl:variable>
185
186 <xsl:variable name="pi.linenumbering.separator">
187 <xsl:call-template name="pi.dbfo_linenumbering.separator">
188 <xsl:with-param name="node" select="$pi.context"/>
189 </xsl:call-template>
190 </xsl:variable>
191
192 <xsl:variable name="pi.linenumbering.width">
193 <xsl:call-template name="pi.dbfo_linenumbering.width">
194 <xsl:with-param name="node" select="$pi.context"/>
195 </xsl:call-template>
196 </xsl:variable>
197
198 <!-- Construct the 'in-context' values -->
199 <xsl:variable name="linenumbering.everyNth">
200 <xsl:choose>
201 <xsl:when test="$pi.linenumbering.everyNth != ''">
202 <xsl:value-of select="$pi.linenumbering.everyNth"/>
203 </xsl:when>
204 <xsl:otherwise>
205 <xsl:value-of select="$global.linenumbering.everyNth"/>
206 </xsl:otherwise>
207 </xsl:choose>
208 </xsl:variable>
209
210 <xsl:variable name="linenumbering.separator">
211 <xsl:choose>
212 <xsl:when test="$pi.linenumbering.separator != ''">
213 <xsl:value-of select="$pi.linenumbering.separator"/>
214 </xsl:when>
215 <xsl:otherwise>
216 <xsl:value-of select="$global.linenumbering.separator"/>
217 </xsl:otherwise>
218 </xsl:choose>
219 </xsl:variable>
220
221 <xsl:variable name="linenumbering.width">
222 <xsl:choose>
223 <xsl:when test="$pi.linenumbering.width != ''">
224 <xsl:value-of select="$pi.linenumbering.width"/>
225 </xsl:when>
226 <xsl:otherwise>
227 <xsl:value-of select="$global.linenumbering.width"/>
228 </xsl:otherwise>
229 </xsl:choose>
230 </xsl:variable>
231
232 <xsl:variable name="linenumbering.startinglinenumber">
233 <xsl:choose>
234 <xsl:when test="$pi.context/@startinglinenumber">
235 <xsl:value-of select="$pi.context/@startinglinenumber"/>
236 </xsl:when>
237 <xsl:when test="$pi.context/@continuation='continues'">
238 <xsl:variable name="lastLine">
239 <xsl:choose>
240 <xsl:when test="$pi.context/self::programlisting">
241 <xsl:call-template name="lastLineNumber">
242 <xsl:with-param name="listings"
243 select="preceding::programlisting[@linenumbering='numbered']"/>
244 </xsl:call-template>
245 </xsl:when>
246 <xsl:when test="$pi.context/self::screen">
247 <xsl:call-template name="lastLineNumber">
248 <xsl:with-param name="listings"
249 select="preceding::screen[@linenumbering='numbered']"/>
250 </xsl:call-template>
251 </xsl:when>
252 <xsl:when test="$pi.context/self::literallayout">
253 <xsl:call-template name="lastLineNumber">
254 <xsl:with-param name="listings"
255 select="preceding::literallayout[@linenumbering='numbered']"/>
256 </xsl:call-template>
257 </xsl:when>
258 <xsl:when test="$pi.context/self::address">
259 <xsl:call-template name="lastLineNumber">
260 <xsl:with-param name="listings"
261 select="preceding::address[@linenumbering='numbered']"/>
262 </xsl:call-template>
263 </xsl:when>
264 <xsl:when test="$pi.context/self::synopsis">
265 <xsl:call-template name="lastLineNumber">
266 <xsl:with-param name="listings"
267 select="preceding::synopsis[@linenumbering='numbered']"/>
268 </xsl:call-template>
269 </xsl:when>
270 <xsl:otherwise>
271 <xsl:message>
272 <xsl:text>Unexpected verbatim environment: </xsl:text>
273 <xsl:value-of select="local-name(.)"/>
274 </xsl:message>
275 <xsl:value-of select="0"/>
276 </xsl:otherwise>
277 </xsl:choose>
278 </xsl:variable>
279
280 <xsl:value-of select="$lastLine + 1"/>
281 </xsl:when>
282 <xsl:otherwise>1</xsl:otherwise>
283 </xsl:choose>
284 </xsl:variable>
285
286 <xsl:choose>
287 <xsl:when test="function-available('sverb:numberLines')">
288 <xsl:copy-of select="sverb:numberLines($rtf)"/>
289 </xsl:when>
290 <xsl:when test="function-available('xverb:numberLines')">
291 <xsl:copy-of select="xverb:numberLines($rtf)"/>
292 </xsl:when>
293 <xsl:otherwise>
294 <xsl:message terminate="yes">
295 <xsl:text>No numberLines function available.</xsl:text>
296 </xsl:message>
297 </xsl:otherwise>
298 </xsl:choose>
299</xsl:template>
300
301<!-- ======================================================================== -->
302
303<xsl:template name="lastLineNumber">
304 <xsl:param name="listings"/>
305 <xsl:param name="number" select="0"/>
306
307 <xsl:variable name="lines">
308 <xsl:call-template name="countLines">
309 <xsl:with-param name="listing" select="string($listings[1])"/>
310 </xsl:call-template>
311 </xsl:variable>
312
313 <xsl:choose>
314 <xsl:when test="not($listings)">
315 <xsl:value-of select="$number"/>
316 </xsl:when>
317 <xsl:when test="$listings[1]/@startinglinenumber">
318 <xsl:value-of select="$number + $listings[1]/@startinglinenumber + $lines - 1"/>
319 </xsl:when>
320 <xsl:when test="$listings[1]/@continuation='continues'">
321 <xsl:call-template name="lastLineNumber">
322 <xsl:with-param name="listings" select="listings[position() &gt; 1]"/>
323 <xsl:with-param name="number" select="$number + $lines"/>
324 </xsl:call-template>
325 </xsl:when>
326 <xsl:otherwise>
327 <xsl:value-of select="$lines"/>
328 </xsl:otherwise>
329 </xsl:choose>
330</xsl:template>
331
332<xsl:template name="countLines">
333 <xsl:param name="listing"/>
334 <xsl:param name="count" select="1"/>
335
336 <xsl:choose>
337 <xsl:when test="contains($listing, '&#10;')">
338 <xsl:call-template name="countLines">
339 <xsl:with-param name="listing" select="substring-after($listing, '&#10;')"/>
340 <xsl:with-param name="count" select="$count + 1"/>
341 </xsl:call-template>
342 </xsl:when>
343 <xsl:otherwise>
344 <xsl:value-of select="$count"/>
345 </xsl:otherwise>
346 </xsl:choose>
347</xsl:template>
348
349<!-- ======================================================================== -->
350
351<xsl:template match="node()|@*" mode="hyphenate.verbatim">
352 <xsl:copy>
353 <xsl:copy-of select="@*"/>
354 <xsl:apply-templates mode="hyphenate.verbatim"/>
355 </xsl:copy>
356</xsl:template>
357
358<xsl:template match="text()" mode="hyphenate.verbatim" priority="2">
359 <xsl:call-template name="hyphenate.verbatim.block">
360 <xsl:with-param name="content" select="."/>
361 </xsl:call-template>
362</xsl:template>
363
364<xsl:template name="hyphenate.verbatim.block">
365 <xsl:param name="content" select="''"/>
366 <xsl:param name="count" select="1"/>
367
368 <!-- recurse on lines first to keep recursion depth reasonable -->
369 <xsl:choose>
370 <xsl:when test="contains($content, '&#xA;')">
371 <xsl:variable name="line" select="substring-before($content, '&#xA;')"/>
372 <xsl:variable name="rest" select="substring-after($content, '&#xA;')"/>
373 <xsl:call-template name="hyphenate.verbatim">
374 <xsl:with-param name="content" select="concat($line, '&#xA;')"/>
375 </xsl:call-template>
376 <xsl:call-template name="hyphenate.verbatim.block">
377 <xsl:with-param name="content" select="$rest"/>
378 <xsl:with-param name="count" select="$count + 1"/>
379 </xsl:call-template>
380 </xsl:when>
381 <xsl:otherwise>
382 <xsl:call-template name="hyphenate.verbatim">
383 <xsl:with-param name="content" select="$content"/>
384 </xsl:call-template>
385 </xsl:otherwise>
386 </xsl:choose>
387
388</xsl:template>
389
390<xsl:template name="hyphenate.verbatim">
391 <xsl:param name="content"/>
392 <xsl:variable name="head" select="substring($content, 1, 1)"/>
393 <xsl:variable name="tail" select="substring($content, 2)"/>
394 <xsl:choose>
395 <!-- Place soft-hyphen after space or non-breakable space. -->
396 <xsl:when test="$head = ' ' or $head = '&#160;'">
397 <xsl:text>&#160;</xsl:text>
398 <xsl:text>&#x00AD;</xsl:text>
399 </xsl:when>
400 <xsl:when test="$hyphenate.verbatim.characters != '' and
401 translate($head, $hyphenate.verbatim.characters, '') = '' and not($tail = '')">
402 <xsl:value-of select="$head"/>
403 <xsl:text>&#x00AD;</xsl:text>
404 </xsl:when>
405 <xsl:otherwise>
406 <xsl:value-of select="$head"/>
407 </xsl:otherwise>
408 </xsl:choose>
409 <xsl:if test="$tail">
410 <xsl:call-template name="hyphenate.verbatim">
411 <xsl:with-param name="content" select="$tail"/>
412 </xsl:call-template>
413 </xsl:if>
414</xsl:template>
415
416
417</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.