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"
10 <!-- ********************************************************************
11 $Id: verbatim.xsl,v 1.1 2007/03/10 05:15:13 scott Exp $
12 ********************************************************************
14 This file is part of the XSL DocBook Stylesheet distribution.
15 See ../README or http://nwalsh.com/docbook/xsl/ for copyright
16 and other information.
18 ******************************************************************** -->
20 <xsl:include href=
"../highlighting/common.xsl"/>
21 <xsl:include href=
"highlight.xsl"/>
23 <lxslt:component prefix=
"xverb"
24 functions=
"numberLines"/>
26 <xsl:template match=
"programlisting|screen|synopsis">
27 <xsl:param name=
"suppress-numbers" select=
"'0'"/>
28 <xsl:variable name=
"id">
29 <xsl:call-template name=
"object.id"/>
32 <xsl:call-template name=
"anchor"/>
34 <xsl:if test=
"$shade.verbatim != 0">
36 <xsl:text>The shade.verbatim parameter is deprecated.
</xsl:text>
37 <xsl:text>Use CSS instead,
</xsl:text>
40 <xsl:text>for example: pre.
</xsl:text>
41 <xsl:value-of select=
"local-name(.)"/>
42 <xsl:text> { background-color: #E0E0E0; }
</xsl:text>
47 <xsl:when test=
"$suppress-numbers = '0'
48 and @linenumbering = 'numbered'
49 and $use.extensions != '0'
50 and $linenumbering.extension != '0'">
51 <xsl:variable name=
"rtf">
52 <xsl:call-template name=
"apply-highlighting"/>
55 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
56 <xsl:call-template name=
"number.rtf.lines">
57 <xsl:with-param name=
"rtf" select=
"$rtf"/>
63 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
64 <xsl:call-template name=
"apply-highlighting"/>
70 <xsl:template match=
"literallayout">
71 <xsl:param name=
"suppress-numbers" select=
"'0'"/>
73 <xsl:variable name=
"rtf">
74 <xsl:apply-templates/>
77 <xsl:if test=
"$shade.verbatim != 0 and @class='monospaced'">
79 <xsl:text>The shade.verbatim parameter is deprecated.
</xsl:text>
80 <xsl:text>Use CSS instead,
</xsl:text>
83 <xsl:text>for example: pre.
</xsl:text>
84 <xsl:value-of select=
"local-name(.)"/>
85 <xsl:text> { background-color: #E0E0E0; }
</xsl:text>
90 <xsl:when test=
"$suppress-numbers = '0'
91 and @linenumbering = 'numbered'
92 and $use.extensions != '0'
93 and $linenumbering.extension != '0'">
95 <xsl:when test=
"@class='monospaced'">
97 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
98 <xsl:call-template name=
"number.rtf.lines">
99 <xsl:with-param name=
"rtf" select=
"$rtf"/>
105 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
107 <xsl:call-template name=
"number.rtf.lines">
108 <xsl:with-param name=
"rtf" select=
"$rtf"/>
117 <xsl:when test=
"@class='monospaced'">
119 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
120 <xsl:copy-of select=
"$rtf"/>
125 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
127 <xsl:call-template name=
"make-verbatim">
128 <xsl:with-param name=
"rtf" select=
"$rtf"/>
138 <xsl:template match=
"address">
139 <xsl:param name=
"suppress-numbers" select=
"'0'"/>
141 <xsl:variable name=
"rtf">
142 <xsl:apply-templates/>
146 <xsl:when test=
"$suppress-numbers = '0'
147 and @linenumbering = 'numbered'
148 and $use.extensions != '0'
149 and $linenumbering.extension != '0'">
151 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
153 <xsl:call-template name=
"number.rtf.lines">
154 <xsl:with-param name=
"rtf" select=
"$rtf"/>
162 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
164 <xsl:call-template name=
"make-verbatim">
165 <xsl:with-param name=
"rtf" select=
"$rtf"/>
173 <xsl:template name=
"number.rtf.lines">
174 <xsl:param name=
"rtf" select=
"''"/>
175 <xsl:param name=
"pi.context" select=
"."/>
177 <!-- Save the global values -->
178 <xsl:variable name=
"global.linenumbering.everyNth"
179 select=
"$linenumbering.everyNth"/>
181 <xsl:variable name=
"global.linenumbering.separator"
182 select=
"$linenumbering.separator"/>
184 <xsl:variable name=
"global.linenumbering.width"
185 select=
"$linenumbering.width"/>
187 <!-- Extract the <?dbhtml linenumbering.*?> PI values -->
188 <xsl:variable name=
"pi.linenumbering.everyNth">
189 <xsl:call-template name=
"dbhtml-attribute">
190 <xsl:with-param name=
"pis"
191 select=
"$pi.context/processing-instruction('dbhtml')"/>
192 <xsl:with-param name=
"attribute" select=
"'linenumbering.everyNth'"/>
196 <xsl:variable name=
"pi.linenumbering.separator">
197 <xsl:call-template name=
"dbhtml-attribute">
198 <xsl:with-param name=
"pis"
199 select=
"$pi.context/processing-instruction('dbhtml')"/>
200 <xsl:with-param name=
"attribute" select=
"'linenumbering.separator'"/>
204 <xsl:variable name=
"pi.linenumbering.width">
205 <xsl:call-template name=
"dbhtml-attribute">
206 <xsl:with-param name=
"pis"
207 select=
"$pi.context/processing-instruction('dbhtml')"/>
208 <xsl:with-param name=
"attribute" select=
"'linenumbering.width'"/>
212 <!-- Construct the 'in-context' values -->
213 <xsl:variable name=
"linenumbering.everyNth">
215 <xsl:when test=
"$pi.linenumbering.everyNth != ''">
216 <xsl:value-of select=
"$pi.linenumbering.everyNth"/>
219 <xsl:value-of select=
"$global.linenumbering.everyNth"/>
224 <xsl:variable name=
"linenumbering.separator">
226 <xsl:when test=
"$pi.linenumbering.separator != ''">
227 <xsl:value-of select=
"$pi.linenumbering.separator"/>
230 <xsl:value-of select=
"$global.linenumbering.separator"/>
235 <xsl:variable name=
"linenumbering.width">
237 <xsl:when test=
"$pi.linenumbering.width != ''">
238 <xsl:value-of select=
"$pi.linenumbering.width"/>
241 <xsl:value-of select=
"$global.linenumbering.width"/>
246 <xsl:variable name=
"linenumbering.startinglinenumber">
248 <xsl:when test=
"$pi.context/@startinglinenumber">
249 <xsl:value-of select=
"$pi.context/@startinglinenumber"/>
251 <xsl:when test=
"$pi.context/@continuation='continues'">
252 <xsl:variable name=
"lastLine">
254 <xsl:when test=
"$pi.context/self::programlisting">
255 <xsl:call-template name=
"lastLineNumber">
256 <xsl:with-param name=
"listings"
257 select=
"preceding::programlisting[@linenumbering='numbered']"/>
260 <xsl:when test=
"$pi.context/self::screen">
261 <xsl:call-template name=
"lastLineNumber">
262 <xsl:with-param name=
"listings"
263 select=
"preceding::screen[@linenumbering='numbered']"/>
266 <xsl:when test=
"$pi.context/self::literallayout">
267 <xsl:call-template name=
"lastLineNumber">
268 <xsl:with-param name=
"listings"
269 select=
"preceding::literallayout[@linenumbering='numbered']"/>
272 <xsl:when test=
"$pi.context/self::address">
273 <xsl:call-template name=
"lastLineNumber">
274 <xsl:with-param name=
"listings"
275 select=
"preceding::address[@linenumbering='numbered']"/>
278 <xsl:when test=
"$pi.context/self::synopsis">
279 <xsl:call-template name=
"lastLineNumber">
280 <xsl:with-param name=
"listings"
281 select=
"preceding::synopsis[@linenumbering='numbered']"/>
286 <xsl:text>Unexpected verbatim environment:
</xsl:text>
287 <xsl:value-of select=
"local-name($pi.context)"/>
289 <xsl:value-of select=
"0"/>
294 <xsl:value-of select=
"$lastLine + 1"/>
296 <xsl:otherwise>1</xsl:otherwise>
301 <xsl:when test=
"function-available('sverb:numberLines')">
302 <xsl:copy-of select=
"sverb:numberLines($rtf)"/>
304 <xsl:when test=
"function-available('xverb:numberLines')">
305 <xsl:copy-of select=
"xverb:numberLines($rtf)"/>
308 <xsl:message terminate=
"yes">
309 <xsl:text>No numberLines function available.
</xsl:text>
315 <xsl:template name=
"make-verbatim">
316 <xsl:param name=
"rtf"/>
318 <!-- I want to make this RTF verbatim. There are two possibilities: either
319 I have access to the exsl:node-set extension function and I can "do it right"
320 or I have to rely on CSS. -->
323 <xsl:when test=
"function-available('exsl:node-set')">
324 <xsl:apply-templates select=
"exsl:node-set($rtf)" mode=
"make.verbatim.mode"/>
327 <span style=
"white-space: pre;">
328 <xsl:copy-of select=
"$rtf"/>
334 <!-- ======================================================================== -->
336 <xsl:template name=
"lastLineNumber">
337 <xsl:param name=
"listings"/>
338 <xsl:param name=
"number" select=
"0"/>
340 <xsl:variable name=
"lines">
341 <xsl:call-template name=
"countLines">
342 <xsl:with-param name=
"listing" select=
"string($listings[1])"/>
347 <xsl:when test=
"not($listings)">
348 <xsl:value-of select=
"$number"/>
350 <xsl:when test=
"$listings[1]/@startinglinenumber">
351 <xsl:value-of select=
"$number + $listings[1]/@startinglinenumber + $lines - 1"/>
353 <xsl:when test=
"$listings[1]/@continuation='continues'">
354 <xsl:call-template name=
"lastLineNumber">
355 <xsl:with-param name=
"listings" select=
"listings[position() > 1]"/>
356 <xsl:with-param name=
"number" select=
"$number + $lines"/>
360 <xsl:value-of select=
"$lines"/>
365 <xsl:template name=
"countLines">
366 <xsl:param name=
"listing"/>
367 <xsl:param name=
"count" select=
"1"/>
370 <xsl:when test=
"contains($listing, ' ')">
371 <xsl:call-template name=
"countLines">
372 <xsl:with-param name=
"listing" select=
"substring-after($listing, ' ')"/>
373 <xsl:with-param name=
"count" select=
"$count + 1"/>
377 <xsl:value-of select=
"$count"/>