Debian Codegraph @

doc/custom-html.xsl

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