VirtualBox

source: vbox/trunk/doc/manual/docbook-refentry-to-manual-dita.xsl@ 99198

Last change on this file since 99198 was 99198, checked in by vboxsync, 20 months ago

manual: More work on the refentry to dita converter - attempt at using non-breaking hyphens (dashes), but doesn't work for the currently PDF monospace font selection (win). bugref:10302

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette