VirtualBox

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

Last change on this file since 95010 was 94216, checked in by vboxsync, 3 years ago

doc/manual/docbook-refentry-to-C-help.xsl: Allow <note></note> sections as a child for <listitem>, ​bugref:9186

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