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 8807 2010-08-09 18:57:41Z bobstayton $
12 ********************************************************************
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.
18 ******************************************************************** -->
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/>
26 <lxslt:component prefix="xverb"
27 functions="numberLines"/>
29 <xsl:template match="programlisting|screen|synopsis">
30 <xsl:param name="suppress-numbers" select="'0'"/>
31 <xsl:variable name="id">
32 <xsl:call-template name="object.id"/>
35 <xsl:call-template name="anchor"/>
37 <xsl:variable name="div.element">
39 <xsl:when test="$make.clean.html != 0">div</xsl:when>
40 <xsl:otherwise>pre</xsl:otherwise>
44 <xsl:if test="$shade.verbatim != 0">
46 <xsl:text>The shade.verbatim parameter is deprecated. </xsl:text>
47 <xsl:text>Use CSS instead,</xsl:text>
50 <xsl:text>for example: pre.</xsl:text>
51 <xsl:value-of select="local-name(.)"/>
52 <xsl:text> { background-color: #E0E0E0; }</xsl:text>
57 <xsl:when test="$suppress-numbers = '0'
58 and @linenumbering = 'numbered'
59 and $use.extensions != '0'
60 and $linenumbering.extension != '0'">
61 <xsl:variable name="rtf">
63 <xsl:when test="$highlight.source != 0">
64 <xsl:call-template name="apply-highlighting"/>
67 <xsl:apply-templates/>
71 <xsl:element name="{$div.element}">
72 <xsl:apply-templates select="." mode="common.html.attributes"/>
73 <xsl:if test="@width != ''">
74 <xsl:attribute name="width">
75 <xsl:value-of select="@width"/>
78 <xsl:call-template name="number.rtf.lines">
79 <xsl:with-param name="rtf" select="$rtf"/>
84 <xsl:element name="{$div.element}">
85 <xsl:apply-templates select="." mode="common.html.attributes"/>
86 <xsl:if test="@width != ''">
87 <xsl:attribute name="width">
88 <xsl:value-of select="@width"/>
92 <xsl:when test="$highlight.source != 0">
93 <xsl:call-template name="apply-highlighting"/>
96 <xsl:apply-templates/>
104 <xsl:template match="literallayout">
105 <xsl:param name="suppress-numbers" select="'0'"/>
107 <xsl:variable name="rtf">
108 <xsl:apply-templates/>
111 <xsl:if test="$shade.verbatim != 0 and @class='monospaced'">
113 <xsl:text>The shade.verbatim parameter is deprecated. </xsl:text>
114 <xsl:text>Use CSS instead,</xsl:text>
117 <xsl:text>for example: pre.</xsl:text>
118 <xsl:value-of select="local-name(.)"/>
119 <xsl:text> { background-color: #E0E0E0; }</xsl:text>
124 <xsl:when test="$suppress-numbers = '0'
125 and @linenumbering = 'numbered'
126 and $use.extensions != '0'
127 and $linenumbering.extension != '0'">
129 <xsl:when test="@class='monospaced'">
131 <xsl:apply-templates select="." mode="common.html.attributes"/>
132 <xsl:call-template name="number.rtf.lines">
133 <xsl:with-param name="rtf" select="$rtf"/>
139 <xsl:apply-templates select="." mode="common.html.attributes"/>
141 <xsl:call-template name="number.rtf.lines">
142 <xsl:with-param name="rtf" select="$rtf"/>
151 <xsl:when test="@class='monospaced'">
153 <xsl:apply-templates select="." mode="common.html.attributes"/>
154 <xsl:copy-of select="$rtf"/>
159 <xsl:apply-templates select="." mode="common.html.attributes"/>
161 <xsl:call-template name="make-verbatim">
162 <xsl:with-param name="rtf" select="$rtf"/>
172 <xsl:template match="address">
173 <xsl:param name="suppress-numbers" select="'0'"/>
175 <xsl:variable name="rtf">
176 <xsl:apply-templates/>
180 <xsl:when test="$suppress-numbers = '0'
181 and @linenumbering = 'numbered'
182 and $use.extensions != '0'
183 and $linenumbering.extension != '0'">
185 <xsl:apply-templates select="." mode="common.html.attributes"/>
187 <xsl:call-template name="number.rtf.lines">
188 <xsl:with-param name="rtf" select="$rtf"/>
196 <xsl:apply-templates select="." mode="common.html.attributes"/>
198 <xsl:call-template name="make-verbatim">
199 <xsl:with-param name="rtf" select="$rtf"/>
207 <xsl:template name="number.rtf.lines">
208 <xsl:param name="rtf" select="''"/>
209 <xsl:param name="pi.context" select="."/>
211 <!-- Save the global values -->
212 <xsl:variable name="global.linenumbering.everyNth"
213 select="$linenumbering.everyNth"/>
215 <xsl:variable name="global.linenumbering.separator"
216 select="$linenumbering.separator"/>
218 <xsl:variable name="global.linenumbering.width"
219 select="$linenumbering.width"/>
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"/>
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"/>
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"/>
240 <!-- Construct the 'in-context' values -->
241 <xsl:variable name="linenumbering.everyNth">
243 <xsl:when test="$pi.linenumbering.everyNth != ''">
244 <xsl:value-of select="$pi.linenumbering.everyNth"/>
247 <xsl:value-of select="$global.linenumbering.everyNth"/>
252 <xsl:variable name="linenumbering.separator">
254 <xsl:when test="$pi.linenumbering.separator != ''">
255 <xsl:value-of select="$pi.linenumbering.separator"/>
258 <xsl:value-of select="$global.linenumbering.separator"/>
263 <xsl:variable name="linenumbering.width">
265 <xsl:when test="$pi.linenumbering.width != ''">
266 <xsl:value-of select="$pi.linenumbering.width"/>
269 <xsl:value-of select="$global.linenumbering.width"/>
274 <xsl:variable name="linenumbering.startinglinenumber">
276 <xsl:when test="$pi.context/@startinglinenumber">
277 <xsl:value-of select="$pi.context/@startinglinenumber"/>
279 <xsl:when test="$pi.context/@continuation='continues'">
280 <xsl:variable name="lastLine">
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']"/>
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']"/>
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']"/>
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']"/>
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']"/>
314 <xsl:text>Unexpected verbatim environment: </xsl:text>
315 <xsl:value-of select="local-name($pi.context)"/>
317 <xsl:value-of select="0"/>
322 <xsl:value-of select="$lastLine + 1"/>
324 <xsl:otherwise>1</xsl:otherwise>
329 <xsl:when test="function-available('sverb:numberLines')">
330 <xsl:copy-of select="sverb:numberLines($rtf)"/>
332 <xsl:when test="function-available('xverb:numberLines')">
333 <xsl:copy-of select="xverb:numberLines($rtf)"/>
336 <xsl:message terminate="yes">
337 <xsl:text>No numberLines function available.</xsl:text>
343 <xsl:template name="make-verbatim">
344 <xsl:param name="rtf"/>
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. -->
351 <xsl:when test="$exsl.node.set.available != 0">
352 <xsl:apply-templates select="exsl:node-set($rtf)" mode="make.verbatim.mode"/>
355 <span style="white-space: pre;">
356 <xsl:copy-of select="$rtf"/>
362 <!-- ======================================================================== -->
364 <xsl:template name="lastLineNumber">
365 <xsl:param name="listings"/>
366 <xsl:param name="number" select="0"/>
368 <xsl:variable name="lines">
369 <xsl:call-template name="countLines">
370 <xsl:with-param name="listing" select="string($listings[1])"/>
375 <xsl:when test="not($listings)">
376 <xsl:value-of select="$number"/>
378 <xsl:when test="$listings[1]/@startinglinenumber">
379 <xsl:value-of select="$number + $listings[1]/@startinglinenumber + $lines - 1"/>
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"/>
388 <xsl:value-of select="$lines"/>
393 <xsl:template name="countLines">
394 <xsl:param name="listing"/>
395 <xsl:param name="count" select="1"/>
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"/>
405 <xsl:value-of select="$count"/>