]> git.evergreen-ils.org Git - working/Evergreen.git/blob - stylesheets/evergreen_docbook_files/docbook-xsl-1.75.2/xhtml-1_1/verbatim.xsl
Add stylesheets for our evergreen docbook site.
[working/Evergreen.git] / stylesheets / evergreen_docbook_files / docbook-xsl-1.75.2 / xhtml-1_1 / verbatim.xsl
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: verbatim.xsl 8421 2009-05-04 07:49:49Z bobstayton $
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 <!-- XSLTHL highlighting is turned off by default. See highlighting/README
17      for instructions on how to turn on XSLTHL -->
18 <xsl:template name="apply-highlighting">
19     <xsl:apply-templates/>
20 </xsl:template>
21
22 <lxslt:component prefix="xverb" functions="numberLines"/>
23
24 <xsl:template match="programlisting|screen|synopsis">
25   <xsl:param name="suppress-numbers" select="'0'"/>
26   <xsl:variable name="id">
27     <xsl:call-template name="object.id"/>
28   </xsl:variable>
29
30   <xsl:call-template name="anchor"/>
31
32   <xsl:if test="$shade.verbatim != 0">
33     <xsl:message>
34       <xsl:text>The shade.verbatim parameter is deprecated. </xsl:text>
35       <xsl:text>Use CSS instead,</xsl:text>
36     </xsl:message>
37     <xsl:message>
38       <xsl:text>for example: pre.</xsl:text>
39       <xsl:value-of select="local-name(.)"/>
40       <xsl:text> { background-color: #E0E0E0; }</xsl:text>
41     </xsl:message>
42   </xsl:if>
43
44   <xsl:choose>
45     <xsl:when test="$suppress-numbers = '0'                     and @linenumbering = 'numbered'                     and $use.extensions != '0'                     and $linenumbering.extension != '0'">
46       <xsl:variable name="rtf">
47         <xsl:choose>
48           <xsl:when test="$highlight.source != 0">
49             <xsl:call-template name="apply-highlighting"/>
50           </xsl:when>
51           <xsl:otherwise>
52             <xsl:apply-templates/>
53           </xsl:otherwise>
54         </xsl:choose>
55       </xsl:variable>
56       <pre>
57         <xsl:apply-templates select="." mode="common.html.attributes"/>
58         <xsl:if test="@width != ''">
59           <xsl:attribute name="width">
60             <xsl:value-of select="@width"/>
61           </xsl:attribute>
62         </xsl:if>
63         <xsl:call-template name="number.rtf.lines">
64           <xsl:with-param name="rtf" select="$rtf"/>
65         </xsl:call-template>
66       </pre>
67     </xsl:when>
68     <xsl:otherwise>
69       <pre>
70         <xsl:apply-templates select="." mode="common.html.attributes"/>
71         <xsl:if test="@width != ''">
72           <xsl:attribute name="width">
73             <xsl:value-of select="@width"/>
74           </xsl:attribute>
75         </xsl:if>
76         <xsl:choose>
77           <xsl:when test="$highlight.source != 0">
78             <xsl:call-template name="apply-highlighting"/>
79           </xsl:when>
80           <xsl:otherwise>
81             <xsl:apply-templates/>
82           </xsl:otherwise>
83         </xsl:choose>
84       </pre>
85     </xsl:otherwise>
86   </xsl:choose>
87 </xsl:template>
88
89 <xsl:template match="literallayout">
90   <xsl:param name="suppress-numbers" select="'0'"/>
91
92   <xsl:variable name="rtf">
93     <xsl:apply-templates/>
94   </xsl:variable>
95
96   <xsl:if test="$shade.verbatim != 0 and @class='monospaced'">
97     <xsl:message>
98       <xsl:text>The shade.verbatim parameter is deprecated. </xsl:text>
99       <xsl:text>Use CSS instead,</xsl:text>
100     </xsl:message>
101     <xsl:message>
102       <xsl:text>for example: pre.</xsl:text>
103       <xsl:value-of select="local-name(.)"/>
104       <xsl:text> { background-color: #E0E0E0; }</xsl:text>
105     </xsl:message>
106   </xsl:if>
107
108   <xsl:choose>
109     <xsl:when test="$suppress-numbers = '0'                     and @linenumbering = 'numbered'                     and $use.extensions != '0'                     and $linenumbering.extension != '0'">
110       <xsl:choose>
111         <xsl:when test="@class='monospaced'">
112           <pre>
113             <xsl:apply-templates select="." mode="common.html.attributes"/>
114             <xsl:call-template name="number.rtf.lines">
115               <xsl:with-param name="rtf" select="$rtf"/>
116             </xsl:call-template>
117           </pre>
118         </xsl:when>
119         <xsl:otherwise>
120           <div>
121             <xsl:apply-templates select="." mode="common.html.attributes"/>
122             <p>
123               <xsl:call-template name="number.rtf.lines">
124                 <xsl:with-param name="rtf" select="$rtf"/>
125               </xsl:call-template>
126             </p>
127           </div>
128         </xsl:otherwise>
129       </xsl:choose>
130     </xsl:when>
131     <xsl:otherwise>
132       <xsl:choose>
133         <xsl:when test="@class='monospaced'">
134           <pre>
135             <xsl:apply-templates select="." mode="common.html.attributes"/>
136             <xsl:copy-of select="$rtf"/>
137           </pre>
138         </xsl:when>
139         <xsl:otherwise>
140           <div>
141             <xsl:apply-templates select="." mode="common.html.attributes"/>
142             <p>
143               <xsl:call-template name="make-verbatim">
144                 <xsl:with-param name="rtf" select="$rtf"/>
145               </xsl:call-template>
146             </p>
147           </div>
148         </xsl:otherwise>
149       </xsl:choose>
150     </xsl:otherwise>
151   </xsl:choose>
152 </xsl:template>
153
154 <xsl:template match="address">
155   <xsl:param name="suppress-numbers" select="'0'"/>
156
157   <xsl:variable name="rtf">
158     <xsl:apply-templates/>
159   </xsl:variable>
160
161   <xsl:choose>
162     <xsl:when test="$suppress-numbers = '0'                     and @linenumbering = 'numbered'                     and $use.extensions != '0'                     and $linenumbering.extension != '0'">
163       <div>
164         <xsl:apply-templates select="." mode="common.html.attributes"/>
165         <p>
166           <xsl:call-template name="number.rtf.lines">
167             <xsl:with-param name="rtf" select="$rtf"/>
168           </xsl:call-template>
169         </p>
170       </div>
171     </xsl:when>
172
173     <xsl:otherwise>
174       <div>
175         <xsl:apply-templates select="." mode="common.html.attributes"/>
176         <p>
177           <xsl:call-template name="make-verbatim">
178             <xsl:with-param name="rtf" select="$rtf"/>
179           </xsl:call-template>
180         </p>
181       </div>
182     </xsl:otherwise>
183   </xsl:choose>
184 </xsl:template>
185
186 <xsl:template name="number.rtf.lines">
187   <xsl:param name="rtf" select="''"/>
188   <xsl:param name="pi.context" select="."/>
189
190   <!-- Save the global values -->
191   <xsl:variable name="global.linenumbering.everyNth" select="$linenumbering.everyNth"/>
192
193   <xsl:variable name="global.linenumbering.separator" select="$linenumbering.separator"/>
194
195   <xsl:variable name="global.linenumbering.width" select="$linenumbering.width"/>
196
197   <!-- Extract the <?dbhtml linenumbering.*?> PI values -->
198   <xsl:variable name="pi.linenumbering.everyNth">
199     <xsl:call-template name="pi.dbhtml_linenumbering.everyNth">
200       <xsl:with-param name="node" select="$pi.context"/>
201     </xsl:call-template>
202   </xsl:variable>
203
204   <xsl:variable name="pi.linenumbering.separator">
205     <xsl:call-template name="pi.dbhtml_linenumbering.separator">
206       <xsl:with-param name="node" select="$pi.context"/>
207     </xsl:call-template>
208   </xsl:variable>
209
210   <xsl:variable name="pi.linenumbering.width">
211     <xsl:call-template name="pi.dbhtml_linenumbering.width">
212       <xsl:with-param name="node" select="$pi.context"/>
213     </xsl:call-template>
214   </xsl:variable>
215
216   <!-- Construct the 'in-context' values -->
217   <xsl:variable name="linenumbering.everyNth">
218     <xsl:choose>
219       <xsl:when test="$pi.linenumbering.everyNth != ''">
220         <xsl:value-of select="$pi.linenumbering.everyNth"/>
221       </xsl:when>
222       <xsl:otherwise>
223         <xsl:value-of select="$global.linenumbering.everyNth"/>
224       </xsl:otherwise>
225     </xsl:choose>
226   </xsl:variable>
227
228   <xsl:variable name="linenumbering.separator">
229     <xsl:choose>
230       <xsl:when test="$pi.linenumbering.separator != ''">
231         <xsl:value-of select="$pi.linenumbering.separator"/>
232       </xsl:when>
233       <xsl:otherwise>
234         <xsl:value-of select="$global.linenumbering.separator"/>
235       </xsl:otherwise>
236     </xsl:choose>
237   </xsl:variable>
238
239   <xsl:variable name="linenumbering.width">
240     <xsl:choose>
241       <xsl:when test="$pi.linenumbering.width != ''">
242         <xsl:value-of select="$pi.linenumbering.width"/>
243       </xsl:when>
244       <xsl:otherwise>
245         <xsl:value-of select="$global.linenumbering.width"/>
246       </xsl:otherwise>
247     </xsl:choose>
248   </xsl:variable>
249
250   <xsl:variable name="linenumbering.startinglinenumber">
251     <xsl:choose>
252       <xsl:when test="$pi.context/@startinglinenumber">
253         <xsl:value-of select="$pi.context/@startinglinenumber"/>
254       </xsl:when>
255       <xsl:when test="$pi.context/@continuation='continues'">
256         <xsl:variable name="lastLine">
257           <xsl:choose>
258             <xsl:when test="$pi.context/self::programlisting">
259               <xsl:call-template name="lastLineNumber">
260                 <xsl:with-param name="listings" select="preceding::programlisting[@linenumbering='numbered']"/>
261               </xsl:call-template>
262             </xsl:when>
263             <xsl:when test="$pi.context/self::screen">
264               <xsl:call-template name="lastLineNumber">
265                 <xsl:with-param name="listings" select="preceding::screen[@linenumbering='numbered']"/>
266               </xsl:call-template>
267             </xsl:when>
268             <xsl:when test="$pi.context/self::literallayout">
269               <xsl:call-template name="lastLineNumber">
270                 <xsl:with-param name="listings" select="preceding::literallayout[@linenumbering='numbered']"/>
271               </xsl:call-template>
272             </xsl:when>
273             <xsl:when test="$pi.context/self::address">
274               <xsl:call-template name="lastLineNumber">
275                 <xsl:with-param name="listings" select="preceding::address[@linenumbering='numbered']"/>
276               </xsl:call-template>
277             </xsl:when>
278             <xsl:when test="$pi.context/self::synopsis">
279               <xsl:call-template name="lastLineNumber">
280                 <xsl:with-param name="listings" select="preceding::synopsis[@linenumbering='numbered']"/>
281               </xsl:call-template>
282             </xsl:when>
283             <xsl:otherwise>
284               <xsl:message>
285                 <xsl:text>Unexpected verbatim environment: </xsl:text>
286                 <xsl:value-of select="local-name($pi.context)"/>
287               </xsl:message>
288               <xsl:value-of select="0"/>
289             </xsl:otherwise>
290           </xsl:choose>
291         </xsl:variable>
292
293         <xsl:value-of select="$lastLine + 1"/>
294       </xsl:when>
295       <xsl:otherwise>1</xsl:otherwise>
296     </xsl:choose>
297   </xsl:variable>
298
299   <xsl:choose>
300     <xsl:when test="function-available('sverb:numberLines')">
301       <xsl:copy-of select="sverb:numberLines($rtf)"/>
302     </xsl:when>
303     <xsl:when test="function-available('xverb:numberLines')">
304       <xsl:copy-of select="xverb:numberLines($rtf)"/>
305     </xsl:when>
306     <xsl:otherwise>
307       <xsl:message terminate="yes">
308         <xsl:text>No numberLines function available.</xsl:text>
309       </xsl:message>
310     </xsl:otherwise>
311   </xsl:choose>
312 </xsl:template>
313
314 <xsl:template name="make-verbatim">
315   <xsl:param name="rtf"/>
316
317   <!-- I want to make this RTF verbatim. There are two possibilities: either
318        I have access to the exsl:node-set extension function and I can "do it right"
319        or I have to rely on CSS. -->
320
321   <xsl:choose>
322     <xsl:when test="$exsl.node.set.available != 0">
323       <xsl:apply-templates select="exsl:node-set($rtf)" mode="make.verbatim.mode"/>
324     </xsl:when>
325     <xsl:otherwise>
326       <span style="white-space: pre;">
327         <xsl:copy-of select="$rtf"/>
328       </span>
329     </xsl:otherwise>
330   </xsl:choose>
331 </xsl:template>
332
333 <!-- ======================================================================== -->
334
335 <xsl:template name="lastLineNumber">
336   <xsl:param name="listings"/>
337   <xsl:param name="number" select="0"/>
338
339   <xsl:variable name="lines">
340     <xsl:call-template name="countLines">
341       <xsl:with-param name="listing" select="string($listings[1])"/>
342     </xsl:call-template>
343   </xsl:variable>
344
345   <xsl:choose>
346     <xsl:when test="not($listings)">
347       <xsl:value-of select="$number"/>
348     </xsl:when>
349     <xsl:when test="$listings[1]/@startinglinenumber">
350       <xsl:value-of select="$number + $listings[1]/@startinglinenumber + $lines - 1"/>
351     </xsl:when>
352     <xsl:when test="$listings[1]/@continuation='continues'">
353       <xsl:call-template name="lastLineNumber">
354         <xsl:with-param name="listings" select="listings[position() &gt; 1]"/>
355         <xsl:with-param name="number" select="$number + $lines"/>
356       </xsl:call-template>
357     </xsl:when>
358     <xsl:otherwise>
359       <xsl:value-of select="$lines"/>
360     </xsl:otherwise>
361   </xsl:choose>
362 </xsl:template>
363
364 <xsl:template name="countLines">
365   <xsl:param name="listing"/>
366   <xsl:param name="count" select="1"/>
367
368   <xsl:choose>
369     <xsl:when test="contains($listing, '&#10;')">
370       <xsl:call-template name="countLines">
371         <xsl:with-param name="listing" select="substring-after($listing, '&#10;')"/>
372         <xsl:with-param name="count" select="$count + 1"/>
373       </xsl:call-template>
374     </xsl:when>
375     <xsl:otherwise>
376       <xsl:value-of select="$count"/>
377     </xsl:otherwise>
378   </xsl:choose>
379 </xsl:template>
380
381 </xsl:stylesheet>