source: BLFS/xsl/gen_pkg_list.xsl@ 7a82194

ablfs-more legacy trunk
Last change on this file since 7a82194 was 1646303, checked in by Pierre Labastie <pierre@…>, 6 years ago

A module can be a special case, too (perl-test-mockmodule)

  • Property mode set to 100644
File size: 19.2 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2
3<!-- $Id$ -->
4<!-- Takes the blfs-full.xml file and extract a list
5 of packages obeying packdesc.dtd + looks for already
6 installed packages in the tracking file (stringparam
7 'installed-packages') -->
8<!-- Extract also a list of LFS packages from stringparam lfs-full -->
9
10<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
11 version="1.0">
12
13 <xsl:param name="lfs-full" select="'./lfs-xml/lfs-full.xml'"/>
14 <xsl:param name="installed-packages" select="'../lib/instpkg.xml'"/>
15
16 <xsl:output method="xml"
17 encoding='ISO-8859-1'
18 doctype-system="./packdesc.dtd"/>
19
20<!-- specialCases.xsl is generated by a shell script:
21 allows for cases where version begins with a letter
22 and when there is no version (such as xorg7 packages) -->
23 <xsl:include href="./specialCases.xsl"/>
24
25 <xsl:template match="/">
26 <princList>
27 <xsl:text>&#xA;&#xA; </xsl:text>
28 <list>
29 <xsl:attribute name="id">lfs</xsl:attribute>
30 <xsl:text>&#xA; </xsl:text>
31 <name>LFS Packages</name>
32 <xsl:text>&#xA; </xsl:text>
33 <sublist>
34 <xsl:attribute name="id">lfs-6</xsl:attribute>
35 <xsl:text>&#xA; </xsl:text>
36 <name>LFS Chapter 6</name>
37 <xsl:apply-templates
38 select='document($lfs-full)//
39 chapter[@id="chapter-building-system"]/
40 sect1/sect1info'/>
41 <xsl:text>&#xA; </xsl:text>
42 </sublist>
43 <sublist>
44 <xsl:attribute name="id">lfs-8</xsl:attribute>
45 <xsl:text>&#xA; </xsl:text>
46 <name>LFS Chapter 8</name>
47 <xsl:apply-templates select='document($lfs-full)//chapter[@id="chapter-bootable"]/sect1/sect1info[./productname="linux"]'/>
48 <xsl:text>&#xA; </xsl:text>
49 </sublist>
50 <sublist>
51 <xsl:attribute name="id">lfs-9</xsl:attribute>
52 <xsl:text>&#xA; </xsl:text>
53 <name>LFS Chapter 9</name>
54 <xsl:apply-templates select='document($lfs-full)//sect1[@id="ch-finish-theend"]//userinput[starts-with(string(),"echo")]'/>
55 <xsl:text>&#xA; </xsl:text>
56 </sublist>
57 <xsl:text>&#xA;&#xA; </xsl:text>
58 </list>
59<!-- How to have blfs-bootscripts versionned? Do not know, so
60 avoid it (TODO ?) -->
61 <xsl:apply-templates select="//part[not(@id='introduction')]"/>
62 </princList>
63 </xsl:template>
64
65 <xsl:template match="userinput">
66<!-- Only used in lFS chapter 9, to retrieve book version -->
67 <package>
68 <name>LFS-Release</name>
69 <xsl:element name="version">
70 <xsl:copy-of select="substring-after(substring-before(string(),' &gt;'),'echo ')"/>
71 </xsl:element>
72 <xsl:if
73 test="document($installed-packages)//package[name='LFS-Release']">
74 <xsl:text>&#xA; </xsl:text>
75 <xsl:element name="inst-version">
76 <xsl:value-of
77 select="document(
78 $installed-packages
79 )//package[name='LFS-Release']/version"/>
80 </xsl:element>
81 </xsl:if>
82 </package>
83 </xsl:template>
84
85 <xsl:template match="sect1info">
86 <xsl:text> </xsl:text>
87 <xsl:choose>
88<!-- Never update linux headers -->
89 <xsl:when test="./productname='linux'
90 and ancestor::chapter[@id='chapter-building-system']"/>
91<!-- Gcc version is taken from BLFS -->
92 <xsl:when test="./productname='gcc'"/>
93<!-- Shadow version is taken from BLFS -->
94 <xsl:when test="./productname='shadow'"/>
95<!-- Vim version is taken from BLFS -->
96 <xsl:when test="./productname='vim'"/>
97<!-- Dbus version is taken from BLFS -->
98 <xsl:when test="./productname='dbus'"/>
99<!-- Systemd version is taken from BLFS -->
100 <xsl:when test="./productname='systemd'"/>
101<!-- Same for python and ninja -->
102 <xsl:when test="./productname='ninja'"/>
103 <xsl:when test="./productname='Python'"/>
104 <xsl:otherwise>
105 <package><xsl:text>&#xA; </xsl:text>
106 <xsl:element name="name">
107 <xsl:value-of select="./productname"/>
108 </xsl:element>
109 <xsl:text>&#xA; </xsl:text>
110 <xsl:element name="version">
111 <xsl:value-of select="./productnumber"/>
112 </xsl:element>
113 <xsl:if
114 test="document($installed-packages)//package[name=current()/productname]">
115 <xsl:text>&#xA; </xsl:text>
116 <xsl:element name="inst-version">
117 <xsl:value-of
118 select="document(
119 $installed-packages
120 )//package[name=current()/productname]/version"/>
121 </xsl:element>
122 </xsl:if>
123 </package>
124 </xsl:otherwise>
125 </xsl:choose>
126<!-- No deps for now: a former version is always installed -->
127 </xsl:template>
128
129 <xsl:template match="part">
130 <xsl:if test="count(.//*[contains(translate(@xreflabel,
131 '123456789',
132 '000000000'),
133 '-0')
134 ]) &gt; 0">
135 <xsl:text> </xsl:text>
136 <list>
137 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
138 <xsl:text>&#xA; </xsl:text>
139 <xsl:element name="name">
140 <xsl:value-of select="normalize-space(title)"/>
141 </xsl:element>
142 <xsl:text>&#xA;&#xA;</xsl:text>
143 <xsl:apply-templates select="chapter"/>
144 <xsl:text> </xsl:text>
145 </list>
146 <xsl:text>&#xA;&#xA;</xsl:text>
147 </xsl:if>
148 </xsl:template>
149
150 <xsl:template match="chapter">
151 <xsl:if test="count(.//*[contains(translate(@xreflabel,
152 '123456789',
153 '000000000'),
154 '-0')
155 ]) &gt; 0">
156 <xsl:text> </xsl:text>
157 <sublist>
158 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
159 <xsl:text>&#xA; </xsl:text>
160 <xsl:element name="name">
161 <xsl:value-of select="normalize-space(title)"/>
162 </xsl:element>
163 <xsl:text>&#xA;</xsl:text>
164 <xsl:apply-templates select=".//sect1">
165 <xsl:sort select="@id"/>
166 </xsl:apply-templates>
167 <xsl:text> </xsl:text>
168 </sublist><xsl:text>&#xA;&#xA;</xsl:text>
169 </xsl:if>
170 </xsl:template>
171
172 <xsl:template match="sect1">
173 <xsl:choose>
174<!-- This test is to find sections containing modules (PERL, Python
175 DBus,...) -->
176 <xsl:when
177 test="not(contains(translate(@xreflabel,
178 '123456789',
179 '000000000'),
180 '-0')) and
181 count(descendant::node()[contains(translate(@xreflabel,
182 '123456789',
183 '000000000'),
184 '-0')
185 ]) &gt; 0">
186 <xsl:text> </xsl:text>
187 <package><xsl:text>&#xA; </xsl:text>
188 <xsl:element name="name">
189 <xsl:value-of select="normalize-space(title)"/>
190 </xsl:element>
191 <xsl:text>&#xA;</xsl:text>
192<!-- Do not use .//*, which would include self.
193 Even a module can be a special case, so
194 call the template of specialCases.xsl,
195 which calls the "normal" template when the
196 case is normal. -->
197 <xsl:apply-templates select="descendant::*" mode="special">
198 <xsl:sort select="@id"/>
199 </xsl:apply-templates>
200 <xsl:text> </xsl:text>
201 </package><xsl:text>&#xA;&#xA;</xsl:text>
202 </xsl:when>
203 <xsl:otherwise>
204<!-- Calls the template of specialCases.xsl,
205 which calls the "normal" template when the
206 case is normal. -->
207 <xsl:apply-templates select='.' mode="special">
208 <xsl:sort select="@id"/>
209 </xsl:apply-templates>
210 </xsl:otherwise>
211 </xsl:choose>
212 </xsl:template>
213
214 <xsl:template match="*" mode="normal">
215 <xsl:variable name="version">
216 <xsl:call-template name="version">
217 <xsl:with-param name="label" select="./@xreflabel"/>
218 </xsl:call-template>
219 </xsl:variable>
220 <xsl:choose>
221<!-- If there is a "sect1" ancestor, this means that
222 we have a module -->
223 <xsl:when test="ancestor::sect1">
224 <xsl:text> </xsl:text>
225 <module><xsl:text>&#xA; </xsl:text>
226 <xsl:element name="name">
227 <xsl:value-of select="./@id"/>
228 </xsl:element>
229 <xsl:text>&#xA; </xsl:text>
230 <xsl:element name="version">
231 <xsl:value-of select="$version"/>
232 </xsl:element>
233 <xsl:if
234 test="document($installed-packages)//package[name=current()/@id]">
235 <xsl:text>&#xA; </xsl:text>
236 <xsl:element name="inst-version">
237 <xsl:value-of
238 select="document(
239 $installed-packages
240 )//package[name=current()/@id]/version"/>
241 </xsl:element>
242 </xsl:if>
243<!-- Dependencies -->
244<!-- First the case of python modules or d-bus bindings -->
245 <xsl:if test="self::sect2">
246<!-- dependencies -->
247 <xsl:apply-templates select=".//para[@role='required' or
248 @role='recommended' or
249 @role='optional']"
250 mode="dependency"/>
251 </xsl:if>
252<!-- For python modules, the preceding module is an optional dep -->
253 <xsl:if test="ancestor::sect1[@id='python-modules']">
254 <xsl:apply-templates
255 select="preceding-sibling::sect2[@role='package']
256 //listitem[para/xref/@linkend=current()/@id]"
257 mode="prec-dep"/>
258 </xsl:if>
259<!-- Now the case of perl modules: let us test our XSLT abilities.
260 Well, "use the sibling, Luke" -->
261 <xsl:if test="self::bridgehead">
262 <xsl:apply-templates select="following-sibling::itemizedlist[1]
263 /listitem/itemizedlist/listitem"
264 mode="perlmod-dep">
265 <xsl:sort select="position()"
266 data-type="number"
267 order="descending"/>
268 </xsl:apply-templates>
269 </xsl:if>
270<!-- End dependencies -->
271 <xsl:text>&#xA; </xsl:text>
272 </module><xsl:text>&#xA;</xsl:text>
273 </xsl:when>
274 <xsl:otherwise>
275 <xsl:text> </xsl:text>
276 <package><xsl:text>&#xA; </xsl:text>
277 <xsl:element name="name">
278 <xsl:value-of select="./@id"/>
279 </xsl:element>
280 <xsl:text>&#xA; </xsl:text>
281 <xsl:element name="version">
282 <xsl:value-of select="$version"/>
283 </xsl:element>
284 <xsl:if
285 test="document($installed-packages)//package[name=current()/@id]">
286 <xsl:text>&#xA; </xsl:text>
287 <xsl:element name="inst-version">
288 <xsl:value-of
289 select="document(
290 $installed-packages
291 )//package[name=current()/@id]/version"/>
292 </xsl:element>
293 </xsl:if>
294<!-- Dependencies -->
295<!-- If in Xorg (not anymore) or KDE chapter, consider that the preceding
296 package is the first dependency (not always noted in the book)-->
297 <xsl:if test="ancestor::chapter[@id='kde4-core'
298 or @id='xfce-core'
299 or @id='lxqt-desktop'
300 or @id='lxde-desktop']
301 and preceding-sibling::sect1[1]">
302 <xsl:text>
303 </xsl:text>
304 <xsl:element name="dependency">
305 <xsl:attribute name="status">required</xsl:attribute>
306 <xsl:attribute name="build">before</xsl:attribute>
307 <xsl:attribute name="name">
308 <xsl:value-of select="preceding-sibling::sect1[1]/@id"/>
309 </xsl:attribute>
310 <xsl:attribute name="type">ref</xsl:attribute>
311 </xsl:element>
312 </xsl:if>
313 <xsl:apply-templates select=".//para[@role='required' or
314 @role='recommended' or
315 @role='optional']"
316 mode="dependency"/>
317<!-- End dependencies -->
318 <xsl:text>&#xA; </xsl:text>
319 </package><xsl:text>&#xA;</xsl:text>
320 </xsl:otherwise>
321 </xsl:choose>
322 </xsl:template>
323
324 <xsl:template name="version">
325 <xsl:param name="label" select="abc-2"/>
326 <xsl:variable name="start" select="string-length(substring-before(translate($label,'123456789','000000000'),'-0'))+2"/>
327 <xsl:variable name="prelim-ver" select="substring($label,$start)"/>
328 <xsl:choose>
329 <xsl:when test="contains($prelim-ver,'onfiguration')"/>
330 <xsl:when test="contains($prelim-ver,'escription')"/>
331 <xsl:when test="contains($prelim-ver,'EggDBus')">
332 <xsl:value-of select="substring-before($prelim-ver,' (EggDBus)')"/>
333 </xsl:when>
334 <xsl:when test="contains($label,'JDK')">
335 <xsl:value-of select="translate($prelim-ver,' ','_')"/>
336 </xsl:when>
337 <xsl:otherwise>
338 <xsl:value-of select="$prelim-ver"/>
339 </xsl:otherwise>
340 </xsl:choose>
341 </xsl:template>
342
343 <xsl:template match="para" mode="dependency">
344 <xsl:variable name="status" select="./@role"/>
345<!-- First internal dependencies -->
346 <xsl:for-each select=".//xref">
347 <xsl:choose>
348<!-- Avoid depending of myself -->
349 <xsl:when test="ancestor::*[@id=current()/@linkend]"/>
350<!-- do not depend on something which is not a dependency -->
351 <xsl:when test="@role='nodep'"/>
352<!-- Call list expansion when we have an xorg7 series of packages -->
353 <xsl:when test="contains(@linkend,'xorg7-')">
354 <xsl:call-template name="expand-deps">
355 <xsl:with-param name="section">
356 <xsl:value-of select="@linkend"/>
357 </xsl:with-param>
358 <xsl:with-param name="status">
359 <xsl:value-of select="$status"/>
360 </xsl:with-param>
361 <xsl:with-param name="build">
362 <xsl:choose>
363 <xsl:when test="@role='runtime'">after</xsl:when>
364 <xsl:when test="@role='first'">first</xsl:when>
365 <xsl:otherwise>before</xsl:otherwise>
366 </xsl:choose>
367 </xsl:with-param>
368 </xsl:call-template>
369 </xsl:when>
370 <xsl:otherwise>
371 <xsl:text>
372 </xsl:text>
373 <xsl:element name="dependency">
374 <xsl:attribute name="status">
375 <xsl:value-of select="$status"/>
376 </xsl:attribute>
377 <xsl:attribute name="build">
378 <xsl:choose>
379 <xsl:when test="@role='runtime'">after</xsl:when>
380 <xsl:when test="@role='first'">first</xsl:when>
381 <xsl:otherwise>before</xsl:otherwise>
382 </xsl:choose>
383 </xsl:attribute>
384 <xsl:attribute name="name">
385 <xsl:value-of select="@linkend"/>
386 </xsl:attribute>
387 <xsl:attribute name="type">ref</xsl:attribute>
388 </xsl:element>
389 </xsl:otherwise>
390 </xsl:choose>
391 </xsl:for-each>
392<!-- then external dependencies -->
393 <xsl:for-each select=".//ulink">
394 <xsl:choose>
395<!-- do not depend on something which is not a dependency -->
396 <xsl:when test="@role='nodep'"/>
397 <xsl:otherwise>
398 <xsl:text>
399 </xsl:text>
400 <xsl:element name="dependency">
401 <xsl:attribute name="status">
402 <xsl:value-of select="$status"/>
403 </xsl:attribute>
404 <xsl:attribute name="build">
405 <xsl:choose>
406 <xsl:when test="@role='runtime'">after</xsl:when>
407 <xsl:when test="@role='first'">first</xsl:when>
408 <xsl:otherwise>before</xsl:otherwise>
409 </xsl:choose>
410 </xsl:attribute>
411 <xsl:attribute name="name">
412 <xsl:value-of select="translate(normalize-space(text()),' /,()','-----')"/>
413 </xsl:attribute>
414 <xsl:attribute name="type">link</xsl:attribute>
415 </xsl:element>
416 </xsl:otherwise>
417 </xsl:choose>
418 </xsl:for-each>
419 </xsl:template>
420
421 <xsl:template match="listitem" mode="prec-dep">
422 <xsl:if test="preceding-sibling::listitem">
423 <xsl:text>
424 </xsl:text>
425 <xsl:element name="dependency">
426<!-- the dep on the preceding package used to be required for python.
427 It seems optional now -->
428 <xsl:attribute name="status">optional</xsl:attribute>
429 <xsl:attribute name="build">before</xsl:attribute>
430 <xsl:attribute name="name">
431 <xsl:value-of select="preceding-sibling::listitem[1]//@linkend"/>
432 </xsl:attribute>
433 <xsl:attribute name="type">ref</xsl:attribute>
434 </xsl:element>
435 </xsl:if>
436 </xsl:template>
437
438 <xsl:template match="listitem" mode="perlmod-dep">
439 <xsl:param name="glue" select="'&#xA; '"/>
440 <xsl:choose>
441 <xsl:when test="para/xref[not(@role) or @role != 'nodep']|para[@id]/ulink">
442 <xsl:value-of select="$glue"/>
443 <xsl:element name="dependency">
444 <xsl:attribute name="status">
445 <xsl:choose>
446 <xsl:when
447 test="count(./para/text()[contains(string(),
448 'ptional')
449 ]
450 )&gt;0">optional</xsl:when>
451 <xsl:otherwise>required</xsl:otherwise>
452 </xsl:choose>
453 </xsl:attribute>
454 <xsl:attribute name="build">
455 <xsl:choose>
456 <xsl:when test="para/xref/@role='runtime'">after</xsl:when>
457 <xsl:when test="para/ulink/@role='runtime'">after</xsl:when>
458 <xsl:otherwise>before</xsl:otherwise>
459 </xsl:choose>
460 </xsl:attribute>
461 <xsl:attribute name="name">
462 <xsl:if test="para/xref">
463 <xsl:value-of select="para/xref/@linkend"/>
464 </xsl:if>
465 <xsl:if test="para/ulink">
466 <xsl:value-of select="para/@id"/>
467 </xsl:if>
468 </xsl:attribute>
469 <xsl:attribute name="type">
470 <xsl:if test="para/xref">ref</xsl:if>
471 <xsl:if test="para/ulink">link</xsl:if>
472 </xsl:attribute>
473 <xsl:apply-templates select="itemizedlist/listitem"
474 mode="perlmod-dep">
475 <xsl:sort select="position()"
476 data-type="number"
477 order="descending"/>
478 <xsl:with-param name="glue" select="concat($glue,' ')"/>
479 </xsl:apply-templates>
480 </xsl:element>
481 </xsl:when>
482 <xsl:otherwise>
483 <xsl:apply-templates select="itemizedlist/listitem"
484 mode="perlmod-dep">
485 <xsl:sort select="position()"
486 data-type="number"
487 order="descending"/>
488 <xsl:with-param name="glue" select="$glue"/>
489 </xsl:apply-templates>
490 </xsl:otherwise>
491 </xsl:choose>
492 </xsl:template>
493
494</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.