source: BLFS/xsl/make_book.xsl@ 6b6d54d

new_features
Last change on this file since 6b6d54d was 642722f, checked in by Pierre Labastie <pierre@…>, 11 years ago

Improve script generation for BLFS tools:

  • introduce a template for downloading code
  • account for various layout of the BLFS pages for package information and additional

downloads

  • Add the possibility for addtional downloads in xorg pages
  • Property mode set to 100644
File size: 17.1 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2
3<!-- $Id: make_book.xsl 31 2012-02-19 08:25:04Z labastie $ -->
4
5<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
6 version="1.0">
7
8 <xsl:param name="list" select="''"/>
9 <xsl:param name="MTA" select="'sendmail'"/>
10
11 <xsl:output
12 method="xml"
13 encoding="ISO-8859-1"
14 doctype-system="http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"/>
15
16 <xsl:template match="/">
17 <book>
18 <xsl:copy-of select="/book/bookinfo"/>
19 <preface>
20 <?dbhtml filename="preface.html"?>
21 <title>Preface</title>
22 <xsl:copy-of select="id('bootscripts')"/>
23 </preface>
24 <chapter>
25 <?dbhtml filename="chapter.html"?>
26 <title>Installing packages in dependency build order</title>
27 <xsl:call-template name="apply-list">
28 <xsl:with-param name="list" select="normalize-space($list)"/>
29 </xsl:call-template>
30 </chapter>
31 <xsl:copy-of select="id('CC')"/>
32 <xsl:copy-of select="id('MIT')"/>
33 <index/>
34 </book>
35 </xsl:template>
36
37<!-- apply-templates for each item in the list.
38 Normally, those items are id of nodes.
39 Those nodes can be sect1 (normal case),
40 sect2 (python modules or DBus bindings)
41 bridgehead (perl modules)
42 para (dependency of perl modules).
43 The templates after this one treat each of those cases.
44 However, some items are xorg package names, and not id.
45 We need special instructions in that case.
46 The difficulty is that some of those names *are* id's,
47 because they are referenced in the index.
48 Hopefully, none of those id's are sect{1,2}, bridgehead or para...-->
49 <xsl:template name="apply-list">
50 <xsl:param name="list" select="''"/>
51 <xsl:if test="string-length($list) &gt; 0">
52 <xsl:choose>
53 <xsl:when test="contains($list,' ')">
54 <xsl:call-template name="apply-list">
55 <xsl:with-param name="list"
56 select="substring-before($list,' ')"/>
57 </xsl:call-template>
58 <xsl:call-template name="apply-list">
59 <xsl:with-param name="list"
60 select="substring-after($list,' ')"/>
61 </xsl:call-template>
62 </xsl:when>
63 <xsl:otherwise>
64 <xsl:choose>
65 <xsl:when test="not(id($list)[self::sect1 or self::sect2 or self::para or self::bridgehead])">
66 <xsl:apply-templates
67 select="//sect1[contains(@id,'xorg7')
68 and contains(string(.//userinput),
69 concat($list,'-'))]"
70 mode="xorg">
71 <xsl:with-param name="package" select="$list"/>
72 </xsl:apply-templates>
73 </xsl:when>
74 <xsl:otherwise>
75 <xsl:apply-templates select="id($list)"/>
76 </xsl:otherwise>
77 </xsl:choose>
78 </xsl:otherwise>
79 </xsl:choose>
80 </xsl:if>
81 </xsl:template>
82
83<!-- The normal case : just copy to the book. Exceptions are if there
84 is a xref, so use a special "mode" template -->
85 <xsl:template match="sect1">
86 <xsl:apply-templates select="." mode="sect1"/>
87 </xsl:template>
88
89 <xsl:template match="processing-instruction()" mode="sect1">
90 <xsl:copy-of select="."/>
91 </xsl:template>
92
93<!-- Any node which has no xref descendant is copied verbatim. If there
94 is an xref descendant, output the node and recurse. -->
95 <xsl:template match="*" mode="sect1">
96 <xsl:choose>
97 <xsl:when test="self::xref">
98 <xsl:choose>
99 <xsl:when test="contains(concat(' ',normalize-space($list),' '),
100 concat(' ',@linkend,' '))">
101 <xsl:choose>
102 <xsl:when test="@linkend='x-window-system' or @linkend='xorg7'">
103 <xref linkend="xorg7-server"/>
104 </xsl:when>
105 <xsl:when test="@linkend='server-mail'">
106 <xref linkend="{$MTA}"/>
107 </xsl:when>
108 <xsl:otherwise>
109 <xsl:copy-of select="."/>
110 </xsl:otherwise>
111 </xsl:choose>
112 </xsl:when>
113 <xsl:otherwise>
114 <xsl:choose>
115 <xsl:when test="@linkend='bootscripts'">
116 <xsl:copy-of select="."/>
117 </xsl:when>
118 <xsl:otherwise>
119 <xsl:value-of select="@linkend"/> (in full book)
120 </xsl:otherwise>
121 </xsl:choose>
122 </xsl:otherwise>
123 </xsl:choose>
124 </xsl:when>
125 <xsl:when test=".//xref">
126 <xsl:element name="{name()}">
127 <xsl:for-each select="attribute::*">
128 <xsl:attribute name="{name()}">
129 <xsl:value-of select="."/>
130 </xsl:attribute>
131 </xsl:for-each>
132 <xsl:apply-templates mode="sect1"/>
133 </xsl:element>
134 </xsl:when>
135 <xsl:otherwise>
136 <xsl:copy-of select="."/>
137 </xsl:otherwise>
138 </xsl:choose>
139 </xsl:template>
140
141<!-- Python modules and DBus bindings -->
142 <xsl:template match="sect2">
143 <xsl:apply-templates select='.' mode="sect2"/>
144 </xsl:template>
145
146 <xsl:template match="*" mode="sect2">
147 <xsl:choose>
148 <xsl:when test="self::sect2">
149 <xsl:element name="sect1">
150 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
151 <xsl:attribute name="xreflabel"><xsl:value-of select="@xreflabel"/></xsl:attribute>
152 <xsl:processing-instruction name="dbhtml">filename="<xsl:value-of
153 select="@id"/>.html"</xsl:processing-instruction>
154 <xsl:apply-templates mode="sect2"/>
155 </xsl:element>
156 </xsl:when>
157 <xsl:when test="self::sect3">
158 <xsl:element name="sect2">
159 <xsl:attribute name="role">
160 <xsl:value-of select="@role"/>
161 </xsl:attribute>
162 <xsl:apply-templates mode="sect2"/>
163 </xsl:element>
164 </xsl:when>
165 <xsl:when test="self::bridgehead">
166 <xsl:element name="bridgehead">
167 <xsl:attribute name="renderas">
168 <xsl:if test="@renderas='sect4'">sect3</xsl:if>
169 <xsl:if test="@renderas='sect5'">sect4</xsl:if>
170 </xsl:attribute>
171 <xsl:value-of select='.'/>
172 </xsl:element>
173 </xsl:when>
174 <xsl:when test="self::xref">
175 <xsl:choose>
176 <xsl:when test="contains(concat(' ',normalize-space($list),' '),
177 concat(' ',@linkend,' '))">
178 <xsl:choose>
179 <xsl:when test="@linkend='x-window-system' or @linkend='xorg7'">
180 <xref linkend="xorg7-server"/>
181 </xsl:when>
182 <xsl:when test="@linkend='server-mail'">
183 <xref linkend="{$MTA}"/>
184 </xsl:when>
185 <xsl:otherwise>
186 <xsl:copy-of select="."/>
187 </xsl:otherwise>
188 </xsl:choose>
189 </xsl:when>
190 <xsl:otherwise>
191 <xsl:value-of select="@linkend"/> (in full book)
192 </xsl:otherwise>
193 </xsl:choose>
194 </xsl:when>
195 <xsl:when test=".//xref">
196 <xsl:element name="{name()}">
197 <xsl:for-each select="attribute::*">
198 <xsl:attribute name="{name()}">
199 <xsl:value-of select="."/>
200 </xsl:attribute>
201 </xsl:for-each>
202 <xsl:apply-templates mode="sect2"/>
203 </xsl:element>
204 </xsl:when>
205 <xsl:otherwise>
206 <xsl:copy-of select="."/>
207 </xsl:otherwise>
208 </xsl:choose>
209 </xsl:template>
210
211<!-- Perl modules : transform them to minimal sect1. Use a template
212 for installation instructions -->
213 <xsl:template match="bridgehead">
214 <xsl:element name="sect1">
215 <xsl:attribute name="id"><xsl:value-of select="./@id"/></xsl:attribute>
216 <xsl:attribute name="xreflabel"><xsl:value-of select="./@xreflabel"/></xsl:attribute>
217 <xsl:processing-instruction name="dbhtml">
218 filename="<xsl:value-of select="@id"/>.html"</xsl:processing-instruction>
219 <title><xsl:value-of select="./@xreflabel"/></title>
220 <sect2 role="package">
221 <title>Introduction to <xsl:value-of select="@id"/></title>
222 <bridgehead renderas="sect3">Package Information</bridgehead>
223 <itemizedlist spacing="compact">
224 <listitem>
225 <para>Download (HTTP): <xsl:copy-of select="./following-sibling::itemizedlist[1]/listitem/para/ulink"/></para>
226 </listitem>
227 <listitem>
228 <para>Download (FTP): <ulink url=" "/></para>
229 </listitem>
230 </itemizedlist>
231 </sect2>
232 <xsl:choose>
233 <xsl:when test="following-sibling::itemizedlist[1]//xref[@linkend='perl-standard-install'] | following-sibling::itemizedlist[1]/preceding-sibling::para//xref[@linkend='perl-standard-install']">
234 <xsl:apply-templates mode="perl-install" select="id('perl-standard-install')"/>
235 </xsl:when>
236 <xsl:otherwise>
237 <sect2 role="installation">
238 <title>Installation of <xsl:value-of select="@xreflabel"/></title>
239 <para>Run the following commands:</para>
240 <for-each select="following-sibling::bridgehead/preceding-sibling::screen[not(@role)]">
241 <xsl:copy-of select="."/>
242 </for-each>
243 <para>Now, as the <systemitem class="username">root</systemitem> user:</para>
244 <for-each select="following-sibling::bridgehead/preceding-sibling::screen[@role='root']">
245 <xsl:copy-of select="."/>
246 </for-each>
247 </sect2>
248 </xsl:otherwise>
249 </xsl:choose>
250 </xsl:element>
251 </xsl:template>
252
253<!-- The case of depdendencies of perl modules. Same treatment
254 as for perl modules. Just easier because always perl standard -->
255 <xsl:template match="para">
256 <xsl:element name="sect1">
257 <xsl:attribute name="id"><xsl:value-of select="./@id"/></xsl:attribute>
258 <xsl:attribute name="xreflabel"><xsl:value-of select="./@xreflabel"/></xsl:attribute>
259 <xsl:processing-instruction name="dbhtml">filename="<xsl:value-of
260 select="@id"/>.html"</xsl:processing-instruction>
261 <title><xsl:value-of select="./@xreflabel"/></title>
262 <sect2 role="package">
263 <title>Introduction to <xsl:value-of select="@id"/></title>
264 <bridgehead renderas="sect3">Package Information</bridgehead>
265 <itemizedlist spacing="compact">
266 <listitem>
267 <para>Download (HTTP): <xsl:copy-of select="./ulink"/></para>
268 </listitem>
269 <listitem>
270 <para>Download (FTP): <ulink url=" "/></para>
271 </listitem>
272 </itemizedlist>
273 </sect2>
274 <xsl:apply-templates mode="perl-install" select="id('perl-standard-install')"/>
275 </xsl:element>
276 </xsl:template>
277
278<!-- copy of the perl standard installation instructions:
279 suppress id (otherwise not unique) and note (which we
280 do not want to apply -->
281 <xsl:template match="sect2" mode="perl-install">
282 <sect2 role="installation">
283 <xsl:for-each select="./*">
284 <xsl:if test="not(self::note)">
285 <xsl:copy-of select="."/>
286 </xsl:if>
287 </xsl:for-each>
288 </sect2>
289 </xsl:template>
290
291<!-- we have got an xorg package. We are at the installation page
292 but now we need to make an autonomous page from the global
293 one -->
294 <xsl:template match="sect1" mode="xorg">
295 <xsl:param name="package"/>
296 <xsl:variable name="tarball">
297 <xsl:call-template name="tarball">
298 <xsl:with-param name="package" select="concat(' ',$package,'-')"/>
299 <xsl:with-param name="cat-md5"
300 select="string(.//userinput[starts-with(string(),'cat ')])"/>
301 </xsl:call-template>
302 </xsl:variable>
303 <xsl:variable name="md5sum">
304 <xsl:call-template name="md5sum">
305 <xsl:with-param name="package" select="concat(' ',$package,'-')"/>
306 <xsl:with-param name="cat-md5"
307 select=".//userinput[starts-with(string(),'cat ')]"/>
308 </xsl:call-template>
309 </xsl:variable>
310 <xsl:variable name="install-instructions">
311 <xsl:call-template name="inst-instr">
312 <xsl:with-param name="inst-instr"
313 select=".//userinput[starts-with(string(),'for ')]"/>
314 </xsl:call-template>
315 </xsl:variable>
316 <xsl:element name="sect1">
317 <xsl:attribute name="id"><xsl:value-of select="$package"/></xsl:attribute>
318 <xsl:processing-instruction name="dbhtml">
319 filename="<xsl:value-of select='$package'/>.html"
320 </xsl:processing-instruction>
321 <title><xsl:value-of select="$package"/></title>
322 <sect2 role="package">
323 <title>Introduction to <xsl:value-of select="$package"/></title>
324 <bridgehead renderas="sect3">Package Information</bridgehead>
325 <itemizedlist spacing="compact">
326 <listitem>
327 <para>Download (HTTP): <xsl:element name="ulink">
328 <xsl:attribute name="url">
329 <xsl:value-of
330 select=".//para[contains(string(),'(HTTP)')]/ulink/@url"/>
331 <xsl:value-of select="$tarball"/>
332 </xsl:attribute>
333 </xsl:element>
334 </para>
335 </listitem>
336 <listitem>
337 <para>Download (FTP): <xsl:element name="ulink">
338 <xsl:attribute name="url">
339 <xsl:value-of
340 select=".//para[contains(string(),'(FTP)')]/ulink/@url"/>
341 <xsl:value-of select="$tarball"/>
342 </xsl:attribute>
343 </xsl:element>
344 </para>
345 </listitem>
346 <listitem>
347 <para>
348 Download MD5 sum: <xsl:value-of select="$md5sum"/>
349 </para>
350 </listitem>
351 </itemizedlist>
352 <!-- If there is an additional download, we need to output that -->
353 <xsl:if test=".//bridgehead[contains(string(),'Additional')]">
354 <xsl:copy-of
355 select=".//bridgehead[contains(string(),'Additional')]"/>
356 <xsl:copy-of
357 select=".//bridgehead[contains(string(),'Additional')]
358 /following-sibling::itemizedlist[1]"/>
359 </xsl:if>
360 </sect2>
361 <sect2 role="installation">
362 <title>Installation of <xsl:value-of select="$package"/></title>
363
364 <para>
365 Install <application><xsl:value-of select="$package"/></application>
366 by running the following commands:
367 </para>
368
369 <screen><userinput>packagedir=<xsl:value-of
370 select="substring-before($tarball,'.tar.bz2')"/>
371 <xsl:text>&#xA;</xsl:text>
372 <xsl:value-of select="substring-before($install-instructions,
373 'as_root')"/>
374 </userinput></screen>
375
376 <para>
377 Now as the <systemitem class="username">root</systemitem> user:
378 </para>
379 <screen role='root'>
380 <userinput><xsl:value-of select="substring-after(
381 $install-instructions,
382 'as_root')"/>
383 </userinput>
384 </screen>
385 </sect2>
386 </xsl:element><!-- sect1 -->
387
388 </xsl:template>
389
390<!-- get the tarball name from the text that comes from the .md5 file -->
391 <xsl:template name="tarball">
392 <xsl:param name="package"/>
393 <xsl:param name="cat-md5"/>
394<!-- DEBUG
395<xsl:message><xsl:text>Entering "tarball" template:
396 package is: </xsl:text>
397<xsl:value-of select="$package"/><xsl:text>
398 cat-md5 is: </xsl:text>
399<xsl:value-of select="$cat-md5"/>
400</xsl:message>
401END DEBUG -->
402 <xsl:choose>
403 <xsl:when test="contains(substring-before($cat-md5,$package),'&#xA;')">
404 <xsl:call-template name="tarball">
405 <xsl:with-param name="package" select="$package"/>
406 <xsl:with-param name="cat-md5"
407 select="substring-after($cat-md5,'&#xA;')"/>
408 </xsl:call-template>
409 </xsl:when>
410 <xsl:otherwise>
411 <xsl:copy-of select="substring-after(
412 substring-before($cat-md5,'&#xA;'),' ')"/>
413 </xsl:otherwise>
414 </xsl:choose>
415 </xsl:template>
416<!-- same for md5sum -->
417 <xsl:template name="md5sum">
418 <xsl:param name="package"/>
419 <xsl:param name="cat-md5"/>
420 <xsl:choose>
421 <xsl:when test="contains(substring-before($cat-md5,$package),'&#xA;')">
422 <xsl:call-template name="md5sum">
423 <xsl:with-param name="package" select="$package"/>
424 <xsl:with-param name="cat-md5"
425 select="substring-after($cat-md5,'&#xA;')"/>
426 </xsl:call-template>
427 </xsl:when>
428 <xsl:otherwise>
429 <xsl:copy-of select="substring-before($cat-md5,' ')"/>
430 </xsl:otherwise>
431 </xsl:choose>
432 </xsl:template>
433
434 <xsl:template name="inst-instr">
435 <xsl:param name="inst-instr"/>
436 <xsl:choose>
437 <xsl:when test="contains($inst-instr,'pushd')">
438 <xsl:call-template name="inst-instr">
439 <xsl:with-param name="inst-instr"
440 select="substring-after(
441 substring-after($inst-instr,'pushd'),
442 '&#xA;')"/>
443 </xsl:call-template>
444 </xsl:when>
445 <xsl:otherwise>
446 <xsl:copy-of select="substring-before($inst-instr,'popd')"/>
447 </xsl:otherwise>
448 </xsl:choose>
449 </xsl:template>
450</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.