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                exclude-result-prefixes="sverb xverb lxslt"
8                version='1.0'>
9
10<!-- ********************************************************************
11     $Id$
12     ********************************************************************
13
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.
17
18     ******************************************************************** -->
19
20<lxslt:component prefix="xverb"
21                 functions="numberLines"/>
22
23<xsl:template match="programlisting|screen">
24  <xsl:param name="suppress-numbers" select="'0'"/>
25  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
26  <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
27
28  <xsl:choose>
29    <xsl:when test="$suppress-numbers = '0'
30                    and @linenumbering = 'numbered'
31                    and $use.extensions != '0'
32                    and $linenumbering.extension != '0'">
33      <xsl:variable name="rtf">
34        <xsl:apply-templates/>
35      </xsl:variable>
36      <fo:block wrap-option='no-wrap'
37                text-align='start'
38                white-space-collapse='false'
39                linefeed-treatment="preserve"
40                xsl:use-attribute-sets="monospace.verbatim.properties">
41        <xsl:call-template name="number.rtf.lines">
42          <xsl:with-param name="rtf" select="$rtf"/>
43        </xsl:call-template>
44      </fo:block>
45    </xsl:when>
46    <xsl:otherwise>
47      <fo:block wrap-option='no-wrap'
48                text-align='start'
49                white-space-collapse='false'
50                linefeed-treatment="preserve"
51                xsl:use-attribute-sets="monospace.verbatim.properties">
52        <xsl:apply-templates/>
53      </fo:block>
54    </xsl:otherwise>
55  </xsl:choose>
56</xsl:template>
57
58<xsl:template match="literallayout">
59  <xsl:param name="suppress-numbers" select="'0'"/>
60  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
61
62  <xsl:variable name="rtf">
63    <xsl:apply-templates/>
64  </xsl:variable>
65
66  <xsl:choose>
67    <xsl:when test="$suppress-numbers = '0'
68                    and @linenumbering = 'numbered'
69                    and $use.extensions != '0'
70                    and $linenumbering.extension != '0'">
71      <xsl:choose>
72        <xsl:when test="@class='monospaced'">
73          <fo:block wrap-option='no-wrap'
74                    text-align='start'
75                    linefeed-treatment="preserve"
76                    white-space-collapse='false'
77                    xsl:use-attribute-sets="monospace.verbatim.properties">
78            <xsl:call-template name="number.rtf.lines">
79              <xsl:with-param name="rtf" select="$rtf"/>
80            </xsl:call-template>
81          </fo:block>
82        </xsl:when>
83        <xsl:otherwise>
84          <fo:block wrap-option='no-wrap'
85                    text-align='start'
86                    linefeed-treatment="preserve"
87                    white-space-collapse='false'
88                    xsl:use-attribute-sets="verbatim.properties">
89            <xsl:call-template name="number.rtf.lines">
90              <xsl:with-param name="rtf" select="$rtf"/>
91            </xsl:call-template>
92          </fo:block>
93        </xsl:otherwise>
94      </xsl:choose>
95    </xsl:when>
96    <xsl:otherwise>
97      <xsl:choose>
98        <xsl:when test="@class='monospaced'">
99          <fo:block wrap-option='no-wrap'
100                    text-align='start'
101                    linefeed-treatment="preserve"
102                    white-space-collapse='false'
103                    xsl:use-attribute-sets="monospace.verbatim.properties">
104            <xsl:copy-of select="$rtf"/>
105          </fo:block>
106        </xsl:when>
107        <xsl:otherwise>
108          <fo:block wrap-option='no-wrap'
109                    text-align='start'
110                    linefeed-treatment="preserve"
111                    white-space-collapse='false'
112                    xsl:use-attribute-sets="verbatim.properties">
113            <xsl:copy-of select="$rtf"/>
114          </fo:block>
115        </xsl:otherwise>
116      </xsl:choose>
117    </xsl:otherwise>
118  </xsl:choose>
119</xsl:template>
120
121<xsl:template match="address">
122  <xsl:param name="suppress-numbers" select="'0'"/>
123  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
124
125  <xsl:variable name="rtf">
126    <xsl:apply-templates/>
127  </xsl:variable>
128
129  <xsl:choose>
130    <xsl:when test="$suppress-numbers = '0'
131                    and @linenumbering = 'numbered'
132                    and $use.extensions != '0'
133                    and $linenumbering.extension != '0'">
134      <fo:block wrap-option='no-wrap'
135                white-space-collapse='false'
136                linefeed-treatment="preserve"
137                xsl:use-attribute-sets="verbatim.properties">
138        <xsl:call-template name="number.rtf.lines">
139          <xsl:with-param name="rtf" select="$rtf"/>
140        </xsl:call-template>
141      </fo:block>
142    </xsl:when>
143    <xsl:otherwise>
144      <fo:block wrap-option='no-wrap'
145                text-align='start'
146                linefeed-treatment="preserve"
147                white-space-collapse='false'
148                xsl:use-attribute-sets="verbatim.properties">
149        <xsl:apply-templates/>
150      </fo:block>
151    </xsl:otherwise>
152  </xsl:choose>
153</xsl:template>
154
155<xsl:template name="number.rtf.lines">
156  <xsl:param name="rtf" select="''"/>
157  <xsl:param name="pi.context" select="."/>
158
159  <!-- Save the global values -->
160  <xsl:variable name="global.linenumbering.everyNth"
161                select="$linenumbering.everyNth"/>
162
163  <xsl:variable name="global.linenumbering.separator"
164                select="$linenumbering.separator"/>
165
166  <xsl:variable name="global.linenumbering.width"
167                select="$linenumbering.width"/>
168
169  <!-- Extract the <?dbfo linenumbering.*?> PI values -->
170  <xsl:variable name="pi.linenumbering.everyNth">
171    <xsl:call-template name="dbfo-attribute">
172      <xsl:with-param name="pis"
173                      select="$pi.context/processing-instruction('dbfo')"/>
174      <xsl:with-param name="attribute" select="'linenumbering.everyNth'"/>
175    </xsl:call-template>
176  </xsl:variable>
177
178  <xsl:variable name="pi.linenumbering.separator">
179    <xsl:call-template name="dbfo-attribute">
180      <xsl:with-param name="pis"
181                      select="$pi.context/processing-instruction('dbfo')"/>
182      <xsl:with-param name="attribute" select="'linenumbering.separator'"/>
183    </xsl:call-template>
184  </xsl:variable>
185
186  <xsl:variable name="pi.linenumbering.width">
187    <xsl:call-template name="dbfo-attribute">
188      <xsl:with-param name="pis"
189                      select="$pi.context/processing-instruction('dbfo')"/>
190      <xsl:with-param name="attribute" select="'linenumbering.width'"/>
191    </xsl:call-template>
192  </xsl:variable>
193
194  <!-- Construct the 'in-context' values -->
195  <xsl:variable name="linenumbering.everyNth">
196    <xsl:choose>
197      <xsl:when test="$pi.linenumbering.everyNth != ''">
198        <xsl:value-of select="$pi.linenumbering.everyNth"/>
199      </xsl:when>
200      <xsl:otherwise>
201        <xsl:value-of select="$global.linenumbering.everyNth"/>
202      </xsl:otherwise>
203    </xsl:choose>
204  </xsl:variable>
205
206  <xsl:variable name="linenumbering.separator">
207    <xsl:choose>
208      <xsl:when test="$pi.linenumbering.separator != ''">
209        <xsl:value-of select="$pi.linenumbering.separator"/>
210      </xsl:when>
211      <xsl:otherwise>
212        <xsl:value-of select="$global.linenumbering.separator"/>
213      </xsl:otherwise>
214    </xsl:choose>
215  </xsl:variable>
216
217  <xsl:variable name="linenumbering.width">
218    <xsl:choose>
219      <xsl:when test="$pi.linenumbering.width != ''">
220        <xsl:value-of select="$pi.linenumbering.width"/>
221      </xsl:when>
222      <xsl:otherwise>
223        <xsl:value-of select="$global.linenumbering.width"/>
224      </xsl:otherwise>
225    </xsl:choose>
226  </xsl:variable>
227
228  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
229
230  <xsl:choose>
231    <xsl:when test="contains($vendor, 'SAXON ')">
232      <xsl:copy-of select="sverb:numberLines($rtf)"/>
233    </xsl:when>
234    <xsl:when test="contains($vendor, 'Apache Software Foundation')">
235      <xsl:copy-of select="xverb:numberLines($rtf)"/>
236    </xsl:when>
237    <xsl:otherwise>
238      <xsl:message terminate="yes">
239        <xsl:text>Don't know how to do line numbering with </xsl:text>
240        <xsl:value-of select="$vendor"/>
241      </xsl:message>
242    </xsl:otherwise>
243  </xsl:choose>
244</xsl:template>
245
246</xsl:stylesheet>
247