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