VirtualBox

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

Last change on this file since 86692 was 85665, checked in by vboxsync, 4 years ago

VBoxManage: Converted the sharedfolder command to RTGetOpt and refentry help. ticketref:19800

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