VirtualBox

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

Last change on this file since 81067 was 79609, checked in by vboxsync, 5 years ago

man_VBoxManage-clonemv.xml,xsl: Using a 'group' for alternative --mode parameter values doesn't match other nested group uses very well, so changed that to spell it out in full instead, at least for now. (need it for dhcpserver, or at least thought I did.) Also found that the 'arg|group' template in the latex and C-help stylesheets had gotten out of sync. bugref:9288

  • 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.0 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-2015 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">
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 <xsl:call-template name="escape_fixed_text">
452 <xsl:with-param name="sText" select="substring-before($sText,'&#x0a;')"/>
453 </xsl:call-template>
454
455 <xsl:if test="substring-after($sText,'&#x0a;')">
456 <xsl:text>" },
457 { RTMSGREFENTRYSTR_SCOPE_SAME,
458 "</xsl:text>
459 <xsl:call-template name="screen_text_line">
460 <xsl:with-param name="sText" select="substring-after($sText,'&#x0a;')"/>
461 </xsl:call-template>
462 </xsl:if>
463 </xsl:template>
464
465
466 <!--
467 Text escaping for C.
468 -->
469 <xsl:template match="text()" name="escape_text">
470 <!-- Leading whitespace hack! -->
471 <xsl:if test="substring(.,1,1) = ' ' and position() != 1">
472 <xsl:text> </xsl:text>
473 <xsl:if test="boolean($g_fDebugText)">
474 <xsl:message>text: add space</xsl:message>
475 </xsl:if>
476 </xsl:if>
477
478 <!-- Body of text -->
479 <xsl:choose>
480
481 <xsl:when test="contains(., '\') or contains(., '&quot;')">
482 <xsl:variable name="sTmp">
483 <xsl:call-template name="str:subst">
484 <xsl:with-param name="text" select="normalize-space(.)"/>
485 <xsl:with-param name="replace" select="'\'"/>
486 <xsl:with-param name="with" select="'\\'"/>
487 <xsl:with-param name="disable-output-escaping" select="yes"/>
488 </xsl:call-template>
489 </xsl:variable>
490 <xsl:variable name="sTmp2">
491 <xsl:call-template name="str:subst">
492 <xsl:with-param name="text" select="$sTmp"/>
493 <xsl:with-param name="replace" select="'&quot;'"/>
494 <xsl:with-param name="with" select="'\&quot;'"/>
495 <xsl:with-param name="disable-output-escaping" select="yes"/>
496 </xsl:call-template>
497 </xsl:variable>
498 <xsl:value-of select="$sTmp2"/>
499 <xsl:if test="boolean($g_fDebugText)">
500 <xsl:message>text: |<xsl:value-of select="$sTmp2"/>|</xsl:message>
501 </xsl:if>
502 </xsl:when>
503
504 <xsl:otherwise>
505 <xsl:value-of select="normalize-space(.)"/>
506 <xsl:if test="boolean($g_fDebugText)">
507 <xsl:message>text: |<xsl:value-of select="normalize-space(.)"/>|</xsl:message>
508 </xsl:if>
509 </xsl:otherwise>
510 </xsl:choose>
511
512 <!-- Trailing whitespace hack! -->
513 <xsl:if test="substring(.,string-length(.)) = ' ' and position() != last() and string-length(.) != 1">
514 <xsl:text> </xsl:text>
515 <xsl:if test="boolean($g_fDebugText)">
516 <xsl:message>text: add space</xsl:message>
517 </xsl:if>
518 </xsl:if>
519
520 </xsl:template>
521
522 <!-- Elements producing non-breaking strings (single line). -->
523 <xsl:template match="command/text()|option/text()|computeroutput/text()|arg/text()" name="escape_fixed_text">
524 <xsl:param name="sText" select="normalize-space(.)"/>
525 <xsl:choose>
526
527 <xsl:when test="contains($sText, '\') or contains($sText, '&quot;')">
528 <xsl:variable name="sTmp1">
529 <xsl:call-template name="str:subst">
530 <xsl:with-param name="text" select="$sText"/>
531 <xsl:with-param name="replace" select="'\'"/>
532 <xsl:with-param name="with" select="'\\'"/>
533 <xsl:with-param name="disable-output-escaping" select="yes"/>
534 </xsl:call-template>
535 </xsl:variable>
536 <xsl:variable name="sTmp2">
537 <xsl:call-template name="str:subst">
538 <xsl:with-param name="text" select="$sTmp1"/>
539 <xsl:with-param name="replace" select="'&quot;'"/>
540 <xsl:with-param name="with" select="'\&quot;'"/>
541 <xsl:with-param name="disable-output-escaping" select="yes"/>
542 </xsl:call-template>
543 </xsl:variable>
544 <xsl:variable name="sTmp3">
545 <xsl:call-template name="str:subst">
546 <xsl:with-param name="text" select="$sTmp2"/>
547 <xsl:with-param name="replace" select="' '"/>
548 <xsl:with-param name="with" select="'\b'"/>
549 <xsl:with-param name="disable-output-escaping" select="yes"/>
550 </xsl:call-template>
551 </xsl:variable>
552 <xsl:value-of select="$sTmp3"/>
553 <xsl:if test="boolean($g_fDebugText)">
554 <xsl:message>text! |<xsl:value-of select="$sTmp3"/>|</xsl:message>
555 </xsl:if>
556 </xsl:when>
557
558 <xsl:when test="contains($sText, ' ')">
559 <xsl:variable name="sTmp">
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="'\b'"/>
564 <xsl:with-param name="disable-output-escaping" select="yes"/>
565 </xsl:call-template>
566 </xsl:variable>
567 <xsl:value-of select="$sTmp"/>
568 <xsl:if test="boolean($g_fDebugText)">
569 <xsl:message>text! |<xsl:value-of select="$sTmp"/>|</xsl:message>
570 </xsl:if>
571 </xsl:when>
572
573 <xsl:otherwise>
574 <xsl:value-of select="$sText"/>
575 <xsl:if test="boolean($g_fDebugText)">
576 <xsl:message>text! |<xsl:value-of select="$sText"/>|</xsl:message>
577 </xsl:if>
578 </xsl:otherwise>
579 </xsl:choose>
580 </xsl:template>
581
582
583 <!--
584 Unsupported elements and elements handled directly.
585 -->
586 <xsl:template match="synopfragment|synopfragmentref|title|refsect1">
587 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>The <xsl:value-of select="name()"/> element is not supported</xsl:message>
588 </xsl:template>
589
590 <!--
591 Fail on misplaced scoping remarks.
592 -->
593 <xsl:template match="remark[@role = 'help-scope']">
594 <xsl:choose>
595 <xsl:when test="parent::refsect1"/>
596 <xsl:when test="parent::refsect2"/>
597 <xsl:when test="parent::cmdsynopsis and ancestor::refsynopsisdiv"/>
598 <xsl:otherwise>
599 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Misplaced remark/@role=help-scope element.
600Only supported on: refsect1, refsect2, refsynopsisdiv/cmdsynopsis</xsl:message>
601 </xsl:otherwise>
602 </xsl:choose>
603 </xsl:template>
604
605 <!--
606 Execute synopsis copy remark (avoids duplication for complicated xml).
607 -->
608 <xsl:template match="remark[@role = 'help-copy-synopsis']">
609 <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>
610 </xsl:template>
611
612 <!--
613 Warn about unhandled elements
614 -->
615 <xsl:template match="*">
616 <xsl:message terminate="no">Warning: Unhandled element: <!-- no newline -->
617 <xsl:for-each select="ancestor-or-self::*">
618 <xsl:text>/</xsl:text>
619 <xsl:value-of select="name(.)"/>
620 <xsl:if test="@id">
621 <xsl:value-of select="concat('[id=', @id ,']')"/>
622 </xsl:if>
623 </xsl:for-each>
624 </xsl:message>
625 </xsl:template>
626
627
628 <!--
629 Functions
630 Functions
631 Functions
632 -->
633
634 <!--
635 Processes mixed children, i.e. both text and regular elements.
636 Normalizes whitespace. -->
637 <xsl:template name="process-mixed">
638 <xsl:text>
639 { RTMSGREFENTRYSTR_SCOPE_SAME,
640 "</xsl:text><xsl:call-template name="emit-indentation"/>
641
642 <xsl:for-each select="node()[not(self::remark)]">
643 <xsl:choose>
644 <xsl:when test="name() = ''">
645 <xsl:call-template name="escape_text"/>
646 </xsl:when>
647 <xsl:otherwise>
648 <xsl:apply-templates select="."/>
649 </xsl:otherwise>
650 </xsl:choose>
651 </xsl:for-each>
652
653 <xsl:text>" },</xsl:text>
654 </xsl:template>
655
656
657 <!--
658 Element specific scoping.
659 -->
660
661 <xsl:template name="calc-scope-for-refentry">
662 <xsl:text>HELP_SCOPE_</xsl:text>
663 <xsl:choose>
664 <xsl:when test="contains(@id, '-')"> <!-- Multi level command. -->
665 <xsl:call-template name="str:to-upper">
666 <xsl:with-param name="text" select="translate(substring-after(@id, '-'), '-', '_')"/>
667 </xsl:call-template>
668 </xsl:when>
669 <xsl:otherwise> <!-- Single command. -->
670 <xsl:call-template name="str:to-upper">
671 <xsl:with-param name="text" select="@id"/>
672 </xsl:call-template>
673 </xsl:otherwise>
674 </xsl:choose>
675 </xsl:template>
676
677 <!-- Figures out the scope of a refsect1 element. -->
678 <xsl:template name="calc-scope-refsect1">
679 <xsl:choose>
680 <xsl:when test="title[text() = 'Description']">
681 <xsl:text>RTMSGREFENTRYSTR_SCOPE_GLOBAL</xsl:text>
682 </xsl:when>
683 <xsl:when test="@id or remark[@role='help-scope']">
684 <xsl:call-template name="calc-scope-from-remark-or-id"/>
685 </xsl:when>
686 <xsl:otherwise>
687 <xsl:text>RTMSGREFENTRYSTR_SCOPE_GLOBAL</xsl:text>
688 </xsl:otherwise>
689 </xsl:choose>
690 </xsl:template>
691
692 <!-- Figures out the scope of a refsect2 element. -->
693 <xsl:template name="calc-scope-refsect2">
694 <xsl:choose>
695 <xsl:when test="@id or remark[@role='help-scope']">
696 <xsl:call-template name="calc-scope-from-remark-or-id"/>
697 </xsl:when>
698 <xsl:otherwise>
699 <xsl:text>RTMSGREFENTRYSTR_SCOPE_SAME</xsl:text>
700 </xsl:otherwise>
701 </xsl:choose>
702 </xsl:template>
703
704 <!-- Figures out the scope of a refsect1 element. -->
705 <xsl:template name="calc-scope-cmdsynopsis">
706 <xsl:choose>
707 <xsl:when test="ancestor::refsynopsisdiv">
708 <xsl:call-template name="calc-scope-from-remark-or-id">
709 <xsl:with-param name="sId" select="substring-after(@id, '-')"/>
710 </xsl:call-template>
711 </xsl:when>
712 <xsl:otherwise>
713 <xsl:text>RTMSGREFENTRYSTR_SCOPE_SAME</xsl:text>
714 </xsl:otherwise>
715 </xsl:choose>
716 </xsl:template>
717
718
719 <!--
720 Scoping worker functions.
721 -->
722
723 <!-- Calculates the current scope from the scope remark or @id. -->
724 <xsl:template name="calc-scope-from-remark-or-id">
725 <xsl:param name="sId" select="@id"/>
726 <xsl:choose>
727 <xsl:when test="remark[@role='help-scope']">
728 <xsl:call-template name="calc-scope-consts-from-remark"/>
729 </xsl:when>
730 <xsl:when test="$sId != ''">
731 <xsl:call-template name="calc-scope-const-from-id">
732 <xsl:with-param name="sId" select="$sId"/>
733 </xsl:call-template>
734 </xsl:when>
735 <xsl:otherwise>
736 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>expected remark child or id attribute.</xsl:message>
737 </xsl:otherwise>
738 </xsl:choose>
739 </xsl:template>
740
741 <!-- Turns a @id into a scope constant.
742 Some woodoo taking place here here that chops the everything up to and
743 including the first refentry/@id word from all IDs before turning them into
744 constants (word delimiter '-'). -->
745 <xsl:template name="calc-scope-const-from-id">
746 <xsl:param name="sId" select="@id"/>
747 <xsl:param name="sAncestorId" select="ancestor::refentry/@id"/>
748 <xsl:text>HELP_SCOPE_</xsl:text>
749 <xsl:choose>
750 <xsl:when test="not($sAncestorId)"> <!-- Sanity check. -->
751 <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>
752 </xsl:when>
753
754 <xsl:when test="contains($sAncestorId, '-')"> <!-- Multi level command. -->
755 <xsl:variable name="sPrefix" select="concat(substring-before($sAncestorId, '-'), '-')"/>
756 <xsl:if test="not(contains($sId, $sPrefix))">
757 <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>
758 </xsl:if>
759 <xsl:call-template name="str:to-upper">
760 <xsl:with-param name="text" select="translate(substring-after($sId, $sPrefix), '-', '_')"/>
761 </xsl:call-template>
762 </xsl:when>
763
764 <xsl:otherwise> <!-- Single command. -->
765 <xsl:call-template name="str:to-upper">
766 <xsl:with-param name="text" select="translate($sId, '-', '_')"/>
767 </xsl:call-template>
768 </xsl:otherwise>
769 </xsl:choose>
770 </xsl:template>
771
772 <!-- Turns a remark into one or more scope constants. -->
773 <xsl:template name="calc-scope-consts-from-remark">
774 <xsl:param name="sCondition" select="remark/@condition"/>
775 <xsl:variable name="sNormalized" select="concat(normalize-space(translate($sCondition, ',;:|', ' ')), ' ')"/>
776 <xsl:if test="$sNormalized = ' ' or $sNormalized = ''">
777 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Empty @condition for help-scope remark.</xsl:message>
778 </xsl:if>
779 <xsl:choose>
780 <xsl:when test="substring-before($sNormalized, ' ') = 'GLOBAL'">
781 <xsl:text>RTMSGREFENTRYSTR_SCOPE_GLOBAL</xsl:text>
782 </xsl:when>
783 <xsl:otherwise>
784 <xsl:text>HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sNormalized, ' ')"/>
785 </xsl:otherwise>
786 </xsl:choose>
787 <xsl:call-template name="calc-scope-const-from-remark-worker">
788 <xsl:with-param name="sList" select="substring-after($sNormalized, ' ')"/>
789 </xsl:call-template>
790 </xsl:template>
791
792 <xsl:template name="calc-scope-const-from-remark-worker">
793 <xsl:param name="sList"/>
794 <xsl:if test="$sList != ''">
795 <xsl:choose>
796 <xsl:when test="substring-before($sList, ' ') = '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($sList, ' ')"/>
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($sList, ' ')"/>
805 </xsl:call-template>
806 </xsl:if>
807 </xsl:template>
808
809
810 <!--
811 Calculates and emits indentation list markup.
812 -->
813 <xsl:template name="emit-indentation">
814 <xsl:variable name="iDepth" select="count(ancestor-or-self::*)"/>
815 <xsl:for-each select="ancestor-or-self::*">
816 <xsl:choose>
817
818 <xsl:when test="self::refsect1
819 | self::refsect2
820 | self::refsect3
821 | self::refsynopsisdiv">
822 <xsl:text> </xsl:text>
823 </xsl:when>
824
825 <xsl:when test="self::term">
826 <!-- currently no indent. -->
827 </xsl:when>
828
829 <!-- Evidence here (especially with orderedlist) that doing list by for-each
830 listitem in the template matching the list type would be easier... -->
831 <xsl:when test="self::listitem and parent::itemizedlist and (position() + 1) = $iDepth">
832 <xsl:text> - </xsl:text>
833 </xsl:when>
834
835 <xsl:when test="self::listitem and parent::orderedlist and (position() + 1) = $iDepth">
836 <xsl:variable name="iNumber" select="count(preceding-sibling::listitem) + 1"/>
837 <xsl:if test="$iNumber &lt;= 9">
838 <xsl:text> </xsl:text>
839 </xsl:if>
840 <xsl:value-of select="$iNumber"/>
841 <xsl:text>. </xsl:text>
842 </xsl:when>
843
844 <xsl:when test="self::listitem">
845 <xsl:text> </xsl:text>
846 </xsl:when>
847
848 </xsl:choose>
849 </xsl:for-each>
850 </xsl:template>
851
852 <!--
853 Captializes the given text.
854 -->
855 <xsl:template name="capitalize">
856 <xsl:param name="text"/>
857 <xsl:call-template name="str:to-upper">
858 <xsl:with-param name="text" select="substring($text,1,1)"/>
859 </xsl:call-template>
860 <xsl:value-of select="substring($text,2)"/>
861 </xsl:template>
862
863
864 <!--
865 Debug/Diagnostics: Return the path to the specified node (by default the current).
866 -->
867 <xsl:template name="get-node-path">
868 <xsl:param name="Node" select="."/>
869 <xsl:for-each select="$Node">
870 <xsl:for-each select="ancestor-or-self::node()">
871 <xsl:choose>
872 <xsl:when test="name(.) = ''">
873 <xsl:text>text()</xsl:text>
874 </xsl:when>
875 <xsl:otherwise>
876 <xsl:value-of select="concat('/', name(.))"/>
877 <xsl:choose>
878 <xsl:when test="@id">
879 <xsl:text>[@id=</xsl:text>
880 <xsl:value-of select="@id"/>
881 <xsl:text>]</xsl:text>
882 </xsl:when>
883 <xsl:when test="position() > 1">
884 <xsl:text>[</xsl:text><xsl:value-of select="position()"/><xsl:text>]</xsl:text>
885 </xsl:when>
886 </xsl:choose>
887 </xsl:otherwise>
888 </xsl:choose>
889 </xsl:for-each>
890 </xsl:for-each>
891 </xsl:template>
892
893 <!--
894 Debug/Diagnostics: Return error message prefix.
895 -->
896 <xsl:template name="error-prefix">
897 <xsl:param name="Node" select="."/>
898 <xsl:text>error: </xsl:text>
899 <xsl:call-template name="get-node-path">
900 <xsl:with-param name="Node" select="$Node"/>
901 </xsl:call-template>
902 <xsl:text>: </xsl:text>
903 </xsl:template>
904
905 <!--
906 Debug/Diagnostics: Print list of nodes (by default all children of current node).
907 -->
908 <xsl:template name="list-nodes">
909 <xsl:param name="Nodes" select="node()"/>
910 <xsl:for-each select="$Nodes">
911 <xsl:if test="position() != 1">
912 <xsl:text>, </xsl:text>
913 </xsl:if>
914 <xsl:choose>
915 <xsl:when test="name(.) = ''">
916 <xsl:text>text:text()</xsl:text>
917 </xsl:when>
918 <xsl:otherwise>
919 <xsl:value-of select="name(.)"/>
920 <xsl:if test="@id">
921 <xsl:text>[@id=</xsl:text>
922 <xsl:value-of select="@id"/>
923 <xsl:text>]</xsl:text>
924 </xsl:if>
925 </xsl:otherwise>
926 </xsl:choose>
927 </xsl:for-each>
928 </xsl:template>
929
930 <xsl:template name="check-children">
931 <xsl:param name="Node" select="."/>
932 <xsl:param name="UnsupportedNodes" select="*"/>
933 <xsl:param name="SupportedNames" select="'none'"/>
934 <xsl:if test="count($UnsupportedNodes) != 0">
935 <xsl:message terminate="yes">
936 <xsl:call-template name="get-node-path">
937 <xsl:with-param name="Node" select="$Node"/>
938 </xsl:call-template>
939 <!-- -->: error: Only <xsl:value-of select="$SupportedNames"/> are supported as children to <!-- -->
940 <xsl:value-of select="name($Node)"/>
941 <!-- -->
942Unsupported children: <!-- -->
943 <xsl:call-template name="list-nodes">
944 <xsl:with-param name="Nodes" select="$UnsupportedNodes"/>
945 </xsl:call-template>
946 </xsl:message>
947 </xsl:if>
948 </xsl:template>
949
950</xsl:stylesheet>
951
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