1 | <?xml version="1.0"?>
|
---|
2 | <!--
|
---|
3 | docbook-refentry-to-manual-sect1.xsl:
|
---|
4 | XSLT stylesheet for converting a refentry (manpage)
|
---|
5 | to dita for use in the user manual.
|
---|
6 | -->
|
---|
7 | <!--
|
---|
8 | Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
9 |
|
---|
10 | This file is part of VirtualBox base platform packages, as
|
---|
11 | available from https://www.virtualbox.org.
|
---|
12 |
|
---|
13 | This program is free software; you can redistribute it and/or
|
---|
14 | modify it under the terms of the GNU General Public License
|
---|
15 | as published by the Free Software Foundation, in version 3 of the
|
---|
16 | License.
|
---|
17 |
|
---|
18 | This program is distributed in the hope that it will be useful, but
|
---|
19 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | General Public License for more details.
|
---|
22 |
|
---|
23 | You should have received a copy of the GNU General Public License
|
---|
24 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
25 |
|
---|
26 | SPDX-License-Identifier: GPL-3.0-only
|
---|
27 | -->
|
---|
28 |
|
---|
29 | <xsl:stylesheet
|
---|
30 | version="1.0"
|
---|
31 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
---|
32 | xmlns:str="http://xsltsl.org/string"
|
---|
33 | >
|
---|
34 |
|
---|
35 | <xsl:import href="string.xsl"/>
|
---|
36 |
|
---|
37 | <xsl:output method="xml" version="1.0" encoding="utf-8" indent="no"/>
|
---|
38 | <xsl:preserve-space elements="*"/>
|
---|
39 | <!-- xsl:strip-space elements="*"/ - never -->
|
---|
40 |
|
---|
41 |
|
---|
42 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
43 | global XSLT variables
|
---|
44 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
49 | base operation is to fail on nodes w/o explicit matching.
|
---|
50 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
51 |
|
---|
52 | <xsl:template match="*">
|
---|
53 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>unhandled element</xsl:message>
|
---|
54 | </xsl:template>
|
---|
55 |
|
---|
56 |
|
---|
57 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
58 | transformations starting with root and going deeper.
|
---|
59 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
60 |
|
---|
61 | <!-- Rename refentry to reference.
|
---|
62 | Also we need to wrap the refsync and refsect1 elements in a refbody. -->
|
---|
63 | <xsl:template match="refentry">
|
---|
64 | <xsl:text disable-output-escaping='yes'><!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd">
|
---|
65 | </xsl:text>
|
---|
66 |
|
---|
67 | <xsl:element name="reference">
|
---|
68 | <xsl:if test="not(@id)">
|
---|
69 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have an id attribute!</xsl:message>
|
---|
70 | </xsl:if>
|
---|
71 | <xsl:attribute name="rev">refentry</xsl:attribute>
|
---|
72 | <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
|
---|
73 |
|
---|
74 | <!-- Copy title element from refentryinfo -->
|
---|
75 | <xsl:if test="./refentryinfo/title">
|
---|
76 | <xsl:copy-of select="./refentryinfo/title"/>
|
---|
77 | </xsl:if>
|
---|
78 |
|
---|
79 | <!-- Create a shortdesc element from the text in refnamediv/refpurpose -->
|
---|
80 | <xsl:if test="./refnamediv/refpurpose">
|
---|
81 | <xsl:element name="shortdesc">
|
---|
82 | <xsl:attribute name="rev">refnamediv/refpurpose</xsl:attribute>
|
---|
83 | <xsl:call-template name="capitalize">
|
---|
84 | <xsl:with-param name="text" select="normalize-space(./refnamediv/refpurpose)"/>
|
---|
85 | </xsl:call-template>
|
---|
86 | </xsl:element>
|
---|
87 | </xsl:if>
|
---|
88 |
|
---|
89 | <!-- Put everything else side a refbody element -->
|
---|
90 | <xsl:element name="refbody">
|
---|
91 | <xsl:apply-templates />
|
---|
92 | </xsl:element>
|
---|
93 |
|
---|
94 | </xsl:element>
|
---|
95 | </xsl:template>
|
---|
96 |
|
---|
97 | <!-- Remove refentryinfo (we extracted the title element already). -->
|
---|
98 | <xsl:template match="refentryinfo" />
|
---|
99 |
|
---|
100 | <!-- Remove refmeta (manpage info). -->
|
---|
101 | <xsl:template match="refmeta"/>
|
---|
102 |
|
---|
103 | <!-- Remove the refnamediv (we extracted a shortdesc from it already). -->
|
---|
104 | <xsl:template match="refnamediv"/>
|
---|
105 |
|
---|
106 | <!-- Morph the refsynopsisdiv part into a refsyn section. -->
|
---|
107 | <xsl:template match="refsynopsisdiv">
|
---|
108 | <xsl:if test="name(*[1]) != 'cmdsynopsis'"><xsl:message terminate="yes">Expected refsynopsisdiv to start with cmdsynopsis</xsl:message></xsl:if>
|
---|
109 | <xsl:if test="title"><xsl:message terminate="yes">No title element supported in refsynopsisdiv</xsl:message></xsl:if>
|
---|
110 |
|
---|
111 | <xsl:element name="refsyn">
|
---|
112 | <xsl:attribute name="rev">refsynopsisdiv</xsl:attribute>
|
---|
113 | <xsl:element name="title">
|
---|
114 | <xsl:text>Synopsis</xsl:text>
|
---|
115 | </xsl:element>
|
---|
116 | <xsl:apply-templates />
|
---|
117 | </xsl:element>
|
---|
118 |
|
---|
119 | </xsl:template>
|
---|
120 |
|
---|
121 | <!-- refsect1 -> section -->
|
---|
122 | <xsl:template match="refsect1">
|
---|
123 | <xsl:if test="not(title)"><xsl:message terminate="yes">refsect1 requires title</xsl:message></xsl:if>
|
---|
124 | <xsl:element name="section">
|
---|
125 | <xsl:attribute name="rev">refsect1</xsl:attribute>
|
---|
126 | <xsl:if test="@id">
|
---|
127 | <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
|
---|
128 | </xsl:if>
|
---|
129 | <xsl:apply-templates />
|
---|
130 | </xsl:element>
|
---|
131 | </xsl:template>
|
---|
132 |
|
---|
133 | <!-- refsect2 -> sectiondiv. -->
|
---|
134 | <xsl:template match="refsect2">
|
---|
135 | <xsl:if test="not(title)"><xsl:message terminate="yes">refsect2 requires title</xsl:message></xsl:if>
|
---|
136 | <xsl:element name="sectiondiv">
|
---|
137 | <xsl:attribute name="rev">refsect2</xsl:attribute>
|
---|
138 | <xsl:attribute name="outputclass">refsect2</xsl:attribute> <!-- how to make xhtml pass these thru... -->
|
---|
139 | <xsl:if test="@id">
|
---|
140 | <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
|
---|
141 | </xsl:if>
|
---|
142 |
|
---|
143 | <xsl:apply-templates />
|
---|
144 |
|
---|
145 | </xsl:element>
|
---|
146 | </xsl:template>
|
---|
147 |
|
---|
148 | <!-- refsect2/title -> b -->
|
---|
149 | <xsl:template match="refsect2/title">
|
---|
150 | <xsl:element name="b">
|
---|
151 | <xsl:attribute name="rev">refsect2/title</xsl:attribute>
|
---|
152 | <xsl:attribute name="outputclass">refsect2title</xsl:attribute> <!-- how to make xhtml pass these thru... -->
|
---|
153 | <xsl:apply-templates />
|
---|
154 | </xsl:element>
|
---|
155 | </xsl:template>
|
---|
156 |
|
---|
157 | <!-- refsect1/title -> title -->
|
---|
158 | <xsl:template match="refsect1/title">
|
---|
159 | <xsl:copy>
|
---|
160 | <xsl:apply-templates />
|
---|
161 | </xsl:copy>
|
---|
162 | </xsl:template>
|
---|
163 |
|
---|
164 | <!-- para -> p -->
|
---|
165 | <xsl:template match="para">
|
---|
166 | <xsl:element name="p">
|
---|
167 | <xsl:attribute name="rev">para</xsl:attribute>
|
---|
168 | <xsl:apply-templates />
|
---|
169 | </xsl:element>
|
---|
170 | </xsl:template>
|
---|
171 |
|
---|
172 | <!-- note in a section -> note (no change needed) -->
|
---|
173 | <xsl:template match="refsect1/note | refsect2/note">
|
---|
174 | <xsl:copy>
|
---|
175 | <xsl:apply-templates />
|
---|
176 | </xsl:copy>
|
---|
177 | </xsl:template>
|
---|
178 |
|
---|
179 | <!-- variablelist -> parml -->
|
---|
180 | <xsl:template match="variablelist">
|
---|
181 | <xsl:element name="parml">
|
---|
182 | <xsl:attribute name="rev">variablelist</xsl:attribute>
|
---|
183 | <xsl:apply-templates />
|
---|
184 | </xsl:element>
|
---|
185 | </xsl:template>
|
---|
186 |
|
---|
187 | <!-- varlistentry -> plentry -->
|
---|
188 | <xsl:template match="varlistentry">
|
---|
189 | <xsl:element name="plentry">
|
---|
190 | <xsl:attribute name="rev">varlistentry</xsl:attribute>
|
---|
191 | <xsl:apply-templates />
|
---|
192 | </xsl:element>
|
---|
193 | </xsl:template>
|
---|
194 |
|
---|
195 | <!-- term (in varlistentry) -> pt -->
|
---|
196 | <xsl:template match="varlistentry/term">
|
---|
197 | <xsl:element name="pt">
|
---|
198 | <xsl:attribute name="rev">term</xsl:attribute>
|
---|
199 | <xsl:apply-templates />
|
---|
200 | </xsl:element>
|
---|
201 | </xsl:template>
|
---|
202 |
|
---|
203 | <!-- listitem (in varlistentry) -> pd -->
|
---|
204 | <xsl:template match="varlistentry/listitem">
|
---|
205 | <xsl:element name="pd">
|
---|
206 | <xsl:attribute name="rev">listitem</xsl:attribute>
|
---|
207 | <xsl:apply-templates />
|
---|
208 | </xsl:element>
|
---|
209 | </xsl:template>
|
---|
210 |
|
---|
211 | <!-- itemizedlist -> ul -->
|
---|
212 | <xsl:template match="itemizedlist">
|
---|
213 | <xsl:element name="ul">
|
---|
214 | <xsl:attribute name="rev">itemizedlist</xsl:attribute>
|
---|
215 | <xsl:apply-templates />
|
---|
216 | </xsl:element>
|
---|
217 | </xsl:template>
|
---|
218 |
|
---|
219 | <!-- listitem in itemizedlist -> li -->
|
---|
220 | <xsl:template match="itemizedlist/listitem">
|
---|
221 | <xsl:element name="li">
|
---|
222 | <xsl:attribute name="rev">listitem</xsl:attribute>
|
---|
223 | <xsl:apply-templates />
|
---|
224 | </xsl:element>
|
---|
225 | </xsl:template>
|
---|
226 |
|
---|
227 | <!-- orderedlist -> ol -->
|
---|
228 | <xsl:template match="orderedlist">
|
---|
229 | <xsl:element name="ol">
|
---|
230 | <xsl:attribute name="rev">orderedlist</xsl:attribute>
|
---|
231 | <xsl:apply-templates />
|
---|
232 | </xsl:element>
|
---|
233 | </xsl:template>
|
---|
234 |
|
---|
235 | <!-- listitem in orderedlist -> li -->
|
---|
236 | <xsl:template match="orderedlist/listitem">
|
---|
237 | <xsl:element name="li">
|
---|
238 | <xsl:attribute name="rev">listitem</xsl:attribute>
|
---|
239 | <xsl:apply-templates />
|
---|
240 | </xsl:element>
|
---|
241 | </xsl:template>
|
---|
242 |
|
---|
243 | <!-- cmdsynopsis -> syntaxdiagram
|
---|
244 | If sbr is used, this gets a bit more complicated... -->
|
---|
245 | <xsl:template match="cmdsynopsis[not(sbr)]">
|
---|
246 | <xsl:element name="syntaxdiagram">
|
---|
247 | <xsl:attribute name="rev">cmdsynopsis</xsl:attribute>
|
---|
248 | <xsl:if test="@id">
|
---|
249 | <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
|
---|
250 | </xsl:if>
|
---|
251 | <xsl:apply-templates />
|
---|
252 | </xsl:element>
|
---|
253 |
|
---|
254 | <!-- HACK ALERT! Add an empty paragraph to keep syntax diagrams apart in the
|
---|
255 | PDF output, otherwise the commands becomes hard to tell apart. -->
|
---|
256 | <xsl:if test="position() < last()">
|
---|
257 | <xsl:element name="p">
|
---|
258 | <xsl:attribute name="platform">ohc</xsl:attribute> <!-- 'och', so it gets filtered out from the html(help) docs. -->
|
---|
259 | <xsl:attribute name="rev">pdf space hack</xsl:attribute>
|
---|
260 | <xsl:text> </xsl:text>
|
---|
261 | </xsl:element>
|
---|
262 | </xsl:if>
|
---|
263 | </xsl:template>
|
---|
264 |
|
---|
265 | <xsl:template match="cmdsynopsis[sbr]">
|
---|
266 | <xsl:element name="syntaxdiagram">
|
---|
267 | <xsl:attribute name="rev">cmdsynopsis</xsl:attribute>
|
---|
268 | <xsl:if test="@id">
|
---|
269 | <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
|
---|
270 | </xsl:if>
|
---|
271 | <xsl:for-each select="sbr">
|
---|
272 | <xsl:variable name="idxSbr" select="position()"/>
|
---|
273 | <!-- TODO: sbr cannot be translated, it seems. Whether we wrap things in
|
---|
274 | synblk, groupcomp or groupseq elements, the result is always the same:
|
---|
275 | - HTML: ignored.
|
---|
276 | - PDF: condensed arguments w/o spaces between. 4.0.2 doesn't seem
|
---|
277 | to condense stuff any more inside synblk elements, but then the
|
---|
278 | rending isn't much changed for PDFs anyway since its one element
|
---|
279 | per line.
|
---|
280 | Update: Turns out the condensing was because we stripped element
|
---|
281 | whitespace instead of preserving it. svn copy. sigh. -->
|
---|
282 | <!-- <xsl:element name="synblk">
|
---|
283 | <xsl:attribute name="rev">sbr/<xsl:value-of select="position()"/></xsl:attribute> -->
|
---|
284 |
|
---|
285 | <xsl:if test="$idxSbr = 1">
|
---|
286 | <xsl:apply-templates select="preceding-sibling::node()"/>
|
---|
287 | </xsl:if>
|
---|
288 | <xsl:if test="$idxSbr != 1">
|
---|
289 | <xsl:apply-templates select="preceding-sibling::node()[ count(. | ../sbr[$idxSbr - 1]/following-sibling::node())
|
---|
290 | = count(../sbr[$idxSbr - 1]/following-sibling::node())]"/>
|
---|
291 | </xsl:if>
|
---|
292 | <!-- </xsl:element> -->
|
---|
293 | <!-- Ensure some space between these.-->
|
---|
294 | <xsl:text>
|
---|
295 | </xsl:text>
|
---|
296 | <xsl:if test="$idxSbr = last()">
|
---|
297 | <!-- <xsl:element name="synblk">
|
---|
298 | <xsl:attribute name="rev">sbr/<xsl:value-of select="position()"/></xsl:attribute> -->
|
---|
299 | <xsl:apply-templates select="following-sibling::node()"/>
|
---|
300 | <!-- </xsl:element> -->
|
---|
301 | </xsl:if>
|
---|
302 | </xsl:for-each>
|
---|
303 | </xsl:element>
|
---|
304 |
|
---|
305 | <!-- HACK ALERT! Add an empty paragraph to keep syntax diagrams apart in the
|
---|
306 | PDF output, otherwise the commands becomes hard to tell apart. -->
|
---|
307 | <xsl:if test="position() < last()">
|
---|
308 | <xsl:element name="p">
|
---|
309 | <xsl:attribute name="platform">ohc</xsl:attribute> <!-- 'och', so it gets filtered out from the html(help) docs. -->
|
---|
310 | <xsl:attribute name="rev">pdf space hack</xsl:attribute>
|
---|
311 | <xsl:text> </xsl:text>
|
---|
312 | </xsl:element>
|
---|
313 | </xsl:if>
|
---|
314 | </xsl:template>
|
---|
315 |
|
---|
316 | <!-- command with text and/or replaceable in cmdsynopsis -> groupseq + kwd -->
|
---|
317 | <xsl:template match="cmdsynopsis/command | cmdsynopsis/*/command" >
|
---|
318 | <xsl:element name="groupseq">
|
---|
319 | <xsl:attribute name="rev">command</xsl:attribute>
|
---|
320 | <xsl:apply-templates />
|
---|
321 | </xsl:element>
|
---|
322 | </xsl:template>
|
---|
323 |
|
---|
324 | <xsl:template match="cmdsynopsis/command/text() | cmdsynopsis/*/command/text()" >
|
---|
325 | <xsl:element name="kwd">
|
---|
326 | <xsl:attribute name="rev">command/text</xsl:attribute>
|
---|
327 | <xsl:value-of select="."/>
|
---|
328 | </xsl:element>
|
---|
329 | </xsl:template>
|
---|
330 |
|
---|
331 | <xsl:template match="cmdsynopsis/command/replaceable | cmdsynopsis/*/command/replaceable" >
|
---|
332 | <xsl:call-template name="check-children"/>
|
---|
333 | <xsl:element name="var">
|
---|
334 | <xsl:attribute name="rev">command/replaceable</xsl:attribute>
|
---|
335 | <xsl:apply-templates />
|
---|
336 | </xsl:element>
|
---|
337 | </xsl:template>
|
---|
338 |
|
---|
339 | <!-- command with text and/or replaceable in not cmdsynopsis -> userinput + cmdname -->
|
---|
340 | <xsl:template match="command[not(ancestor::cmdsynopsis)]">
|
---|
341 | <xsl:element name="userinput">
|
---|
342 | <xsl:attribute name="rev">command</xsl:attribute>
|
---|
343 | <xsl:apply-templates />
|
---|
344 | </xsl:element>
|
---|
345 | </xsl:template>
|
---|
346 |
|
---|
347 | <xsl:template match="command[not(ancestor::cmdsynopsis)]/text()">
|
---|
348 | <xsl:element name="cmdname">
|
---|
349 | <xsl:attribute name="rev">command/text</xsl:attribute>
|
---|
350 | <xsl:value-of select="."/>
|
---|
351 | </xsl:element>
|
---|
352 | </xsl:template>
|
---|
353 |
|
---|
354 | <xsl:template match="command[not(ancestor::cmdsynopsis)]/replaceable">
|
---|
355 | <xsl:call-template name="check-children"/>
|
---|
356 | <xsl:element name="varname">
|
---|
357 | <xsl:attribute name="rev">command/replaceable</xsl:attribute>
|
---|
358 | <xsl:value-of select="."/>
|
---|
359 | </xsl:element>
|
---|
360 | </xsl:template>
|
---|
361 |
|
---|
362 | <!--
|
---|
363 | arg -> groupseq; A bit complicated though, because text needs to be wrapping
|
---|
364 | in 'kwd' and any nested arguments needs explicit 'sep' elements containing a
|
---|
365 | space or the nested arguments gets bunched up tight.
|
---|
366 | Examples:
|
---|
367 | {arg}-output={replaceable}file{/replaceable}{/arg}
|
---|
368 | = {groupcomp importance="optional"}{kwd}-output{/kwd}{sep}={/sep}{var}file{/var}{/groupcomp}
|
---|
369 |
|
---|
370 | {arg}-output {replaceable}file{/replaceable}{/arg}
|
---|
371 | = {groupcomp importance="optional"}{kwd}-output{/kwd}{sep} {/sep}{var}file{/var}{/groupcomp}
|
---|
372 |
|
---|
373 | {arg}-R {arg}-L{/arg}{/arg}
|
---|
374 | = {groupseq importance="optional"}{groupcomp}{kwd}-R{/groupcomp}{sep} {/sep}
|
---|
375 | or {groupseq importance="optional"}{kwd}-R{sep} {/sep}{groupcomp}{kwd}-L{/groupcomp}{/groupseq}
|
---|
376 | note: Important to specify {sep} here as whitespace might otherwise be squashed.
|
---|
377 | -->
|
---|
378 |
|
---|
379 | <!-- Plaintext within arg is generally translated to kwd, but value separators
|
---|
380 | like '=' and ',' should be wrapped in a delim element. -->
|
---|
381 | <xsl:template match="arg/text()">
|
---|
382 | <xsl:choose>
|
---|
383 | <!-- put trailing '=' inside <sep> -->
|
---|
384 | <xsl:when test="substring(., string-length(.)) = '='">
|
---|
385 | <xsl:element name="kwd">
|
---|
386 | <xsl:attribute name="rev">arg=</xsl:attribute>
|
---|
387 | <xsl:value-of select="substring(., 1, string-length(.) - 1)"/>
|
---|
388 | </xsl:element>
|
---|
389 | <xsl:element name="delim">
|
---|
390 | <xsl:attribute name="rev">arg=</xsl:attribute>
|
---|
391 | <xsl:text>=</xsl:text>
|
---|
392 | </xsl:element>
|
---|
393 | </xsl:when>
|
---|
394 |
|
---|
395 | <!-- Special case, single space, assuming it's deliberate so put in inside a sep element. -->
|
---|
396 | <xsl:when test=". = ' '">
|
---|
397 | <xsl:element name="sep">
|
---|
398 | <xsl:attribute name="rev">arg-space</xsl:attribute>
|
---|
399 | <xsl:value-of select="."/>
|
---|
400 | </xsl:element>
|
---|
401 | </xsl:when>
|
---|
402 |
|
---|
403 | <!-- Don't wrap other pure whitespace kwd sequences, but emit single space 'sep'
|
---|
404 | element if a arg or groups follows. If the whitespace includes a newline
|
---|
405 | we'll emit it, but otherways we'll generally suppress it to avoid
|
---|
406 | accidentally padding spaces between arguments. -->
|
---|
407 | <xsl:when test="normalize-space(.) = ''">
|
---|
408 | <xsl:if test="following::*[position() = 1 and (self::arg or self::group)] and not(ancestor-or-self::*[@role='compact'])">
|
---|
409 | <xsl:element name="sep">
|
---|
410 | <xsl:attribute name="rev">arg-whitespace</xsl:attribute>
|
---|
411 | <xsl:text> </xsl:text>
|
---|
412 | </xsl:element>
|
---|
413 | </xsl:if>
|
---|
414 | <xsl:if test="contains(., ' ')">
|
---|
415 | <xsl:value-of select="."/>
|
---|
416 | </xsl:if>
|
---|
417 | </xsl:when>
|
---|
418 |
|
---|
419 | <!-- Remainder is all wrapped in kwd, after space normalization. -->
|
---|
420 | <xsl:otherwise>
|
---|
421 | <xsl:element name="kwd">
|
---|
422 | <xsl:attribute name="rev">arg</xsl:attribute>
|
---|
423 | <xsl:value-of select="normalize-space(.)"/>
|
---|
424 | </xsl:element>
|
---|
425 | <xsl:if test="normalize-space(substring(., string-length(.), 1)) = ''
|
---|
426 | and following::*[position() = 1 and (self::arg or self::group)]
|
---|
427 | and not(ancestor-or-self::*[@role='compact'])">
|
---|
428 | <xsl:element name="sep">
|
---|
429 | <xsl:attribute name="rev">arg-trailing</xsl:attribute>
|
---|
430 | <xsl:text> </xsl:text>
|
---|
431 | </xsl:element>
|
---|
432 | </xsl:if>
|
---|
433 | </xsl:otherwise>
|
---|
434 | </xsl:choose>
|
---|
435 | </xsl:template>
|
---|
436 |
|
---|
437 | <!-- arg -> groupseq or groupcomp and optionally a repsep element if repeatable. -->
|
---|
438 | <xsl:template match="arg" >
|
---|
439 | <!-- If it's a tighly packed arg, we use groupcomp instead of groupseq to try
|
---|
440 | avoid it being split in the middle. -->
|
---|
441 | <xsl:variable name="sGroupType">
|
---|
442 | <xsl:call-template name="determine_arg_wrapper_element"/>
|
---|
443 | </xsl:variable>
|
---|
444 | <xsl:element name="{$sGroupType}">
|
---|
445 | <xsl:attribute name="rev">arg[<xsl:value-of select="concat(@choice,',',@rep)"/>]</xsl:attribute>
|
---|
446 | <xsl:choose>
|
---|
447 | <xsl:when test="not(@choice) or @choice = 'opt'">
|
---|
448 | <xsl:attribute name="importance">optional</xsl:attribute>
|
---|
449 | </xsl:when>
|
---|
450 | <xsl:when test="@choice = 'req'">
|
---|
451 | <xsl:attribute name="importance">required</xsl:attribute>
|
---|
452 | </xsl:when>
|
---|
453 | <xsl:when test="@choice = 'plain'"/>
|
---|
454 | <xsl:otherwise>
|
---|
455 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Unexpected @choice value: <xsl:value-of select="@choice"/></xsl:message>
|
---|
456 | </xsl:otherwise>
|
---|
457 | </xsl:choose>
|
---|
458 |
|
---|
459 | <xsl:apply-templates />
|
---|
460 |
|
---|
461 | <xsl:if test="@rep = 'repeat'">
|
---|
462 | <!-- repsep can only be placed at the start of a groupseq/whatever and
|
---|
463 | the documenation and examples of the element is very sparse. The
|
---|
464 | PDF output plugin will place the '...' where it finds it and do
|
---|
465 | nothing if it's empty. The XHTML output plugin ignores it, it seems. -->
|
---|
466 | <xsl:element name="sep">
|
---|
467 | <xsl:attribute name="rev">arg[<xsl:value-of select="@choice"/>,repeat]</xsl:attribute>
|
---|
468 | <xsl:text> </xsl:text>
|
---|
469 | </xsl:element>
|
---|
470 | <xsl:element name="groupcomp">
|
---|
471 | <xsl:attribute name="importance">optional</xsl:attribute>
|
---|
472 | <xsl:attribute name="rev">arg[<xsl:value-of select="@choice"/>,repeat]</xsl:attribute>
|
---|
473 | <xsl:attribute name="outputclass">repeatarg</xsl:attribute> <!-- how to make xhtml pass these thru... -->
|
---|
474 | <xsl:element name="repsep">
|
---|
475 | <xsl:attribute name="rev">arg[<xsl:value-of select="@choice"/>,repeat]</xsl:attribute>
|
---|
476 | <xsl:text>...</xsl:text>
|
---|
477 | </xsl:element>
|
---|
478 | </xsl:element>
|
---|
479 | </xsl:if>
|
---|
480 |
|
---|
481 | </xsl:element>
|
---|
482 |
|
---|
483 | <xsl:if test="parent::group and @choice != 'plain'">
|
---|
484 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Expected arg in group to be plain, not optional.</xsl:message>
|
---|
485 | </xsl:if>
|
---|
486 | </xsl:template>
|
---|
487 |
|
---|
488 | <xsl:template name="determine_arg_wrapper_element">
|
---|
489 | <xsl:choose>
|
---|
490 | <xsl:when test="not(descendant::group) and not(descendant::text()[contains(.,' ') or normalize-space(.) != .])">
|
---|
491 | <xsl:text>groupcomp</xsl:text>
|
---|
492 | </xsl:when>
|
---|
493 | <xsl:otherwise>
|
---|
494 | <xsl:text>groupseq</xsl:text>
|
---|
495 | </xsl:otherwise>
|
---|
496 | </xsl:choose>
|
---|
497 | </xsl:template>
|
---|
498 |
|
---|
499 | <!-- Plain (required) argument in group with only text() content -> kwd; -->
|
---|
500 | <!--
|
---|
501 | <xsl:template match="group/arg[@choice='plain' and (not(@rep) or @rep='norepeat') and not(replaceable) and not(arg) and not(group)]" >
|
---|
502 | <xsl:call-template name="check-children" />
|
---|
503 | <xsl:element name="kwd">
|
---|
504 | <xsl:attribute name="rev">arg[plain#3]</xsl:attribute>
|
---|
505 | <xsl:value-of select="."/>
|
---|
506 | </xsl:element>
|
---|
507 | </xsl:template> -->
|
---|
508 |
|
---|
509 | <!-- replaceable under arg -> var -->
|
---|
510 | <xsl:template match="arg/replaceable" >
|
---|
511 | <xsl:element name="var">
|
---|
512 | <xsl:attribute name="rev">replaceable</xsl:attribute>
|
---|
513 | <xsl:apply-templates />
|
---|
514 | </xsl:element>
|
---|
515 | </xsl:template>
|
---|
516 |
|
---|
517 | <!-- replaceable in para or term -> synph+var -->
|
---|
518 | <xsl:template match="para/replaceable | term/replaceable | screen/replaceable" >
|
---|
519 | <xsl:element name="synph">
|
---|
520 | <xsl:attribute name="rev">replaceable</xsl:attribute>
|
---|
521 | <xsl:element name="var">
|
---|
522 | <xsl:attribute name="rev">replaceable</xsl:attribute>
|
---|
523 | <xsl:apply-templates />
|
---|
524 | </xsl:element>
|
---|
525 | </xsl:element>
|
---|
526 | </xsl:template>
|
---|
527 |
|
---|
528 | <!-- replaceable in option -> var -->
|
---|
529 | <xsl:template match="option/replaceable" >
|
---|
530 | <xsl:element name="var">
|
---|
531 | <xsl:attribute name="rev">option/replaceable</xsl:attribute>
|
---|
532 | <xsl:apply-templates />
|
---|
533 | </xsl:element>
|
---|
534 | </xsl:template>
|
---|
535 |
|
---|
536 | <!-- replaceable in computeroutput or filename -> varname -->
|
---|
537 | <xsl:template match="computeroutput/replaceable | filename/replaceable" >
|
---|
538 | <xsl:element name="varname">
|
---|
539 | <xsl:attribute name="rev">computeroutput/replaceable</xsl:attribute>
|
---|
540 | <xsl:apply-templates />
|
---|
541 | </xsl:element>
|
---|
542 | </xsl:template>
|
---|
543 |
|
---|
544 | <!--
|
---|
545 | DocBook 'group' elements are only ever used for multiple choice options
|
---|
546 | in our refentry XML, it is never used for argument groupings. For
|
---|
547 | grouping arguments we use nested 'arg' elements.
|
---|
548 |
|
---|
549 | This is because 'group' with 'group' parent is poorly defned/handled.
|
---|
550 | Whether the DocBook HTML formatters uses ' | ' separators depends on what
|
---|
551 | other elements are in the group and their order. arg1+group2+group3 won't
|
---|
552 | get any, but group1+arg2+group3 will get one between the first two.
|
---|
553 | -->
|
---|
554 |
|
---|
555 | <xsl:template match="group[group]" priority="3.0">
|
---|
556 | <xsl:message terminate="yes">
|
---|
557 | <xsl:call-template name="error-prefix"/>Immediate group nesting is not allowed! Put nested group inside arg element.
|
---|
558 | </xsl:message>
|
---|
559 | </xsl:template>
|
---|
560 |
|
---|
561 | <xsl:template match="group[count(arg) < 2]" priority="3.0">
|
---|
562 | <xsl:message terminate="yes">
|
---|
563 | <xsl:call-template name="error-prefix"/>Group with fewer than two 'arg' elements is not allowed!
|
---|
564 | </xsl:message>
|
---|
565 | </xsl:template>
|
---|
566 |
|
---|
567 | <!-- Required group under arg or cmdsynopsis -> groupchoice w/attrib -->
|
---|
568 | <xsl:template match="arg/group | cmdsynopsis/group">
|
---|
569 | <xsl:element name="groupchoice">
|
---|
570 | <xsl:choose>
|
---|
571 | <xsl:when test="@choice = 'req'">
|
---|
572 | <xsl:attribute name="rev">group[req]</xsl:attribute>
|
---|
573 | <xsl:attribute name="importance">required</xsl:attribute>
|
---|
574 | </xsl:when>
|
---|
575 | <xsl:when test="@choice = 'plain'">
|
---|
576 | <xsl:attribute name="rev">group[plain]</xsl:attribute>
|
---|
577 | <!-- We don't set the importance here. @todo Check what it does to the output formatting -->
|
---|
578 | </xsl:when>
|
---|
579 | <xsl:otherwise>
|
---|
580 | <xsl:attribute name="rev">group[opt]</xsl:attribute>
|
---|
581 | <xsl:attribute name="importance">optional</xsl:attribute>
|
---|
582 | </xsl:otherwise>
|
---|
583 | </xsl:choose>
|
---|
584 |
|
---|
585 | <xsl:apply-templates />
|
---|
586 |
|
---|
587 | <xsl:if test="@rep = 'repeat'">
|
---|
588 | <!-- repsep can only be placed at the start of a groupseq/whatever and
|
---|
589 | the documenation and examples of the element is very sparse. The
|
---|
590 | PDF output plugin will place the '...' where it finds it and do
|
---|
591 | nothing if it's empty. The XHTML output plugin ignores it, it seems. -->
|
---|
592 | <xsl:message terminate="no"><xsl:call-template name="error-prefix"/>Repeating group is not a good idea...</xsl:message>
|
---|
593 | <xsl:element name="sep">
|
---|
594 | <xsl:attribute name="rev">arg[<xsl:value-of select="@choice"/>,repeat]</xsl:attribute>
|
---|
595 | <xsl:text> </xsl:text>
|
---|
596 | </xsl:element>
|
---|
597 | <xsl:element name="groupcomp">
|
---|
598 | <xsl:attribute name="importance">optional</xsl:attribute>
|
---|
599 | <xsl:attribute name="rev">arg[<xsl:value-of select="@choice"/>,repeat]</xsl:attribute>
|
---|
600 | <xsl:attribute name="outputclass">repeatarg</xsl:attribute> <!-- how to make xhtml pass these thru... -->
|
---|
601 | <xsl:element name="repsep">
|
---|
602 | <xsl:attribute name="rev">arg[<xsl:value-of select="@choice"/>,repeat]</xsl:attribute>
|
---|
603 | <xsl:text>...</xsl:text>
|
---|
604 | </xsl:element>
|
---|
605 | </xsl:element>
|
---|
606 | </xsl:if>
|
---|
607 | </xsl:element>
|
---|
608 | </xsl:template>
|
---|
609 |
|
---|
610 | <!-- option -->
|
---|
611 | <xsl:template match="option/text()" >
|
---|
612 | <xsl:element name="kwd">
|
---|
613 | <xsl:attribute name="rev">option</xsl:attribute>
|
---|
614 | <xsl:value-of select="."/>
|
---|
615 | </xsl:element>
|
---|
616 | </xsl:template>
|
---|
617 |
|
---|
618 | <xsl:template match="option" >
|
---|
619 | <xsl:element name="synph">
|
---|
620 | <xsl:attribute name="rev">option</xsl:attribute>
|
---|
621 | <xsl:apply-templates />
|
---|
622 | </xsl:element>
|
---|
623 | </xsl:template>
|
---|
624 |
|
---|
625 | <!-- literal w/o sub-elements -> codeph -->
|
---|
626 | <xsl:template match="literal[not(*)]" >
|
---|
627 | <xsl:element name="codeph">
|
---|
628 | <xsl:attribute name="rev">literal</xsl:attribute>
|
---|
629 | <xsl:apply-templates />
|
---|
630 | </xsl:element>
|
---|
631 | </xsl:template>
|
---|
632 |
|
---|
633 | <!-- literal with replaceable sub-elements -> synph -->
|
---|
634 | <xsl:template match="literal[replaceable]" >
|
---|
635 | <xsl:element name="synph">
|
---|
636 | <xsl:attribute name="rev">literal/replaceable</xsl:attribute>
|
---|
637 | <xsl:for-each select="node()">
|
---|
638 | <xsl:choose>
|
---|
639 | <xsl:when test="self::text()">
|
---|
640 | <xsl:element name="kwd">
|
---|
641 | <xsl:value-of select="."/>
|
---|
642 | </xsl:element>
|
---|
643 | </xsl:when>
|
---|
644 | <xsl:when test="self::replaceable">
|
---|
645 | <xsl:if test="./*">
|
---|
646 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Unexpected literal/replaceable child</xsl:message>
|
---|
647 | </xsl:if>
|
---|
648 | <xsl:element name="var">
|
---|
649 | <xsl:value-of select="."/>
|
---|
650 | </xsl:element>
|
---|
651 | </xsl:when>
|
---|
652 | <xsl:otherwise>
|
---|
653 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Unexpected literal child:
|
---|
654 | <xsl:value-of select="name(.)" />
|
---|
655 | </xsl:message>
|
---|
656 | </xsl:otherwise>
|
---|
657 | </xsl:choose>
|
---|
658 | </xsl:for-each>
|
---|
659 | </xsl:element>
|
---|
660 | </xsl:template>
|
---|
661 |
|
---|
662 | <!-- filename -> filepath -->
|
---|
663 | <xsl:template match="filename" >
|
---|
664 | <xsl:element name="filepath">
|
---|
665 | <xsl:attribute name="rev">filename</xsl:attribute>
|
---|
666 | <xsl:apply-templates />
|
---|
667 | </xsl:element>
|
---|
668 | </xsl:template>
|
---|
669 |
|
---|
670 | <!-- screen - pass thru -->
|
---|
671 | <xsl:template match="screen" >
|
---|
672 | <xsl:copy>
|
---|
673 | <xsl:apply-templates />
|
---|
674 | </xsl:copy>
|
---|
675 | </xsl:template>
|
---|
676 |
|
---|
677 | <!-- computeroutput -> systemoutput-->
|
---|
678 | <xsl:template match="computeroutput">
|
---|
679 | <xsl:element name="systemoutput">
|
---|
680 | <xsl:attribute name="rev">computeroutput</xsl:attribute>
|
---|
681 | <xsl:apply-templates />
|
---|
682 | </xsl:element>
|
---|
683 | </xsl:template>
|
---|
684 |
|
---|
685 | <!-- xref -> xref, but attributes differ. -->
|
---|
686 | <xsl:template match="xref">
|
---|
687 | <xsl:element name="xref">
|
---|
688 | <xsl:attribute name="href"><xsl:value-of select="@linkend"/></xsl:attribute>
|
---|
689 | <xsl:if test="contains(@linkend, 'http')"><xsl:message terminate="yes">xref/linkend with http</xsl:message></xsl:if>
|
---|
690 | </xsl:element>
|
---|
691 | </xsl:template>
|
---|
692 |
|
---|
693 | <!-- ulink -> xref -->
|
---|
694 | <xsl:template match="ulink">
|
---|
695 | <xsl:element name="xref">
|
---|
696 | <xsl:attribute name="rev">ulink</xsl:attribute>
|
---|
697 | <xsl:attribute name="scope">external</xsl:attribute> <!-- Just assumes this is external. -->
|
---|
698 | <xsl:attribute name="href"><xsl:value-of select="@url"/></xsl:attribute>
|
---|
699 | <xsl:attribute name="format">html</xsl:attribute>
|
---|
700 | <xsl:if test="not(starts-with(@url, 'http'))"><xsl:message terminate="yes">ulink url is not http: <xsl:value-of select="@url"/></xsl:message></xsl:if>
|
---|
701 | </xsl:element>
|
---|
702 | </xsl:template>
|
---|
703 |
|
---|
704 | <!-- emphasis -> i -->
|
---|
705 | <xsl:template match="emphasis">
|
---|
706 | <xsl:if test="*">
|
---|
707 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Did not expect emphasis to have children!</xsl:message>
|
---|
708 | </xsl:if>
|
---|
709 | <xsl:element name="i">
|
---|
710 | <xsl:attribute name="rev">emphasis</xsl:attribute>
|
---|
711 | <xsl:apply-templates />
|
---|
712 | </xsl:element>
|
---|
713 | </xsl:template>
|
---|
714 |
|
---|
715 | <!-- note -> note -->
|
---|
716 | <xsl:template match="note">
|
---|
717 | <xsl:copy>
|
---|
718 | <xsl:apply-templates />
|
---|
719 | </xsl:copy>
|
---|
720 | </xsl:template>
|
---|
721 |
|
---|
722 | <!-- citetitle -> cite -->
|
---|
723 | <xsl:template match="citetitle">
|
---|
724 | <xsl:element name="cite">
|
---|
725 | <xsl:attribute name="rev">citetitle</xsl:attribute>
|
---|
726 | <xsl:apply-templates />
|
---|
727 | </xsl:element>
|
---|
728 | </xsl:template>
|
---|
729 |
|
---|
730 | <!--
|
---|
731 | remark extensions:
|
---|
732 | -->
|
---|
733 | <!-- Default: remove all remarks. -->
|
---|
734 | <xsl:template match="remark"/>
|
---|
735 |
|
---|
736 |
|
---|
737 | <!--
|
---|
738 | Captializes the given text.
|
---|
739 | -->
|
---|
740 | <xsl:template name="capitalize">
|
---|
741 | <xsl:param name="text"/>
|
---|
742 | <xsl:call-template name="str:to-upper">
|
---|
743 | <xsl:with-param name="text" select="substring($text,1,1)"/>
|
---|
744 | </xsl:call-template>
|
---|
745 | <xsl:value-of select="substring($text,2)"/>
|
---|
746 | </xsl:template>
|
---|
747 |
|
---|
748 | <!--
|
---|
749 | Debug/Diagnostics: Return the path to the specified node (by default the current).
|
---|
750 | -->
|
---|
751 | <xsl:template name="get-node-path">
|
---|
752 | <xsl:param name="Node" select="."/>
|
---|
753 | <xsl:for-each select="$Node">
|
---|
754 | <xsl:for-each select="ancestor-or-self::node()">
|
---|
755 | <xsl:choose>
|
---|
756 | <xsl:when test="name(.) = ''">
|
---|
757 | <xsl:value-of select="concat('/text(',')')"/>
|
---|
758 | </xsl:when>
|
---|
759 | <xsl:otherwise>
|
---|
760 | <xsl:value-of select="concat('/', name(.))"/>
|
---|
761 | <xsl:choose>
|
---|
762 | <xsl:when test="@id">
|
---|
763 | <xsl:text>[@id=</xsl:text>
|
---|
764 | <xsl:value-of select="@id"/>
|
---|
765 | <xsl:text>]</xsl:text>
|
---|
766 | </xsl:when>
|
---|
767 | <xsl:otherwise>
|
---|
768 | <!-- Use generate-id() to find the current node position among its siblings. -->
|
---|
769 | <xsl:variable name="id" select="generate-id(.)"/>
|
---|
770 | <xsl:for-each select="../node()">
|
---|
771 | <xsl:if test="generate-id(.) = $id">
|
---|
772 | <xsl:text>[</xsl:text><xsl:value-of select="position()"/><xsl:text>]</xsl:text>
|
---|
773 | </xsl:if>
|
---|
774 | </xsl:for-each>
|
---|
775 | </xsl:otherwise>
|
---|
776 | </xsl:choose>
|
---|
777 | </xsl:otherwise>
|
---|
778 | </xsl:choose>
|
---|
779 | </xsl:for-each>
|
---|
780 | </xsl:for-each>
|
---|
781 | </xsl:template>
|
---|
782 |
|
---|
783 | <!--
|
---|
784 | Debug/Diagnostics: Return error message prefix.
|
---|
785 | -->
|
---|
786 | <xsl:template name="error-prefix">
|
---|
787 | <xsl:param name="Node" select="."/>
|
---|
788 | <xsl:text>error: </xsl:text>
|
---|
789 | <xsl:call-template name="get-node-path">
|
---|
790 | <xsl:with-param name="Node" select="$Node"/>
|
---|
791 | </xsl:call-template>
|
---|
792 | <xsl:text>: </xsl:text>
|
---|
793 | </xsl:template>
|
---|
794 |
|
---|
795 | <!--
|
---|
796 | Debug/Diagnostics: Print list of nodes (by default all children of current node).
|
---|
797 | -->
|
---|
798 | <xsl:template name="list-nodes">
|
---|
799 | <xsl:param name="Nodes" select="node()"/>
|
---|
800 | <xsl:for-each select="$Nodes">
|
---|
801 | <xsl:if test="position() != 1">
|
---|
802 | <xsl:text>, </xsl:text>
|
---|
803 | </xsl:if>
|
---|
804 | <xsl:choose>
|
---|
805 | <xsl:when test="name(.) = ''">
|
---|
806 | <xsl:text>text:text()</xsl:text>
|
---|
807 | </xsl:when>
|
---|
808 | <xsl:otherwise>
|
---|
809 | <xsl:value-of select="name(.)"/>
|
---|
810 | <xsl:if test="@id">
|
---|
811 | <xsl:text>[@id=</xsl:text>
|
---|
812 | <xsl:value-of select="@id"/>
|
---|
813 | <xsl:text>]</xsl:text>
|
---|
814 | </xsl:if>
|
---|
815 | </xsl:otherwise>
|
---|
816 | </xsl:choose>
|
---|
817 | </xsl:for-each>
|
---|
818 | </xsl:template>
|
---|
819 |
|
---|
820 | <xsl:template name="check-children">
|
---|
821 | <xsl:param name="Node" select="."/>
|
---|
822 | <xsl:param name="UnsupportedNodes" select="*"/>
|
---|
823 | <xsl:param name="SupportedNames" select="'none'"/>
|
---|
824 | <xsl:if test="count($UnsupportedNodes) != 0">
|
---|
825 | <xsl:message terminate="yes">
|
---|
826 | <xsl:call-template name="get-node-path">
|
---|
827 | <xsl:with-param name="Node" select="$Node"/>
|
---|
828 | </xsl:call-template>
|
---|
829 | <!-- -->: error: Only <xsl:value-of select="$SupportedNames"/> are supported as children to <!-- -->
|
---|
830 | <xsl:value-of select="name($Node)"/>
|
---|
831 | <!-- -->
|
---|
832 | Unsupported children: <!-- -->
|
---|
833 | <xsl:call-template name="list-nodes">
|
---|
834 | <xsl:with-param name="Nodes" select="$UnsupportedNodes"/>
|
---|
835 | </xsl:call-template>
|
---|
836 | </xsl:message>
|
---|
837 | </xsl:if>
|
---|
838 | </xsl:template>
|
---|
839 |
|
---|
840 | </xsl:stylesheet>
|
---|
841 |
|
---|