source: BLFS/xsl/gen_pkg_list.xsl@ dd08e14

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

install-blfs-tools.sh:

  • Add instructions to retrieve and parse LFS book into packages.xml
  • Property mode set to 100644
File size: 17.5 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<!-- Dbus version is taken from BLFS -->
96 <xsl:when test="./productname='dbus'"/>
97<!-- Systemd version is taken from BLFS -->
98 <xsl:when test="./productname='systemd'"/>
99 <xsl:otherwise>
100 <package><xsl:text>&#xA; </xsl:text>
101 <xsl:element name="name">
102 <xsl:value-of select="./productname"/>
103 </xsl:element>
104 <xsl:text>&#xA; </xsl:text>
105 <xsl:element name="version">
106 <xsl:value-of select="./productnumber"/>
107 </xsl:element>
108 <xsl:if
109 test="document($installed-packages)//package[name=current()/productname]">
110 <xsl:text>&#xA; </xsl:text>
111 <xsl:element name="inst-version">
112 <xsl:value-of
113 select="document(
114 $installed-packages
115 )//package[name=current()/productname]/version"/>
116 </xsl:element>
117 </xsl:if>
118 </package>
119 </xsl:otherwise>
120 </xsl:choose>
121<!-- No deps for now: a former version is always installed -->
122 </xsl:template>
123
124 <xsl:template match="part">
125 <xsl:if test="count(.//*[contains(translate(@xreflabel,
126 '123456789',
127 '000000000'),
128 '-0')
129 ]) &gt; 0">
130 <xsl:text> </xsl:text>
131 <list>
132 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
133 <xsl:text>&#xA; </xsl:text>
134 <xsl:element name="name">
135 <xsl:value-of select="normalize-space(title)"/>
136 </xsl:element>
137 <xsl:text>&#xA;&#xA;</xsl:text>
138 <xsl:apply-templates select="chapter"/>
139 <xsl:text> </xsl:text>
140 </list>
141 <xsl:text>&#xA;&#xA;</xsl:text>
142 </xsl:if>
143 </xsl:template>
144
145 <xsl:template match="chapter">
146 <xsl:if test="count(.//*[contains(translate(@xreflabel,
147 '123456789',
148 '000000000'),
149 '-0')
150 ]) &gt; 0">
151 <xsl:text> </xsl:text>
152 <sublist>
153 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
154 <xsl:text>&#xA; </xsl:text>
155 <xsl:element name="name">
156 <xsl:value-of select="normalize-space(title)"/>
157 </xsl:element>
158 <xsl:text>&#xA;</xsl:text>
159 <xsl:apply-templates select=".//sect1">
160 <xsl:sort select="@id"/>
161 </xsl:apply-templates>
162 <xsl:text> </xsl:text>
163 </sublist><xsl:text>&#xA;&#xA;</xsl:text>
164 </xsl:if>
165 </xsl:template>
166
167 <xsl:template match="sect1">
168 <xsl:choose>
169<!-- This test is to find sections containing modules (PERL, Python
170 DBus,...) -->
171 <xsl:when
172 test="not(contains(translate(@xreflabel,
173 '123456789',
174 '000000000'),
175 '-0')) and
176 count(descendant::node()[contains(translate(@xreflabel,
177 '123456789',
178 '000000000'),
179 '-0')
180 ]) &gt; 0">
181 <xsl:text> </xsl:text>
182 <package><xsl:text>&#xA; </xsl:text>
183 <xsl:element name="name">
184 <xsl:value-of select="normalize-space(title)"/>
185 </xsl:element>
186 <xsl:text>&#xA;</xsl:text>
187<!-- Do not use .//*, which would include self. -->
188 <xsl:apply-templates
189 select="descendant::node()[contains(translate(@xreflabel,
190 '123456789',
191 '000000000'),
192 '-0')
193 ]"
194 mode="normal">
195 <xsl:sort select="@id"/>
196 </xsl:apply-templates>
197 <xsl:text> </xsl:text>
198 </package><xsl:text>&#xA;&#xA;</xsl:text>
199 </xsl:when>
200 <xsl:otherwise>
201<!-- Calls the template of specialCases.xsl,
202 which calls the "normal" template when the
203 case is normal. -->
204 <xsl:apply-templates select='.' mode="special">
205 <xsl:sort select="@id"/>
206 </xsl:apply-templates>
207 </xsl:otherwise>
208 </xsl:choose>
209 </xsl:template>
210
211 <xsl:template match="*" mode="normal">
212 <xsl:variable name="version">
213 <xsl:call-template name="version">
214 <xsl:with-param name="label" select="./@xreflabel"/>
215 </xsl:call-template>
216 </xsl:variable>
217 <xsl:choose>
218<!-- If there is a "sect1" ancestor, this means that
219 we have a module -->
220 <xsl:when test="ancestor::sect1">
221 <xsl:text> </xsl:text>
222 <module><xsl:text>&#xA; </xsl:text>
223 <xsl:element name="name">
224 <xsl:value-of select="./@id"/>
225 </xsl:element>
226 <xsl:text>&#xA; </xsl:text>
227 <xsl:element name="version">
228 <xsl:value-of select="$version"/>
229 </xsl:element>
230 <xsl:if
231 test="document($installed-packages)//package[name=current()/@id]">
232 <xsl:text>&#xA; </xsl:text>
233 <xsl:element name="inst-version">
234 <xsl:value-of
235 select="document(
236 $installed-packages
237 )//package[name=current()/@id]/version"/>
238 </xsl:element>
239 </xsl:if>
240<!-- Dependencies -->
241<!-- First the case of python modules or d-bus bindings -->
242 <xsl:if test="self::sect2">
243<!-- dependencies -->
244 <xsl:apply-templates select=".//para[@role='required' or
245 @role='recommended' or
246 @role='optional']"
247 mode="dependency"/>
248 </xsl:if>
249<!-- For python modules, the preceding module is an optional dep -->
250 <xsl:if test="ancestor::sect1[@id='python-modules']">
251 <xsl:apply-templates
252 select="preceding-sibling::sect2[@role='package']
253 //listitem[para/xref/@linkend=current()/@id]"
254 mode="prec-dep"/>
255 </xsl:if>
256<!-- Now the case of perl modules: let us test our XSLT abilities.
257 Well, "use the sibling, Luke" -->
258 <xsl:if test="self::bridgehead">
259 <xsl:apply-templates select="following-sibling::itemizedlist[1]
260 /listitem/itemizedlist/listitem"
261 mode="perlmod-dep">
262 <xsl:sort select="position()"
263 data-type="number"
264 order="descending"/>
265 </xsl:apply-templates>
266 </xsl:if>
267<!-- End dependencies -->
268 <xsl:text>&#xA; </xsl:text>
269 </module><xsl:text>&#xA;</xsl:text>
270 </xsl:when>
271 <xsl:otherwise>
272 <xsl:text> </xsl:text>
273 <package><xsl:text>&#xA; </xsl:text>
274 <xsl:element name="name">
275 <xsl:value-of select="./@id"/>
276 </xsl:element>
277 <xsl:text>&#xA; </xsl:text>
278 <xsl:element name="version">
279 <xsl:value-of select="$version"/>
280 </xsl:element>
281 <xsl:if
282 test="document($installed-packages)//package[name=current()/@id]">
283 <xsl:text>&#xA; </xsl:text>
284 <xsl:element name="inst-version">
285 <xsl:value-of
286 select="document(
287 $installed-packages
288 )//package[name=current()/@id]/version"/>
289 </xsl:element>
290 </xsl:if>
291<!-- Dependencies -->
292<!-- If in Xorg (not anymore) or KDE chapter, consider that the preceding
293 package is the first dependency (not always noted in the book)-->
294 <xsl:if test="ancestor::chapter[@id='kde4-core'
295 or @id='xfce-core'
296 or @id='lxqt-desktop'
297 or @id='lxde-desktop']
298 and preceding-sibling::sect1[1]">
299 <xsl:text>
300 </xsl:text>
301 <xsl:element name="dependency">
302 <xsl:attribute name="status">required</xsl:attribute>
303 <xsl:attribute name="name">
304 <xsl:value-of select="preceding-sibling::sect1[1]/@id"/>
305 </xsl:attribute>
306 <xsl:attribute name="type">ref</xsl:attribute>
307 </xsl:element>
308 </xsl:if>
309 <xsl:apply-templates select=".//para[@role='required' or
310 @role='recommended' or
311 @role='optional']"
312 mode="dependency"/>
313<!-- End dependencies -->
314 <xsl:text>&#xA; </xsl:text>
315 </package><xsl:text>&#xA;</xsl:text>
316 </xsl:otherwise>
317 </xsl:choose>
318 </xsl:template>
319
320 <xsl:template name="version">
321 <xsl:param name="label" select="abc-2"/>
322 <xsl:variable name="start" select="string-length(substring-before(translate($label,'123456789','000000000'),'-0'))+2"/>
323 <xsl:variable name="prelim-ver" select="substring($label,$start)"/>
324 <xsl:choose>
325 <xsl:when test="contains($prelim-ver,'onfiguration')"/>
326 <xsl:when test="contains($prelim-ver,'escription')"/>
327 <xsl:when test="contains($prelim-ver,'EggDBus')">
328 <xsl:value-of select="substring-before($prelim-ver,' (EggDBus)')"/>
329 </xsl:when>
330 <xsl:when test="contains($label,'JDK')">
331 <xsl:value-of select="translate($prelim-ver,' ','_')"/>
332 </xsl:when>
333 <xsl:otherwise>
334 <xsl:value-of select="$prelim-ver"/>
335 </xsl:otherwise>
336 </xsl:choose>
337 </xsl:template>
338
339 <xsl:template match="para" mode="dependency">
340 <xsl:variable name="status" select="./@role"/>
341<!-- First internal dependencies -->
342 <xsl:for-each select=".//xref">
343 <xsl:choose>
344<!-- Avoid depending of myself -->
345 <xsl:when test="ancestor::*[@id=current()/@linkend]"/>
346<!-- Call list expansion when we have an xorg7 series of packages -->
347 <xsl:when test="contains(@linkend,'xorg7-')">
348 <xsl:call-template name="expand-deps">
349 <xsl:with-param name="section">
350 <xsl:value-of select="@linkend"/>
351 </xsl:with-param>
352 <xsl:with-param name="status">
353 <xsl:value-of select="$status"/>
354 </xsl:with-param>
355 </xsl:call-template>
356 </xsl:when>
357 <xsl:otherwise>
358 <xsl:text>
359 </xsl:text>
360 <xsl:element name="dependency">
361 <xsl:attribute name="status">
362 <xsl:value-of select="$status"/>
363 </xsl:attribute>
364 <xsl:attribute name="name">
365 <xsl:value-of select="@linkend"/>
366 </xsl:attribute>
367 <xsl:attribute name="type">ref</xsl:attribute>
368 </xsl:element>
369 </xsl:otherwise>
370 </xsl:choose>
371 </xsl:for-each>
372<!-- then external dependencies -->
373 <xsl:for-each select=".//ulink">
374 <xsl:text>
375 </xsl:text>
376 <xsl:element name="dependency">
377 <xsl:attribute name="status">
378 <xsl:value-of select="$status"/>
379 </xsl:attribute>
380 <xsl:attribute name="name">
381 <xsl:value-of select="translate(normalize-space(text()),' ','-')"/>
382 </xsl:attribute>
383 <xsl:attribute name="type">link</xsl:attribute>
384 </xsl:element>
385 </xsl:for-each>
386 </xsl:template>
387
388 <xsl:template match="listitem" mode="prec-dep">
389 <xsl:if test="preceding-sibling::listitem">
390 <xsl:text>
391 </xsl:text>
392 <xsl:element name="dependency">
393<!-- the dep on the preceding package used to be required for python.
394 It seems optional now -->
395 <xsl:attribute name="status">optional</xsl:attribute>
396 <xsl:attribute name="name">
397 <xsl:value-of select="preceding-sibling::listitem[1]//@linkend"/>
398 </xsl:attribute>
399 <xsl:attribute name="type">ref</xsl:attribute>
400 </xsl:element>
401 </xsl:if>
402 </xsl:template>
403
404 <xsl:template match="listitem" mode="perlmod-dep">
405 <xsl:param name="glue" select="'&#xA; '"/>
406 <xsl:choose>
407 <xsl:when test="para/xref|para[@id]/ulink">
408 <xsl:value-of select="$glue"/>
409 <xsl:element name="dependency">
410 <xsl:attribute name="status">
411 <xsl:choose>
412 <xsl:when
413 test="count(./para/text()[contains(string(),
414 'ptional')
415 ]
416 )&gt;0">optional</xsl:when>
417 <xsl:otherwise>required</xsl:otherwise>
418 </xsl:choose>
419 </xsl:attribute>
420 <xsl:attribute name="name">
421 <xsl:if test="para/xref">
422 <xsl:value-of select="para/xref/@linkend"/>
423 </xsl:if>
424 <xsl:if test="para/ulink">
425 <xsl:value-of select="para/@id"/>
426 </xsl:if>
427 </xsl:attribute>
428 <xsl:attribute name="type">
429 <xsl:if test="para/xref">ref</xsl:if>
430 <xsl:if test="para/ulink">link</xsl:if>
431 </xsl:attribute>
432 <xsl:apply-templates select="itemizedlist/listitem"
433 mode="perlmod-dep">
434 <xsl:sort select="position()"
435 data-type="number"
436 order="descending"/>
437 <xsl:with-param name="glue" select="concat($glue,' ')"/>
438 </xsl:apply-templates>
439 </xsl:element>
440 </xsl:when>
441 <xsl:otherwise>
442 <xsl:apply-templates select="itemizedlist/listitem"
443 mode="perlmod-dep">
444 <xsl:sort select="position()"
445 data-type="number"
446 order="descending"/>
447 <xsl:with-param name="glue" select="$glue"/>
448 </xsl:apply-templates>
449 </xsl:otherwise>
450 </xsl:choose>
451 </xsl:template>
452
453</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.