chiark / gitweb /
Use a top-to-bottom numbering scheme for generating ids of subheadings and terms...
[elogind.git] / man / custom-html.xsl
1 <?xml version='1.0'?> <!--*-nxml-*-->
2
3 <!--
4   This file is part of systemd.
5
6   Copyright 2011 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 -->
21
22 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
23
24 <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"/>
25
26 <!-- translate man page references to links to html pages -->
27 <xsl:template match="citerefentry[not(@project)]">
28   <a>
29     <xsl:attribute name="href">
30       <xsl:value-of select="refentrytitle"/><xsl:text>.html</xsl:text>
31     </xsl:attribute>
32     <xsl:call-template name="inline.charseq"/>
33   </a>
34 </xsl:template>
35
36 <xsl:template match="citerefentry[@project='man-pages'] | citerefentry[manvolnum='2'] | citerefentry[manvolnum='4']">
37   <a>
38     <xsl:attribute name="href">
39       <xsl:text>http://man7.org/linux/man-pages/man</xsl:text>
40       <xsl:value-of select="manvolnum"/>
41       <xsl:text>/</xsl:text>
42       <xsl:value-of select="refentrytitle"/>
43       <xsl:text>.</xsl:text>
44       <xsl:value-of select="manvolnum"/>
45       <xsl:text>.html</xsl:text>
46     </xsl:attribute>
47     <xsl:call-template name="inline.charseq"/>
48   </a>
49 </xsl:template>
50
51 <xsl:template match="citerefentry[@project='die-net']">
52   <a>
53     <xsl:attribute name="href">
54       <xsl:text>http://linux.die.net/man/</xsl:text>
55       <xsl:value-of select="manvolnum"/>
56       <xsl:text>/</xsl:text>
57       <xsl:value-of select="refentrytitle"/>
58     </xsl:attribute>
59     <xsl:call-template name="inline.charseq"/>
60   </a>
61 </xsl:template>
62
63 <xsl:template match="citerefentry[@project='mankier']">
64   <a>
65     <xsl:attribute name="href">
66       <xsl:text>https://www.mankier.com/</xsl:text>
67       <xsl:value-of select="manvolnum"/>
68       <xsl:text>/</xsl:text>
69       <xsl:value-of select="refentrytitle"/>
70     </xsl:attribute>
71     <xsl:call-template name="inline.charseq"/>
72   </a>
73 </xsl:template>
74
75 <xsl:template match="citerefentry[@project='archlinux']">
76   <a>
77     <xsl:attribute name="href">
78       <xsl:text>https://www.archlinux.org/</xsl:text>
79       <xsl:value-of select="refentrytitle"/>
80       <xsl:text>/</xsl:text>
81       <xsl:value-of select="refentrytitle"/>
82       <xsl:text>.</xsl:text>
83       <xsl:value-of select="manvolnum"/>
84       <xsl:text>.html</xsl:text>
85     </xsl:attribute>
86     <xsl:call-template name="inline.charseq"/>
87   </a>
88 </xsl:template>
89
90 <xsl:template match="citerefentry[@project='freebsd']">
91   <a>
92     <xsl:attribute name="href">
93       <xsl:text>https://www.freebsd.org/cgi/man.cgi?</xsl:text>
94       <xsl:value-of select="refentrytitle"/>
95       <xsl:text>(</xsl:text>
96       <xsl:value-of select="manvolnum"/>
97       <xsl:text>)</xsl:text>
98     </xsl:attribute>
99     <xsl:call-template name="inline.charseq"/>
100   </a>
101 </xsl:template>
102
103 <xsl:template match="citerefentry[@project='dbus']">
104   <a>
105     <xsl:attribute name="href">
106       <xsl:text>http://dbus.freedesktop.org/doc/</xsl:text>
107       <xsl:value-of select="refentrytitle"/>
108       <xsl:text>.</xsl:text>
109       <xsl:value-of select="manvolnum"/>
110       <xsl:text>.html</xsl:text>
111     </xsl:attribute>
112     <xsl:call-template name="inline.charseq"/>
113   </a>
114 </xsl:template>
115
116 <!--
117   - helper template to do conflict resolution between various headings with the same inferred ID attribute/tag from the headerlink template
118   - this conflict resolution is necessary to prevent malformed HTML ouput (multiple id attributes with the same value)
119   - and it fixes xsltproc warnings during compilation of HTML man pages
120   -
121   - A simple top-to-bottom numbering scheme is implemented for nodes with the same ID value to derive unique ID values for HTML output.
122   - It uses two parameters:
123       templateID  the proposed ID string to use which must be checked for conflicts
124       keyNode     the context node which 'produced' the given templateID.
125   -
126   - Conflicts are detected solely based on keyNode, templateID is not taken into account for that purpose.
127  -->
128 <xsl:template name="generateID">
129   <!-- node which generatedID needs to assume as the 'source' of the ID -->
130   <xsl:param name="keyNode"/>
131   <!-- suggested value for generatedID output, a contextually meaningful ID string -->
132   <xsl:param name="templateID"/>
133   <xsl:variable name="conflictSource" select="preceding::refsect1/title|preceding::refsect1/info/title|
134                                               preceding::refsect2/title|preceding::refsect2/info/title|
135                                               preceding::varlistentry/term[1]"/>
136   <xsl:variable name="conflictCount" select="count($conflictSource[. = $keyNode])"/>
137   <xsl:choose>
138     <!-- special case conflictCount = 0 to preserve compatibility with URLs generated by previous versions of this XSL stylesheet where possible -->
139     <xsl:when test="$conflictCount = 0">
140       <xsl:value-of select="$templateID"/>
141     </xsl:when>
142     <xsl:otherwise>
143       <xsl:value-of select="concat($templateID, $conflictCount)"/>
144     </xsl:otherwise>
145   </xsl:choose>
146 </xsl:template>
147
148 <!--
149   - a helper template to abstract over the structure of generated subheading + permalink HTML output
150   - It helps reduce tedious repetition and groups all actual markup output (as opposed to URL/ID logic) in a single location.
151  -->
152 <xsl:template name="permalink">
153   <xsl:param name="nodeType"/> <!-- local name of the element node to generate, e.g. 'h2' for <h2></h2> -->
154   <xsl:param name="nodeContent"/> <!-- nodeset to apply further templates to obtain the content of the subheading/term -->
155   <xsl:param name="linkTitle"/> <!-- value for title attribute of generated permalink, e.g. 'this is a permalink' -->
156
157   <!-- parameters passed to generateID template, otherwise unused. -->
158   <xsl:param name="keyNode"/>
159   <xsl:param name="templateID"/>
160
161   <!--
162     - If stable URLs with fragment markers (references to the ID) turn out not to be important:
163     - generatedID could simply take the value of generate-id(), and various other helper templates may be dropped entirely.
164     - Alternatively if xsltproc is patched to generate reproducible generate-id() output the same simplifications can be
165     - applied at the cost of breaking compatibility with URLs generated from output of previous versions of this stylesheet.
166    -->
167   <xsl:variable name="generatedID">
168     <xsl:call-template name="generateID">
169       <xsl:with-param name="keyNode" select="$keyNode"/>
170       <xsl:with-param name="templateID" select="$templateID"/>
171     </xsl:call-template>
172   </xsl:variable>
173
174   <xsl:element name="{$nodeType}">
175     <xsl:attribute name="id">
176       <xsl:value-of select="$generatedID"/>
177     </xsl:attribute>
178     <xsl:apply-templates select="$nodeContent"/>
179     <a class="headerlink" title="{$linkTitle}" href="#{$generatedID}">ΒΆ</a>
180   </xsl:element>
181 </xsl:template>
182
183 <!-- simple wrapper around permalink to avoid repeating common info for each level of subheading covered by the permalink logic (h2, h3) -->
184 <xsl:template name="headerlink">
185   <xsl:param name="nodeType"/>
186   <xsl:call-template name="permalink">
187     <xsl:with-param name="nodeType" select="$nodeType"/>
188     <xsl:with-param name="linkTitle" select="'Permalink to this headline'"/>
189     <xsl:with-param name="nodeContent" select="node()"/>
190     <xsl:with-param name="keyNode" select="."/>
191     <!--
192       - To retain compatibility with IDs generated by previous versions of the template, inline.charseq must be called.
193       - The purpose of that template is to generate markup (according to docbook documentation its purpose is to mark/format something as plain text).
194       - The only reason to call this template is to get the auto-generated text such as brackets ([]) before flattening it.
195      -->
196     <xsl:with-param name="templateID">
197       <xsl:call-template name="inline.charseq"/>
198     </xsl:with-param>
199   </xsl:call-template>
200 </xsl:template>
201
202 <xsl:template match="refsect1/title|refsect1/info/title">
203   <!-- the ID is output in the block.object call for refsect1 -->
204   <xsl:call-template name="headerlink">
205     <xsl:with-param name="nodeType" select="'h2'"/>
206   </xsl:call-template>
207 </xsl:template>
208
209 <xsl:template match="refsect2/title|refsect2/info/title">
210   <xsl:call-template name="headerlink">
211     <xsl:with-param name="nodeType" select="'h3'"/>
212   </xsl:call-template>
213 </xsl:template>
214
215 <xsl:template match="varlistentry">
216   <xsl:call-template name="permalink">
217     <xsl:with-param name="nodeType" select="'dt'"/>
218     <xsl:with-param name="linkTitle" select="'Permalink to this term'"/>
219     <xsl:with-param name="nodeContent" select="term"/>
220     <xsl:with-param name="keyNode" select="term[1]"/>
221     <!--
222       - To retain compatibility with IDs generated by previous versions of the template, inline.charseq must be called.
223       - The purpose of that template is to generate markup (according to docbook documentation its purpose is to mark/format something as plain text).
224       - The only reason to call this template is to get the auto-generated text such as brackets ([]) before flattening it.
225      -->
226     <xsl:with-param name="templateID">
227       <xsl:call-template name="inline.charseq">
228         <xsl:with-param name="content" select="term[1]"/>
229       </xsl:call-template>
230     </xsl:with-param>
231   </xsl:call-template>
232   <dd>
233     <xsl:apply-templates select="listitem"/>
234   </dd>
235 </xsl:template>
236
237
238 <!-- add Index link at top of page -->
239 <xsl:template name="user.header.content">
240   <style>
241     a.headerlink {
242       color: #c60f0f;
243       font-size: 0.8em;
244       padding: 0 4px 0 4px;
245       text-decoration: none;
246       visibility: hidden;
247     }
248
249     a.headerlink:hover {
250       background-color: #c60f0f;
251       color: white;
252     }
253
254     h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink {
255       visibility: visible;
256     }
257   </style>
258
259   <a>
260     <xsl:attribute name="href">
261       <xsl:text>index.html</xsl:text>
262     </xsl:attribute>
263     <xsl:text>Index </xsl:text>
264
265   <span style="float:right">
266     <xsl:text>elogind </xsl:text>
267     <xsl:value-of select="$elogind.version"/>
268   </span>
269   <hr/>
270 </xsl:template>
271
272 <xsl:template match="literal">
273   <xsl:text>"</xsl:text>
274   <xsl:call-template name="inline.monoseq"/>
275   <xsl:text>"</xsl:text>
276 </xsl:template>
277
278 <!-- Switch things to UTF-8, ISO-8859-1 is soo yesteryear -->
279 <xsl:output method="html" encoding="UTF-8" indent="no"/>
280
281 </xsl:stylesheet>