forked from docbook/xslt10-stylesheets
/
ldocbook.xweb
444 lines (366 loc) · 14 KB
/
ldocbook.xweb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<!DOCTYPE article [
<!ENTITY xweb "<acronym>XWEB</acronym>">
<!ENTITY lt "&#60;"> <!-- LESS-THAN SIGN -->
<!ENTITY gt ">"> <!-- GREATER-THAN SIGN -->
<!ENTITY amp "&#38;"> <!-- AMPERSAND -->
]>
<article xmlns:src="http://nwalsh.com/xmlns/litprog/fragment"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<articleinfo>
<title>Literate DocBook XML Stylesheets</title>
<subtitle>Part of
<citetitle>Literate Programming in XML</citetitle></subtitle>
<pubdate>05 Oct 2001</pubdate>
<releaseinfo role="meta">
</releaseinfo>
<revhistory>
<revision>
<revnumber>0.1</revnumber>
<date>05 Oct 2001</date>
<authorinitials>ndw</authorinitials>
<revremark>Initial draft.</revremark>
</revision>
</revhistory>
<author><firstname>Norman</firstname><surname>Walsh</surname>
</author>
</articleinfo>
<!-- ============================================================ -->
<para>The <filename>ldocbook.xsl</filename> stylesheet transforms an
&xweb; documentation file (a <quote>woven</quote> &xweb; document)
into HTML documentation.</para>
<para>This stylesheet assumes that fragments appear inside DocBook
<sgmltag>section</sgmltag> elements. Some additional customization of
the <src:fragref linkend="fragment-label"/> and
<src:fragref linkend="fragment-title"/> will be required
to support a different organization.</para>
<section><title>The Stylesheets</title>
<para>This document describes both the HTML and XSL Formatting Objects
versions of the stylesheet.</para>
<section><title>The HTML Stylesheet</title>
<para>The stylesheet performs some initialization and establishes
templates for the Literate Programming elements that can appear in
the documentation. Most of the documentation elements will be
DocBook elements handled by the imported stylesheet.</para>
<src:fragment id="top" mundane-result-prefixes="xsl fo verb">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:src="http://nwalsh.com/xmlns/litprog/fragment"
xmlns:verb="com.nwalsh.saxon.Verbatim"
exclude-result-prefixes="verb src"
version="1.0">
<xsl:import href="https://cdn.docbook.org/release/xsl/current/html/docbook.xsl"/>
<src:fragref linkend="init"/>
<src:fragref linkend="proc-html-fragment"/>
<src:fragref linkend="proc-html-fragref"/>
</xsl:stylesheet>
</src:fragment>
</section>
<section><title>The Chunking HTML Stylesheet</title>
<para>The stylesheet performs some initialization and establishes
templates for the Literate Programming elements that can appear in
the documentation. Most of the documentation elements will be
DocBook elements handled by the imported stylesheet.</para>
<src:fragment id="top-chunk" mundane-result-prefixes="xsl fo verb">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:src="http://nwalsh.com/xmlns/litprog/fragment"
xmlns:verb="com.nwalsh.saxon.Verbatim"
exclude-result-prefixes="verb src"
version="1.0">
<xsl:import href="https://cdn.docbook.org/release/xsl/current/html/chunk.xsl"/>
<src:fragref linkend="init"/>
<src:fragref linkend="proc-html-fragment"/>
<src:fragref linkend="proc-html-fragref"/>
</xsl:stylesheet>
</src:fragment>
</section>
<section><title>The FO Stylesheet</title>
<para>The stylesheet performs some initialization and establishes
templates for the Literate Programming elements that can appear in
the documentation. Most of the documentation elements will be
DocBook elements handled by the imported stylesheet.</para>
<src:fragment id="fo-top" mundane-result-prefixes="xsl fo verb">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:src="http://nwalsh.com/xmlns/litprog/fragment"
xmlns:verb="com.nwalsh.saxon.Verbatim"
exclude-result-prefixes="verb src fo"
version="1.0">
<xsl:import href="https://cdn.docbook.org/release/xsl/current/fo/docbook.xsl"/>
<xsl:param name="page.margin.outer" select="'1in'"/>
<xsl:param name="title.margin.left" select="'-0pt'"/>
<src:fragref linkend="init"/>
<src:fragref linkend="proc-fo-fragment"/>
<src:fragref linkend="proc-fo-fragref"/>
</xsl:stylesheet>
</src:fragment>
</section>
<section><title>Initialization</title>
<para>The stylesheet initializes the processor by loading its version
information (stored in a separate file because it is shared by several
stylesheets), importing the base DocBook stylesheet, setting some
parameters, and setting up
some internationalized text.</para>
<src:fragment id="init">
<xsl:include href="../VERSION"/>
<xsl:template match="revhistory" mode="titlepage.mode"/>
<src:fragref linkend="param"/>
<src:fragref linkend="i18n"/>
</src:fragment>
<section><title>Parameters</title>
<para>In DocBook Literate Programming documentation, we always number
sections and verbatim environments.</para>
<src:fragment id="param">
<xsl:param name="section.autolabel" select="1"/>
<xsl:param name="linenumbering.everyNth" select="5"/>
<xsl:param name="linenumbering.separator" select="'| '"/>
</src:fragment>
</section>
<section><title>Localization</title>
<para>Localized text in the DocBook stylesheets makes use of an
external document to determine the nature of, among other things,
element titles and cross references.</para>
<para>Cross references to <sgmltag>src:fragments</sgmltag> are not
supported in the stock stylesheets (since there is no such element
in DocBook).</para>
<para>In order to make cross references work properly, we must provide
an appropriate localization for <sgmltag>src:fragment</sgmltag> titles.
We do this by pointing the <parameter>local.l10n.xml</parameter>
<emphasis>at ourselves</emphasis> (at the stylesheet document).</para>
<para>In our local localization document, we add an
<sgmltag>l:i18n</sgmltag> element to provide the necessary context.</para>
<para>If you want to support DocBook Literate Programming in other
languages, this section will have to be updated.</para>
<src:fragment id="i18n">
<xsl:param name="local.l10n.xml" select="document('')"/>
<l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">
<l:l10n language="en">
<l:context name="title">
<l:template name="fragment" text="%t"/>
</l:context>
</l:l10n>
</l:i18n>
</src:fragment>
</section>
</section>
</section>
<section><title>Process HTML Fragments</title>
<para>Fragments are output as verbatim environments with numbered lines,
if possible. A table is used to make the listings stand out.</para>
<src:fragment id="proc-html-fragment">
<xsl:template match="src:fragment">
<xsl:param name="suppress-numbers" select="'0'"/>
<xsl:param name="linenumbering" select="'numbered'"/>
<xsl:variable name="section" select="ancestor::section[1]"/>
<xsl:variable name="id" select="@id"/>
<xsl:variable name="referents"
select="//src:fragment[.//src:fragref[@linkend=$id]]"/>
<div class="src-fragment">
<a name="{@id}"/>
<table border="1" width="100%">
<tr>
<td>
<p>
<b>
<xsl:apply-templates select="." mode="label.markup"/>
</b>
<xsl:if test="$referents">
<xsl:text>: </xsl:text>
<xsl:for-each select="$referents">
<xsl:if test="position() > 1">, </xsl:if>
<a>
<xsl:attribute name="href">
<xsl:call-template name="href.target">
<xsl:with-param name="object" select="."/>
</xsl:call-template>
</xsl:attribute>
<xsl:apply-templates select="." mode="label.markup"/>
</a>
</xsl:for-each>
</xsl:if>
</p>
</td>
</tr>
<tr>
<td>
<xsl:choose>
<xsl:when test="$suppress-numbers = '0'
and $linenumbering = 'numbered'
and $use.extensions != '0'
and $linenumbering.extension != '0'">
<xsl:variable name="rtf">
<xsl:apply-templates/>
</xsl:variable>
<pre class="{name(.)}">
<xsl:copy-of select="verb:numberLines($rtf)"/>
</pre>
</xsl:when>
<xsl:otherwise>
<pre class="{name(.)}">
<xsl:apply-templates/>
</pre>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</table>
</div>
</xsl:template>
<src:fragref linkend="fragment-label"/>
<src:fragref linkend="fragment-title"/>
</src:fragment>
<para>Fragment labels and titles must also be supported.</para>
<section><title>Fragment Labels</title>
<para>A fragment label consists of a section mark followed by the
label of the current section and the number of the fragment within
that section.</para>
<src:fragment id="fragment-label">
<xsl:template match="src:fragment" mode="label.markup">
<xsl:variable name="section" select="ancestor::section[1]"/>
<xsl:text>§</xsl:text>
<xsl:choose>
<xsl:when test="$section">
<xsl:variable name="section.label">
<xsl:apply-templates select="$section" mode="label.markup"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="string($section.label) = ''">
<xsl:number from="section"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$section.label"/>
<xsl:text>.</xsl:text>
<xsl:number from="section"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:number from="/"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</src:fragment>
</section>
<section><title>Fragment Titles</title>
<para>A fragment title is the title of the section that contains it.
</para>
<src:fragment id="fragment-title">
<xsl:template match="src:fragment" mode="title.markup">
<xsl:variable name="section" select="ancestor::section[1]"/>
<xsl:if test="$section">
<xsl:apply-templates select="$section" mode="title.markup"/>
</xsl:if>
</xsl:template>
</src:fragment>
</section>
</section>
<section><title>Process FO Fragments</title>
<para>Fragments are output as verbatim environments with numbered lines,
if possible.</para>
<src:fragment id="proc-fo-fragment">
<xsl:template match="src:fragment">
<xsl:param name="suppress-numbers" select="'0'"/>
<xsl:param name="linenumbering" select="'numbered'"/>
<xsl:variable name="section" select="ancestor::section[1]"/>
<xsl:variable name="id" select="@id"/>
<xsl:variable name="referents"
select="//src:fragment[.//src:fragref[@linkend=$id]]"/>
<fo:block xsl:use-attribute-sets="formal.object.properties"
keep-together="always"
border-style="solid"
border-width="0pt"
border-before-width="0.25pt"
border-after-width="0.25pt">
<fo:block id="{@id}"
border-width="0pt"
border-style="solid"
border-after-width="0.25pt">
<fo:inline font-weight="bold">
<xsl:apply-templates select="." mode="label.markup"/>
</fo:inline>
<fo:inline>
<xsl:if test="$referents">
<xsl:text>: </xsl:text>
<xsl:for-each select="$referents">
<xsl:if test="position() > 1">, </xsl:if>
<xsl:apply-templates select="." mode="label.markup"/>
</xsl:for-each>
</xsl:if>
</fo:inline>
</fo:block>
<fo:block wrap-option='no-wrap'
text-align='start'
white-space-collapse='false'
linefeed-treatment="preserve"
xsl:use-attribute-sets="monospace.verbatim.properties">
<xsl:variable name="rtf">
<xsl:apply-templates/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$suppress-numbers = '0'
and $linenumbering = 'numbered'
and $use.extensions != '0'
and $linenumbering.extension != '0'">
<xsl:call-template name="number.rtf.lines">
<xsl:with-param name="rtf" select="$rtf"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$rtf"/>
</xsl:otherwise>
</xsl:choose>
</fo:block>
</fo:block>
</xsl:template>
<src:fragref linkend="fragment-label"/>
<src:fragref linkend="fragment-title"/>
</src:fragment>
</section>
<section><title>Process HTML Fragment References</title>
<para>A fragment reference has exactly the same semantics as a DocBook
<sgmltag>xref</sgmltag>.</para>
<src:fragment id="proc-html-fragref">
<xsl:template match="src:fragref">
<xsl:call-template name="xref"/>
</xsl:template>
<src:fragref linkend="fragref-html-xref-to"/>
</src:fragment>
<section><title>Fragment Cross-Reference Text</title>
<para>Cross references to fragments produce the fragment label
and title.</para>
<src:fragment id="fragref-html-xref-to">
<xsl:template match="src:fragment" mode="xref-to">
<xsl:variable name="section" select="ancestor::section[1]"/>
<i>
<xsl:apply-templates select="." mode="label.markup"/>
<xsl:text>. </xsl:text>
<xsl:apply-templates select="." mode="title.markup"/>
</i>
</xsl:template>
</src:fragment>
</section>
</section>
<section><title>Process FO Fragment References</title>
<para>A fragment reference has exactly the same semantics as a DocBook
<sgmltag>xref</sgmltag>.</para>
<src:fragment id="proc-fo-fragref">
<xsl:template match="src:fragref">
<xsl:call-template name="xref"/>
</xsl:template>
<src:fragref linkend="fragref-fo-xref-to"/>
</src:fragment>
<section><title>Fragment Cross-Reference Text</title>
<para>Cross references to fragments produce the fragment label
and title.</para>
<src:fragment id="fragref-fo-xref-to">
<xsl:template match="src:fragment" mode="xref-to">
<xsl:variable name="section" select="ancestor::section[1]"/>
<fo:inline font-style="italic">
<xsl:apply-templates select="." mode="label.markup"/>
<xsl:text>. </xsl:text>
<xsl:apply-templates select="." mode="title.markup"/>
</fo:inline>
</xsl:template>
</src:fragment>
</section>
</section>
</article>