VirtualBox

source: vbox/trunk/doc/manual/docbook-refentry-to-C-help.xsl@ 99116

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

manual: Compacted the C and latex syntax diagrams a tiny bit, adding a special role=compact to arg/group to selectively make nested groups tighter too. Fixed controlvm natpf syntax.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svn:mergeinfo set to (toggle deleted branches)
    /branches/VBox-3.0/doc/manual/docbook-refentry-to-manual-overview.xsl58652,​70973
    /branches/VBox-3.2/doc/manual/docbook-refentry-to-manual-overview.xsl66309,​66318
    /branches/VBox-4.0/doc/manual/docbook-refentry-to-manual-overview.xsl70873
    /branches/VBox-4.1/doc/manual/docbook-refentry-to-manual-overview.xsl74233,​78414,​78691,​82579,​85941,​85944-85947,​85949-85950,​85953,​86701,​86728,​87009
    /branches/VBox-4.2/doc/manual/docbook-refentry-to-manual-overview.xsl82653,​86229-86230,​86234,​86529,​91503-91504,​91506-91508,​91510,​91514-91515,​91521
    /branches/VBox-4.3/doc/manual/docbook-refentry-to-manual-overview.xsl91223,​94066,​94839,​94897,​95154,​95164,​95167,​95295,​95338,​95353-95354,​95356,​95367,​95451,​95475,​95477,​95480,​95507,​95640,​95659,​95661,​95663,​98913-98915,​99358
    /branches/VBox-4.3/trunk/doc/manual/docbook-refentry-to-manual-overview.xsl91223
    /branches/andy/draganddrop/doc/manual/docbook-refentry-to-manual-overview.xsl90781-91268
    /branches/andy/guestctrl20/doc/manual/docbook-refentry-to-manual-overview.xsl78916,​78930
    /branches/andy/pdmaudio/doc/manual/docbook-refentry-to-manual-overview.xsl94582,​94641,​94654,​94688,​94778,​94783,​94816,​95197,​95215-95216,​95250,​95279,​95505-95506,​95543,​95694,​96323,​96470-96471,​96582,​96587,​96802-96803,​96817,​96904,​96967,​96999,​97020-97021,​97025,​97050,​97099
    /branches/bird/hardenedwindows/doc/manual/docbook-refentry-to-manual-overview.xsl92692-94610
    /branches/dsen/gui/doc/manual/docbook-refentry-to-manual-overview.xsl79076-79078,​79089,​79109-79110,​79112-79113,​79127-79130,​79134,​79141,​79151,​79155,​79157-79159,​79193,​79197
    /branches/dsen/gui2/doc/manual/docbook-refentry-to-manual-overview.xsl79224,​79228,​79233,​79235,​79258,​79262-79263,​79273,​79341,​79345,​79354,​79357,​79387-79388,​79559-79569,​79572-79573,​79578,​79581-79582,​79590-79591,​79598-79599,​79602-79603,​79605-79606,​79632,​79635,​79637,​79644
    /branches/dsen/gui3/doc/manual/docbook-refentry-to-manual-overview.xsl79645-79692
    /trunk/src/doc/manual/docbook-refentry-to-manual-overview.xsl92342
