VirtualBox

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

Last change on this file since 93585 was 92824, checked in by vboxsync, 3 years ago

Main: bugref:1909: Added handling built-in docbook help for languages other than en_US in the VBoxManage

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