source: stylesheets/lfs-xsl/common.xsl@ 52dcb7d

11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since 52dcb7d was 52dcb7d, checked in by Xℹ Ruoyao <xry111@…>, 3 years ago

remove $Date$ and $LastChangedBy$

They are unsupported by Git.

  • Property mode set to 100644
File size: 18.3 KB
Line 
1<?xml version='1.0' encoding='ISO-8859-1'?>
2
3<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns="http://www.w3.org/1999/xhtml"
5 version="1.0">
6
7 <!-- This stylesheet contains common params and templates for all outputs. -->
8
9 <!-- This file contains our localization strings (for internationalization) -->
10 <xsl:param name="local.l10n.xml" select="document('lfs-l10n.xml')"/>
11
12
13<!-- INDEX -->
14
15 <!-- Should the Index be generated? 1 = yes, 0 = no -->
16 <xsl:param name="generate.index" select="1"></xsl:param>
17
18 <!-- The indexing method used. Only 'basic' is supported by xsltproc -->
19 <xsl:param name="index.method" select="'basic'"></xsl:param>
20
21 <!-- The Index title:
22 We create this param to can have gentext support in both
23 the Index page title and links that point to the Index page.
24 It also allow us to change the title, if wanted.
25 Note: To change the title involves creating the appropriate
26 entries in lfs-l10n.xml -->
27 <xsl:param name="index-title">Index</xsl:param>
28
29 <!-- Index title generation. -->
30 <!-- The original template is in {docbook-xsl}/common/titles.xsl -->
31 <xsl:template match="index" mode="title.markup">
32 <xsl:param name="allow-anchors" select="0"/>
33 <xsl:call-template name="gentext">
34 <xsl:with-param name="key" select="$index-title"/>
35 </xsl:call-template>
36 </xsl:template>
37
38 <!-- indexterm:
39 Dropping unneeded anchors and fo:wraper elemments. -->
40 <!-- The original templates are in {docbook-xsl}/{xhtml,fo}/index.xsl -->
41 <xsl:template match="indexterm"/>
42
43<!-- -->
44
45<!-- LABELS -->
46
47 <!-- Are sections enumerated? 1 = yes, 0 = no -->
48 <xsl:param name="section.autolabel" select="1"/>
49
50 <!-- Do section labels include the component label? 1 = yes, 0 = no -->
51 <xsl:param name="section.label.includes.component.label" select="1"/>
52
53 <!-- sect1 label.markup:
54 Use lowercase roman numbers for sect1 in preface. -->
55 <!-- The original template is in {docbook-xsl}/common/labels.xsl -->
56 <xsl:template match="sect1" mode="label.markup">
57 <!-- if the parent is a component, maybe label that too -->
58 <xsl:variable name="parent.is.component">
59 <xsl:call-template name="is.component">
60 <xsl:with-param name="node" select=".."/>
61 </xsl:call-template>
62 </xsl:variable>
63 <xsl:variable name="component.label">
64 <xsl:if test="$section.label.includes.component.label != 0
65 and $parent.is.component != 0">
66 <xsl:variable name="parent.label">
67 <xsl:apply-templates select=".." mode="label.markup"/>
68 </xsl:variable>
69 <xsl:if test="$parent.label != ''">
70 <xsl:apply-templates select=".." mode="label.markup"/>
71 <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
72 </xsl:if>
73 </xsl:if>
74 </xsl:variable>
75 <xsl:choose>
76 <xsl:when test="@label">
77 <xsl:value-of select="@label"/>
78 </xsl:when>
79 <xsl:when test="$section.autolabel != 0">
80 <xsl:copy-of select="$component.label"/>
81 <xsl:choose>
82 <xsl:when test="ancestor::preface">
83 <xsl:number format="i" count="sect1"/>
84 </xsl:when>
85 <xsl:otherwise>
86 <xsl:number format="1" count="sect1"/>
87 </xsl:otherwise>
88 </xsl:choose>
89 </xsl:when>
90 </xsl:choose>
91 </xsl:template>
92
93 <!-- sect2 label.markup:
94 Skip numeration for sect2 with empty title. -->
95 <!-- The original template is in {docbook-xsl}/common/labels.xsl
96 It match also sect3, sect4, and sect5, that are unchanged. -->
97 <xsl:template match="sect2" mode="label.markup">
98 <!-- label the parent -->
99 <xsl:variable name="parent.section.label">
100 <xsl:call-template name="label.this.section">
101 <xsl:with-param name="section" select=".."/>
102 </xsl:call-template>
103 </xsl:variable>
104 <xsl:if test="$parent.section.label != '0'">
105 <xsl:apply-templates select=".." mode="label.markup"/>
106 <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
107 </xsl:if>
108 <xsl:choose>
109 <xsl:when test="@label">
110 <xsl:value-of select="@label"/>
111 </xsl:when>
112 <xsl:when test="$section.autolabel != 0">
113 <xsl:choose>
114 <!-- If the first sect2 isn't numbered, renumber the remainig sections -->
115 <xsl:when test="string-length(../sect2[1]/title) = 0">
116 <xsl:variable name="totalsect2">
117 <xsl:number count="sect2"/>
118 </xsl:variable>
119 <xsl:number value="$totalsect2 - 1"/>
120 </xsl:when>
121 <xsl:otherwise>
122 <xsl:number count="sect2"/>
123 </xsl:otherwise>
124 </xsl:choose>
125 </xsl:when>
126 </xsl:choose>
127 </xsl:template>
128
129 <!-- object.title.template:
130 Skip numeration for sectX > sect1 in preface. -->
131 <!-- The original template is in {docbook-xsl}/common/gentext.xsl. -->
132 <xsl:template match="section|sect1|sect2|sect3|sect4|sect5|simplesect|bridgehead"
133 mode="object.title.template">
134 <xsl:variable name="is.numbered">
135 <xsl:call-template name="label.this.section"/>
136 </xsl:variable>
137 <xsl:choose>
138 <xsl:when test="$is.numbered != 0 and not(ancestor::preface/sect1)">
139 <xsl:call-template name="gentext.template">
140 <xsl:with-param name="context" select="'title-numbered'"/>
141 <xsl:with-param name="name">
142 <xsl:call-template name="xpath.location"/>
143 </xsl:with-param>
144 </xsl:call-template>
145 </xsl:when>
146 <xsl:otherwise>
147 <xsl:call-template name="gentext.template">
148 <xsl:with-param name="context" select="'title-unnumbered'"/>
149 <xsl:with-param name="name">
150 <xsl:call-template name="xpath.location"/>
151 </xsl:with-param>
152 </xsl:call-template>
153 </xsl:otherwise>
154 </xsl:choose>
155 </xsl:template>
156
157<!-- -->
158
159<!-- XREF (see {xhtml,pdf}/xref.xsl) -->
160
161 <!-- mode object.xref.markup:
162 Propagate role to named template substitute-markup -->
163 <!-- The original template is in {docbook-xsl}/common/gentext.xsl -->
164 <xsl:template match="*" mode="object.xref.markup">
165 <xsl:param name="purpose"/>
166 <xsl:param name="xrefstyle"/>
167 <xsl:param name="referrer"/>
168 <xsl:param name="verbose" select="1"/>
169 <xsl:param name="role"/>
170 <xsl:variable name="template">
171 <xsl:choose>
172 <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')">
173 <xsl:call-template name="make.gentext.template">
174 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
175 <xsl:with-param name="purpose" select="$purpose"/>
176 <xsl:with-param name="referrer" select="$referrer"/>
177 </xsl:call-template>
178 </xsl:when>
179 <xsl:when test="starts-with(normalize-space($xrefstyle), 'template:')">
180 <xsl:value-of select="substring-after(normalize-space($xrefstyle), 'template:')"/>
181 </xsl:when>
182 <xsl:otherwise>
183 <xsl:apply-templates select="." mode="object.xref.template">
184 <xsl:with-param name="purpose" select="$purpose"/>
185 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
186 <xsl:with-param name="referrer" select="$referrer"/>
187 </xsl:apply-templates>
188 </xsl:otherwise>
189 </xsl:choose>
190 </xsl:variable>
191 <xsl:if test="$template = '' and $verbose != 0">
192 <xsl:message>
193 <xsl:text>object.xref.markup: empty xref template</xsl:text>
194 <xsl:text> for linkend="</xsl:text>
195 <xsl:value-of select="@id|@xml:id"/>
196 <xsl:text>" and @xrefstyle="</xsl:text>
197 <xsl:value-of select="$xrefstyle"/>
198 <xsl:text>"</xsl:text>
199 </xsl:message>
200 </xsl:if>
201 <xsl:call-template name="substitute-markup">
202 <xsl:with-param name="purpose" select="$purpose"/>
203 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
204 <xsl:with-param name="referrer" select="$referrer"/>
205 <xsl:with-param name="template" select="$template"/>
206 <xsl:with-param name="verbose" select="$verbose"/>
207 <xsl:with-param name="role" select="$role"/>
208 </xsl:call-template>
209 </xsl:template>
210
211 <!-- substitute-markup:
212 Propagate role to mode insert.title.markup -->
213 <!-- The original template is in {docbook-xsl}/common/gentext.xsl -->
214 <xsl:template name="substitute-markup">
215 <xsl:param name="template" select="''"/>
216 <xsl:param name="allow-anchors" select="'0'"/>
217 <xsl:param name="title" select="''"/>
218 <xsl:param name="subtitle" select="''"/>
219 <xsl:param name="docname" select="''"/>
220 <xsl:param name="label" select="''"/>
221 <xsl:param name="pagenumber" select="''"/>
222 <xsl:param name="purpose"/>
223 <xsl:param name="xrefstyle"/>
224 <xsl:param name="referrer"/>
225 <xsl:param name="verbose"/>
226 <xsl:param name="role"/>
227 <xsl:choose>
228 <xsl:when test="contains($template, '%')">
229 <xsl:value-of select="substring-before($template, '%')"/>
230 <xsl:variable name="candidate"
231 select="substring(substring-after($template, '%'), 1, 1)"/>
232 <xsl:choose>
233 <xsl:when test="$candidate = 't'">
234 <xsl:apply-templates select="." mode="insert.title.markup">
235 <xsl:with-param name="purpose" select="$purpose"/>
236 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
237 <xsl:with-param name="role" select="$role"/>
238 <xsl:with-param name="title">
239 <xsl:choose>
240 <xsl:when test="$title != ''">
241 <xsl:copy-of select="$title"/>
242 </xsl:when>
243 <xsl:otherwise>
244 <xsl:apply-templates select="." mode="title.markup">
245 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
246 <xsl:with-param name="verbose" select="$verbose"/>
247 </xsl:apply-templates>
248 </xsl:otherwise>
249 </xsl:choose>
250 </xsl:with-param>
251 </xsl:apply-templates>
252 </xsl:when>
253 <xsl:when test="$candidate = 's'">
254 <xsl:apply-templates select="." mode="insert.subtitle.markup">
255 <xsl:with-param name="purpose" select="$purpose"/>
256 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
257 <xsl:with-param name="subtitle">
258 <xsl:choose>
259 <xsl:when test="$subtitle != ''">
260 <xsl:copy-of select="$subtitle"/>
261 </xsl:when>
262 <xsl:otherwise>
263 <xsl:apply-templates select="." mode="subtitle.markup">
264 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
265 </xsl:apply-templates>
266 </xsl:otherwise>
267 </xsl:choose>
268 </xsl:with-param>
269 </xsl:apply-templates>
270 </xsl:when>
271 <xsl:when test="$candidate = 'n'">
272 <xsl:apply-templates select="." mode="insert.label.markup">
273 <xsl:with-param name="purpose" select="$purpose"/>
274 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
275 <xsl:with-param name="label">
276 <xsl:choose>
277 <xsl:when test="$label != ''">
278 <xsl:copy-of select="$label"/>
279 </xsl:when>
280 <xsl:otherwise>
281 <xsl:apply-templates select="." mode="label.markup"/>
282 </xsl:otherwise>
283 </xsl:choose>
284 </xsl:with-param>
285 </xsl:apply-templates>
286 </xsl:when>
287 <xsl:when test="$candidate = 'p'">
288 <xsl:apply-templates select="." mode="insert.pagenumber.markup">
289 <xsl:with-param name="purpose" select="$purpose"/>
290 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
291 <xsl:with-param name="pagenumber">
292 <xsl:choose>
293 <xsl:when test="$pagenumber != ''">
294 <xsl:copy-of select="$pagenumber"/>
295 </xsl:when>
296 <xsl:otherwise>
297 <xsl:apply-templates select="." mode="pagenumber.markup"/>
298 </xsl:otherwise>
299 </xsl:choose>
300 </xsl:with-param>
301 </xsl:apply-templates>
302 </xsl:when>
303 <xsl:when test="$candidate = 'o'">
304 <!-- olink target document title -->
305 <xsl:apply-templates select="." mode="insert.olink.docname.markup">
306 <xsl:with-param name="purpose" select="$purpose"/>
307 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
308 <xsl:with-param name="docname">
309 <xsl:choose>
310 <xsl:when test="$docname != ''">
311 <xsl:copy-of select="$docname"/>
312 </xsl:when>
313 <xsl:otherwise>
314 <xsl:apply-templates select="." mode="olink.docname.markup"/>
315 </xsl:otherwise>
316 </xsl:choose>
317 </xsl:with-param>
318 </xsl:apply-templates>
319 </xsl:when>
320 <xsl:when test="$candidate = 'd'">
321 <xsl:apply-templates select="." mode="insert.direction.markup">
322 <xsl:with-param name="purpose" select="$purpose"/>
323 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
324 <xsl:with-param name="direction">
325 <xsl:choose>
326 <xsl:when test="$referrer">
327 <xsl:variable name="referent-is-below">
328 <xsl:for-each select="preceding::xref">
329 <xsl:if test="generate-id(.) = generate-id($referrer)">1</xsl:if>
330 </xsl:for-each>
331 </xsl:variable>
332 <xsl:choose>
333 <xsl:when test="$referent-is-below = ''">
334 <xsl:call-template name="gentext">
335 <xsl:with-param name="key" select="'above'"/>
336 </xsl:call-template>
337 </xsl:when>
338 <xsl:otherwise>
339 <xsl:call-template name="gentext">
340 <xsl:with-param name="key" select="'below'"/>
341 </xsl:call-template>
342 </xsl:otherwise>
343 </xsl:choose>
344 </xsl:when>
345 <xsl:otherwise>
346 <xsl:message>Attempt to use %d in gentext with no referrer!</xsl:message>
347 </xsl:otherwise>
348 </xsl:choose>
349 </xsl:with-param>
350 </xsl:apply-templates>
351 </xsl:when>
352 <xsl:when test="$candidate = '%' ">
353 <xsl:text>%</xsl:text>
354 </xsl:when>
355 <xsl:otherwise>
356 <xsl:text>%</xsl:text><xsl:value-of select="$candidate"/>
357 </xsl:otherwise>
358 </xsl:choose>
359 <!-- recurse with the rest of the template string -->
360 <xsl:variable name="rest"
361 select="substring($template,
362 string-length(substring-before($template, '%'))+3)"/>
363 <xsl:call-template name="substitute-markup">
364 <xsl:with-param name="template" select="$rest"/>
365 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
366 <xsl:with-param name="title" select="$title"/>
367 <xsl:with-param name="subtitle" select="$subtitle"/>
368 <xsl:with-param name="docname" select="$docname"/>
369 <xsl:with-param name="label" select="$label"/>
370 <xsl:with-param name="pagenumber" select="$pagenumber"/>
371 <xsl:with-param name="purpose" select="$purpose"/>
372 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
373 <xsl:with-param name="referrer" select="$referrer"/>
374 <xsl:with-param name="verbose" select="$verbose"/>
375 <xsl:with-param name="role" select="$role"/>
376 </xsl:call-template>
377 </xsl:when>
378 <xsl:otherwise>
379 <xsl:value-of select="$template"/>
380 </xsl:otherwise>
381 </xsl:choose>
382 </xsl:template>
383
384<!-- -->
385
386<!-- Total packages size calculation -->
387
388 <!-- returnvalue:
389 If the tag is not empty, apply the original template.
390 Otherwise apply the calculation template. -->
391 <xsl:template match="returnvalue">
392 <xsl:choose>
393 <xsl:when test="count(*)&gt;0">
394 <xsl:apply-imports/>
395 </xsl:when>
396 <xsl:otherwise>
397 <xsl:call-template name="calculation">
398 <xsl:with-param name="scope" select="../../variablelist"/>
399 </xsl:call-template>
400 </xsl:otherwise>
401 </xsl:choose>
402 </xsl:template>
403
404 <!-- Self-made calculation template. -->
405 <xsl:template name="calculation">
406 <xsl:param name="scope"/>
407 <xsl:param name="total">0</xsl:param>
408 <xsl:param name="position">1</xsl:param>
409 <xsl:variable name="tokens" select="count($scope/varlistentry)"/>
410 <xsl:variable name="token" select="$scope/varlistentry[$position]/term/token"/>
411 <xsl:variable name="size" select="substring-before($token,' KB')"/>
412 <xsl:variable name="rawsize">
413 <xsl:choose>
414 <xsl:when test="contains($size,',')">
415 <xsl:value-of select="concat(substring-before($size,','),substring-after($size,','))"/>
416 </xsl:when>
417 <xsl:otherwise>
418 <xsl:value-of select="$size"/>
419 </xsl:otherwise>
420 </xsl:choose>
421 </xsl:variable>
422 <xsl:choose>
423 <xsl:when test="$position &lt;= $tokens">
424 <xsl:call-template name="calculation">
425 <xsl:with-param name="scope" select="$scope"/>
426 <xsl:with-param name="position" select="$position +1"/>
427 <xsl:with-param name="total" select="$total + $rawsize"/>
428 </xsl:call-template>
429 </xsl:when>
430 <xsl:otherwise>
431 <xsl:choose>
432 <xsl:when test="$total &lt; '1000'">
433 <xsl:value-of select="$total"/>
434 <xsl:text> KB</xsl:text>
435 </xsl:when>
436 <xsl:when test="$total &gt; '1000' and $total &lt; '5000'">
437 <xsl:value-of select="substring($total,1,1)"/>
438 <xsl:text>,</xsl:text>
439 <xsl:value-of select="substring($total,2)"/>
440 <xsl:text> KB</xsl:text>
441 </xsl:when>
442 <xsl:otherwise>
443 <xsl:value-of select="round($total div 1024)"/>
444 <xsl:text> MB</xsl:text>
445 </xsl:otherwise>
446 </xsl:choose>
447 </xsl:otherwise>
448 </xsl:choose>
449 </xsl:template>
450
451<!-- -->
452
453</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.