File size: 38.3 KB
Line 
1<?xml version="1.0"?>
2<!--
3 docbook-refentry-to-manual-sect1.xsl:
4 XSLT stylesheet for nicking the refsynopsisdiv bit of a
5 refentry (manpage) for use in the command overview section
6 in the user manual.
7-->
8<!--
9 Copyright (C) 2006-2023 Oracle and/or its affiliates.
10
11 This file is part of VirtualBox base platform packages, as
12 available from https://www.virtualbox.org.
13
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License
16 as published by the Free Software Foundation, in version 3 of the
17 License.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, see <https://www.gnu.org/licenses>.
26
27 SPDX-License-Identifier: GPL-3.0-only
28-->
29
30<xsl:stylesheet
31 version="1.0"
32 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
33 xmlns:str="http://xsltsl.org/string"
34 >
35
36 <xsl:import href="string.xsl"/>
37 <xsl:import href="common-formatcfg.xsl"/>
38
39 <xsl:output method="text" version="1.0" encoding="utf-8" indent="yes"/>
40 <xsl:strip-space elements="*"/>
41
42 <xsl:param name="g_fDebugText" select="0"/>
43
44 <xsl:variable name="g_sUnderlineRefSect1">
45 <xsl:text>===================================================================================================================</xsl:text>
46 </xsl:variable>
47 <xsl:variable name="g_sUnderlineRefSect2">
48 <xsl:text>-------------------------------------------------------------------------------------------------------------------</xsl:text>
49 </xsl:variable>
50 <xsl:variable name="g_sNewLine"><xsl:value-of select="'&#10;'" /></xsl:variable>
51
52 <!-- Sub-command style command (true) or single command (false). -->
53 <xsl:variable name="g_fSubCommands" select="not(not(//refsect2[@id]))" />
54
55 <!-- Translatable strings -->
56 <xsl:variable name="sUsage" select="'Usage'"/>
57 <xsl:variable name="sUsageUnderscore" select="'====='"/>
58
59
60 <!-- Default action, do nothing. -->
61 <xsl:template match="node()|@*"/>
62
63 <!--
64 main() - because we need to order the output in a specific manner
65 that is contrary to the data flow in the refentry, this is
66 going to look a bit more like a C program than a stylesheet.
67 -->
68 <xsl:template match="refentry">
69 <!-- Assert refetry expectations. -->
70 <xsl:if test="not(./refsynopsisdiv)">
71 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have a refsynopsisdiv</xsl:message>
72 </xsl:if>
73 <xsl:if test="not(./refentryinfo/title)">
74 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have a refentryinfo with title</xsl:message>
75 </xsl:if>
76 <xsl:if test="not(./refmeta/refentrytitle)">
77 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have a refentryinfo with title</xsl:message>
78 </xsl:if>
79 <xsl:if test="./refmeta/refentrytitle != ./refnamediv/refname">
80 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>The refmeta/refentrytitle and the refnamediv/refname must be identical</xsl:message>
81 </xsl:if>
82 <xsl:if test="not(./refsect1/title)">
83 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have a refsect1 with title</xsl:message>
84 </xsl:if>
85 <xsl:if test="not(@id) or @id = ''">
86 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have an id attribute</xsl:message>
87 </xsl:if>
88
89 <!-- variables -->
90 <xsl:variable name="sBaseId" select="@id"/>
91 <xsl:variable name="sDataBaseSym" select="concat('g_', translate(@id, '-', '_'))"/>
92
93
94 <!--
95 Convert the refsynopsisdiv into REFENTRY::Synopsis data.
96 -->
97 <xsl:text>
98
99static const RTMSGREFENTRYSTR </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis[] =
100{</xsl:text>
101 <xsl:for-each select="./refsynopsisdiv/cmdsynopsis">
102 <!-- Assert synopsis expectations -->
103 <xsl:if test="not(@id) or substring-before(@id, '-') != 'synopsis'">
104 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>The refsynopsisdiv/cmdsynopsis elements must have an id starting with 'synopsis-'.</xsl:message>
105 </xsl:if>
106 <xsl:if test="not(starts-with(substring-after(@id, '-'), $sBaseId))">
107 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>The refsynopsisdiv/cmdsynopsis elements @id is expected to include the refentry @id.</xsl:message>
108 </xsl:if>
109 <xsl:if test="not(../../refsect1/refsect2[@id=./@id]) and $g_fSubCommands">
110 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>No refsect2 with id="<xsl:value-of select="@id"/>" found.</xsl:message>
111 </xsl:if>
112
113 <!-- Do the work. -->
114 <xsl:apply-templates select="."/>
115
116 </xsl:for-each>
117 <xsl:text>
118};</xsl:text>
119
120
121 <!--
122 Convert the whole manpage to help text.
123 -->
124 <xsl:text>
125static const RTMSGREFENTRYSTR </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help[] =
126{</xsl:text>
127 <!-- We start by combining the refentry title and the refpurpose into a short description. -->
128 <xsl:text>
129 { </xsl:text><xsl:call-template name="calc-scope-for-refentry"/><xsl:text>,
130 "</xsl:text>
131 <xsl:apply-templates select="./refentryinfo/title/node()"/>
132 <xsl:text> -- </xsl:text>
133 <xsl:call-template name="capitalize">
134 <xsl:with-param name="text">
135 <xsl:apply-templates select="./refnamediv/refpurpose/node()"/>
136 </xsl:with-param>
137 </xsl:call-template>
138 <xsl:text>." },
139 { RTMSGREFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
140
141 <!-- The follows the usage (synopsis) section. -->
142 <xsl:text>
143 { RTMSGREFENTRYSTR_SCOPE_GLOBAL,
144 "</xsl:text><xsl:value-of select="$sUsage"/><xsl:text>" },
145 { RTMSGREFENTRYSTR_SCOPE_SAME,
146 "</xsl:text><xsl:value-of select="$sUsageUnderscore"/><xsl:text>" },</xsl:text>
147 <xsl:apply-templates select="./refsynopsisdiv/node()"/>
148
149 <!-- Then comes the description and other refsect1 -->
150 <xsl:for-each select="./refsect1">
151 <xsl:if test="name(*[1]) != 'title'"><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Expected title as the first element in refsect1.</xsl:message></xsl:if>
152 <xsl:if test="text()"><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>No text supported in refsect1.</xsl:message></xsl:if>
153 <xsl:if test="not(./remark[@role='help-skip'])">
154 <xsl:variable name="sTitle">
155 <xsl:apply-templates select="./title/node()"/>
156 </xsl:variable>
157 <xsl:text>
158 { </xsl:text><xsl:call-template name="calc-scope-refsect1"/><xsl:text>, "" },
159 { RTMSGREFENTRYSTR_SCOPE_SAME,
160 "</xsl:text><xsl:value-of select="$sTitle"/><xsl:text>" },
161 { RTMSGREFENTRYSTR_SCOPE_SAME,
162 "</xsl:text>
163 <xsl:value-of select="substring($g_sUnderlineRefSect1, 1, string-length($sTitle))"/>
164 <xsl:text>" },</xsl:text>
165
166 <xsl:apply-templates select="./*[name() != 'title']"/>
167
168 <xsl:text>
169 { RTMSGREFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
170 </xsl:if>
171 </xsl:for-each>
172
173 <xsl:text>
174};</xsl:text>
175
176 <!--
177 Generate the refentry structure.
178 -->
179 <xsl:text>
180static const RTMSGREFENTRY </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text> =
181{
182 /* .idInternal = */ HELP_CMD_</xsl:text>
183 <xsl:choose>
184 <xsl:when test="contains(@id, '-')">
185 <xsl:call-template name="str:to-upper"> <!-- Multi level command. -->
186 <xsl:with-param name="text" select="translate(substring-after(@id, '-'), '-', '_')"/>
187 </xsl:call-template>
188 </xsl:when>
189 <xsl:otherwise>
190 <xsl:call-template name="str:to-upper"> <!-- Simple command. -->
191 <xsl:with-param name="text" select="@id"/>
192 </xsl:call-template>
193 </xsl:otherwise>
194 </xsl:choose>
195 <xsl:text>,
196 /* .Synopsis = */ { RT_ELEMENTS(</xsl:text>
197 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis), 0, </xsl:text>
198 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis },
199 /* .Help = */ { RT_ELEMENTS(</xsl:text>
200 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help), 0, </xsl:text>
201 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help },
202 /* pszBrief = */ "</xsl:text>
203 <xsl:apply-templates select="./refnamediv/refpurpose/node()"/>
204 <!-- TODO: Add the command name too. -->
205 <xsl:text>"
206};
207</xsl:text>
208 </xsl:template>
209
210
211 <!--
212 Convert command synopsis to text.
213 -->
214 <xsl:template match="cmdsynopsis">
215 <xsl:if test="text()"><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>cmdsynopsis with text is not supported.</xsl:message></xsl:if>
216 <xsl:if test="position() = 1">
217 <xsl:text>
218 { </xsl:text><xsl:call-template name="calc-scope-cmdsynopsis"/><xsl:text> | RTMSGREFENTRYSTR_FLAGS_SYNOPSIS, "" },</xsl:text>
219 </xsl:if>
220 <xsl:text>
221 { </xsl:text><xsl:call-template name="calc-scope-cmdsynopsis"/><xsl:text> | RTMSGREFENTRYSTR_FLAGS_SYNOPSIS,
222 "</xsl:text><xsl:call-template name="emit-indentation"/><xsl:apply-templates select="*|@*"/><xsl:text>" },</xsl:text>
223 </xsl:template>
224
225 <xsl:template match="sbr">
226 <xsl:text>" },
227 { RTMSGREFENTRYSTR_SCOPE_SAME | RTMSGREFENTRYSTR_FLAGS_SYNOPSIS,
228 " </xsl:text><xsl:call-template name="emit-indentation"/> <!-- hardcoded in VBoxManageHelp.cpp too -->
229 </xsl:template>
230
231 <xsl:template match="cmdsynopsis/command">
232 <xsl:text>" },
233 { RTMSGREFENTRYSTR_SCOPE_SAME | RTMSGREFENTRYSTR_FLAGS_SYNOPSIS,
234 "</xsl:text><xsl:call-template name="emit-indentation"/>
235 <xsl:apply-templates select="node()|@*"/>
236 </xsl:template>
237
238 <xsl:template match="cmdsynopsis/command[1]" priority="2">
239 <xsl:apply-templates select="node()|@*"/>
240 </xsl:template>
241
242 <xsl:template match="command|option|computeroutput|literal|emphasis|filename|citetitle|note">
243 <xsl:apply-templates select="node()|@*"/>
244 </xsl:template>
245
246 <xsl:template match="ulink">
247 <xsl:value-of select="@url"/>
248 </xsl:template>
249
250 <xsl:template match="replaceable">
251 <xsl:choose>
252 <xsl:when test="ancestor::arg">
253 <xsl:apply-templates />
254 </xsl:when>
255 <xsl:otherwise>
256 <xsl:text>&lt;</xsl:text>
257 <xsl:apply-templates />
258 <xsl:text>&gt;</xsl:text>
259 </xsl:otherwise>
260 </xsl:choose>
261 </xsl:template>
262
263 <!-- duplicated in docbook2latex.xsl -->
264 <xsl:template match="arg|group">
265 <!-- separator char if we're not the first child -->
266 <xsl:if test="position() > 1">
267 <!--<xsl:value-of select="concat('*',name(),'=', position(),'#')"/>-->
268 <xsl:choose>
269 <xsl:when test="parent::group and ancestor::*[@role='compact']"><xsl:value-of select="$arg.or.sep.compact"/></xsl:when>
270 <xsl:when test="parent::group"><xsl:value-of select="$arg.or.sep"/></xsl:when>
271 <xsl:when test="parent::arg"></xsl:when>
272 <xsl:when test="ancestor::*/@sepchar"><xsl:value-of select="ancestor::*/@sepchar"/></xsl:when>
273 <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
274 </xsl:choose>
275 </xsl:if>
276
277 <!-- open wrapping -->
278 <xsl:variable name="fWrappers" select="not(ancestor::group)"/>
279 <xsl:if test="$fWrappers">
280 <xsl:choose>
281 <xsl:when test="not(@choice) or @choice = ''"> <xsl:value-of select="$arg.choice.def.open.str"/></xsl:when>
282 <xsl:when test="@choice = 'opt'"> <xsl:value-of select="$arg.choice.opt.open.str"/></xsl:when>
283 <xsl:when test="@choice = 'req'"> <xsl:value-of select="$arg.choice.req.open.str"/></xsl:when>
284 <xsl:when test="@choice = 'plain'"/>
285 <xsl:otherwise><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Invalid arg choice: "<xsl:value-of select="@choice"/>"</xsl:message></xsl:otherwise>
286 </xsl:choose>
287 </xsl:if>
288
289 <!-- render the arg (TODO: may need to do more work here) -->
290 <xsl:apply-templates />
291
292 <!-- repeat wrapping -->
293 <xsl:choose>
294 <xsl:when test="@rep = 'norepeat' or not(@rep) or @rep = ''"/>
295 <xsl:when test="@rep = 'repeat'"> <xsl:value-of select="$arg.rep.repeat.str"/></xsl:when>
296 <xsl:otherwise><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Invalid rep choice: "<xsl:value-of select="@rep"/>"</xsl:message></xsl:otherwise>
297 </xsl:choose>
298
299 <!-- close wrapping -->
300 <xsl:if test="$fWrappers">
301 <xsl:choose>
302 <xsl:when test="not(@choice) or @choice = ''"> <xsl:value-of select="$arg.choice.def.close.str"/></xsl:when>
303 <xsl:when test="@choice = 'opt'"> <xsl:value-of select="$arg.choice.opt.close.str"/></xsl:when>
304 <xsl:when test="@choice = 'req'"> <xsl:value-of select="$arg.choice.req.close.str"/></xsl:when>
305 </xsl:choose>
306 </xsl:if>
307 </xsl:template>
308
309
310 <!--
311 refsect2
312 -->
313 <xsl:template match="refsect2">
314 <!-- assertions -->
315 <xsl:if test="text()"><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refsect2 shouldn't contain text</xsl:message></xsl:if>
316 <xsl:if test="count(./title) != 1"><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refsect2 requires a title (<xsl:value-of select="ancestor-or-self::*[@id][1]/@id"/>)</xsl:message></xsl:if>
317
318 <!-- title / command synopsis - sets the scope. -->
319 <xsl:variable name="sTitle">
320 <xsl:apply-templates select="./title/text()"/>
321 </xsl:variable>
322 <xsl:text>
323 { </xsl:text><xsl:call-template name="calc-scope-refsect2"/><xsl:text>, "" },
324 { RTMSGREFENTRYSTR_SCOPE_SAME,
325 "</xsl:text><xsl:call-template name="emit-indentation"/>
326 <xsl:value-of select="$sTitle"/>
327 <xsl:text>" },
328 { RTMSGREFENTRYSTR_SCOPE_SAME,
329 "</xsl:text><xsl:call-template name="emit-indentation"/>
330 <xsl:value-of select="substring($g_sUnderlineRefSect2, 1, string-length($sTitle))"/>
331 <xsl:text>" },</xsl:text>
332
333<!-- <xsl:if test="./*[name() != 'title']/following::
334 { RTMSGREFENTRYSTR_SCOPE_SAME, "y" },</xsl:text> cmdsynopsis -->
335
336 <!-- Format the text in the section -->
337 <xsl:for-each select="./*[name() != 'title']">
338 <xsl:apply-templates select="."/>
339 </xsl:for-each>
340
341 <!-- Add two blank lines, unless we're the last element in this refsect1. -->
342 <xsl:if test="position() != last()">
343 <xsl:text>
344 { RTMSGREFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
345 </xsl:if>
346 </xsl:template>
347
348
349 <!--
350 para
351 -->
352 <xsl:template match="para">
353 <xsl:if test="position() != 1 or not(parent::listitem)">
354 <xsl:text>
355 { RTMSGREFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
356 </xsl:if>
357 <xsl:call-template name="process-mixed"/>
358 </xsl:template>
359
360
361 <!--
362 variablelist
363 -->
364 <xsl:template match="variablelist">
365 <xsl:if test="*[not(self::varlistentry)]|text()">
366 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Only varlistentry elements are supported in variablelist </xsl:message>
367 </xsl:if>
368 <xsl:for-each select="./varlistentry">
369 <xsl:if test="not(term) or not(listitem) or count(listitem) > 1">
370 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Expected one or more term members and exactly one listentry member in varlistentry element.</xsl:message>
371 </xsl:if>
372 <xsl:if test="(not(@spacing) or @spacing != 'compact') and (position() > 1 or (count(../preceding-sibling::*) - count(../preceding-sibling::title) > 0))">
373 <xsl:text>
374 { RTMSGREFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
375 </xsl:if>
376 <xsl:apply-templates select="*"/>
377 </xsl:for-each>
378 </xsl:template>
379
380 <xsl:template match="varlistentry/term">
381 <xsl:call-template name="process-mixed"/>
382 </xsl:template>
383
384 <xsl:template match="varlistentry/listitem">
385 <xsl:call-template name="check-children">
386 <xsl:with-param name="UnsupportedNodes" select="*[not(self::para or self::itemizedlist or self::orderedlist or self::variablelist or self::note)]|text()"/>
387 <xsl:with-param name="SupportedNames">para, itemizedlist, orderedlist and note</xsl:with-param>
388 </xsl:call-template>
389
390 <xsl:apply-templates select="*"/>
391 </xsl:template>
392
393
394 <!--
395 itemizedlist and orderedlist
396 -->
397 <xsl:template match="itemizedlist|orderedlist">
398 <xsl:if test="*[not(self::listitem)]|text()">
399 <xsl:message terminate="yes">
400 <xsl:call-template name="error-prefix"/>Only listitem elements are supported in <xsl:value-of select="name()"/>:
401 <xsl:call-template name="list-nodes">
402 <xsl:with-param name="Nodes" select="*[not(self::listitem)]|text()"/>
403 </xsl:call-template>
404 </xsl:message>
405 </xsl:if>
406 <xsl:if test="parent::para">
407 <xsl:message terminate="yes"><xsl:value-of select="name()"/> inside a para is current not supported. <!-- no newline
408 -->Close the para before the list, it makes no difference to html and latex/pdf output.</xsl:message>
409 </xsl:if>
410 <xsl:if test="position() != 1 and (not(@spacing) or @spacing != 'compact')">
411 <xsl:text>
412 { RTMSGREFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
413 </xsl:if>
414 <xsl:for-each select="./listitem">
415 <xsl:apply-templates select="*"/>
416 </xsl:for-each>
417 </xsl:template>
418
419 <xsl:template match="itemizedlist/listitem|orderedlist/listitem">
420 <xsl:if test="*[not(self::para)]|text()">
421 <xsl:message terminate="yes">
422 <xsl:call-template name="error-prefix"/>Expected <xsl:value-of select="name()"/>/listitem to only contain para elements:
423 <xsl:call-template name="list-nodes">
424 <xsl:with-param name="Nodes" select="*[not(self::para)]|text()"/>
425 </xsl:call-template>
426 </xsl:message>
427 </xsl:if>
428
429 <xsl:if test="position() != 1 and @spaceing != 'compact'">
430 <xsl:text>
431 { RTMSGREFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
432 </xsl:if>
433 <xsl:apply-templates select="*"/>
434 </xsl:template>
435
436
437 <!--
438 Screen
439 -->
440 <xsl:template match="screen">
441 <xsl:if test="ancestor::para">
442 <xsl:text>" },</xsl:text>
443 </xsl:if>
444
445 <xsl:text>
446 { RTMSGREFENTRYSTR_SCOPE_SAME,
447 "</xsl:text>
448
449 <xsl:for-each select="node()">
450 <xsl:choose>
451 <xsl:when test="name() = ''">
452 <xsl:call-template name="screen_text_line">
453 <xsl:with-param name="sText" select="."/>
454 </xsl:call-template>
455 </xsl:when>
456 <xsl:otherwise>
457 <xsl:if test="*">
458 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Support for elements under screen has not been implemented: <xsl:value-of select="name()"/></xsl:message>
459 </xsl:if>
460 </xsl:otherwise>
461 </xsl:choose>
462 </xsl:for-each>
463
464 <xsl:if test="not(ancestor::para)">
465 <xsl:text>" },</xsl:text>
466 </xsl:if>
467 </xsl:template>
468
469 <xsl:template name="screen_text_line">
470 <xsl:param name="sText"/>
471
472 <xsl:choose>
473 <xsl:when test="contains($sText, '&#x0a;')">
474 <xsl:call-template name="escape_fixed_text">
475 <xsl:with-param name="sText" select="substring-before($sText,'&#x0a;')"/>
476 </xsl:call-template>
477
478 <xsl:if test="substring-after($sText,'&#x0a;')">
479 <xsl:text>" },
480 { RTMSGREFENTRYSTR_SCOPE_SAME,
481 "</xsl:text>
482 <xsl:call-template name="screen_text_line">
483 <xsl:with-param name="sText" select="substring-after($sText,'&#x0a;')"/>
484 </xsl:call-template>
485 </xsl:if>
486 </xsl:when>
487
488 <xsl:otherwise> <!-- no newline, so use the whole string -->
489 <xsl:call-template name="escape_fixed_text">
490 <xsl:with-param name="sText" select="$sText"/>
491 </xsl:call-template>
492 </xsl:otherwise>
493 </xsl:choose>
494 </xsl:template>
495
496 <!-- Normalizes the current text node taking tailing and leading spaces
497 into account (unlike normalize-space which strips them mercilessly). -->
498 <xsl:template name="my-normalize-space-current">
499 <!-- <xsl:message>dbg0: position=<xsl:value-of select="position()"/> last=<xsl:value-of select="last()"/> .=|<xsl:value-of select="."/>|</xsl:message> -->
500 <xsl:if test="(starts-with(.,' ') or starts-with(., $g_sNewLine)) and position() != 1">
501 <xsl:value-of select="' '"/>
502 </xsl:if>
503 <xsl:value-of select="normalize-space(.)"/>
504 <xsl:if test="((substring(.,string-length(.)) = ' ') or (substring(.,string-length(.)) = $g_sNewLine)) and position() != last()">
505 <xsl:value-of select="' '"/>
506 </xsl:if>
507 </xsl:template>
508
509 <!--
510 Text escaping for C.
511 -->
512 <xsl:template match="text()" name="escape_text">
513 <!-- Leading whitespace hack! -->
514 <xsl:if test="(starts-with(.,' ') or starts-with(.,$g_sNewLine)) and position() != 1">
515 <xsl:text> </xsl:text>
516 <xsl:if test="boolean($g_fDebugText)">
517 <xsl:message>text: add lead space</xsl:message>
518 </xsl:if>
519 </xsl:if>
520
521 <!-- Body of text -->
522 <xsl:choose>
523
524 <xsl:when test="contains(., '\') or contains(., '&quot;')">
525 <xsl:variable name="sTmp">
526 <xsl:call-template name="str:subst">
527 <xsl:with-param name="text" select="normalize-space(.)"/>
528 <xsl:with-param name="replace" select="'\'"/>
529 <xsl:with-param name="with" select="'\\'"/>
530 <xsl:with-param name="disable-output-escaping" select="yes"/>
531 </xsl:call-template>
532 </xsl:variable>
533 <xsl:variable name="sTmp2">
534 <xsl:call-template name="str:subst">
535 <xsl:with-param name="text" select="$sTmp"/>
536 <xsl:with-param name="replace" select="'&quot;'"/>
537 <xsl:with-param name="with" select="'\&quot;'"/>
538 <xsl:with-param name="disable-output-escaping" select="yes"/>
539 </xsl:call-template>
540 </xsl:variable>
541 <xsl:value-of select="$sTmp2"/>
542 <xsl:if test="boolean($g_fDebugText)">
543 <xsl:message>text: |<xsl:value-of select="$sTmp2"/>|(1)</xsl:message>
544 </xsl:if>
545 </xsl:when>
546
547 <xsl:otherwise>
548 <xsl:value-of select="normalize-space(.)"/>
549 <xsl:if test="boolean($g_fDebugText)">
550 <xsl:message>text: |<xsl:value-of select="normalize-space(.)"/>|(2)</xsl:message>
551 </xsl:if>
552 </xsl:otherwise>
553 </xsl:choose>
554
555 <!-- Trailing whitespace hack! -->
556 <xsl:if test="(substring(.,string-length(.)) = ' ' or substring(.,string-length(.)) = $g_sNewLine) and position() != last() and string-length(.) != 1">
557 <xsl:text> </xsl:text>
558 <xsl:if test="boolean($g_fDebugText)">
559 <xsl:message>text: add tail space</xsl:message>
560 </xsl:if>
561 </xsl:if>
562
563 </xsl:template>
564
565 <!-- Elements producing non-breaking strings (single line). -->
566 <xsl:template match="command/text()|option/text()|computeroutput/text()|arg/text()|filename/text()" name="escape_fixed_text">
567 <xsl:param name="sText"><xsl:call-template name="my-normalize-space-current"/></xsl:param>
568 <xsl:choose>
569
570 <xsl:when test="contains($sText, '\') or contains($sText, '&quot;')">
571 <xsl:variable name="sTmp1">
572 <xsl:call-template name="str:subst">
573 <xsl:with-param name="text" select="$sText"/>
574 <xsl:with-param name="replace" select="'\'"/>
575 <xsl:with-param name="with" select="'\\'"/>
576 <xsl:with-param name="disable-output-escaping" select="yes"/>
577 </xsl:call-template>
578 </xsl:variable>
579 <xsl:variable name="sTmp2">
580 <xsl:call-template name="str:subst">
581 <xsl:with-param name="text" select="$sTmp1"/>
582 <xsl:with-param name="replace" select="'&quot;'"/>
583 <xsl:with-param name="with" select="'\&quot;'"/>
584 <xsl:with-param name="disable-output-escaping" select="yes"/>
585 </xsl:call-template>
586 </xsl:variable>
587 <xsl:variable name="sTmp3">
588 <xsl:call-template name="str:subst">
589 <xsl:with-param name="text" select="$sTmp2"/>
590 <xsl:with-param name="replace" select="' '"/>
591 <xsl:with-param name="with" select="'\b'"/>
592 <xsl:with-param name="disable-output-escaping" select="yes"/>
593 </xsl:call-template>
594 </xsl:variable>
595 <xsl:value-of select="$sTmp3"/>
596 <xsl:if test="boolean($g_fDebugText)">
597 <xsl:message>text! |<xsl:value-of select="$sTmp3"/>|</xsl:message>
598 </xsl:if>
599 </xsl:when>
600
601 <xsl:when test="contains($sText, ' ')">
602 <xsl:variable name="sTmp">
603 <xsl:call-template name="str:subst">
604 <xsl:with-param name="text" select="$sText"/>
605 <xsl:with-param name="replace" select="' '"/>
606 <xsl:with-param name="with" select="'\b'"/>
607 <xsl:with-param name="disable-output-escaping" select="yes"/>
608 </xsl:call-template>
609 </xsl:variable>
610 <xsl:value-of select="$sTmp"/>
611 <xsl:if test="boolean($g_fDebugText)">
612 <xsl:message>text! |<xsl:value-of select="$sTmp"/>|</xsl:message>
613 </xsl:if>
614 </xsl:when>
615
616 <xsl:otherwise>
617 <xsl:value-of select="$sText"/>
618 <xsl:if test="boolean($g_fDebugText)">
619 <xsl:message>text! |<xsl:value-of select="$sText"/>|</xsl:message>
620 </xsl:if>
621 </xsl:otherwise>
622 </xsl:choose>
623 </xsl:template>
624
625
626 <!--
627 Unsupported elements and elements handled directly.
628 -->
629 <xsl:template match="synopfragment|synopfragmentref|title|refsect1">
630 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>The <xsl:value-of select="name()"/> element is not supported</xsl:message>
631 </xsl:template>
632
633 <xsl:template match="xref">
634 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>The <xsl:value-of select="name()"/> element is not supported, most likely the linkend is not defined or incorrectly processed by docbook-refentry-link-replacement-xsl-gen.xsl</xsl:message>
635 </xsl:template>
636
637 <!--
638 Fail on misplaced scoping remarks.
639 -->
640 <xsl:template match="remark[@role = 'help-scope']">
641 <xsl:choose>
642 <xsl:when test="parent::refsect1"/>
643 <xsl:when test="parent::refsect2"/>
644 <xsl:when test="parent::cmdsynopsis and ancestor::refsynopsisdiv"/>
645 <xsl:otherwise>
646 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Misplaced remark/@role=help-scope element.
647Only supported on: refsect1, refsect2, refsynopsisdiv/cmdsynopsis</xsl:message>
648 </xsl:otherwise>
649 </xsl:choose>
650 </xsl:template>
651
652 <!--
653 Execute synopsis copy remark (avoids duplication for complicated xml).
654 -->
655 <xsl:template match="remark[@role = 'help-copy-synopsis']">
656 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>remark/@role=help-copy-synopsis is not supported by this stylesheet. Must preprocess input!</xsl:message>
657 </xsl:template>
658
659 <!--
660 Warn about unhandled elements
661 -->
662 <xsl:template match="*">
663 <xsl:message terminate="no">Warning: Unhandled element: <!-- no newline -->
664 <xsl:for-each select="ancestor-or-self::*">
665 <xsl:text>/</xsl:text>
666 <xsl:value-of select="name(.)"/>
667 <xsl:if test="@id">
668 <xsl:value-of select="concat('[id=', @id ,']')"/>
669 </xsl:if>
670 </xsl:for-each>
671 </xsl:message>
672 </xsl:template>
673
674
675 <!--
676 Functions
677 Functions
678 Functions
679 -->
680
681 <!--
682 Processes mixed children, i.e. both text and regular elements.
683 Normalizes whitespace. -->
684 <xsl:template name="process-mixed">
685 <xsl:text>
686 { RTMSGREFENTRYSTR_SCOPE_SAME,
687 "</xsl:text><xsl:call-template name="emit-indentation"/>
688
689 <xsl:for-each select="node()[not(self::remark)]">
690 <xsl:choose>
691 <xsl:when test="name() = ''">
692 <xsl:call-template name="escape_text"/>
693 </xsl:when>
694 <xsl:otherwise>
695 <xsl:apply-templates select="."/>
696 </xsl:otherwise>
697 </xsl:choose>
698 </xsl:for-each>
699
700 <xsl:text>" },</xsl:text>
701 </xsl:template>
702
703
704 <!--
705 Element specific scoping.
706 -->
707
708 <xsl:template name="calc-scope-for-refentry">
709 <xsl:text>HELP_SCOPE_</xsl:text>
710 <xsl:choose>
711 <xsl:when test="contains(@id, '-')"> <!-- Multi level command. -->
712 <xsl:call-template name="str:to-upper">
713 <xsl:with-param name="text" select="translate(substring-after(@id, '-'), '-', '_')"/>
714 </xsl:call-template>
715 </xsl:when>
716 <xsl:otherwise> <!-- Single command. -->
717 <xsl:call-template name="str:to-upper">
718 <xsl:with-param name="text" select="@id"/>
719 </xsl:call-template>
720 </xsl:otherwise>
721 </xsl:choose>
722 </xsl:template>
723
724 <!-- Figures out the scope of a refsect1 element. -->
725 <xsl:template name="calc-scope-refsect1">
726 <xsl:choose>
727 <xsl:when test="title[text() = 'Description']">
728 <xsl:text>RTMSGREFENTRYSTR_SCOPE_GLOBAL</xsl:text>
729 </xsl:when>
730 <xsl:when test="@id or remark[@role='help-scope']">
731 <xsl:call-template name="calc-scope-from-remark-or-id"/>
732 </xsl:when>
733 <xsl:otherwise>
734 <xsl:text>RTMSGREFENTRYSTR_SCOPE_GLOBAL</xsl:text>
735 </xsl:otherwise>
736 </xsl:choose>
737 </xsl:template>
738
739 <!-- Figures out the scope of a refsect2 element. -->
740 <xsl:template name="calc-scope-refsect2">
741 <xsl:choose>
742 <xsl:when test="@id or remark[@role='help-scope']">
743 <xsl:call-template name="calc-scope-from-remark-or-id"/>
744 </xsl:when>
745 <xsl:otherwise>
746 <xsl:text>RTMSGREFENTRYSTR_SCOPE_SAME</xsl:text>
747 </xsl:otherwise>
748 </xsl:choose>
749 </xsl:template>
750
751 <!-- Figures out the scope of a refsect1 element. -->
752 <xsl:template name="calc-scope-cmdsynopsis">
753 <xsl:choose>
754 <xsl:when test="ancestor::refsynopsisdiv">
755 <xsl:call-template name="calc-scope-from-remark-or-id">
756 <xsl:with-param name="sId" select="substring-after(@id, '-')"/>
757 </xsl:call-template>
758 </xsl:when>
759 <xsl:otherwise>
760 <xsl:text>RTMSGREFENTRYSTR_SCOPE_SAME</xsl:text>
761 </xsl:otherwise>
762 </xsl:choose>
763 </xsl:template>
764
765
766 <!--
767 Scoping worker functions.
768 -->
769
770 <!-- Calculates the current scope from the scope remark or @id. -->
771 <xsl:template name="calc-scope-from-remark-or-id">
772 <xsl:param name="sId" select="@id"/>
773 <xsl:choose>
774 <xsl:when test="remark[@role='help-scope']">
775 <xsl:call-template name="calc-scope-consts-from-remark"/>
776 </xsl:when>
777 <xsl:when test="$sId != ''">
778 <xsl:call-template name="calc-scope-const-from-id">
779 <xsl:with-param name="sId" select="$sId"/>
780 </xsl:call-template>
781 </xsl:when>
782 <xsl:otherwise>
783 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>expected remark child or id attribute.</xsl:message>
784 </xsl:otherwise>
785 </xsl:choose>
786 </xsl:template>
787
788 <!-- Turns a @id into a scope constant.
789 Some woodoo taking place here here that chops the everything up to and
790 including the first refentry/@id word from all IDs before turning them into
791 constants (word delimiter '-'). -->
792 <xsl:template name="calc-scope-const-from-id">
793 <xsl:param name="sId" select="@id"/>
794 <xsl:param name="sAncestorId" select="ancestor::refentry/@id"/>
795 <xsl:text>HELP_SCOPE_</xsl:text>
796 <xsl:choose>
797 <xsl:when test="not($sAncestorId)"> <!-- Sanity check. -->
798 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>calc-scope-const-from-id is invoked without an refentry ancestor with a id. <xsl:call-template name="get-node-path"/> </xsl:message>
799 </xsl:when>
800
801 <xsl:when test="contains($sAncestorId, '-')"> <!-- Multi level command. -->
802 <xsl:variable name="sPrefix" select="concat(substring-before($sAncestorId, '-'), '-')"/>
803 <xsl:if test="not(contains($sId, $sPrefix))">
804 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Expected sId (<xsl:value-of select="$sId"/>) to contain <xsl:value-of select="$sPrefix"/></xsl:message>
805 </xsl:if>
806 <xsl:call-template name="str:to-upper">
807 <xsl:with-param name="text" select="translate(substring-after($sId, $sPrefix), '-', '_')"/>
808 </xsl:call-template>
809 </xsl:when>
810
811 <xsl:otherwise> <!-- Single command. -->
812 <xsl:call-template name="str:to-upper">
813 <xsl:with-param name="text" select="translate($sId, '-', '_')"/>
814 </xsl:call-template>
815 </xsl:otherwise>
816 </xsl:choose>
817 </xsl:template>
818
819 <!-- Turns a remark into one or more scope constants. -->
820 <xsl:template name="calc-scope-consts-from-remark">
821 <xsl:param name="sCondition" select="remark/@condition"/>
822 <xsl:variable name="sNormalized" select="concat(normalize-space(translate($sCondition, ',;:|', ' ')), ' ')"/>
823 <xsl:if test="$sNormalized = ' ' or $sNormalized = ''">
824 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Empty @condition for help-scope remark.</xsl:message>
825 </xsl:if>
826 <xsl:choose>
827 <xsl:when test="substring-before($sNormalized, ' ') = 'GLOBAL'">
828 <xsl:text>RTMSGREFENTRYSTR_SCOPE_GLOBAL</xsl:text>
829 </xsl:when>
830 <xsl:otherwise>
831 <xsl:text>HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sNormalized, ' ')"/>
832 </xsl:otherwise>
833 </xsl:choose>
834 <xsl:call-template name="calc-scope-const-from-remark-worker">
835 <xsl:with-param name="sList" select="substring-after($sNormalized, ' ')"/>
836 </xsl:call-template>
837 </xsl:template>
838
839 <xsl:template name="calc-scope-const-from-remark-worker">
840 <xsl:param name="sList"/>
841 <xsl:if test="$sList != ''">
842 <xsl:choose>
843 <xsl:when test="substring-before($sList, ' ') = 'GLOBAL'">
844 <xsl:text>| RTMSGREFENTRYSTR_SCOPE_GLOBAL</xsl:text>
845 </xsl:when>
846 <xsl:otherwise>
847 <xsl:text> | HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sList, ' ')"/>
848 </xsl:otherwise>
849 </xsl:choose>
850 <xsl:call-template name="calc-scope-const-from-remark-worker">
851 <xsl:with-param name="sList" select="substring-after($sList, ' ')"/>
852 </xsl:call-template>
853 </xsl:if>
854 </xsl:template>
855
856
857 <!--
858 Calculates and emits indentation list markup.
859 -->
860 <xsl:template name="emit-indentation">
861 <xsl:variable name="iDepth" select="count(ancestor-or-self::*)"/>
862 <xsl:for-each select="ancestor-or-self::*">
863 <xsl:choose>
864
865 <xsl:when test="self::refsect1
866 | self::refsect2
867 | self::refsect3
868 | self::refsynopsisdiv">
869 <xsl:text> </xsl:text>
870 </xsl:when>
871
872 <xsl:when test="self::term">
873 <!-- currently no indent. -->
874 </xsl:when>
875
876 <!-- Evidence here (especially with orderedlist) that doing list by for-each
877 listitem in the template matching the list type would be easier... -->
878 <xsl:when test="self::listitem and parent::itemizedlist and (position() + 1) = $iDepth">
879 <xsl:text> - </xsl:text>
880 </xsl:when>
881
882 <xsl:when test="self::listitem and parent::orderedlist and (position() + 1) = $iDepth">
883 <xsl:variable name="iNumber" select="count(preceding-sibling::listitem) + 1"/>
884 <xsl:if test="$iNumber &lt;= 9">
885 <xsl:text> </xsl:text>
886 </xsl:if>
887 <xsl:value-of select="$iNumber"/>
888 <xsl:text>. </xsl:text>
889 </xsl:when>
890
891 <xsl:when test="self::listitem">
892 <xsl:text> </xsl:text>
893 </xsl:when>
894
895 </xsl:choose>
896 </xsl:for-each>
897 </xsl:template>
898
899 <!--
900 Captializes the given text.
901 -->
902 <xsl:template name="capitalize">
903 <xsl:param name="text"/>
904 <xsl:call-template name="str:to-upper">
905 <xsl:with-param name="text" select="substring($text,1,1)"/>
906 </xsl:call-template>
907 <xsl:value-of select="substring($text,2)"/>
908 </xsl:template>
909
910
911 <!--
912 Debug/Diagnostics: Return the path to the specified node (by default the current).
913 -->
914 <xsl:template name="get-node-path">
915 <xsl:param name="Node" select="."/>
916 <xsl:for-each select="$Node">
917 <xsl:for-each select="ancestor-or-self::node()">
918 <xsl:choose>
919 <xsl:when test="name(.) = ''">
920 <xsl:text>text()</xsl:text>
921 </xsl:when>
922 <xsl:otherwise>
923 <xsl:value-of select="concat('/', name(.))"/>
924 <xsl:choose>
925 <xsl:when test="@id">
926 <xsl:text>[@id=</xsl:text>
927 <xsl:value-of select="@id"/>
928 <xsl:text>]</xsl:text>
929 </xsl:when>
930 <xsl:when test="position() > 1">
931 <xsl:text>[</xsl:text><xsl:value-of select="position()"/><xsl:text>]</xsl:text>
932 </xsl:when>
933 </xsl:choose>
934 </xsl:otherwise>
935 </xsl:choose>
936 </xsl:for-each>
937 </xsl:for-each>
938 </xsl:template>
939
940 <!--
941 Debug/Diagnostics: Return error message prefix.
942 -->
943 <xsl:template name="error-prefix">
944 <xsl:param name="Node" select="."/>
945 <xsl:text>error: </xsl:text>
946 <xsl:call-template name="get-node-path">
947 <xsl:with-param name="Node" select="$Node"/>
948 </xsl:call-template>
949 <xsl:text>: </xsl:text>
950 </xsl:template>
951
952 <!--
953 Debug/Diagnostics: Print list of nodes (by default all children of current node).
954 -->
955 <xsl:template name="list-nodes">
956 <xsl:param name="Nodes" select="node()"/>
957 <xsl:for-each select="$Nodes">
958 <xsl:if test="position() != 1">
959 <xsl:text>, </xsl:text>
960 </xsl:if>
961 <xsl:choose>
962 <xsl:when test="name(.) = ''">
963 <xsl:text>text:text()</xsl:text>
964 </xsl:when>
965 <xsl:otherwise>
966 <xsl:value-of select="name(.)"/>
967 <xsl:if test="@id">
968 <xsl:text>[@id=</xsl:text>
969 <xsl:value-of select="@id"/>
970 <xsl:text>]</xsl:text>
971 </xsl:if>
972 </xsl:otherwise>
973 </xsl:choose>
974 </xsl:for-each>
975 </xsl:template>
976
977 <xsl:template name="check-children">
978 <xsl:param name="Node" select="."/>
979 <xsl:param name="UnsupportedNodes" select="*"/>
980 <xsl:param name="SupportedNames" select="'none'"/>
981 <xsl:if test="count($UnsupportedNodes) != 0">
982 <xsl:message terminate="yes">
983 <xsl:call-template name="get-node-path">
984 <xsl:with-param name="Node" select="$Node"/>
985 </xsl:call-template>
986 <!-- -->: error: Only <xsl:value-of select="$SupportedNames"/> are supported as children to <!-- -->
987 <xsl:value-of select="name($Node)"/>
988 <!-- -->
989Unsupported children: <!-- -->
990 <xsl:call-template name="list-nodes">
991 <xsl:with-param name="Nodes" select="$UnsupportedNodes"/>
992 </xsl:call-template>
993 </xsl:message>
994 </xsl:if>
995 </xsl:template>
996
997</xsl:stylesheet>
998
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