VirtualBox

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

Last change on this file since 56570 was 56570, checked in by vboxsync, 10 years ago

More details.

  • 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: 29.3 KB
Line 
1<?xml version="1.0"?>
2<!--
3 docbook-refentry-to-manual-sect1.xsl:
4 XSLT stylesheet for nicking the refsynopsisdiv bit of a
5 refentry (manpage) for use in the command overview section
6 in the user manual.
7
8 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 REFENTRYSTR </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 REFENTRYSTR </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 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
121
122 <!-- The follows the usage (synopsis) section. -->
123 <xsl:text>
124 { REFENTRYSTR_SCOPE_GLOBAL,
125 "Usage" },
126 { REFENTRYSTR_SCOPE_SAME,
127 "=====" },
128 { REFENTRYSTR_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 { REFENTRYSTR_SCOPE_SAME,
143 "</xsl:text><xsl:value-of select="$sTitle"/><xsl:text>" },
144 { REFENTRYSTR_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 REFENTRY </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text> =
161{
162 /* .idInternal = */ HELP_CMD_</xsl:text>
163 <xsl:call-template name="str:to-upper">
164 <xsl:with-param name="text" select="translate(substring-after(@id, '-'), '-', '_')"/>
165 </xsl:call-template>
166 <xsl:text>,
167 /* .Synopsis = */ { RT_ELEMENTS(</xsl:text>
168 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis), 0, </xsl:text>
169 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis },
170 /* .Help = */ { RT_ELEMENTS(</xsl:text>
171 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help), 0, </xsl:text>
172 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help },
173 /* pszBrief = */ "</xsl:text>
174 <xsl:apply-templates select="./refnamediv/refpurpose/node()"/>
175 <!-- TODO: Add the command name too. -->
176 <xsl:text>"
177};
178</xsl:text>
179 </xsl:template>
180
181
182 <!--
183 Convert command synopsis to text.
184 -->
185 <xsl:template match="cmdsynopsis">
186 <xsl:if test="text()"><xsl:message terminate="yes">cmdsynopsis with text is not supported.</xsl:message></xsl:if>
187 <xsl:text>
188 { </xsl:text><xsl:call-template name="calc-scope-cmdsynopsis"/><xsl:text> | REFENTRYSTR_FLAGS_SYNOPSIS,
189 "</xsl:text><xsl:call-template name="emit-indentation"/><xsl:apply-templates select="*|@*"/><xsl:text>" },</xsl:text>
190 </xsl:template>
191
192 <xsl:template match="sbr">
193 <xsl:text>" },
194 { REFENTRYSTR_SCOPE_SAME | REFENTRYSTR_FLAGS_SYNOPSIS,
195 " </xsl:text><xsl:call-template name="emit-indentation"/> <!-- hardcoded in VBoxManageHelp.cpp too -->
196 </xsl:template>
197
198 <xsl:template match="cmdsynopsis/command">
199 <xsl:text>" },
200 { REFENTRYSTR_SCOPE_SAME | REFENTRYSTR_FLAGS_SYNOPSIS,
201 "</xsl:text><xsl:call-template name="emit-indentation"/>
202 <xsl:apply-templates select="node()|@*"/>
203 </xsl:template>
204
205 <xsl:template match="cmdsynopsis/command[1]" priority="2">
206 <xsl:apply-templates select="node()|@*"/>
207 </xsl:template>
208
209 <xsl:template match="command|option|computeroutput">
210 <xsl:apply-templates select="node()|@*"/>
211 </xsl:template>
212
213 <xsl:template match="replaceable">
214 <xsl:choose>
215 <xsl:when test="not(ancestor::cmdsynopsis) or ancestor::arg">
216 <xsl:apply-templates />
217 </xsl:when>
218 <xsl:otherwise>
219 <xsl:text>&lt;</xsl:text>
220 <xsl:apply-templates />
221 <xsl:text>&gt;</xsl:text>
222 </xsl:otherwise>
223 </xsl:choose>
224 </xsl:template>
225
226 <!-- duplicated in docbook2latex.xsl -->
227 <xsl:template match="arg|group">
228 <!-- separator char if we're not the first child -->
229 <xsl:if test="position() > 1">
230 <xsl:choose>
231 <xsl:when test="parent::group"><xsl:value-of select="$arg.or.sep"/></xsl:when>
232 <xsl:when test="ancestor-or-self::*/@sepchar"><xsl:value-of select="ancestor-or-self::*/@sepchar"/></xsl:when>
233 <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
234 </xsl:choose>
235 </xsl:if>
236 <!-- open wrapping -->
237 <xsl:choose>
238 <xsl:when test="not(@choice) or @choice = ''"> <xsl:value-of select="$arg.choice.def.open.str"/></xsl:when>
239 <xsl:when test="@choice = 'opt'"> <xsl:value-of select="$arg.choice.opt.open.str"/></xsl:when>
240 <xsl:when test="@choice = 'req'"> <xsl:value-of select="$arg.choice.req.open.str"/></xsl:when>
241 <xsl:when test="@choice = 'plain'"/>
242 <xsl:otherwise><xsl:message terminate="yes">Invalid arg choice: "<xsl:value-of select="@choice"/>"</xsl:message></xsl:otherwise>
243 </xsl:choose>
244
245 <!-- render the arg (TODO: may need to do more work here) -->
246 <xsl:apply-templates />
247
248 <!-- repeat wrapping -->
249 <xsl:choose>
250 <xsl:when test="@rep = 'norepeat' or not(@rep) or @rep = ''"/>
251 <xsl:when test="@rep = 'repeat'"> <xsl:value-of select="$arg.rep.repeat.str"/></xsl:when>
252 <xsl:otherwise><xsl:message terminate="yes">Invalid rep choice: "<xsl:value-of select="@rep"/>"</xsl:message></xsl:otherwise>
253 </xsl:choose>
254 <!-- close wrapping -->
255 <xsl:choose>
256 <xsl:when test="not(@choice) or @choice = ''"> <xsl:value-of select="$arg.choice.def.close.str"/></xsl:when>
257 <xsl:when test="@choice = 'opt'"> <xsl:value-of select="$arg.choice.opt.close.str"/></xsl:when>
258 <xsl:when test="@choice = 'req'"> <xsl:value-of select="$arg.choice.req.close.str"/></xsl:when>
259 </xsl:choose>
260 </xsl:template>
261
262
263 <!--
264 refsect2
265 -->
266 <xsl:template match="refsect2">
267 <!-- assertions -->
268 <xsl:if test="text()"><xsl:message terminate="yes">refsect2 shouldn't contain text</xsl:message></xsl:if>
269 <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>
270
271 <!-- title / command synopsis - sets the scope. -->
272 <xsl:variable name="sTitle">
273 <xsl:apply-templates select="./title/text()"/>
274 </xsl:variable>
275 <xsl:text>
276 { </xsl:text><xsl:call-template name="calc-scope-refsect2"/><xsl:text>, "" },
277 { REFENTRYSTR_SCOPE_SAME,
278 "</xsl:text><xsl:call-template name="emit-indentation"/>
279 <xsl:value-of select="$sTitle"/>
280 <xsl:text>" },
281 { REFENTRYSTR_SCOPE_SAME,
282 "</xsl:text><xsl:call-template name="emit-indentation"/>
283 <xsl:value-of select="substring($g_sUnderlineRefSect2, 1, string-length($sTitle))"/>
284 <xsl:text>" },
285 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
286
287 <!-- Format the text in the section -->
288 <xsl:for-each select="./*[name() != 'title']">
289 <xsl:apply-templates select="."/>
290 </xsl:for-each>
291
292 <!-- Add two blank lines, unless we're the last element in this refsect1. -->
293 <xsl:if test="position() != last()">
294 <xsl:text>
295 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
296 </xsl:if>
297 </xsl:template>
298
299
300 <!--
301 para
302 -->
303 <xsl:template match="para">
304 <xsl:if test="position() != 1 or not(parent::listitem)">
305 <xsl:text>
306 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
307 </xsl:if>
308 <xsl:call-template name="process-mixed"/>
309 </xsl:template>
310
311
312 <!--
313 variablelist
314 -->
315 <xsl:template match="variablelist">
316 <xsl:if test="*[not(self::varlistentry)]|text()">
317 <xsl:message terminate="yes">Only varlistentry elements are supported in variablelist</xsl:message>
318 </xsl:if>
319 <xsl:for-each select="./varlistentry">
320 <xsl:if test="count(*) != 2 or not(term) or not(listitem)">
321 <xsl:message terminate="yes">Expected exactly one term and one listentry member in varlistentry element.</xsl:message>
322 </xsl:if>
323 <xsl:if test="not(@spacing) or @spacing != 'compact'">
324 <xsl:text>
325 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
326 </xsl:if>
327 <xsl:apply-templates select="*"/>
328 </xsl:for-each>
329 </xsl:template>
330
331 <xsl:template match="varlistentry/term">
332 <xsl:call-template name="process-mixed"/>
333 </xsl:template>
334
335 <xsl:template match="varlistentry/listitem">
336 <xsl:if test="text() or *[not(self::para or self::itemizedlist or self::orderedlist)]">
337 <xsl:message terminate="yes">Expected varlistentry/listitem to only contain para, itemizedlist and orderedlist elements:<!-- no newline -->
338 <xsl:if test="text()">text(), </xsl:if>
339 <for-each select="*[self::para or self::itemizedlist or self::orderedlist]">
340 <xsl:value-of select="concat(name(.), ', ')"/>
341 </for-each>
342 </xsl:message>
343 </xsl:if>
344
345 <xsl:apply-templates select="*"/>
346 </xsl:template>
347
348
349 <!--
350 itemizedlist and orderedlist
351 -->
352 <xsl:template match="itemizedlist|orderedlist">
353 <xsl:if test="*[not(self::listitem)]|text()">
354 <xsl:message terminate="yes">Only listitem elements are supported in <xsl:value-of select="name()"/>.</xsl:message>
355 </xsl:if>
356 <xsl:if test="parent::para">
357 <xsl:message terminate="yes"><xsl:value-of select="name()"/> inside a para is current not supported. <!-- no newline
358 -->Close the para before the list, it makes no difference to html and latex/pdf output.</xsl:message>
359 </xsl:if>
360 <xsl:if test="position() != 1 and (not(@spacing) or @spacing != 'compact')">
361 <xsl:text>
362 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
363 </xsl:if>
364 <xsl:for-each select="./listitem">
365 <xsl:apply-templates select="*"/>
366 </xsl:for-each>
367 </xsl:template>
368
369 <xsl:template match="itemizedlist/listitem|orderedlist/listitem">
370 <xsl:if test="text() or *[not(self::para)]">
371 <xsl:message terminate="yes">Expected <xsl:value-of select="name()"/>/listitem to only contain para elements</xsl:message>
372 </xsl:if>
373 <xsl:if test="position() != 1 and @spaceing != 'compact'">
374 <xsl:text>
375 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
376 </xsl:if>
377 <xsl:apply-templates select="*"/>
378 </xsl:template>
379
380
381 <!--
382 Screen
383 -->
384 <xsl:template match="screen">
385 <xsl:if test="ancestor::para">
386 <xsl:text>" },</xsl:text>
387 </xsl:if>
388
389 <xsl:text>
390 { REFENTRYSTR_SCOPE_SAME,
391 "</xsl:text>
392
393 <xsl:for-each select="node()">
394 <xsl:choose>
395 <xsl:when test="name() = ''">
396 <xsl:call-template name="screen_text_line">
397 <xsl:with-param name="sText" select="."/>
398 </xsl:call-template>
399 </xsl:when>
400 <xsl:otherwise>
401 <xsl:if test="*">
402 <xsl:message terminate="yes">Support for elements under screen has not been implemented: <xsl:value-of select="name()"/></xsl:message>
403 </xsl:if>
404 </xsl:otherwise>
405 </xsl:choose>
406 </xsl:for-each>
407
408 <xsl:if test="not(ancestor::para)">
409 <xsl:text>" },</xsl:text>
410 </xsl:if>
411 </xsl:template>
412
413 <xsl:template name="screen_text_line">
414 <xsl:param name="sText"/>
415 <xsl:call-template name="escape_fixed_text">
416 <xsl:with-param name="sText" select="substring-before($sText,'&#x0a;')"/>
417 </xsl:call-template>
418
419 <xsl:if test="substring-after($sText,'&#x0a;')">
420 <xsl:text>" },
421 { REFENTRYSTR_SCOPE_SAME,
422 "</xsl:text>
423 <xsl:call-template name="screen_text_line">
424 <xsl:with-param name="sText" select="substring-after($sText,'&#x0a;')"/>
425 </xsl:call-template>
426 </xsl:if>
427 </xsl:template>
428
429
430 <!--
431 Text escaping for C.
432 -->
433 <xsl:template match="text()" name="escape_text">
434 <!-- Leading whitespace hack! -->
435 <xsl:if test="substring(.,1,1) = ' ' and position() != 1">
436 <xsl:text> </xsl:text>
437 <xsl:if test="boolean($g_fDebugText)">
438 <xsl:message>text: add space</xsl:message>
439 </xsl:if>
440 </xsl:if>
441
442 <!-- Body of text -->
443 <xsl:choose>
444
445 <xsl:when test="contains(., '\') or contains(., '&quot;')">
446 <xsl:variable name="sTmp">
447 <xsl:call-template name="str:subst">
448 <xsl:with-param name="text" select="normalize-space(.)"/>
449 <xsl:with-param name="replace" select="'\'"/>
450 <xsl:with-param name="with" select="'\\'"/>
451 <xsl:with-param name="disable-output-escaping" select="yes"/>
452 </xsl:call-template>
453 </xsl:variable>
454 <xsl:variable name="sTmp2">
455 <xsl:call-template name="str:subst">
456 <xsl:with-param name="text" select="$sTmp"/>
457 <xsl:with-param name="replace" select="'&quot;'"/>
458 <xsl:with-param name="with" select="'\&quot;'"/>
459 <xsl:with-param name="disable-output-escaping" select="yes"/>
460 </xsl:call-template>
461 </xsl:variable>
462 <xsl:value-of select="$sTmp2"/>
463 <xsl:if test="boolean($g_fDebugText)">
464 <xsl:message>text: |<xsl:value-of select="$sTmp2"/>|</xsl:message>
465 </xsl:if>
466 </xsl:when>
467
468 <xsl:otherwise>
469 <xsl:value-of select="normalize-space(.)"/>
470 <xsl:if test="boolean($g_fDebugText)">
471 <xsl:message>text: |<xsl:value-of select="normalize-space(.)"/>|</xsl:message>
472 </xsl:if>
473 </xsl:otherwise>
474 </xsl:choose>
475
476 <!-- Trailing whitespace hack! -->
477 <xsl:if test="substring(.,string-length(.)) = ' ' and position() != last() and string-length(.) != 1">
478 <xsl:text> </xsl:text>
479 <xsl:if test="boolean($g_fDebugText)">
480 <xsl:message>text: add space</xsl:message>
481 </xsl:if>
482 </xsl:if>
483
484 </xsl:template>
485
486 <!-- Elements producing non-breaking strings (single line). -->
487 <xsl:template match="command/text()|option/text()|computeroutput/text()|arg/text()" name="escape_fixed_text">
488 <xsl:param name="sText" select="."/>
489 <xsl:choose>
490
491 <xsl:when test="contains($sText, '\') or contains($sText, '&quot;')">
492 <xsl:variable name="sTmp1">
493 <xsl:call-template name="str:subst">
494 <xsl:with-param name="text" select="$sText"/>
495 <xsl:with-param name="replace" select="'\'"/>
496 <xsl:with-param name="with" select="'\\'"/>
497 <xsl:with-param name="disable-output-escaping" select="yes"/>
498 </xsl:call-template>
499 </xsl:variable>
500 <xsl:variable name="sTmp2">
501 <xsl:call-template name="str:subst">
502 <xsl:with-param name="text" select="$sTmp1"/>
503 <xsl:with-param name="replace" select="'&quot;'"/>
504 <xsl:with-param name="with" select="'\&quot;'"/>
505 <xsl:with-param name="disable-output-escaping" select="yes"/>
506 </xsl:call-template>
507 </xsl:variable>
508 <xsl:variable name="sTmp3">
509 <xsl:call-template name="str:subst">
510 <xsl:with-param name="text" select="$sTmp2"/>
511 <xsl:with-param name="replace" select="' '"/>
512 <xsl:with-param name="with" select="'\b'"/>
513 <xsl:with-param name="disable-output-escaping" select="yes"/>
514 </xsl:call-template>
515 </xsl:variable>
516 <xsl:value-of select="$sTmp3"/>
517 <xsl:if test="boolean($g_fDebugText)">
518 <xsl:message>text! |<xsl:value-of select="$sTmp3"/>|</xsl:message>
519 </xsl:if>
520 </xsl:when>
521
522 <xsl:when test="contains($sText, ' ')">
523 <xsl:variable name="sTmp">
524 <xsl:call-template name="str:subst">
525 <xsl:with-param name="text" select="$sText"/>
526 <xsl:with-param name="replace" select="' '"/>
527 <xsl:with-param name="with" select="'\b'"/>
528 <xsl:with-param name="disable-output-escaping" select="yes"/>
529 </xsl:call-template>
530 </xsl:variable>
531 <xsl:value-of select="$sTmp"/>
532 <xsl:if test="boolean($g_fDebugText)">
533 <xsl:message>text! |<xsl:value-of select="$sTmp"/>|</xsl:message>
534 </xsl:if>
535 </xsl:when>
536
537 <xsl:otherwise>
538 <xsl:value-of select="$sText"/>
539 <xsl:if test="boolean($g_fDebugText)">
540 <xsl:message>text! |<xsl:value-of select="$sText"/>|</xsl:message>
541 </xsl:if>
542 </xsl:otherwise>
543 </xsl:choose>
544 </xsl:template>
545
546
547 <!--
548 Unsupported elements and elements handled directly.
549 -->
550 <xsl:template match="synopfragment|synopfragmentref|title|refsect1">
551 <xsl:message terminate="yes">The <xsl:value-of select="name()"/> element is not supported</xsl:message>
552 </xsl:template>
553
554 <!--
555 Fail on misplaced scoping remarks.
556 -->
557 <xsl:template match="remark[@role = 'help-scope']">
558 <xsl:choose>
559 <xsl:when test="parent::refsect1"/>
560 <xsl:when test="parent::refsect2"/>
561 <xsl:when test="parent::cmdsynopsis and ancestor::refsynopsisdiv"/>
562 <xsl:otherwise>
563 <xsl:message terminate="yes">Misplaced remark/@role=help-scope element.
564Only supported on: refsect1, refsect2, refsynopsisdiv/cmdsynopsis</xsl:message>
565 </xsl:otherwise>
566 </xsl:choose>
567 </xsl:template>
568
569 <!--
570 Execute synopsis copy remark (avoids duplication for complicated xml).
571 -->
572 <xsl:template match="remark[@role = 'help-copy-synopsis']">
573 <xsl:message terminate="yes">remark/@role=help-copy-synopsis is not supported by this stylesheet. Must preprocess input!</xsl:message>
574 </xsl:template>
575
576 <!--
577 Warn about unhandled elements
578 -->
579 <xsl:template match="*">
580 <xsl:message terminate="no">Warning: Unhandled element: <!-- no newline -->
581 <xsl:for-each select="ancestor-or-self::*">
582 <xsl:text>/</xsl:text>
583 <xsl:value-of select="name(.)"/>
584 <xsl:if test="@id">
585 <xsl:value-of select="concat('[id=', @id ,']')"/>
586 </xsl:if>
587 </xsl:for-each>
588 </xsl:message>
589 </xsl:template>
590
591
592 <!--
593 Functions
594 Functions
595 Functions
596 -->
597
598 <!--
599 Processes mixed children, i.e. both text and regular elements.
600 Normalizes whitespace. -->
601 <xsl:template name="process-mixed">
602 <xsl:text>
603 { REFENTRYSTR_SCOPE_SAME,
604 "</xsl:text><xsl:call-template name="emit-indentation"/>
605
606 <xsl:for-each select="node()[not(self::remark)]">
607 <xsl:choose>
608 <xsl:when test="name() = ''">
609 <xsl:call-template name="escape_text"/>
610 </xsl:when>
611 <xsl:otherwise>
612 <xsl:apply-templates select="."/>
613 </xsl:otherwise>
614 </xsl:choose>
615 </xsl:for-each>
616
617 <xsl:text>" },</xsl:text>
618 </xsl:template>
619
620
621 <!--
622 Element specific scoping.
623 -->
624
625 <xsl:template name="calc-scope-for-refentry">
626 <xsl:call-template name="calc-scope-const-from-id"/>
627 </xsl:template>
628
629 <!-- Figures out the scope of a refsect1 element. -->
630 <xsl:template name="calc-scope-refsect1">
631 <xsl:choose>
632 <xsl:when test="title[text() = 'Description']">
633 <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
634 </xsl:when>
635 <xsl:when test="@id or remark[@role='help-scope']">
636 <xsl:call-template name="calc-scope-from-remark-or-id"/>
637 </xsl:when>
638 <xsl:otherwise>
639 <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
640 </xsl:otherwise>
641 </xsl:choose>
642 </xsl:template>
643
644 <!-- Figures out the scope of a refsect2 element. -->
645 <xsl:template name="calc-scope-refsect2">
646 <xsl:choose>
647 <xsl:when test="@id or remark[@role='help-scope']">
648 <xsl:call-template name="calc-scope-from-remark-or-id"/>
649 </xsl:when>
650 <xsl:otherwise>
651 <xsl:text>REFENTRYSTR_SCOPE_SAME</xsl:text>
652 </xsl:otherwise>
653 </xsl:choose>
654 </xsl:template>
655
656 <!-- Figures out the scope of a refsect1 element. -->
657 <xsl:template name="calc-scope-cmdsynopsis">
658 <xsl:choose>
659 <xsl:when test="ancestor::refsynopsisdiv">
660 <xsl:call-template name="calc-scope-from-remark-or-id">
661 <xsl:with-param name="sId" select="substring-after(@id, '-')"/>
662 </xsl:call-template>
663 </xsl:when>
664 <xsl:otherwise>
665 <xsl:text>REFENTRYSTR_SCOPE_SAME</xsl:text>
666 </xsl:otherwise>
667 </xsl:choose>
668 </xsl:template>
669
670
671 <!--
672 Scoping worker functions.
673 -->
674
675 <!-- Calculates the current scope from the scope remark or @id. -->
676 <xsl:template name="calc-scope-from-remark-or-id">
677 <xsl:param name="sId" select="@id"/>
678 <xsl:choose>
679 <xsl:when test="remark[@role='help-scope']">
680 <xsl:call-template name="calc-scope-consts-from-remark"/>
681 </xsl:when>
682 <xsl:when test="$sId != ''">
683 <xsl:call-template name="calc-scope-const-from-id">
684 <xsl:with-param name="sId" select="$sId"/>
685 </xsl:call-template>
686 </xsl:when>
687 <xsl:otherwise>
688 <xsl:message terminate="yes">expected remark child or id attribute.</xsl:message>
689 </xsl:otherwise>
690 </xsl:choose>
691 </xsl:template>
692
693 <!-- Turns a @id into a scope constant.
694 Some woodoo taking place here here that chops the everything up to and
695 including the first refentry/@id word from all IDs before turning them into
696 constants (word delimiter '-'). -->
697 <xsl:template name="calc-scope-const-from-id">
698 <xsl:param name="sId" select="@id"/>
699 <xsl:variable name="sPrefix" select="concat(substring-before(ancestor::refentry/@id, '-'), '-')"/>
700 <xsl:if test="not(contains($sId, sPrefix))">
701 <xsl:message terminate="yes">Expected sId (<xsl:value-of select="$sId"/>) to contain <xsl:value-of select="$sPrefix"/></xsl:message>
702 </xsl:if>
703 <xsl:text>HELP_SCOPE_</xsl:text>
704 <xsl:call-template name="str:to-upper">
705 <xsl:with-param name="text" select="translate(substring-after($sId, $sPrefix), '-', '_')"/>
706 </xsl:call-template>
707 </xsl:template>
708
709 <!-- Turns a remark into one or more scope constant. -->
710 <xsl:template name="calc-scope-consts-from-remark">
711 <xsl:param name="sCondition" select="remark/@condition"/>
712 <xsl:variable name="sNormalized" select="concat(normalize-space(translate($sCondition, ',;:|', ' ')), ' ')"/>
713 <xsl:if test="$sNormalized = ' ' or $sNormalized = ''">
714 <xsl:message terminate="yes">Empty @condition for help-scope remark.</xsl:message>
715 </xsl:if>
716 <xsl:choose>
717 <xsl:when test="substring-before($sNormalized, ' ') = 'GLOBAL'">
718 <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
719 </xsl:when>
720 <xsl:otherwise>
721 <xsl:text>HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sNormalized, ' ')"/>
722 </xsl:otherwise>
723 </xsl:choose>
724 <xsl:call-template name="calc-scope-const-from-remark-worker">
725 <xsl:with-param name="sList" select="substring-after($sNormalized, ' ')"/>
726 </xsl:call-template>
727 </xsl:template>
728
729 <xsl:template name="calc-scope-const-from-remark-worker">
730 <xsl:param name="sList"/>
731 <xsl:if test="$sList != ''">
732 <xsl:choose>
733 <xsl:when test="substring-before($sList, ' ') = 'GLOBAL'">
734 <xsl:text>| REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
735 </xsl:when>
736 <xsl:otherwise>
737 <xsl:text> | HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sList, ' ')"/>
738 </xsl:otherwise>
739 </xsl:choose>
740 <xsl:call-template name="calc-scope-const-from-remark-worker">
741 <xsl:with-param name="sList" select="substring-after($sList, ' ')"/>
742 </xsl:call-template>
743 </xsl:if>
744 </xsl:template>
745
746
747 <!--
748 Calculates and emits indentation list markup.
749 -->
750 <xsl:template name="emit-indentation">
751 <xsl:variable name="iDepth" select="count(ancestor-or-self::*)"/>
752 <xsl:for-each select="ancestor-or-self::*">
753 <xsl:choose>
754
755 <xsl:when test="self::refsect1
756 | self::refsect2
757 | self::refsect3
758 | self::refsynopsisdiv">
759 <xsl:text> </xsl:text>
760 </xsl:when>
761
762 <xsl:when test="self::term">
763 <!-- currently no indent. -->
764 </xsl:when>
765
766 <!-- Evidence here (especially with orderedlist) that doing list by for-each
767 listitem in the template matching the list type would be easier... -->
768 <xsl:when test="self::listitem and parent::itemizedlist and (position() + 1) = $iDepth">
769 <xsl:text> - </xsl:text>
770 </xsl:when>
771
772 <xsl:when test="self::listitem and parent::orderedlist and (position() + 1) = $iDepth">
773 <xsl:variable name="iNumber" select="count(preceding-sibling::listitem) + 1"/>
774 <xsl:if test="$iNumber &lt;= 9">
775 <xsl:text> </xsl:text>
776 </xsl:if>
777 <xsl:value-of select="$iNumber"/>
778 <xsl:text>. </xsl:text>
779 </xsl:when>
780
781 <xsl:when test="self::listitem">
782 <xsl:text> </xsl:text>
783 </xsl:when>
784
785 </xsl:choose>
786 </xsl:for-each>
787 </xsl:template>
788
789 <!--
790 Captializes the given text.
791 -->
792 <xsl:template name="capitalize">
793 <xsl:param name="text"/>
794 <xsl:call-template name="str:to-upper">
795 <xsl:with-param name="text" select="substring($text,1,1)"/>
796 </xsl:call-template>
797 <xsl:value-of select="substring($text,2)"/>
798 </xsl:template>
799
800</xsl:stylesheet>
801
Note: See TracBrowser for help on using the repository browser.

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