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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
|
<?xml version='1.0' encoding='ISO-8859-1'?>
<!--
$LastChangedBy$
$Date$
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
version="1.0">
<!-- This stylesheet contains common params and templates for all outputs. -->
<!-- This file contains our localization strings (for internationalization) -->
<xsl:param name="local.l10n.xml" select="document('lfs-l10n.xml')"/>
<!-- INDEX -->
<!-- Should the Index be generated? 1 = yes, 0 = no -->
<xsl:param name="generate.index" select="1"></xsl:param>
<!-- The indexing method used. Only 'basic' is supported by xsltproc -->
<xsl:param name="index.method" select="'basic'"></xsl:param>
<!-- The Index title:
We create this param to can have gentext support in both
the Index page title and links that point to the Index page.
It also allow us to change the title, if wanted.
Note: To change the title involves creating the appropiate
entries in lfs-l10n.xml -->
<xsl:param name="index-title">Index</xsl:param>
<!-- Index title generation. -->
<!-- The original template is in {docbook-xsl}/common/titles.xsl -->
<xsl:template match="index" mode="title.markup">
<xsl:param name="allow-anchors" select="0"/>
<xsl:call-template name="gentext">
<xsl:with-param name="key" select="$index-title"/>
</xsl:call-template>
</xsl:template>
<!-- indexterm:
Dropping unneeded anchors and fo:wraper elemments. -->
<!-- The original templates are in {docbook-xsl}/{xhtml,fo}/index.xsl -->
<xsl:template match="indexterm"/>
<!-- -->
<!-- LABELS -->
<!-- Are sections enumerated? 1 = yes, 0 = no -->
<xsl:param name="section.autolabel" select="1"/>
<!-- Do section labels include the component label? 1 = yes, 0 = no -->
<xsl:param name="section.label.includes.component.label" select="1"/>
<!-- sect1 label.markup:
Use lowercase roman numbers for sect1 in preface. -->
<!-- The original template is in {docbook-xsl}/common/labels.xsl -->
<xsl:template match="sect1" mode="label.markup">
<!-- if the parent is a component, maybe label that too -->
<xsl:variable name="parent.is.component">
<xsl:call-template name="is.component">
<xsl:with-param name="node" select=".."/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="component.label">
<xsl:if test="$section.label.includes.component.label != 0
and $parent.is.component != 0">
<xsl:variable name="parent.label">
<xsl:apply-templates select=".." mode="label.markup"/>
</xsl:variable>
<xsl:if test="$parent.label != ''">
<xsl:apply-templates select=".." mode="label.markup"/>
<xsl:apply-templates select=".." mode="intralabel.punctuation"/>
</xsl:if>
</xsl:if>
</xsl:variable>
<xsl:choose>
<xsl:when test="@label">
<xsl:value-of select="@label"/>
</xsl:when>
<xsl:when test="$section.autolabel != 0">
<xsl:copy-of select="$component.label"/>
<xsl:choose>
<xsl:when test="ancestor::preface">
<xsl:number format="i" count="sect1"/>
</xsl:when>
<xsl:otherwise>
<xsl:number format="1" count="sect1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- sect2 label.markup:
Skip numeration for sect2 with empty title. -->
<!-- The original template is in {docbook-xsl}/common/labels.xsl
It match also sect3, sect4, and sect5, that are unchanged. -->
<xsl:template match="sect2" mode="label.markup">
<!-- label the parent -->
<xsl:variable name="parent.section.label">
<xsl:call-template name="label.this.section">
<xsl:with-param name="section" select=".."/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$parent.section.label != '0'">
<xsl:apply-templates select=".." mode="label.markup"/>
<xsl:apply-templates select=".." mode="intralabel.punctuation"/>
</xsl:if>
<xsl:choose>
<xsl:when test="@label">
<xsl:value-of select="@label"/>
</xsl:when>
<xsl:when test="$section.autolabel != 0">
<xsl:choose>
<!-- If the first sect2 isn't numbered, renumber the remainig sections -->
<xsl:when test="string-length(../sect2[1]/title) = 0">
<xsl:variable name="totalsect2">
<xsl:number count="sect2"/>
</xsl:variable>
<xsl:number value="$totalsect2 - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:number count="sect2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- object.title.template:
Skip numeration for sectX > sect1 in preface. -->
<!-- The original template is in {docbook-xsl}/common/gentext.xsl. -->
<xsl:template match="section|sect1|sect2|sect3|sect4|sect5|simplesect|bridgehead"
mode="object.title.template">
<xsl:variable name="is.numbered">
<xsl:call-template name="label.this.section"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$is.numbered != 0 and not(ancestor::preface/sect1)">
<xsl:call-template name="gentext.template">
<xsl:with-param name="context" select="'title-numbered'"/>
<xsl:with-param name="name">
<xsl:call-template name="xpath.location"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="gentext.template">
<xsl:with-param name="context" select="'title-unnumbered'"/>
<xsl:with-param name="name">
<xsl:call-template name="xpath.location"/>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- -->
<!-- XREF (see {xhtml,pdf}/xref.xsl) -->
<!-- mode object.xref.markup:
Propagate role to named template substitute-markup -->
<!-- The original template is in {docbook-xsl}/common/gentext.xsl -->
<xsl:template match="*" mode="object.xref.markup">
<xsl:param name="purpose"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="referrer"/>
<xsl:param name="verbose" select="1"/>
<xsl:param name="role"/>
<xsl:variable name="template">
<xsl:choose>
<xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')">
<xsl:call-template name="make.gentext.template">
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="purpose" select="$purpose"/>
<xsl:with-param name="referrer" select="$referrer"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with(normalize-space($xrefstyle), 'template:')">
<xsl:value-of select="substring-after(normalize-space($xrefstyle), 'template:')"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="object.xref.template">
<xsl:with-param name="purpose" select="$purpose"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$template = '' and $verbose != 0">
<xsl:message>
<xsl:text>object.xref.markup: empty xref template</xsl:text>
<xsl:text> for linkend="</xsl:text>
<xsl:value-of select="@id|@xml:id"/>
<xsl:text>" and @xrefstyle="</xsl:text>
<xsl:value-of select="$xrefstyle"/>
<xsl:text>"</xsl:text>
</xsl:message>
</xsl:if>
<xsl:call-template name="substitute-markup">
<xsl:with-param name="purpose" select="$purpose"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="template" select="$template"/>
<xsl:with-param name="verbose" select="$verbose"/>
<xsl:with-param name="role" select="$role"/>
</xsl:call-template>
</xsl:template>
<!-- substitute-markup:
Propagate role to mode insert.title.markup -->
<!-- The original template is in {docbook-xsl}/common/gentext.xsl -->
<xsl:template name="substitute-markup">
<xsl:param name="template" select="''"/>
<xsl:param name="allow-anchors" select="'0'"/>
<xsl:param name="title" select="''"/>
<xsl:param name="subtitle" select="''"/>
<xsl:param name="docname" select="''"/>
<xsl:param name="label" select="''"/>
<xsl:param name="pagenumber" select="''"/>
<xsl:param name="purpose"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="referrer"/>
<xsl:param name="verbose"/>
<xsl:param name="role"/>
<xsl:choose>
<xsl:when test="contains($template, '%')">
<xsl:value-of select="substring-before($template, '%')"/>
<xsl:variable name="candidate"
select="substring(substring-after($template, '%'), 1, 1)"/>
<xsl:choose>
<xsl:when test="$candidate = 't'">
<xsl:apply-templates select="." mode="insert.title.markup">
<xsl:with-param name="purpose" select="$purpose"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="role" select="$role"/>
<xsl:with-param name="title">
<xsl:choose>
<xsl:when test="$title != ''">
<xsl:copy-of select="$title"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="title.markup">
<xsl:with-param name="allow-anchors" select="$allow-anchors"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$candidate = 's'">
<xsl:apply-templates select="." mode="insert.subtitle.markup">
<xsl:with-param name="purpose" select="$purpose"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="subtitle">
<xsl:choose>
<xsl:when test="$subtitle != ''">
<xsl:copy-of select="$subtitle"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="subtitle.markup">
<xsl:with-param name="allow-anchors" select="$allow-anchors"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$candidate = 'n'">
<xsl:apply-templates select="." mode="insert.label.markup">
<xsl:with-param name="purpose" select="$purpose"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="label">
<xsl:choose>
<xsl:when test="$label != ''">
<xsl:copy-of select="$label"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="label.markup"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$candidate = 'p'">
<xsl:apply-templates select="." mode="insert.pagenumber.markup">
<xsl:with-param name="purpose" select="$purpose"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="pagenumber">
<xsl:choose>
<xsl:when test="$pagenumber != ''">
<xsl:copy-of select="$pagenumber"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="pagenumber.markup"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$candidate = 'o'">
<!-- olink target document title -->
<xsl:apply-templates select="." mode="insert.olink.docname.markup">
<xsl:with-param name="purpose" select="$purpose"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="docname">
<xsl:choose>
<xsl:when test="$docname != ''">
<xsl:copy-of select="$docname"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="olink.docname.markup"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$candidate = 'd'">
<xsl:apply-templates select="." mode="insert.direction.markup">
<xsl:with-param name="purpose" select="$purpose"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="direction">
<xsl:choose>
<xsl:when test="$referrer">
<xsl:variable name="referent-is-below">
<xsl:for-each select="preceding::xref">
<xsl:if test="generate-id(.) = generate-id($referrer)">1</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="$referent-is-below = ''">
<xsl:call-template name="gentext">
<xsl:with-param name="key" select="'above'"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="gentext">
<xsl:with-param name="key" select="'below'"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:message>Attempt to use %d in gentext with no referrer!</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$candidate = '%' ">
<xsl:text>%</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>%</xsl:text><xsl:value-of select="$candidate"/>
</xsl:otherwise>
</xsl:choose>
<!-- recurse with the rest of the template string -->
<xsl:variable name="rest"
select="substring($template,
string-length(substring-before($template, '%'))+3)"/>
<xsl:call-template name="substitute-markup">
<xsl:with-param name="template" select="$rest"/>
<xsl:with-param name="allow-anchors" select="$allow-anchors"/>
<xsl:with-param name="title" select="$title"/>
<xsl:with-param name="subtitle" select="$subtitle"/>
<xsl:with-param name="docname" select="$docname"/>
<xsl:with-param name="label" select="$label"/>
<xsl:with-param name="pagenumber" select="$pagenumber"/>
<xsl:with-param name="purpose" select="$purpose"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
<xsl:with-param name="role" select="$role"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$template"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- -->
<!-- Total packages size calculation -->
<!-- returnvalue:
If the tag is not empty, apply the original template.
Otherwise apply the calculation template. -->
<xsl:template match="returnvalue">
<xsl:choose>
<xsl:when test="count(*)>0">
<xsl:apply-imports/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="calculation">
<xsl:with-param name="scope" select="../../variablelist"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Self-made calculation template. -->
<xsl:template name="calculation">
<xsl:param name="scope"/>
<xsl:param name="total">0</xsl:param>
<xsl:param name="position">1</xsl:param>
<xsl:variable name="tokens" select="count($scope/varlistentry)"/>
<xsl:variable name="token" select="$scope/varlistentry[$position]/term/token"/>
<xsl:variable name="size" select="substring-before($token,' KB')"/>
<xsl:variable name="rawsize">
<xsl:choose>
<xsl:when test="contains($size,',')">
<xsl:value-of select="concat(substring-before($size,','),substring-after($size,','))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$size"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$position <= $tokens">
<xsl:call-template name="calculation">
<xsl:with-param name="scope" select="$scope"/>
<xsl:with-param name="position" select="$position +1"/>
<xsl:with-param name="total" select="$total + $rawsize"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$total < '1000'">
<xsl:value-of select="$total"/>
<xsl:text> KB</xsl:text>
</xsl:when>
<xsl:when test="$total > '1000' and $total < '5000'">
<xsl:value-of select="substring($total,1,1)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="substring($total,2)"/>
<xsl:text> KB</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="round($total div 1024)"/>
<xsl:text> MB</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- -->
</xsl:stylesheet>
|