VirtualBox

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

Last change on this file since 98865 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

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