VirtualBox

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

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

scm copyright and license note update

  • 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: 37.4 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-2022 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
51 <!-- Sub-command style command (true) or single command (false). -->
52 <xsl:variable name="g_fSubCommands" select="not(not(//refsect2[@id]))" />
53
54 <!-- Translatable strings -->
55 <xsl:variable name="sUsage" select="'Usage'"/>
56 <xsl:variable name="sUsageUnderscore" select="'====='"/>
57
58
59 <!-- Default action, do nothing. -->
60 <xsl:template match="node()|@*"/>
61
62 <!--
63 main() - because we need to order the output in a specific manner
64 that is contrary to the data flow in the refentry, this is
65 going to look a bit more like a C program than a stylesheet.
66 -->
67 <xsl:template match="refentry">
68 <!-- Assert refetry expectations. -->
69 <xsl:if test="not(./refsynopsisdiv)">
70 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have a refsynopsisdiv</xsl:message>
71 </xsl:if>
72 <xsl:if test="not(./refentryinfo/title)">
73 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have a refentryinfo with title</xsl:message>
74 </xsl:if>
75 <xsl:if test="not(./refmeta/refentrytitle)">
76 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have a refentryinfo with title</xsl:message>
77 </xsl:if>
78 <xsl:if test="./refmeta/refentrytitle != ./refnamediv/refname">
79 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>The refmeta/refentrytitle and the refnamediv/refname must be identical</xsl:message>
80 </xsl:if>
81 <xsl:if test="not(./refsect1/title)">
82 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have a refsect1 with title</xsl:message>
83 </xsl:if>
84 <xsl:if test="not(@id) or @id = ''">
85 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have an id attribute</xsl:message>
86 </xsl:if>
87
88 <!-- variables -->
89 <xsl:variable name="sBaseId" select="@id"/>
90 <xsl:variable name="sDataBaseSym" select="concat('g_', translate(@id, '-', '_'))"/>
91
92
93 <!--
94 Convert the refsynopsisdiv into REFENTRY::Synopsis data.
95 -->
96 <xsl:text>
97
98static const RTMSGREFENTRYSTR </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis[] =
99{</xsl:text>
100 <xsl:for-each select="./refsynopsisdiv/cmdsynopsis">
101 <!-- Assert synopsis expectations -->
102 <xsl:if test="not(@id) or substring-before(@id, '-') != 'synopsis'">
103 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>The refsynopsisdiv/cmdsynopsis elements must have an id starting with 'synopsis-'.</xsl:message>
104 </xsl:if>
105 <xsl:if test="not(starts-with(substring-after(@id, '-'), $sBaseId))">
106 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>The refsynopsisdiv/cmdsynopsis elements @id is expected to include the refentry @id.</xsl:message>
107 </xsl:if>
108 <xsl:if test="not(../../refsect1/refsect2[@id=./@id]) and $g_fSubCommands">
109 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>No refsect2 with id="<xsl:value-of select="@id"/>" found.</xsl:message>
110 </xsl:if>
111
112 <!-- Do the work. -->
113 <xsl:apply-templates select="."/>
114
115 </xsl:for-each>
116 <xsl:text>
117};</xsl:text>
118
119
120 <!--
121 Convert the whole manpage to help text.
122 -->
123 <xsl:text>
124static const RTMSGREFENTRYSTR </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help[] =
125{</xsl:text>
126 <!-- We start by combining the refentry title and the refpurpose into a short description. -->
127 <xsl:text>
128 { </xsl:text><xsl:call-template name="calc-scope-for-refentry"/><xsl:text>,
129 "</xsl:text>
130 <xsl:apply-templates select="./refentryinfo/title/node()"/>
131 <xsl:text> -- </xsl:text>
132 <xsl:call-template name="capitalize">
133 <xsl:with-param name="text">
134 <xsl:apply-templates select="./refnamediv/refpurpose/node()"/>
135 </xsl:with-param>
136 </xsl:call-template>
137 <xsl:text>." },
138 { RTMSGREFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
139
140 <!-- The follows the usage (synopsis) section. -->
141 <xsl:text>
142 { RTMSGREFENTRYSTR_SCOPE_GLOBAL,
143 "</xsl:text><xsl:value-of select="$sUsage"/><xsl:text>" },
144 { RTMSGREFENTRYSTR_SCOPE_SAME,
145 "</xsl:text><xsl:value-of select="$sUsageUnderscore"/><xsl:text>" },</xsl:text>
146 <xsl:apply-templates select="./refsynopsisdiv/node()"/>
147
148 <!-- Then comes the description and other refsect1 -->
149 <xsl:for-each select="./refsect1">
150 <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>
151 <xsl:if test="text()"><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>No text supported in refsect1.</xsl:message></xsl:if>
152 <xsl:if test="not(./remark[@role='help-skip'])">
153 <xsl:variable name="sTitle">
154 <xsl:apply-templates select="./title/node()"/>
155 </xsl:variable>
156 <xsl:text>
157 { </xsl:text><xsl:call-template name="calc-scope-refsect1"/><xsl:text>, "" },
158 { RTMSGREFENTRYSTR_SCOPE_SAME,
159 "</xsl:text><xsl:value-of select="$sTitle"/><xsl:text>" },
160 { RTMSGREFENTRYSTR_SCOPE_SAME,
161 "</xsl:text>
162 <xsl:value-of select="substring($g_sUnderlineRefSect1, 1, string-length($sTitle))"/>
163 <xsl:text>" },</xsl:text>
164
165 <xsl:apply-templates select="./*[name() != 'title']"/>
166
167 <xsl:text>
168 { RTMSGREFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
169 </xsl:if>
170 </xsl:for-each>
171
172 <xsl:text>
173};</xsl:text>
174
175 <!--
176 Generate the refentry structure.
177 -->
178 <xsl:text>
179static const RTMSGREFENTRY </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text> =
180{
181 /* .idInternal = */ HELP_CMD_</xsl:text>
182 <xsl:choose>
183 <xsl:when test="contains(@id, '-')">
184 <xsl:call-template name="str:to-upper"> <!-- Multi level command. -->
185 <xsl:with-param name="text" select="translate(substring-after(@id, '-'), '-', '_')"/>
186 </xsl:call-template>
187 </xsl:when>
188 <xsl:otherwise>
189 <xsl:call-template name="str:to-upper"> <!-- Simple command. -->
190 <xsl:with-param name="text" select="@id"/>
191 </xsl:call-template>
192 </xsl:otherwise>
193 </xsl:choose>
194 <xsl:text>,
195 /* .Synopsis = */ { RT_ELEMENTS(</xsl:text>
196 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis), 0, </xsl:text>
197 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis },
198 /* .Help = */ { RT_ELEMENTS(</xsl:text>
199 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help), 0, </xsl:text>
200 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help },
201 /* pszBrief = */ "</xsl:text>
202 <xsl:apply-templates select="./refnamediv/refpurpose/node()"/>
203 <!-- TODO: Add the command name too. -->
204 <xsl:text>"
205};
206</xsl:text>
207 </xsl:template>
208
209
210 <!--
211 Convert command synopsis to text.
212 -->
213 <xsl:template match="cmdsynopsis">
214 <xsl:if test="text()"><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>cmdsynopsis with text is not supported.</xsl:message></xsl:if>
215 <xsl:if test="position() = 1">
216 <xsl:text>
217 { </xsl:text><xsl:call-template name="calc-scope-cmdsynopsis"/><xsl:text> | RTMSGREFENTRYSTR_FLAGS_SYNOPSIS, "" },</xsl:text>
218 </xsl:if>
219 <xsl:text>
220 { </xsl:text><xsl:call-template name="calc-scope-cmdsynopsis"/><xsl:text> | RTMSGREFENTRYSTR_FLAGS_SYNOPSIS,
221 "</xsl:text><xsl:call-template name="emit-indentation"/><xsl:apply-templates select="*|@*"/><xsl:text>" },</xsl:text>
222 </xsl:template>
223
224 <xsl:template match="sbr">
225 <xsl:text>" },
226 { RTMSGREFENTRYSTR_SCOPE_SAME | RTMSGREFENTRYSTR_FLAGS_SYNOPSIS,
227 " </xsl:text><xsl:call-template name="emit-indentation"/> <!-- hardcoded in VBoxManageHelp.cpp too -->
228 </xsl:template>
229
230 <xsl:template match="cmdsynopsis/command">
231 <xsl:text>" },
232 { RTMSGREFENTRYSTR_SCOPE_SAME | RTMSGREFENTRYSTR_FLAGS_SYNOPSIS,
233 "</xsl:text><xsl:call-template name="emit-indentation"/>
234 <xsl:apply-templates select="node()|@*"/>
235 </xsl:template>
236
237 <xsl:template match="cmdsynopsis/command[1]" priority="2">
238 <xsl:apply-templates select="node()|@*"/>
239 </xsl:template>
240
241 <xsl:template match="command|option|computeroutput|literal|emphasis|filename|citetitle|note">
242 <xsl:apply-templates select="node()|@*"/>
243 </xsl:template>
244
245 <xsl:template match="ulink">
246 <xsl:value-of select="@url"/>
247 </xsl:template>
248
249 <xsl:template match="replaceable">
250 <xsl:choose>
251 <xsl:when test="ancestor::arg">
252 <xsl:apply-templates />
253 </xsl:when>
254 <xsl:otherwise>
255 <xsl:text>&lt;</xsl:text>
256 <xsl:apply-templates />
257 <xsl:text>&gt;</xsl:text>
258 </xsl:otherwise>
259 </xsl:choose>
260 </xsl:template>
261
262 <!-- duplicated in docbook2latex.xsl -->
263 <xsl:template match="arg|group">
264 <!-- separator char if we're not the first child -->
265 <xsl:if test="position() > 1">
266 <xsl:choose>
267 <xsl:when test="parent::group"><xsl:value-of select="$arg.or.sep"/></xsl:when>
268 <xsl:when test="ancestor-or-self::*/@sepchar"><xsl:value-of select="ancestor-or-self::*/@sepchar"/></xsl:when>
269 <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
270 </xsl:choose>
271 </xsl:if>
272
273 <!-- open wrapping -->
274 <xsl:variable name="fWrappers" select="not(ancestor::group)"/>
275 <xsl:if test="$fWrappers">
276 <xsl:choose>
277 <xsl:when test="not(@choice) or @choice = ''"> <xsl:value-of select="$arg.choice.def.open.str"/></xsl:when>
278 <xsl:when test="@choice = 'opt'"> <xsl:value-of select="$arg.choice.opt.open.str"/></xsl:when>
279 <xsl:when test="@choice = 'req'"> <xsl:value-of select="$arg.choice.req.open.str"/></xsl:when>
280 <xsl:when test="@choice = 'plain'"/>
281 <xsl:otherwise><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Invalid arg choice: "<xsl:value-of select="@choice"/>"</xsl:message></xsl:otherwise>
282 </xsl:choose>
283 </xsl:if>
284
285 <!-- render the arg (TODO: may need to do more work here) -->
286 <xsl:apply-templates />
287
288 <!-- repeat wrapping -->
289 <xsl:choose>
290 <xsl:when test="@rep = 'norepeat' or not(@rep) or @rep = ''"/>
291 <xsl:when test="@rep = 'repeat'"> <xsl:value-of select="$arg.rep.repeat.str"/></xsl:when>
292 <xsl:otherwise><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Invalid rep choice: "<xsl:value-of select="@rep"/>"</xsl:message></xsl:otherwise>
293 </xsl:choose>
294
295 <!-- close wrapping -->
296 <xsl:if test="$fWrappers">
297 <xsl:choose>
298 <xsl:when test="not(@choice) or @choice = ''"> <xsl:value-of select="$arg.choice.def.close.str"/></xsl:when>
299 <xsl:when test="@choice = 'opt'"> <xsl:value-of select="$arg.choice.opt.close.str"/></xsl:when>
300 <xsl:when test="@choice = 'req'"> <xsl:value-of select="$arg.choice.req.close.str"/></xsl:when>
301 </xsl:choose>
302 <!-- Add a space padding if we're the last element in a repeating arg or group -->
303 <xsl:if test="(parent::arg or parent::group) and not(following-sibiling)">
304 <xsl:text> </xsl:text>
305 </xsl:if>
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
497 <!--
498 Text escaping for C.
499 -->
500 <xsl:template match="text()" name="escape_text">
501 <!-- Leading whitespace hack! -->
502 <xsl:if test="substring(.,1,1) = ' ' and position() != 1">
503 <xsl:text> </xsl:text>
504 <xsl:if test="boolean($g_fDebugText)">
505 <xsl:message>text: add space</xsl:message>
506 </xsl:if>
507 </xsl:if>
508
509 <!-- Body of text -->
510 <xsl:choose>
511
512 <xsl:when test="contains(., '\') or contains(., '&quot;')">
513 <xsl:variable name="sTmp">
514 <xsl:call-template name="str:subst">
515 <xsl:with-param name="text" select="normalize-space(.)"/>
516 <xsl:with-param name="replace" select="'\'"/>
517 <xsl:with-param name="with" select="'\\'"/>
518 <xsl:with-param name="disable-output-escaping" select="yes"/>
519 </xsl:call-template>
520 </xsl:variable>
521 <xsl:variable name="sTmp2">
522 <xsl:call-template name="str:subst">
523 <xsl:with-param name="text" select="$sTmp"/>
524 <xsl:with-param name="replace" select="'&quot;'"/>
525 <xsl:with-param name="with" select="'\&quot;'"/>
526 <xsl:with-param name="disable-output-escaping" select="yes"/>
527 </xsl:call-template>
528 </xsl:variable>
529 <xsl:value-of select="$sTmp2"/>
530 <xsl:if test="boolean($g_fDebugText)">
531 <xsl:message>text: |<xsl:value-of select="$sTmp2"/>|</xsl:message>
532 </xsl:if>
533 </xsl:when>
534
535 <xsl:otherwise>
536 <xsl:value-of select="normalize-space(.)"/>
537 <xsl:if test="boolean($g_fDebugText)">
538 <xsl:message>text: |<xsl:value-of select="normalize-space(.)"/>|</xsl:message>
539 </xsl:if>
540 </xsl:otherwise>
541 </xsl:choose>
542
543 <!-- Trailing whitespace hack! -->
544 <xsl:if test="substring(.,string-length(.)) = ' ' and position() != last() and string-length(.) != 1">
545 <xsl:text> </xsl:text>
546 <xsl:if test="boolean($g_fDebugText)">
547 <xsl:message>text: add space</xsl:message>
548 </xsl:if>
549 </xsl:if>
550
551 </xsl:template>
552
553 <!-- Elements producing non-breaking strings (single line). -->
554 <xsl:template match="command/text()|option/text()|computeroutput/text()|arg/text()|filename/text()" name="escape_fixed_text">
555 <xsl:param name="sText" select="normalize-space(.)"/>
556 <xsl:choose>
557
558 <xsl:when test="contains($sText, '\') or contains($sText, '&quot;')">
559 <xsl:variable name="sTmp1">
560 <xsl:call-template name="str:subst">
561 <xsl:with-param name="text" select="$sText"/>
562 <xsl:with-param name="replace" select="'\'"/>
563 <xsl:with-param name="with" select="'\\'"/>
564 <xsl:with-param name="disable-output-escaping" select="yes"/>
565 </xsl:call-template>
566 </xsl:variable>
567 <xsl:variable name="sTmp2">
568 <xsl:call-template name="str:subst">
569 <xsl:with-param name="text" select="$sTmp1"/>
570 <xsl:with-param name="replace" select="'&quot;'"/>
571 <xsl:with-param name="with" select="'\&quot;'"/>
572 <xsl:with-param name="disable-output-escaping" select="yes"/>
573 </xsl:call-template>
574 </xsl:variable>
575 <xsl:variable name="sTmp3">
576 <xsl:call-template name="str:subst">
577 <xsl:with-param name="text" select="$sTmp2"/>
578 <xsl:with-param name="replace" select="' '"/>
579 <xsl:with-param name="with" select="'\b'"/>
580 <xsl:with-param name="disable-output-escaping" select="yes"/>
581 </xsl:call-template>
582 </xsl:variable>
583 <xsl:value-of select="$sTmp3"/>
584 <xsl:if test="boolean($g_fDebugText)">
585 <xsl:message>text! |<xsl:value-of select="$sTmp3"/>|</xsl:message>
586 </xsl:if>
587 </xsl:when>
588
589 <xsl:when test="contains($sText, ' ')">
590 <xsl:variable name="sTmp">
591 <xsl:call-template name="str:subst">
592 <xsl:with-param name="text" select="$sText"/>
593 <xsl:with-param name="replace" select="' '"/>
594 <xsl:with-param name="with" select="'\b'"/>
595 <xsl:with-param name="disable-output-escaping" select="yes"/>
596 </xsl:call-template>
597 </xsl:variable>
598 <xsl:value-of select="$sTmp"/>
599 <xsl:if test="boolean($g_fDebugText)">
600 <xsl:message>text! |<xsl:value-of select="$sTmp"/>|</xsl:message>
601 </xsl:if>
602 </xsl:when>
603
604 <xsl:otherwise>
605 <xsl:value-of select="$sText"/>
606 <xsl:if test="boolean($g_fDebugText)">
607 <xsl:message>text! |<xsl:value-of select="$sText"/>|</xsl:message>
608 </xsl:if>
609 </xsl:otherwise>
610 </xsl:choose>
611 </xsl:template>
612
613
614 <!--
615 Unsupported elements and elements handled directly.
616 -->
617 <xsl:template match="synopfragment|synopfragmentref|title|refsect1">
618 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>The <xsl:value-of select="name()"/> element is not supported</xsl:message>
619 </xsl:template>
620
621 <xsl:template match="xref">
622 <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>
623 </xsl:template>
624
625 <!--
626 Fail on misplaced scoping remarks.
627 -->
628 <xsl:template match="remark[@role = 'help-scope']">
629 <xsl:choose>
630 <xsl:when test="parent::refsect1"/>
631 <xsl:when test="parent::refsect2"/>
632 <xsl:when test="parent::cmdsynopsis and ancestor::refsynopsisdiv"/>
633 <xsl:otherwise>
634 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Misplaced remark/@role=help-scope element.
635Only supported on: refsect1, refsect2, refsynopsisdiv/cmdsynopsis</xsl:message>
636 </xsl:otherwise>
637 </xsl:choose>
638 </xsl:template>
639
640 <!--
641 Execute synopsis copy remark (avoids duplication for complicated xml).
642 -->
643 <xsl:template match="remark[@role = 'help-copy-synopsis']">
644 <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>
645 </xsl:template>
646
647 <!--
648 Warn about unhandled elements
649 -->
650 <xsl:template match="*">
651 <xsl:message terminate="no">Warning: Unhandled element: <!-- no newline -->
652 <xsl:for-each select="ancestor-or-self::*">
653 <xsl:text>/</xsl:text>
654 <xsl:value-of select="name(.)"/>
655 <xsl:if test="@id">
656 <xsl:value-of select="concat('[id=', @id ,']')"/>
657 </xsl:if>
658 </xsl:for-each>
659 </xsl:message>
660 </xsl:template>
661
662
663 <!--
664 Functions
665 Functions
666 Functions
667 -->
668
669 <!--
670 Processes mixed children, i.e. both text and regular elements.
671 Normalizes whitespace. -->
672 <xsl:template name="process-mixed">
673 <xsl:text>
674 { RTMSGREFENTRYSTR_SCOPE_SAME,
675 "</xsl:text><xsl:call-template name="emit-indentation"/>
676
677 <xsl:for-each select="node()[not(self::remark)]">
678 <xsl:choose>
679 <xsl:when test="name() = ''">
680 <xsl:call-template name="escape_text"/>
681 </xsl:when>
682 <xsl:otherwise>
683 <xsl:apply-templates select="."/>
684 </xsl:otherwise>
685 </xsl:choose>
686 </xsl:for-each>
687
688 <xsl:text>" },</xsl:text>
689 </xsl:template>
690
691
692 <!--
693 Element specific scoping.
694 -->
695
696 <xsl:template name="calc-scope-for-refentry">
697 <xsl:text>HELP_SCOPE_</xsl:text>
698 <xsl:choose>
699 <xsl:when test="contains(@id, '-')"> <!-- Multi level command. -->
700 <xsl:call-template name="str:to-upper">
701 <xsl:with-param name="text" select="translate(substring-after(@id, '-'), '-', '_')"/>
702 </xsl:call-template>
703 </xsl:when>
704 <xsl:otherwise> <!-- Single command. -->
705 <xsl:call-template name="str:to-upper">
706 <xsl:with-param name="text" select="@id"/>
707 </xsl:call-template>
708 </xsl:otherwise>
709 </xsl:choose>
710 </xsl:template>
711
712 <!-- Figures out the scope of a refsect1 element. -->
713 <xsl:template name="calc-scope-refsect1">
714 <xsl:choose>
715 <xsl:when test="title[text() = 'Description']">
716 <xsl:text>RTMSGREFENTRYSTR_SCOPE_GLOBAL</xsl:text>
717 </xsl:when>
718 <xsl:when test="@id or remark[@role='help-scope']">
719 <xsl:call-template name="calc-scope-from-remark-or-id"/>
720 </xsl:when>
721 <xsl:otherwise>
722 <xsl:text>RTMSGREFENTRYSTR_SCOPE_GLOBAL</xsl:text>
723 </xsl:otherwise>
724 </xsl:choose>
725 </xsl:template>
726
727 <!-- Figures out the scope of a refsect2 element. -->
728 <xsl:template name="calc-scope-refsect2">
729 <xsl:choose>
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_SAME</xsl:text>
735 </xsl:otherwise>
736 </xsl:choose>
737 </xsl:template>
738
739 <!-- Figures out the scope of a refsect1 element. -->
740 <xsl:template name="calc-scope-cmdsynopsis">
741 <xsl:choose>
742 <xsl:when test="ancestor::refsynopsisdiv">
743 <xsl:call-template name="calc-scope-from-remark-or-id">
744 <xsl:with-param name="sId" select="substring-after(@id, '-')"/>
745 </xsl:call-template>
746 </xsl:when>
747 <xsl:otherwise>
748 <xsl:text>RTMSGREFENTRYSTR_SCOPE_SAME</xsl:text>
749 </xsl:otherwise>
750 </xsl:choose>
751 </xsl:template>
752
753
754 <!--
755 Scoping worker functions.
756 -->
757
758 <!-- Calculates the current scope from the scope remark or @id. -->
759 <xsl:template name="calc-scope-from-remark-or-id">
760 <xsl:param name="sId" select="@id"/>
761 <xsl:choose>
762 <xsl:when test="remark[@role='help-scope']">
763 <xsl:call-template name="calc-scope-consts-from-remark"/>
764 </xsl:when>
765 <xsl:when test="$sId != ''">
766 <xsl:call-template name="calc-scope-const-from-id">
767 <xsl:with-param name="sId" select="$sId"/>
768 </xsl:call-template>
769 </xsl:when>
770 <xsl:otherwise>
771 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>expected remark child or id attribute.</xsl:message>
772 </xsl:otherwise>
773 </xsl:choose>
774 </xsl:template>
775
776 <!-- Turns a @id into a scope constant.
777 Some woodoo taking place here here that chops the everything up to and
778 including the first refentry/@id word from all IDs before turning them into
779 constants (word delimiter '-'). -->
780 <xsl:template name="calc-scope-const-from-id">
781 <xsl:param name="sId" select="@id"/>
782 <xsl:param name="sAncestorId" select="ancestor::refentry/@id"/>
783 <xsl:text>HELP_SCOPE_</xsl:text>
784 <xsl:choose>
785 <xsl:when test="not($sAncestorId)"> <!-- Sanity check. -->
786 <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>
787 </xsl:when>
788
789 <xsl:when test="contains($sAncestorId, '-')"> <!-- Multi level command. -->
790 <xsl:variable name="sPrefix" select="concat(substring-before($sAncestorId, '-'), '-')"/>
791 <xsl:if test="not(contains($sId, $sPrefix))">
792 <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>
793 </xsl:if>
794 <xsl:call-template name="str:to-upper">
795 <xsl:with-param name="text" select="translate(substring-after($sId, $sPrefix), '-', '_')"/>
796 </xsl:call-template>
797 </xsl:when>
798
799 <xsl:otherwise> <!-- Single command. -->
800 <xsl:call-template name="str:to-upper">
801 <xsl:with-param name="text" select="translate($sId, '-', '_')"/>
802 </xsl:call-template>
803 </xsl:otherwise>
804 </xsl:choose>
805 </xsl:template>
806
807 <!-- Turns a remark into one or more scope constants. -->
808 <xsl:template name="calc-scope-consts-from-remark">
809 <xsl:param name="sCondition" select="remark/@condition"/>
810 <xsl:variable name="sNormalized" select="concat(normalize-space(translate($sCondition, ',;:|', ' ')), ' ')"/>
811 <xsl:if test="$sNormalized = ' ' or $sNormalized = ''">
812 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Empty @condition for help-scope remark.</xsl:message>
813 </xsl:if>
814 <xsl:choose>
815 <xsl:when test="substring-before($sNormalized, ' ') = 'GLOBAL'">
816 <xsl:text>RTMSGREFENTRYSTR_SCOPE_GLOBAL</xsl:text>
817 </xsl:when>
818 <xsl:otherwise>
819 <xsl:text>HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sNormalized, ' ')"/>
820 </xsl:otherwise>
821 </xsl:choose>
822 <xsl:call-template name="calc-scope-const-from-remark-worker">
823 <xsl:with-param name="sList" select="substring-after($sNormalized, ' ')"/>
824 </xsl:call-template>
825 </xsl:template>
826
827 <xsl:template name="calc-scope-const-from-remark-worker">
828 <xsl:param name="sList"/>
829 <xsl:if test="$sList != ''">
830 <xsl:choose>
831 <xsl:when test="substring-before($sList, ' ') = 'GLOBAL'">
832 <xsl:text>| RTMSGREFENTRYSTR_SCOPE_GLOBAL</xsl:text>
833 </xsl:when>
834 <xsl:otherwise>
835 <xsl:text> | HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sList, ' ')"/>
836 </xsl:otherwise>
837 </xsl:choose>
838 <xsl:call-template name="calc-scope-const-from-remark-worker">
839 <xsl:with-param name="sList" select="substring-after($sList, ' ')"/>
840 </xsl:call-template>
841 </xsl:if>
842 </xsl:template>
843
844
845 <!--
846 Calculates and emits indentation list markup.
847 -->
848 <xsl:template name="emit-indentation">
849 <xsl:variable name="iDepth" select="count(ancestor-or-self::*)"/>
850 <xsl:for-each select="ancestor-or-self::*">
851 <xsl:choose>
852
853 <xsl:when test="self::refsect1
854 | self::refsect2
855 | self::refsect3
856 | self::refsynopsisdiv">
857 <xsl:text> </xsl:text>
858 </xsl:when>
859
860 <xsl:when test="self::term">
861 <!-- currently no indent. -->
862 </xsl:when>
863
864 <!-- Evidence here (especially with orderedlist) that doing list by for-each
865 listitem in the template matching the list type would be easier... -->
866 <xsl:when test="self::listitem and parent::itemizedlist and (position() + 1) = $iDepth">
867 <xsl:text> - </xsl:text>
868 </xsl:when>
869
870 <xsl:when test="self::listitem and parent::orderedlist and (position() + 1) = $iDepth">
871 <xsl:variable name="iNumber" select="count(preceding-sibling::listitem) + 1"/>
872 <xsl:if test="$iNumber &lt;= 9">
873 <xsl:text> </xsl:text>
874 </xsl:if>
875 <xsl:value-of select="$iNumber"/>
876 <xsl:text>. </xsl:text>
877 </xsl:when>
878
879 <xsl:when test="self::listitem">
880 <xsl:text> </xsl:text>
881 </xsl:when>
882
883 </xsl:choose>
884 </xsl:for-each>
885 </xsl:template>
886
887 <!--
888 Captializes the given text.
889 -->
890 <xsl:template name="capitalize">
891 <xsl:param name="text"/>
892 <xsl:call-template name="str:to-upper">
893 <xsl:with-param name="text" select="substring($text,1,1)"/>
894 </xsl:call-template>
895 <xsl:value-of select="substring($text,2)"/>
896 </xsl:template>
897
898
899 <!--
900 Debug/Diagnostics: Return the path to the specified node (by default the current).
901 -->
902 <xsl:template name="get-node-path">
903 <xsl:param name="Node" select="."/>
904 <xsl:for-each select="$Node">
905 <xsl:for-each select="ancestor-or-self::node()">
906 <xsl:choose>
907 <xsl:when test="name(.) = ''">
908 <xsl:text>text()</xsl:text>
909 </xsl:when>
910 <xsl:otherwise>
911 <xsl:value-of select="concat('/', name(.))"/>
912 <xsl:choose>
913 <xsl:when test="@id">
914 <xsl:text>[@id=</xsl:text>
915 <xsl:value-of select="@id"/>
916 <xsl:text>]</xsl:text>
917 </xsl:when>
918 <xsl:when test="position() > 1">
919 <xsl:text>[</xsl:text><xsl:value-of select="position()"/><xsl:text>]</xsl:text>
920 </xsl:when>
921 </xsl:choose>
922 </xsl:otherwise>
923 </xsl:choose>
924 </xsl:for-each>
925 </xsl:for-each>
926 </xsl:template>
927
928 <!--
929 Debug/Diagnostics: Return error message prefix.
930 -->
931 <xsl:template name="error-prefix">
932 <xsl:param name="Node" select="."/>
933 <xsl:text>error: </xsl:text>
934 <xsl:call-template name="get-node-path">
935 <xsl:with-param name="Node" select="$Node"/>
936 </xsl:call-template>
937 <xsl:text>: </xsl:text>
938 </xsl:template>
939
940 <!--
941 Debug/Diagnostics: Print list of nodes (by default all children of current node).
942 -->
943 <xsl:template name="list-nodes">
944 <xsl:param name="Nodes" select="node()"/>
945 <xsl:for-each select="$Nodes">
946 <xsl:if test="position() != 1">
947 <xsl:text>, </xsl:text>
948 </xsl:if>
949 <xsl:choose>
950 <xsl:when test="name(.) = ''">
951 <xsl:text>text:text()</xsl:text>
952 </xsl:when>
953 <xsl:otherwise>
954 <xsl:value-of select="name(.)"/>
955 <xsl:if test="@id">
956 <xsl:text>[@id=</xsl:text>
957 <xsl:value-of select="@id"/>
958 <xsl:text>]</xsl:text>
959 </xsl:if>
960 </xsl:otherwise>
961 </xsl:choose>
962 </xsl:for-each>
963 </xsl:template>
964
965 <xsl:template name="check-children">
966 <xsl:param name="Node" select="."/>
967 <xsl:param name="UnsupportedNodes" select="*"/>
968 <xsl:param name="SupportedNames" select="'none'"/>
969 <xsl:if test="count($UnsupportedNodes) != 0">
970 <xsl:message terminate="yes">
971 <xsl:call-template name="get-node-path">
972 <xsl:with-param name="Node" select="$Node"/>
973 </xsl:call-template>
974 <!-- -->: error: Only <xsl:value-of select="$SupportedNames"/> are supported as children to <!-- -->
975 <xsl:value-of select="name($Node)"/>
976 <!-- -->
977Unsupported children: <!-- -->
978 <xsl:call-template name="list-nodes">
979 <xsl:with-param name="Nodes" select="$UnsupportedNodes"/>
980 </xsl:call-template>
981 </xsl:message>
982 </xsl:if>
983 </xsl:template>
984
985</xsl:stylesheet>
986
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