VirtualBox

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

Last change on this file since 68872 was 68872, checked in by vboxsync, 7 years ago

isomakercmd.cpp,docbook-refentry*.xsl: Converted the rest of the iso maker help text. Made some refentry text conversion adjustments.

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