source: BOOK/stylesheets/clfs-profile.xsl @ 7b0cc7e8

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

Automatically generate the indexterm element from the title. This will
need to be changed in the future because a real package will have a
version number attached to the title.

  • Property mode set to 100644
File size: 9.5 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="multibuild" select="$multibuild" />
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="multibuild" /> <!-- Are there multiple instances of this package? -->
74
75    <xsl:for-each select="sect1">
76
77      <xsl:copy>
78
79        <xsl:attribute name="id">
80          <xsl:value-of select="concat($id, $idsuffix)" />
81        </xsl:attribute>
82
83        <xsl:processing-instruction name="dbhtml">
84          <xsl:text>filename=&quot;</xsl:text>
85          <xsl:value-of select="concat($id, $idsuffix)" />
86          <xsl:text>.html&quot;</xsl:text>
87        </xsl:processing-instruction>
88
89        <xsl:variable name="titlesuffix">
90          <xsl:if test="contains($clfs.multilib, ',') and ($multibuild = 'true')">
91            <xsl:choose>
92              <xsl:when test="$bits = '32'">
93                <xsl:text>32Bit</xsl:text>
94              </xsl:when>
95              <xsl:when test="$bits = 'n32'">
96                <xsl:text>N32</xsl:text>
97              </xsl:when>
98              <xsl:when test="$bits = '64'">
99                <xsl:text>64Bit</xsl:text>
100              </xsl:when>
101            </xsl:choose>
102          </xsl:if>
103        </xsl:variable>
104
105        <xsl:for-each select="title">
106          <xsl:element name="title">
107            <xsl:copy-of select="@*|node()" />
108            <xsl:if test="string-length($titlesuffix) > 0">
109              <xsl:text> - </xsl:text>
110              <xsl:value-of select="$titlesuffix"/>
111            </xsl:if>
112          </xsl:element>
113        </xsl:for-each>
114
115        <xsl:element name="indexterm">
116          <xsl:attribute name="zone">
117            <xsl:value-of select="concat($id, $idsuffix)" />
118          </xsl:attribute>
119          <xsl:element name="primary">
120            <xsl:attribute name="sortas">
121              <xsl:text>a-</xsl:text>
122              <xsl:value-of select="title" />
123            </xsl:attribute>
124            <xsl:value-of select="title" />
125          </xsl:element>
126          <xsl:if test="string-length($titlesuffix) > 0">
127            <xsl:element name="secondary">
128              <xsl:value-of select="$titlesuffix" />
129            </xsl:element>
130          </xsl:if>
131        </xsl:element>
132
133        <xsl:choose>
134          <xsl:when test="$bits = '32'">
135            <xsl:apply-templates select="@*|node()[not(self::title)]" mode="filter-bits-32" />
136          </xsl:when>
137          <xsl:when test="$bits = 'n32'">
138            <xsl:apply-templates select="@*|node()[not(self::title)]" mode="filter-bits-n32" />
139          </xsl:when>
140          <xsl:when test="$bits = '64'">
141            <xsl:apply-templates select="@*|node()[not(self::title)]" mode="filter-bits-64" />
142          </xsl:when>
143        </xsl:choose>
144
145      </xsl:copy>
146
147    </xsl:for-each>
148
149  </xsl:template>
150
151  <!-- Apply the profile to the 32bit package -->
152
153  <xsl:template match="@*|node()" mode="filter-bits-32">
154    <xsl:variable name="ismultilib">
155      <xsl:choose>
156        <xsl:when test="contains($clfs.multilib, ',')">
157          <xsl:text>true</xsl:text>
158        </xsl:when>
159        <xsl:otherwise>
160          <xsl:text>false</xsl:text>
161        </xsl:otherwise>
162      </xsl:choose>
163    </xsl:variable>
164    <xsl:if test="(string-length(@c:arch) = 0) or contains(concat(',',@c:arch,','), concat(',', $clfs.arch, ','))">
165      <xsl:if test="(string-length(@c:multilib) = 0) or contains(concat(',',@c:multilib,','), concat(',', $ismultilib, ','))">
166        <xsl:if test="(string-length(@c:bits) = 0) or contains(concat(',',@c:bits,','), ',32,')">
167          <xsl:copy>
168            <xsl:apply-templates select="@*|node()" mode="filter-bits-32" />
169          </xsl:copy>
170        </xsl:if>
171      </xsl:if>
172    </xsl:if>
173  </xsl:template>
174
175  <xsl:template match="@c:arch" mode="filter-bits-32" />
176  <xsl:template match="@c:bits" mode="filter-bits-32" />
177  <xsl:template match="@c:multilib" mode="filter-bits-32" />
178
179  <!-- Apply the profile to the n32 package -->
180
181  <xsl:template match="@*|node()" mode="filter-bits-n32">
182    <xsl:variable name="ismultilib">
183      <xsl:choose>
184        <xsl:when test="contains($clfs.multilib, ',')">
185          <xsl:text>true</xsl:text>
186        </xsl:when>
187        <xsl:otherwise>
188          <xsl:text>false</xsl:text>
189        </xsl:otherwise>
190      </xsl:choose>
191    </xsl:variable>
192    <xsl:if test="(string-length(@c:arch) = 0) or contains(concat(',',@c:arch,','), concat(',', $clfs.arch, ','))">
193      <xsl:if test="(string-length(@c:multilib) = 0) or contains(concat(',',@c:multilib,','), concat(',', $ismultilib, ','))">
194        <xsl:if test="(string-length(@c:bits) = 0) or contains(concat(',',@c:bits,','), ',n32,')">
195          <xsl:copy>
196            <xsl:apply-templates select="@*|node()" mode="filter-bits-n32" />
197          </xsl:copy>
198        </xsl:if>
199      </xsl:if>
200    </xsl:if>
201  </xsl:template>
202
203  <xsl:template match="@c:arch" mode="filter-bits-n32" />
204  <xsl:template match="@c:bits" mode="filter-bits-n32" />
205  <xsl:template match="@c:multilib" mode="filter-bits-n32" />
206
207  <!-- Apply the profile to the 64bit package -->
208
209  <xsl:template match="@*|node()" mode="filter-bits-64">
210    <xsl:variable name="ismultilib">
211      <xsl:choose>
212        <xsl:when test="contains($clfs.multilib, ',')">
213          <xsl:text>true</xsl:text>
214        </xsl:when>
215        <xsl:otherwise>
216          <xsl:text>false</xsl:text>
217        </xsl:otherwise>
218      </xsl:choose>
219    </xsl:variable>
220    <xsl:if test="(string-length(@c:arch) = 0) or contains(concat(',',@c:arch,','), concat(',', $clfs.arch, ','))">
221      <xsl:if test="(string-length(@c:multilib) = 0) or contains(concat(',',@c:multilib,','), concat(',', $ismultilib, ','))">
222        <xsl:if test="(string-length(@c:bits) = 0) or contains(concat(',',@c:bits,','), ',64,')">
223          <xsl:copy>
224            <xsl:apply-templates select="@*|node()" mode="filter-bits-64" />
225          </xsl:copy>
226        </xsl:if>
227      </xsl:if>
228    </xsl:if>
229  </xsl:template>
230
231  <xsl:template match="@c:arch" mode="filter-bits-64" />
232  <xsl:template match="@c:bits" mode="filter-bits-64" />
233  <xsl:template match="@c:multilib" mode="filter-bits-64" />
234
235  <!-- Apply the profile filter to the entire document -->
236  <xsl:template match="//*[@c:arch]|//*[@c:multilib]">
237    <xsl:variable name="ismultilib">
238      <xsl:choose>
239        <xsl:when test="contains($clfs.multilib, ',')">
240          <xsl:text>true</xsl:text>
241        </xsl:when>
242        <xsl:otherwise>
243          <xsl:text>false</xsl:text>
244        </xsl:otherwise>
245      </xsl:choose>
246    </xsl:variable>
247    <xsl:if test="(string-length(@c:arch) = 0) or contains(concat(',',@c:arch,','), concat(',', $clfs.arch, ','))">
248      <xsl:if test="(string-length(@c:multilib) = 0) or contains(concat(',',@c:multilib,','), concat(',', $ismultilib, ','))">
249        <xsl:copy>
250          <xsl:apply-templates select="@*|node()" />
251        </xsl:copy>
252      </xsl:if>
253    </xsl:if>
254  </xsl:template>
255
256  <!-- Remove the profileing attributes for the remaining objects -->
257  <xsl:template match="@c:arch" />
258  <xsl:template match="@c:bits" />
259  <xsl:template match="@c:multilib" />
260
261</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.