* Fixed problem when BASEDIR paths were given without a trailing '/'.
[linux_from_scratch.git] / newxml / stylesheets / xhtml / lfs-index.xsl
blob2405e5586470045c5c6588d719834a7f2394a027
1 <?xml version='1.0' encoding='ISO-8859-1'?>
2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
4 <!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
5 <!ENTITY primary 'normalize-space(concat(primary/@sortas, primary[not(@sortas)]))'>
6 <!ENTITY scope 'count(ancestor::node()|$scope) = count(ancestor::node())'>
7 ]>
9 <!-- Version 0.8.0 - Manuel Canales Esparcia <macana@lfs-es.org> -->
11 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
12 xmlns="http://www.w3.org/1999/xhtml"
13 version="1.0">
15 <!--Index Stuff-->
17 <!--Filename-->
18 <xsl:template match="index" mode="recursive-chunk-filename">
19 <xsl:text>longindex.html</xsl:text>
20 </xsl:template>
22 <!--Title-->
23 <xsl:template match="index" mode="title.markup">
24 <xsl:param name="allow-anchors" select="0"/>
25 <xsl:text>Index of packages and important installed files</xsl:text>
26 </xsl:template>
28 <!--Divisions-->
29 <xsl:template match="indexterm" mode="index-div">
30 <xsl:param name="scope" select="."/>
31 <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
32 <xsl:variable name="divtitle" select="translate($key, &lowercase;, &uppercase;)"/>
33 <!-- Make sure that we don't generate a div if there are no terms in scope -->
34 <xsl:if test="key('letter', $key)[&scope;] [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
35 <div class="indexdiv">
36 <xsl:if test="contains(concat(&lowercase;, &uppercase;), $key)">
37 <h2>
38 <xsl:choose>
39 <xsl:when test="$divtitle = 'A'">
40 <xsl:text>Packages</xsl:text>
41 </xsl:when>
42 <xsl:when test="$divtitle = 'B'">
43 <xsl:text>Programs</xsl:text>
44 </xsl:when>
45 <xsl:when test="$divtitle = 'C'">
46 <xsl:text>Libraries</xsl:text>
47 </xsl:when>
48 <xsl:when test="$divtitle = 'D'">
49 <xsl:text>Scripts</xsl:text>
50 </xsl:when>
51 <xsl:when test="$divtitle = 'E'">
52 <xsl:text>Others</xsl:text>
53 </xsl:when>
54 <xsl:otherwise>
55 <xsl:value-of select="$divtitle"/>
56 </xsl:otherwise>
57 </xsl:choose>
58 </h2>
59 </xsl:if>
60 <ul>
61 <xsl:apply-templates select="key('letter', $key)[&scope;]
62 [count(.|key('primary', &primary;)[&scope;][1])=1]" mode="index-primary">
63 <xsl:with-param name="scope" select="$scope"/>
64 <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
65 </xsl:apply-templates>
66 </ul>
67 </div>
68 </xsl:if>
69 </xsl:template>
71 <!-- Dropping the separator from here-->
72 <xsl:template match="indexterm" mode="reference">
73 <xsl:param name="scope" select="."/>
74 <xsl:call-template name="reference">
75 <xsl:with-param name="zones" select="normalize-space(@zone)"/>
76 <xsl:with-param name="scope" select="$scope"/>
77 </xsl:call-template>
78 </xsl:template>
80 <!-- Changing the output tags and re-addind the separator-->
81 <xsl:template match="indexterm" mode="index-primary">
82 <xsl:param name="scope" select="."/>
83 <xsl:variable name="key" select="&primary;"/>
84 <xsl:variable name="refs" select="key('primary', $key)[&scope;]"/>
85 <li>
86 <strong class="item">
87 <xsl:value-of select="primary"/>
88 <xsl:text>: </xsl:text>
89 </strong>
90 <xsl:for-each select="$refs[generate-id() = generate-id(key('primary-section',
91 concat($key, &#34; &#34;, generate-id((ancestor-or-self::book |ancestor-or-self::part
92 |ancestor-or-self::chapter |ancestor-or-self::appendix |ancestor-or-self::preface
93 |ancestor-or-self::sect1 |ancestor-or-self::sect2 |ancestor-or-self::sect3
94 |ancestor-or-self::sect4 |ancestor-or-self::sect5 |ancestor-or-self::index)[last()])))[&scope;][1])]">
95 <xsl:apply-templates select="." mode="reference">
96 <xsl:with-param name="scope" select="$scope"/>
97 </xsl:apply-templates>
98 </xsl:for-each>
99 <xsl:if test="$refs/secondary">
100 <ul>
101 <xsl:apply-templates select="$refs[secondary and count(.|key('secondary',
102 concat($key, &#34; &#34;, normalize-space(concat(secondary/@sortas,
103 secondary[not(@sortas)]))))[&scope;][1]) = 1]" mode="index-secondary">
104 <xsl:with-param name="scope" select="$scope"/>
105 <xsl:sort select="translate(normalize-space(concat(secondary/@sortas,
106 secondary[not(@sortas)])), &lowercase;, &uppercase;)"/>
107 </xsl:apply-templates>
108 </ul>
109 </xsl:if>
110 </li>
111 </xsl:template>
112 <xsl:template match="indexterm" mode="index-secondary">
113 <xsl:param name="scope" select="."/>
114 <xsl:variable name="key" select="concat(&primary;, &#34; &#34;,
115 normalize-space(concat(secondary/@sortas, secondary[not(@sortas)])))"/>
116 <xsl:variable name="refs" select="key('secondary', $key)[&scope;]"/>
117 <li>
118 <strong class="secitem">
119 <xsl:value-of select="secondary"/>
120 <xsl:text>: </xsl:text>
121 </strong>
122 <xsl:for-each select="$refs[generate-id() = generate-id(key('secondary-section',
123 concat($key, &#34; &#34;, generate-id((ancestor-or-self::book |ancestor-or-self::part
124 |ancestor-or-self::chapter |ancestor-or-self::appendix |ancestor-or-self::preface
125 |ancestor-or-self::sect1 |ancestor-or-self::sect2 |ancestor-or-self::sect3
126 |ancestor-or-self::sect4 |ancestor-or-self::sect5 |ancestor-or-self::index)[last()])))[&scope;][1])]">
127 <xsl:apply-templates select="." mode="reference">
128 <xsl:with-param name="scope" select="$scope"/>
129 </xsl:apply-templates>
130 </xsl:for-each>
131 </li>
132 </xsl:template>
134 <!--Links (This template also fix a bug in the original code)-->
135 <xsl:template name="reference">
136 <xsl:param name="scope" select="."/>
137 <xsl:param name="zones"/>
138 <xsl:choose>
139 <xsl:when test="contains($zones, ' ')">
140 <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
141 <xsl:variable name="zone2" select="substring-after($zones, ' ')"/>
142 <xsl:variable name="target" select="key('sections', $zone)[&scope;]"/>
143 <xsl:variable name="target2" select="key('sections', $zone2)[&scope;]"/>
145 <xsl:attribute name="href">
146 <xsl:call-template name="href.target.uri">
147 <xsl:with-param name="object" select="$target[1]"/>
148 </xsl:call-template>
149 </xsl:attribute>
150 <xsl:apply-templates select="$target[1]" mode="index-title-content"/>
151 </a>
152 <xsl:text> -- </xsl:text>
154 <xsl:attribute name="href">
155 <xsl:call-template name="href.target.uri">
156 <xsl:with-param name="object" select="$target2[1]"/>
157 </xsl:call-template>
158 </xsl:attribute>
159 <xsl:text>description</xsl:text>
160 </a>
161 </xsl:when>
162 <xsl:otherwise>
163 <xsl:variable name="zone" select="$zones"/>
164 <xsl:variable name="target" select="key('sections', $zone)[&scope;]"/>
166 <xsl:attribute name="href">
167 <xsl:call-template name="href.target.uri">
168 <xsl:with-param name="object" select="$target[1]"/>
169 </xsl:call-template>
170 </xsl:attribute>
171 <xsl:apply-templates select="$target[1]" mode="index-title-content"/>
172 </a>
173 </xsl:otherwise>
174 </xsl:choose>
175 </xsl:template>
177 </xsl:stylesheet>