source: BLFS/xsl/gen_pkg_list.xsl@ 5a8939e

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

Add code to account to the new role attribute in dependencies

  • 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 <xsl:apply-templates
194 select="descendant::node()[contains(translate(@xreflabel,
195 '123456789',
196 '000000000'),
197 '-0')
198 ]"
199 mode="normal">
200 <xsl:sort select="@id"/>
201 </xsl:apply-templates>
202 <xsl:text> </xsl:text>
203 </package><xsl:text>&#xA;&#xA;</xsl:text>
204 </xsl:when>
205 <xsl:otherwise>
206<!-- Calls the template of specialCases.xsl,
207 which calls the "normal" template when the
208 case is normal. -->
209 <xsl:apply-templates select='.' mode="special">
210 <xsl:sort select="@id"/>
211 </xsl:apply-templates>
212 </xsl:otherwise>
213 </xsl:choose>
214 </xsl:template>
215
216 <xsl:template match="*" mode="normal">
217 <xsl:variable name="version">
218 <xsl:call-template name="version">
219 <xsl:with-param name="label" select="./@xreflabel"/>
220 </xsl:call-template>
221 </xsl:variable>
222 <xsl:choose>
223<!-- If there is a "sect1" ancestor, this means that
224 we have a module -->
225 <xsl:when test="ancestor::sect1">
226 <xsl:text> </xsl:text>
227 <module><xsl:text>&#xA; </xsl:text>
228 <xsl:element name="name">
229 <xsl:value-of select="./@id"/>
230 </xsl:element>
231 <xsl:text>&#xA; </xsl:text>
232 <xsl:element name="version">
233 <xsl:value-of select="$version"/>
234 </xsl:element>
235 <xsl:if
236 test="document($installed-packages)//package[name=current()/@id]">
237 <xsl:text>&#xA; </xsl:text>
238 <xsl:element name="inst-version">
239 <xsl:value-of
240 select="document(
241 $installed-packages
242 )//package[name=current()/@id]/version"/>
243 </xsl:element>
244 </xsl:if>
245<!-- Dependencies -->
246<!-- First the case of python modules or d-bus bindings -->
247 <xsl:if test="self::sect2">
248<!-- dependencies -->
249 <xsl:apply-templates select=".//para[@role='required' or
250 @role='recommended' or
251 @role='optional']"
252 mode="dependency"/>
253 </xsl:if>
254<!-- For python modules, the preceding module is an optional dep -->
255 <xsl:if test="ancestor::sect1[@id='python-modules']">
256 <xsl:apply-templates
257 select="preceding-sibling::sect2[@role='package']
258 //listitem[para/xref/@linkend=current()/@id]"
259 mode="prec-dep"/>
260 </xsl:if>
261<!-- Now the case of perl modules: let us test our XSLT abilities.
262 Well, "use the sibling, Luke" -->
263 <xsl:if test="self::bridgehead">
264 <xsl:apply-templates select="following-sibling::itemizedlist[1]
265 /listitem/itemizedlist/listitem"
266 mode="perlmod-dep">
267 <xsl:sort select="position()"
268 data-type="number"
269 order="descending"/>
270 </xsl:apply-templates>
271 </xsl:if>
272<!-- End dependencies -->
273 <xsl:text>&#xA; </xsl:text>
274 </module><xsl:text>&#xA;</xsl:text>
275 </xsl:when>
276 <xsl:otherwise>
277 <xsl:text> </xsl:text>
278 <package><xsl:text>&#xA; </xsl:text>
279 <xsl:element name="name">
280 <xsl:value-of select="./@id"/>
281 </xsl:element>
282 <xsl:text>&#xA; </xsl:text>
283 <xsl:element name="version">
284 <xsl:value-of select="$version"/>
285 </xsl:element>
286 <xsl:if
287 test="document($installed-packages)//package[name=current()/@id]">
288 <xsl:text>&#xA; </xsl:text>
289 <xsl:element name="inst-version">
290 <xsl:value-of
291 select="document(
292 $installed-packages
293 )//package[name=current()/@id]/version"/>
294 </xsl:element>
295 </xsl:if>
296<!-- Dependencies -->
297<!-- If in Xorg (not anymore) or KDE chapter, consider that the preceding
298 package is the first dependency (not always noted in the book)-->
299 <xsl:if test="ancestor::chapter[@id='kde4-core'
300 or @id='xfce-core'
301 or @id='lxqt-desktop'
302 or @id='lxde-desktop']
303 and preceding-sibling::sect1[1]">
304 <xsl:text>
305 </xsl:text>
306 <xsl:element name="dependency">
307 <xsl:attribute name="status">required</xsl:attribute>
308 <xsl:attribute name="build">before</xsl:attribute>
309 <xsl:attribute name="name">
310 <xsl:value-of select="preceding-sibling::sect1[1]/@id"/>
311 </xsl:attribute>
312 <xsl:attribute name="type">ref</xsl:attribute>
313 </xsl:element>
314 </xsl:if>
315 <xsl:apply-templates select=".//para[@role='required' or
316 @role='recommended' or
317 @role='optional']"
318 mode="dependency"/>
319<!-- End dependencies -->
320 <xsl:text>&#xA; </xsl:text>
321 </package><xsl:text>&#xA;</xsl:text>
322 </xsl:otherwise>
323 </xsl:choose>
324 </xsl:template>
325
326 <xsl:template name="version">
327 <xsl:param name="label" select="abc-2"/>
328 <xsl:variable name="start" select="string-length(substring-before(translate($label,'123456789','000000000'),'-0'))+2"/>
329 <xsl:variable name="prelim-ver" select="substring($label,$start)"/>
330 <xsl:choose>
331 <xsl:when test="contains($prelim-ver,'onfiguration')"/>
332 <xsl:when test="contains($prelim-ver,'escription')"/>
333 <xsl:when test="contains($prelim-ver,'EggDBus')">
334 <xsl:value-of select="substring-before($prelim-ver,' (EggDBus)')"/>
335 </xsl:when>
336 <xsl:when test="contains($label,'JDK')">
337 <xsl:value-of select="translate($prelim-ver,' ','_')"/>
338 </xsl:when>
339 <xsl:otherwise>
340 <xsl:value-of select="$prelim-ver"/>
341 </xsl:otherwise>
342 </xsl:choose>
343 </xsl:template>
344
345 <xsl:template match="para" mode="dependency">
346 <xsl:variable name="status" select="./@role"/>
347<!-- First internal dependencies -->
348 <xsl:for-each select=".//xref">
349 <xsl:choose>
350<!-- Avoid depending of myself -->
351 <xsl:when test="ancestor::*[@id=current()/@linkend]"/>
352<!-- do not depend on something which is not a dependency -->
353 <xsl:when test="@role='nodep'"/>
354<!-- Call list expansion when we have an xorg7 series of packages -->
355 <xsl:when test="contains(@linkend,'xorg7-')">
356 <xsl:call-template name="expand-deps">
357 <xsl:with-param name="section">
358 <xsl:value-of select="@linkend"/>
359 </xsl:with-param>
360 <xsl:with-param name="status">
361 <xsl:value-of select="$status"/>
362 </xsl:with-param>
363 <xsl:with-param name="build">
364 <xsl:choose>
365 <xsl:when test="@role='runtime'">after</xsl:when>
366 <xsl:otherwise>before</xsl:otherwise>
367 </xsl:choose>
368 </xsl:with-param>
369 </xsl:call-template>
370 </xsl:when>
371 <xsl:otherwise>
372 <xsl:text>
373 </xsl:text>
374 <xsl:element name="dependency">
375 <xsl:attribute name="status">
376 <xsl:value-of select="$status"/>
377 </xsl:attribute>
378 <xsl:attribute name="build">
379 <xsl:choose>
380 <xsl:when test="@role='runtime'">after</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:otherwise>before</xsl:otherwise>
408 </xsl:choose>
409 </xsl:attribute>
410 <xsl:attribute name="name">
411 <xsl:value-of select="translate(normalize-space(text()),' /,()','-----')"/>
412 </xsl:attribute>
413 <xsl:attribute name="type">link</xsl:attribute>
414 </xsl:element>
415 </xsl:otherwise>
416 </xsl:choose>
417 </xsl:for-each>
418 </xsl:template>
419
420 <xsl:template match="listitem" mode="prec-dep">
421 <xsl:if test="preceding-sibling::listitem">
422 <xsl:text>
423 </xsl:text>
424 <xsl:element name="dependency">
425<!-- the dep on the preceding package used to be required for python.
426 It seems optional now -->
427 <xsl:attribute name="status">optional</xsl:attribute>
428 <xsl:attribute name="build">before</xsl:attribute>
429 <xsl:attribute name="name">
430 <xsl:value-of select="preceding-sibling::listitem[1]//@linkend"/>
431 </xsl:attribute>
432 <xsl:attribute name="type">ref</xsl:attribute>
433 </xsl:element>
434 </xsl:if>
435 </xsl:template>
436
437 <xsl:template match="listitem" mode="perlmod-dep">
438 <xsl:param name="glue" select="'&#xA; '"/>
439 <xsl:choose>
440 <xsl:when test="para/xref[not(@role) or @role != 'nodep']|para[@id]/ulink">
441 <xsl:value-of select="$glue"/>
442 <xsl:element name="dependency">
443 <xsl:attribute name="status">
444 <xsl:choose>
445 <xsl:when
446 test="count(./para/text()[contains(string(),
447 'ptional')
448 ]
449 )&gt;0">optional</xsl:when>
450 <xsl:otherwise>required</xsl:otherwise>
451 </xsl:choose>
452 </xsl:attribute>
453 <xsl:attribute name="build">
454 <xsl:choose>
455 <xsl:when test="para/xref/@role='runtime'">after</xsl:when>
456 <xsl:when test="para/ulink/@role='runtime'">after</xsl:when>
457 <xsl:otherwise>before</xsl:otherwise>
458 </xsl:choose>
459 </xsl:attribute>
460 <xsl:attribute name="name">
461 <xsl:if test="para/xref">
462 <xsl:value-of select="para/xref/@linkend"/>
463 </xsl:if>
464 <xsl:if test="para/ulink">
465 <xsl:value-of select="para/@id"/>
466 </xsl:if>
467 </xsl:attribute>
468 <xsl:attribute name="type">
469 <xsl:if test="para/xref">ref</xsl:if>
470 <xsl:if test="para/ulink">link</xsl:if>
471 </xsl:attribute>
472 <xsl:apply-templates select="itemizedlist/listitem"
473 mode="perlmod-dep">
474 <xsl:sort select="position()"
475 data-type="number"
476 order="descending"/>
477 <xsl:with-param name="glue" select="concat($glue,' ')"/>
478 </xsl:apply-templates>
479 </xsl:element>
480 </xsl:when>
481 <xsl:otherwise>
482 <xsl:apply-templates select="itemizedlist/listitem"
483 mode="perlmod-dep">
484 <xsl:sort select="position()"
485 data-type="number"
486 order="descending"/>
487 <xsl:with-param name="glue" select="$glue"/>
488 </xsl:apply-templates>
489 </xsl:otherwise>
490 </xsl:choose>
491 </xsl:template>
492
493</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.