VirtualBox

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

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

docbook-refentry-to-C-help.xsl: More tweaks.

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