source: BOOK/stylesheets/clfs-profile.xsl @ 5171adc

Last change on this file since 5171adc was 5171adc, checked in by Joe Ciccone <jciccone@…>, 13 years ago

Update the package-iterator in the stylesheet. Fixed an issue where
the default bits on a multilib system was the first in the list instead
of the last. Also simplified the xsl.

  • Property mode set to 100644
File size: 9.0 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3  xmlns:c="http://schema.cross-lfs.org/book"
4  version="1.0">
5
6  <!-- Declare our output type -->
7  <xsl:output method="xml"
8    indent="no"
9    omit-xml-declaration="no"
10    encoding="utf-8"
11    doctype-public="-//OASIS//DTD DocBook XML V4.5//EN"
12    doctype-system="http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" />
13
14  <xsl:param name="clfs.arch" select="''" />
15  <xsl:param name="clfs.multilib" select="''" />
16
17  <!-- Apply the other templates -->
18  <xsl:template match="@*|node()" priority="-1">
19    <xsl:copy>
20      <xsl:apply-templates select="@*|node()" />
21    </xsl:copy>
22  </xsl:template>
23
24  <!-- Build the package xml -->
25  <xsl:template match="//c:package">
26    <xsl:param name="id" select="@id" />
27    <xsl:param name="multibuild" select="@c:multibuild" />
28    <xsl:call-template name="package-iterator">
29      <xsl:with-param name="id" select="$id" />
30      <xsl:with-param name="multibuild" select="$multibuild" />
31      <xsl:with-param name="bits" select="$clfs.multilib" />
32    </xsl:call-template>
33  </xsl:template>
34
35  <xsl:template name="package-iterator">
36    <xsl:param name="id" /> <!-- Base ID of the resulting package -->
37    <xsl:param name="multibuild" /> <!-- Do we need to install for each bitsize? -->
38    <xsl:param name="bits" /> <!-- Which bit sizes to create a package for -->
39
40    <xsl:variable name="currentbits" select="substring-before(concat($bits, ','), ',')" />
41    <xsl:variable name="remainingbits" select="substring-after($bits, ',')" />
42
43    <xsl:if test="not(boolean($remainingbits) and $multibuild = 'false')">
44      <xsl:call-template name="package-stub">
45        <xsl:with-param name="id" select="$id" />
46        <xsl:with-param name="idsuffix">
47          <xsl:if test="$remainingbits">
48            <xsl:value-of select="concat('-', $currentbits)" />
49          </xsl:if>
50        </xsl:with-param>
51        <xsl:with-param name="bits" select="substring-before(concat($bits, ','), ',')" />
52        <xsl:with-param name="multi"><xsl:text>multi</xsl:text></xsl:with-param>
53      </xsl:call-template>
54    </xsl:if>
55
56    <xsl:if test="$remainingbits">
57      <xsl:text>
58
59      </xsl:text>
60      <xsl:call-template name="package-iterator">
61        <xsl:with-param name="id" select="$id" />
62        <xsl:with-param name="multibuild" select="$multibuild" />
63        <xsl:with-param name="bits" select="$remainingbits" />
64      </xsl:call-template>
65    </xsl:if>
66
67  </xsl:template>
68
69  <xsl:template name="package-stub">
70    <xsl:param name="id" /> <!-- Base ID of the resulting package -->
71    <xsl:param name="idsuffix" /> <!-- Suffix to attach to the end of the ID for this perticular instance -->
72    <xsl:param name="bits" /> <!-- Which bit sizes to create a package for -->
73    <xsl:param name="multi" /> <!-- multi/single build -->
74
75    <xsl:for-each select="sect1">
76      <xsl:copy>
77        <xsl:attribute name="id">
78          <xsl:value-of select="concat($id, $idsuffix)" />
79        </xsl:attribute>
80        <xsl:attribute name="role">
81          <xsl:text>package</xsl:text>
82        </xsl:attribute>
83        <xsl:attribute name="condition">
84          <xsl:value-of select="$multi" />
85        </xsl:attribute>
86        <xsl:processing-instruction name="dbhtml">
87          <xsl:text>filename=&quot;</xsl:text>
88          <xsl:value-of select="concat($id, $idsuffix)" />
89          <xsl:text>.html&quot;</xsl:text>
90        </xsl:processing-instruction>
91        <xsl:choose>
92          <xsl:when test="$bits = '32'">
93            <xsl:apply-templates select="@*|node()" mode="filter-bits-32" />
94          </xsl:when>
95          <xsl:when test="$bits = 'n32'">
96            <xsl:apply-templates select="@*|node()" mode="filter-bits-n32" />
97          </xsl:when>
98          <xsl:when test="$bits = '64'">
99            <xsl:apply-templates select="@*|node()" mode="filter-bits-64" />
100          </xsl:when>
101        </xsl:choose>
102      </xsl:copy>
103    </xsl:for-each>
104  </xsl:template>
105
106  <!-- Apply the profile to the 32bit package -->
107
108  <xsl:template match="//sect1/title" mode="filter-bits-32">
109    <xsl:element name="title">
110      <xsl:copy-of select="@*|node()" />
111      <xsl:if test="contains($clfs.multilib, ',')">
112        <xsl:text> - 32Bit</xsl:text>
113      </xsl:if>
114    </xsl:element>
115  </xsl:template>
116
117  <xsl:template match="@*|node()" mode="filter-bits-32">
118    <xsl:variable name="ismultilib">
119      <xsl:choose>
120        <xsl:when test="contains($clfs.multilib, ',')">
121          <xsl:text>true</xsl:text>
122        </xsl:when>
123        <xsl:otherwise>
124          <xsl:text>false</xsl:text>
125        </xsl:otherwise>
126      </xsl:choose>
127    </xsl:variable>
128    <xsl:if test="(string-length(@c:arch) = 0) or contains(concat(',',@c:arch,','), concat(',', $clfs.arch, ','))">
129      <xsl:if test="(string-length(@c:multilib) = 0) or contains(concat(',',@c:multilib,','), concat(',', $ismultilib, ','))">
130        <xsl:if test="(string-length(@c:bits) = 0) or contains(concat(',',@c:bits,','), ',32,')">
131          <xsl:copy>
132            <xsl:apply-templates select="@*|node()" mode="filter-bits-32" />
133          </xsl:copy>
134        </xsl:if>
135      </xsl:if>
136    </xsl:if>
137  </xsl:template>
138
139  <xsl:template match="@c:arch" mode="filter-bits-32" />
140  <xsl:template match="@c:bits" mode="filter-bits-32" />
141  <xsl:template match="@c:multilib" mode="filter-bits-32" />
142
143  <!-- Apply the profile to the n32 package -->
144 
145  <xsl:template match="//sect1/title" mode="filter-bits-n32">
146    <xsl:element name="title">
147      <xsl:copy-of select="@*|node()" />
148      <xsl:if test="contains($clfs.multilib, ',')">
149        <xsl:text> - N32</xsl:text>
150      </xsl:if>
151    </xsl:element>
152  </xsl:template>
153
154  <xsl:template match="@*|node()" mode="filter-bits-n32">
155    <xsl:variable name="ismultilib">
156      <xsl:choose>
157        <xsl:when test="contains($clfs.multilib, ',')">
158          <xsl:text>true</xsl:text>
159        </xsl:when>
160        <xsl:otherwise>
161          <xsl:text>false</xsl:text>
162        </xsl:otherwise>
163      </xsl:choose>
164    </xsl:variable>
165    <xsl:if test="(string-length(@c:arch) = 0) or contains(concat(',',@c:arch,','), concat(',', $clfs.arch, ','))">
166      <xsl:if test="(string-length(@c:multilib) = 0) or contains(concat(',',@c:multilib,','), concat(',', $ismultilib, ','))">
167        <xsl:if test="(string-length(@c:bits) = 0) or contains(concat(',',@c:bits,','), ',n32,')">
168          <xsl:copy>
169            <xsl:apply-templates select="@*|node()" mode="filter-bits-n32" />
170          </xsl:copy>
171        </xsl:if>
172      </xsl:if>
173    </xsl:if>
174  </xsl:template>
175
176  <xsl:template match="@c:arch" mode="filter-bits-n32" />
177  <xsl:template match="@c:bits" mode="filter-bits-n32" />
178  <xsl:template match="@c:multilib" mode="filter-bits-n32" />
179
180  <!-- Apply the profile to the 64bit package -->
181 
182  <xsl:template match="//sect1/title" mode="filter-bits-64">
183    <xsl:element name="title">
184      <xsl:copy-of select="@*|node()" />
185      <xsl:if test="contains($clfs.multilib, ',')">
186        <xsl:text> - 64Bit</xsl:text>
187      </xsl:if>
188    </xsl:element>
189  </xsl:template>
190
191  <xsl:template match="@*|node()" mode="filter-bits-64">
192    <xsl:variable name="ismultilib">
193      <xsl:choose>
194        <xsl:when test="contains($clfs.multilib, ',')">
195          <xsl:text>true</xsl:text>
196        </xsl:when>
197        <xsl:otherwise>
198          <xsl:text>false</xsl:text>
199        </xsl:otherwise>
200      </xsl:choose>
201    </xsl:variable>
202    <xsl:if test="(string-length(@c:arch) = 0) or contains(concat(',',@c:arch,','), concat(',', $clfs.arch, ','))">
203      <xsl:if test="(string-length(@c:multilib) = 0) or contains(concat(',',@c:multilib,','), concat(',', $ismultilib, ','))">
204        <xsl:if test="(string-length(@c:bits) = 0) or contains(concat(',',@c:bits,','), ',64,')">
205          <xsl:copy>
206            <xsl:apply-templates select="@*|node()" mode="filter-bits-64" />
207          </xsl:copy>
208        </xsl:if>
209      </xsl:if>
210    </xsl:if>
211  </xsl:template>
212
213  <xsl:template match="@c:arch" mode="filter-bits-64" />
214  <xsl:template match="@c:bits" mode="filter-bits-64" />
215  <xsl:template match="@c:multilib" mode="filter-bits-64" />
216
217  <!-- Apply the profile filter to the entire document -->
218  <xsl:template match="//*[@c:arch]|//*[@c:multilib]">
219    <xsl:variable name="ismultilib">
220      <xsl:choose>
221        <xsl:when test="contains($clfs.multilib, ',')">
222          <xsl:text>true</xsl:text>
223        </xsl:when>
224        <xsl:otherwise>
225          <xsl:text>false</xsl:text>
226        </xsl:otherwise>
227      </xsl:choose>
228    </xsl:variable>
229    <xsl:if test="(string-length(@c:arch) = 0) or contains(concat(',',@c:arch,','), concat(',', $clfs.arch, ','))">
230      <xsl:if test="(string-length(@c:multilib) = 0) or contains(concat(',',@c:multilib,','), concat(',', $ismultilib, ','))">
231        <xsl:copy>
232          <xsl:apply-templates select="@*|node()" />
233        </xsl:copy>
234      </xsl:if>
235    </xsl:if>
236  </xsl:template>
237
238  <!-- Remove the profileing attributes for the remaining objects -->
239  <xsl:template match="@c:arch" />
240  <xsl:template match="@c:bits" />
241  <xsl:template match="@c:multilib" />
242
243</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.