source: BOOK/stylesheets/clfs-profile.xsl @ 4a39252

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

Properly filter the descendents of c:package based on the filtering
attributes that are set. This marks a point where the stylesheet is stable.

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