VirtualBox

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

最後變更 在這個檔案從96301是 96300,由 vboxsync 提交於 3 年 前

doc: comment fixing

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette