VirtualBox

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

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

iprt,vboxmanage,manual: Try write the iso maker docs as a docbook refentry document. Tried to generalize the vboxmanage refentry output handling, moving it to RTMsg*. Made VBoxManage and IPRT generate their C/H sources in their own Makefiles. Hacked the C/H source generation till it can deal with the rather different RTIsoMaker command structure (no sub or sub-sub command stuff).

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