VirtualBox

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

Last change on this file since 99099 was 99099, checked in by vboxsync, 2 years ago

manual: Start of a refentry to dita converter. bugref:10302

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.6 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="yes"/>
38 <xsl:strip-space elements="*"/>
39
40
41<!-- - - - - - - - - - - - - - - - - - - - - - -
42 global XSLT variables
43 - - - - - - - - - - - - - - - - - - - - - - -->
44
45
46
47<!-- - - - - - - - - - - - - - - - - - - - - - -
48 base operation is to fail on nodes w/o explicit matching.
49 - - - - - - - - - - - - - - - - - - - - - - -->
50
51<xsl:template match="*">
52 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>unhandled element</xsl:message>
53</xsl:template>
54
55
56<!-- - - - - - - - - - - - - - - - - - - - - - -
57 transformations starting with root and going deeper.
58 - - - - - - - - - - - - - - - - - - - - - - -->
59
60<!-- Rename refentry to reference.
61 Also we need to wrap the refsync and refsect1 elements in a refbody. -->
62<xsl:template match="refentry">
63 <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd"&gt;</xsl:text>
64
65 <xsl:element name="reference">
66 <xsl:if test="not(@id)">
67 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have an id attribute!</xsl:message>
68 </xsl:if>
69 <xsl:attribute name="rev">refentry</xsl:attribute>
70 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
71
72 <!-- Copy title element from refentryinfo -->
73 <xsl:if test="./refentryinfo/title">
74 <xsl:copy-of select="./refentryinfo/title"/>
75 </xsl:if>
76
77 <!-- Create a shortdesc element from the text in refnamediv/refpurpose -->
78 <xsl:if test="./refnamediv/refpurpose">
79 <xsl:element name="shortdesc">
80 <xsl:attribute name="rev">refnamediv/refpurpose</xsl:attribute>
81 <xsl:call-template name="capitalize">
82 <xsl:with-param name="text" select="normalize-space(./refnamediv/refpurpose)"/>
83 </xsl:call-template>
84 </xsl:element>
85 </xsl:if>
86
87 <!-- Put everything else side a refbody element -->
88 <xsl:element name="refbody">
89 <xsl:apply-templates />
90 </xsl:element>
91
92 </xsl:element>
93</xsl:template>
94
95<!-- Remove refentryinfo (we extracted the title element already). -->
96<xsl:template match="refentryinfo" />
97
98<!-- Remove refmeta (manpage info). -->
99<xsl:template match="refmeta"/>
100
101<!-- Remove the refnamediv (we extracted a shortdesc from it already). -->
102<xsl:template match="refnamediv"/>
103
104<!-- Morph the refsynopsisdiv part into a refsyn section. -->
105<xsl:template match="refsynopsisdiv">
106 <xsl:if test="name(*[1]) != 'cmdsynopsis'"><xsl:message terminate="yes">Expected refsynopsisdiv to start with cmdsynopsis</xsl:message></xsl:if>
107 <xsl:if test="title"><xsl:message terminate="yes">No title element supported in refsynopsisdiv</xsl:message></xsl:if>
108
109 <xsl:element name="refsyn">
110 <xsl:attribute name="rev">refsynopsisdiv</xsl:attribute>
111 <xsl:element name="title">
112 <xsl:text>Synopsis</xsl:text>
113 </xsl:element>
114 <xsl:apply-templates />
115 </xsl:element>
116
117</xsl:template>
118
119<!-- refsect1 -> section -->
120<xsl:template match="refsect1">
121 <xsl:if test="not(title)"><xsl:message terminate="yes">refsect1 requires title</xsl:message></xsl:if>
122 <xsl:element name="section">
123 <xsl:attribute name="rev">refsect1</xsl:attribute>
124 <xsl:if test="@id">
125 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
126 </xsl:if>
127 <xsl:apply-templates />
128 </xsl:element>
129</xsl:template>
130
131<!-- refsect2 -> sectiondiv. -->
132<xsl:template match="refsect2">
133 <xsl:if test="not(title)"><xsl:message terminate="yes">refsect2 requires title</xsl:message></xsl:if>
134 <xsl:element name="sectiondiv">
135 <xsl:attribute name="rev">refsect2</xsl:attribute>
136 <xsl:if test="@id">
137 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
138 </xsl:if>
139
140 <xsl:apply-templates />
141
142 </xsl:element>
143</xsl:template>
144
145<!-- refsect2/title -> b -->
146<xsl:template match="refsect2/title">
147 <xsl:element name="b">
148 <xsl:attribute name="rev">refsect2/title</xsl:attribute>
149 <xsl:apply-templates />
150 </xsl:element>
151</xsl:template>
152
153<!-- refsect1/title -> title -->
154<xsl:template match="refsect1/title">
155 <xsl:copy>
156 <xsl:apply-templates />
157 </xsl:copy>
158</xsl:template>
159
160<!-- para -> p -->
161<xsl:template match="para">
162 <xsl:element name="p">
163 <xsl:attribute name="rev">para</xsl:attribute>
164 <xsl:apply-templates />
165 </xsl:element>
166</xsl:template>
167
168<!-- note in a section -> note (no change needed) -->
169<xsl:template match="refsect1/note | refsect2/note">
170 <xsl:copy>
171 <xsl:apply-templates />
172 </xsl:copy>
173</xsl:template>
174
175<!-- variablelist -> dl -->
176<xsl:template match="variablelist">
177 <xsl:element name="dl">
178 <xsl:attribute name="rev">variablelist</xsl:attribute>
179 <xsl:apply-templates />
180 </xsl:element>
181</xsl:template>
182
183<!-- varlistentry -> dlentry -->
184<xsl:template match="varlistentry">
185 <xsl:element name="dlentry">
186 <xsl:attribute name="rev">varlistentry</xsl:attribute>
187 <xsl:apply-templates />
188 </xsl:element>
189</xsl:template>
190
191<!-- term (in varlistentry) -> dt -->
192<xsl:template match="varlistentry/term">
193 <xsl:element name="dt">
194 <xsl:attribute name="rev">term</xsl:attribute>
195 <xsl:apply-templates />
196 </xsl:element>
197</xsl:template>
198
199<!-- listitem (in varlistentry) -> dd -->
200<xsl:template match="varlistentry/listitem">
201 <xsl:element name="dd">
202 <xsl:attribute name="rev">listitem</xsl:attribute>
203 <xsl:apply-templates />
204 </xsl:element>
205</xsl:template>
206
207<!-- itemizedlist -> ul -->
208<xsl:template match="itemizedlist">
209 <xsl:element name="ul">
210 <xsl:attribute name="rev">itemizedlist</xsl:attribute>
211 <xsl:apply-templates />
212 </xsl:element>
213</xsl:template>
214
215<!-- listitem in itemizedlist -> li -->
216<xsl:template match="itemizedlist/listitem">
217 <xsl:element name="li">
218 <xsl:attribute name="rev">listitem</xsl:attribute>
219 <xsl:apply-templates />
220 </xsl:element>
221</xsl:template>
222
223<!-- command in cmdsynopsis -> syntaxdiagram -->
224<xsl:template match="cmdsynopsis">
225 <xsl:element name="syntaxdiagram">
226 <xsl:attribute name="rev">cmdsynopsis</xsl:attribute>
227 <xsl:if test="@id">
228 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
229 </xsl:if>
230 <xsl:apply-templates />
231 </xsl:element>
232</xsl:template>
233
234<!-- command in cmdsynopsis -> groupseq + kwd -->
235<xsl:template match="cmdsynopsis/command | cmdsynopsis/*/command" >
236 <xsl:element name="groupseq">
237 <xsl:attribute name="rev">command</xsl:attribute>
238 <xsl:element name="kwd">
239 <xsl:attribute name="rev">command</xsl:attribute>
240 <xsl:apply-templates />
241 </xsl:element>
242 </xsl:element>
243</xsl:template>
244
245<!-- command in not cmdsynopsis -> userinput -->
246<xsl:template match="command">
247 <xsl:element name="userinput">
248 <xsl:attribute name="rev">command</xsl:attribute>
249 <xsl:apply-templates />
250 </xsl:element>
251</xsl:template>
252
253<!-- arg -->
254<xsl:template match="arg/text()">
255 <xsl:element name="kwd">
256 <xsl:attribute name="rev">arg</xsl:attribute>
257 <xsl:value-of select="."/>
258 </xsl:element>
259</xsl:template>
260
261<xsl:template match="arg[(not(@choice) or @choice='opt') and (not(@rep) or @rep='norepeat')]" >
262 <xsl:element name="groupseq">
263 <xsl:attribute name="rev">arg[opt,norepeat]</xsl:attribute>
264 <xsl:attribute name="importance">optional</xsl:attribute>
265 <xsl:apply-templates />
266 </xsl:element>
267</xsl:template>
268
269<xsl:template match="arg[@choice='req' and (not(@rep) or @rep='norepeat')]" >
270 <xsl:element name="groupseq">
271 <xsl:attribute name="rev">arg[req,norepeat]</xsl:attribute>
272 <xsl:attribute name="importance">required</xsl:attribute>
273 <xsl:apply-templates />
274 </xsl:element>
275</xsl:template>
276
277<xsl:template match="arg[@choice='plain' and (not(@rep) or @rep='norepeat')]" >
278 <xsl:if test="./*">
279 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Expected only text under arg[choice=plain]</xsl:message>
280 </xsl:if>
281 <xsl:element name="kwd">
282 <xsl:attribute name="rev">arg[plain]</xsl:attribute>
283 <xsl:value-of select="."/>
284 </xsl:element>
285</xsl:template>
286
287<!-- replaceable under arg -> var -->
288<xsl:template match="arg/replaceable" >
289 <xsl:element name="var">
290 <xsl:attribute name="rev">replaceable</xsl:attribute>
291 <xsl:apply-templates />
292 </xsl:element>
293</xsl:template>
294
295<!-- replaceable in para or term -> synph+var -->
296<xsl:template match="para/replaceable | term/replaceable" >
297 <xsl:element name="synph">
298 <xsl:attribute name="rev">replaceable</xsl:attribute>
299 <xsl:element name="var">
300 <xsl:attribute name="rev">replaceable</xsl:attribute>
301 <xsl:apply-templates />
302 </xsl:element>
303 </xsl:element>
304</xsl:template>
305
306<!-- replaceable in option -> var -->
307<xsl:template match="option/replaceable" >
308 <xsl:element name="var">
309 <xsl:attribute name="rev">option/replaceable</xsl:attribute>
310 <xsl:apply-templates />
311 </xsl:element>
312</xsl:template>
313
314<!-- group under cmdsynopsis -> groupchoice -->
315<xsl:template match="arg/group[@choice='plain'] | cmdsynopsis/group[@choice='plain']">
316 <xsl:element name="groupchoice">
317 <xsl:attribute name="rev">group</xsl:attribute>
318 <xsl:apply-templates />
319 </xsl:element>
320</xsl:template>
321
322
323<!-- option -->
324<xsl:template match="option/text()" >
325 <xsl:element name="kwd">
326 <xsl:attribute name="rev">option</xsl:attribute>
327 <xsl:value-of select="."/>
328 </xsl:element>
329</xsl:template>
330
331<xsl:template match="option" >
332 <xsl:element name="synph">
333 <xsl:attribute name="rev">option</xsl:attribute>
334 <xsl:apply-templates />
335 </xsl:element>
336</xsl:template>
337
338<!-- literal -> codeph -->
339<xsl:template match="literal" >
340 <xsl:element name="codeph">
341 <xsl:attribute name="rev">literal</xsl:attribute>
342 <xsl:apply-templates />
343 </xsl:element>
344</xsl:template>
345
346<!-- filename -> filepath -->
347<xsl:template match="filename" >
348 <xsl:element name="filepath">
349 <xsl:attribute name="rev">filename</xsl:attribute>
350 <xsl:apply-templates />
351 </xsl:element>
352</xsl:template>
353
354<!-- screen - pass thru -->
355<xsl:template match="screen" >
356 <xsl:copy>
357 <xsl:apply-templates />
358 </xsl:copy>
359</xsl:template>
360
361
362
363<!--
364 remark extensions:
365 -->
366<!-- Default: remove all remarks. -->
367<xsl:template match="remark"/>
368
369
370<!--
371 Captializes the given text.
372 -->
373<xsl:template name="capitalize">
374 <xsl:param name="text"/>
375 <xsl:call-template name="str:to-upper">
376 <xsl:with-param name="text" select="substring($text,1,1)"/>
377 </xsl:call-template>
378 <xsl:value-of select="substring($text,2)"/>
379</xsl:template>
380
381<!--
382 Debug/Diagnostics: Return the path to the specified node (by default the current).
383 -->
384<xsl:template name="get-node-path">
385 <xsl:param name="Node" select="."/>
386 <xsl:for-each select="$Node">
387 <xsl:for-each select="ancestor-or-self::node()">
388 <xsl:choose>
389 <xsl:when test="name(.) = ''">
390 <xsl:text>text()</xsl:text>
391 </xsl:when>
392 <xsl:otherwise>
393 <xsl:value-of select="concat('/', name(.))"/>
394 <xsl:choose>
395 <xsl:when test="@id">
396 <xsl:text>[@id=</xsl:text>
397 <xsl:value-of select="@id"/>
398 <xsl:text>]</xsl:text>
399 </xsl:when>
400 <xsl:when test="position() > 1">
401 <xsl:text>[</xsl:text><xsl:value-of select="position()"/><xsl:text>]</xsl:text>
402 </xsl:when>
403 </xsl:choose>
404 </xsl:otherwise>
405 </xsl:choose>
406 </xsl:for-each>
407 </xsl:for-each>
408</xsl:template>
409
410<!--
411 Debug/Diagnostics: Return error message prefix.
412 -->
413<xsl:template name="error-prefix">
414 <xsl:param name="Node" select="."/>
415 <xsl:text>error: </xsl:text>
416 <xsl:call-template name="get-node-path">
417 <xsl:with-param name="Node" select="$Node"/>
418 </xsl:call-template>
419 <xsl:text>: </xsl:text>
420</xsl:template>
421
422</xsl:stylesheet>
423
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