VirtualBox

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

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

change check.

  • 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: 31.8 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:call-template name="check-children">
337 <xsl:with-param name="UnsupportedNodes" select="*[not(self::para or self::itemizedlist or self::orderedlist)]|text()"/>
338 <xsl:with-param name="SupportedNames">para, itemizedlist and orderedlist</xsl:with-param>
339 </xsl:call-template>
340
341 <xsl:apply-templates select="*"/>
342 </xsl:template>
343
344
345 <!--
346 itemizedlist and orderedlist
347 -->
348 <xsl:template match="itemizedlist|orderedlist">
349 <xsl:if test="*[not(self::listitem)]|text()">
350 <xsl:message terminate="yes">
351 <xsl:call-template name="get-node-path"/>: error: Only listitem elements are supported in <xsl:value-of select="name()"/>:
352 <xsl:call-template name="list-nodes">
353 <xsl:with-param name="Nodes" select="*[not(self::listitem)]|text()"/>
354 </xsl:call-template>
355 </xsl:message>
356 </xsl:if>
357 <xsl:if test="parent::para">
358 <xsl:message terminate="yes"><xsl:value-of select="name()"/> inside a para is current not supported. <!-- no newline
359 -->Close the para before the list, it makes no difference to html and latex/pdf output.</xsl:message>
360 </xsl:if>
361 <xsl:if test="position() != 1 and (not(@spacing) or @spacing != 'compact')">
362 <xsl:text>
363 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
364 </xsl:if>
365 <xsl:for-each select="./listitem">
366 <xsl:apply-templates select="*"/>
367 </xsl:for-each>
368 </xsl:template>
369
370 <xsl:template match="itemizedlist/listitem|orderedlist/listitem">
371 <xsl:if test="*[not(self::para)]|text()">
372 <xsl:message terminate="yes">
373 <xsl:call-template name="get-node-path"/>: error: Expected <xsl:value-of select="name()"/>/listitem to only contain para elements:
374 <xsl:call-template name="list-nodes">
375 <xsl:with-param name="Nodes" select="*[not(self::para)]|text()"/>
376 </xsl:call-template>
377 </xsl:message>
378 </xsl:if>
379
380 <xsl:if test="position() != 1 and @spaceing != 'compact'">
381 <xsl:text>
382 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
383 </xsl:if>
384 <xsl:apply-templates select="*"/>
385 </xsl:template>
386
387
388 <!--
389 Screen
390 -->
391 <xsl:template match="screen">
392 <xsl:if test="ancestor::para">
393 <xsl:text>" },</xsl:text>
394 </xsl:if>
395
396 <xsl:text>
397 { REFENTRYSTR_SCOPE_SAME,
398 "</xsl:text>
399
400 <xsl:for-each select="node()">
401 <xsl:choose>
402 <xsl:when test="name() = ''">
403 <xsl:call-template name="screen_text_line">
404 <xsl:with-param name="sText" select="."/>
405 </xsl:call-template>
406 </xsl:when>
407 <xsl:otherwise>
408 <xsl:if test="*">
409 <xsl:message terminate="yes">Support for elements under screen has not been implemented: <xsl:value-of select="name()"/></xsl:message>
410 </xsl:if>
411 </xsl:otherwise>
412 </xsl:choose>
413 </xsl:for-each>
414
415 <xsl:if test="not(ancestor::para)">
416 <xsl:text>" },</xsl:text>
417 </xsl:if>
418 </xsl:template>
419
420 <xsl:template name="screen_text_line">
421 <xsl:param name="sText"/>
422 <xsl:call-template name="escape_fixed_text">
423 <xsl:with-param name="sText" select="substring-before($sText,'&#x0a;')"/>
424 </xsl:call-template>
425
426 <xsl:if test="substring-after($sText,'&#x0a;')">
427 <xsl:text>" },
428 { REFENTRYSTR_SCOPE_SAME,
429 "</xsl:text>
430 <xsl:call-template name="screen_text_line">
431 <xsl:with-param name="sText" select="substring-after($sText,'&#x0a;')"/>
432 </xsl:call-template>
433 </xsl:if>
434 </xsl:template>
435
436
437 <!--
438 Text escaping for C.
439 -->
440 <xsl:template match="text()" name="escape_text">
441 <!-- Leading whitespace hack! -->
442 <xsl:if test="substring(.,1,1) = ' ' and position() != 1">
443 <xsl:text> </xsl:text>
444 <xsl:if test="boolean($g_fDebugText)">
445 <xsl:message>text: add space</xsl:message>
446 </xsl:if>
447 </xsl:if>
448
449 <!-- Body of text -->
450 <xsl:choose>
451
452 <xsl:when test="contains(., '\') or contains(., '&quot;')">
453 <xsl:variable name="sTmp">
454 <xsl:call-template name="str:subst">
455 <xsl:with-param name="text" select="normalize-space(.)"/>
456 <xsl:with-param name="replace" select="'\'"/>
457 <xsl:with-param name="with" select="'\\'"/>
458 <xsl:with-param name="disable-output-escaping" select="yes"/>
459 </xsl:call-template>
460 </xsl:variable>
461 <xsl:variable name="sTmp2">
462 <xsl:call-template name="str:subst">
463 <xsl:with-param name="text" select="$sTmp"/>
464 <xsl:with-param name="replace" select="'&quot;'"/>
465 <xsl:with-param name="with" select="'\&quot;'"/>
466 <xsl:with-param name="disable-output-escaping" select="yes"/>
467 </xsl:call-template>
468 </xsl:variable>
469 <xsl:value-of select="$sTmp2"/>
470 <xsl:if test="boolean($g_fDebugText)">
471 <xsl:message>text: |<xsl:value-of select="$sTmp2"/>|</xsl:message>
472 </xsl:if>
473 </xsl:when>
474
475 <xsl:otherwise>
476 <xsl:value-of select="normalize-space(.)"/>
477 <xsl:if test="boolean($g_fDebugText)">
478 <xsl:message>text: |<xsl:value-of select="normalize-space(.)"/>|</xsl:message>
479 </xsl:if>
480 </xsl:otherwise>
481 </xsl:choose>
482
483 <!-- Trailing whitespace hack! -->
484 <xsl:if test="substring(.,string-length(.)) = ' ' and position() != last() and string-length(.) != 1">
485 <xsl:text> </xsl:text>
486 <xsl:if test="boolean($g_fDebugText)">
487 <xsl:message>text: add space</xsl:message>
488 </xsl:if>
489 </xsl:if>
490
491 </xsl:template>
492
493 <!-- Elements producing non-breaking strings (single line). -->
494 <xsl:template match="command/text()|option/text()|computeroutput/text()|arg/text()" name="escape_fixed_text">
495 <xsl:param name="sText" select="."/>
496 <xsl:choose>
497
498 <xsl:when test="contains($sText, '\') or contains($sText, '&quot;')">
499 <xsl:variable name="sTmp1">
500 <xsl:call-template name="str:subst">
501 <xsl:with-param name="text" select="$sText"/>
502 <xsl:with-param name="replace" select="'\'"/>
503 <xsl:with-param name="with" select="'\\'"/>
504 <xsl:with-param name="disable-output-escaping" select="yes"/>
505 </xsl:call-template>
506 </xsl:variable>
507 <xsl:variable name="sTmp2">
508 <xsl:call-template name="str:subst">
509 <xsl:with-param name="text" select="$sTmp1"/>
510 <xsl:with-param name="replace" select="'&quot;'"/>
511 <xsl:with-param name="with" select="'\&quot;'"/>
512 <xsl:with-param name="disable-output-escaping" select="yes"/>
513 </xsl:call-template>
514 </xsl:variable>
515 <xsl:variable name="sTmp3">
516 <xsl:call-template name="str:subst">
517 <xsl:with-param name="text" select="$sTmp2"/>
518 <xsl:with-param name="replace" select="' '"/>
519 <xsl:with-param name="with" select="'\b'"/>
520 <xsl:with-param name="disable-output-escaping" select="yes"/>
521 </xsl:call-template>
522 </xsl:variable>
523 <xsl:value-of select="$sTmp3"/>
524 <xsl:if test="boolean($g_fDebugText)">
525 <xsl:message>text! |<xsl:value-of select="$sTmp3"/>|</xsl:message>
526 </xsl:if>
527 </xsl:when>
528
529 <xsl:when test="contains($sText, ' ')">
530 <xsl:variable name="sTmp">
531 <xsl:call-template name="str:subst">
532 <xsl:with-param name="text" select="$sText"/>
533 <xsl:with-param name="replace" select="' '"/>
534 <xsl:with-param name="with" select="'\b'"/>
535 <xsl:with-param name="disable-output-escaping" select="yes"/>
536 </xsl:call-template>
537 </xsl:variable>
538 <xsl:value-of select="$sTmp"/>
539 <xsl:if test="boolean($g_fDebugText)">
540 <xsl:message>text! |<xsl:value-of select="$sTmp"/>|</xsl:message>
541 </xsl:if>
542 </xsl:when>
543
544 <xsl:otherwise>
545 <xsl:value-of select="$sText"/>
546 <xsl:if test="boolean($g_fDebugText)">
547 <xsl:message>text! |<xsl:value-of select="$sText"/>|</xsl:message>
548 </xsl:if>
549 </xsl:otherwise>
550 </xsl:choose>
551 </xsl:template>
552
553
554 <!--
555 Unsupported elements and elements handled directly.
556 -->
557 <xsl:template match="synopfragment|synopfragmentref|title|refsect1">
558 <xsl:message terminate="yes">The <xsl:value-of select="name()"/> element is not supported</xsl:message>
559 </xsl:template>
560
561 <!--
562 Fail on misplaced scoping remarks.
563 -->
564 <xsl:template match="remark[@role = 'help-scope']">
565 <xsl:choose>
566 <xsl:when test="parent::refsect1"/>
567 <xsl:when test="parent::refsect2"/>
568 <xsl:when test="parent::cmdsynopsis and ancestor::refsynopsisdiv"/>
569 <xsl:otherwise>
570 <xsl:message terminate="yes">Misplaced remark/@role=help-scope element.
571Only supported on: refsect1, refsect2, refsynopsisdiv/cmdsynopsis</xsl:message>
572 </xsl:otherwise>
573 </xsl:choose>
574 </xsl:template>
575
576 <!--
577 Execute synopsis copy remark (avoids duplication for complicated xml).
578 -->
579 <xsl:template match="remark[@role = 'help-copy-synopsis']">
580 <xsl:message terminate="yes">remark/@role=help-copy-synopsis is not supported by this stylesheet. Must preprocess input!</xsl:message>
581 </xsl:template>
582
583 <!--
584 Warn about unhandled elements
585 -->
586 <xsl:template match="*">
587 <xsl:message terminate="no">Warning: Unhandled element: <!-- no newline -->
588 <xsl:for-each select="ancestor-or-self::*">
589 <xsl:text>/</xsl:text>
590 <xsl:value-of select="name(.)"/>
591 <xsl:if test="@id">
592 <xsl:value-of select="concat('[id=', @id ,']')"/>
593 </xsl:if>
594 </xsl:for-each>
595 </xsl:message>
596 </xsl:template>
597
598
599 <!--
600 Functions
601 Functions
602 Functions
603 -->
604
605 <!--
606 Processes mixed children, i.e. both text and regular elements.
607 Normalizes whitespace. -->
608 <xsl:template name="process-mixed">
609 <xsl:text>
610 { REFENTRYSTR_SCOPE_SAME,
611 "</xsl:text><xsl:call-template name="emit-indentation"/>
612
613 <xsl:for-each select="node()[not(self::remark)]">
614 <xsl:choose>
615 <xsl:when test="name() = ''">
616 <xsl:call-template name="escape_text"/>
617 </xsl:when>
618 <xsl:otherwise>
619 <xsl:apply-templates select="."/>
620 </xsl:otherwise>
621 </xsl:choose>
622 </xsl:for-each>
623
624 <xsl:text>" },</xsl:text>
625 </xsl:template>
626
627
628 <!--
629 Element specific scoping.
630 -->
631
632 <xsl:template name="calc-scope-for-refentry">
633 <xsl:call-template name="calc-scope-const-from-id"/>
634 </xsl:template>
635
636 <!-- Figures out the scope of a refsect1 element. -->
637 <xsl:template name="calc-scope-refsect1">
638 <xsl:choose>
639 <xsl:when test="title[text() = 'Description']">
640 <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
641 </xsl:when>
642 <xsl:when test="@id or remark[@role='help-scope']">
643 <xsl:call-template name="calc-scope-from-remark-or-id"/>
644 </xsl:when>
645 <xsl:otherwise>
646 <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
647 </xsl:otherwise>
648 </xsl:choose>
649 </xsl:template>
650
651 <!-- Figures out the scope of a refsect2 element. -->
652 <xsl:template name="calc-scope-refsect2">
653 <xsl:choose>
654 <xsl:when test="@id or remark[@role='help-scope']">
655 <xsl:call-template name="calc-scope-from-remark-or-id"/>
656 </xsl:when>
657 <xsl:otherwise>
658 <xsl:text>REFENTRYSTR_SCOPE_SAME</xsl:text>
659 </xsl:otherwise>
660 </xsl:choose>
661 </xsl:template>
662
663 <!-- Figures out the scope of a refsect1 element. -->
664 <xsl:template name="calc-scope-cmdsynopsis">
665 <xsl:choose>
666 <xsl:when test="ancestor::refsynopsisdiv">
667 <xsl:call-template name="calc-scope-from-remark-or-id">
668 <xsl:with-param name="sId" select="substring-after(@id, '-')"/>
669 </xsl:call-template>
670 </xsl:when>
671 <xsl:otherwise>
672 <xsl:text>REFENTRYSTR_SCOPE_SAME</xsl:text>
673 </xsl:otherwise>
674 </xsl:choose>
675 </xsl:template>
676
677
678 <!--
679 Scoping worker functions.
680 -->
681
682 <!-- Calculates the current scope from the scope remark or @id. -->
683 <xsl:template name="calc-scope-from-remark-or-id">
684 <xsl:param name="sId" select="@id"/>
685 <xsl:choose>
686 <xsl:when test="remark[@role='help-scope']">
687 <xsl:call-template name="calc-scope-consts-from-remark"/>
688 </xsl:when>
689 <xsl:when test="$sId != ''">
690 <xsl:call-template name="calc-scope-const-from-id">
691 <xsl:with-param name="sId" select="$sId"/>
692 </xsl:call-template>
693 </xsl:when>
694 <xsl:otherwise>
695 <xsl:message terminate="yes">expected remark child or id attribute.</xsl:message>
696 </xsl:otherwise>
697 </xsl:choose>
698 </xsl:template>
699
700 <!-- Turns a @id into a scope constant.
701 Some woodoo taking place here here that chops the everything up to and
702 including the first refentry/@id word from all IDs before turning them into
703 constants (word delimiter '-'). -->
704 <xsl:template name="calc-scope-const-from-id">
705 <xsl:param name="sId" select="@id"/>
706 <xsl:variable name="sPrefix" select="concat(substring-before(ancestor::refentry/@id, '-'), '-')"/>
707 <xsl:if test="not(contains($sId, sPrefix))">
708 <xsl:message terminate="yes">Expected sId (<xsl:value-of select="$sId"/>) to contain <xsl:value-of select="$sPrefix"/></xsl:message>
709 </xsl:if>
710 <xsl:text>HELP_SCOPE_</xsl:text>
711 <xsl:call-template name="str:to-upper">
712 <xsl:with-param name="text" select="translate(substring-after($sId, $sPrefix), '-', '_')"/>
713 </xsl:call-template>
714 </xsl:template>
715
716 <!-- Turns a remark into one or more scope constant. -->
717 <xsl:template name="calc-scope-consts-from-remark">
718 <xsl:param name="sCondition" select="remark/@condition"/>
719 <xsl:variable name="sNormalized" select="concat(normalize-space(translate($sCondition, ',;:|', ' ')), ' ')"/>
720 <xsl:if test="$sNormalized = ' ' or $sNormalized = ''">
721 <xsl:message terminate="yes">Empty @condition for help-scope remark.</xsl:message>
722 </xsl:if>
723 <xsl:choose>
724 <xsl:when test="substring-before($sNormalized, ' ') = 'GLOBAL'">
725 <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
726 </xsl:when>
727 <xsl:otherwise>
728 <xsl:text>HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sNormalized, ' ')"/>
729 </xsl:otherwise>
730 </xsl:choose>
731 <xsl:call-template name="calc-scope-const-from-remark-worker">
732 <xsl:with-param name="sList" select="substring-after($sNormalized, ' ')"/>
733 </xsl:call-template>
734 </xsl:template>
735
736 <xsl:template name="calc-scope-const-from-remark-worker">
737 <xsl:param name="sList"/>
738 <xsl:if test="$sList != ''">
739 <xsl:choose>
740 <xsl:when test="substring-before($sList, ' ') = 'GLOBAL'">
741 <xsl:text>| REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
742 </xsl:when>
743 <xsl:otherwise>
744 <xsl:text> | HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sList, ' ')"/>
745 </xsl:otherwise>
746 </xsl:choose>
747 <xsl:call-template name="calc-scope-const-from-remark-worker">
748 <xsl:with-param name="sList" select="substring-after($sList, ' ')"/>
749 </xsl:call-template>
750 </xsl:if>
751 </xsl:template>
752
753
754 <!--
755 Calculates and emits indentation list markup.
756 -->
757 <xsl:template name="emit-indentation">
758 <xsl:variable name="iDepth" select="count(ancestor-or-self::*)"/>
759 <xsl:for-each select="ancestor-or-self::*">
760 <xsl:choose>
761
762 <xsl:when test="self::refsect1
763 | self::refsect2
764 | self::refsect3
765 | self::refsynopsisdiv">
766 <xsl:text> </xsl:text>
767 </xsl:when>
768
769 <xsl:when test="self::term">
770 <!-- currently no indent. -->
771 </xsl:when>
772
773 <!-- Evidence here (especially with orderedlist) that doing list by for-each
774 listitem in the template matching the list type would be easier... -->
775 <xsl:when test="self::listitem and parent::itemizedlist and (position() + 1) = $iDepth">
776 <xsl:text> - </xsl:text>
777 </xsl:when>
778
779 <xsl:when test="self::listitem and parent::orderedlist and (position() + 1) = $iDepth">
780 <xsl:variable name="iNumber" select="count(preceding-sibling::listitem) + 1"/>
781 <xsl:if test="$iNumber &lt;= 9">
782 <xsl:text> </xsl:text>
783 </xsl:if>
784 <xsl:value-of select="$iNumber"/>
785 <xsl:text>. </xsl:text>
786 </xsl:when>
787
788 <xsl:when test="self::listitem">
789 <xsl:text> </xsl:text>
790 </xsl:when>
791
792 </xsl:choose>
793 </xsl:for-each>
794 </xsl:template>
795
796 <!--
797 Captializes the given text.
798 -->
799 <xsl:template name="capitalize">
800 <xsl:param name="text"/>
801 <xsl:call-template name="str:to-upper">
802 <xsl:with-param name="text" select="substring($text,1,1)"/>
803 </xsl:call-template>
804 <xsl:value-of select="substring($text,2)"/>
805 </xsl:template>
806
807
808 <!--
809 Debug/Diagnostics: Return the path to the specified node (by default the current).
810 -->
811 <xsl:template name="get-node-path">
812 <xsl:param name="Node" select="."/>
813 <xsl:for-each select="$Node">
814 <xsl:for-each select="ancestor-or-self::node()">
815 <xsl:choose>
816 <xsl:when test="name(.) = ''">
817 <xsl:text>text()</xsl:text>
818 </xsl:when>
819 <xsl:otherwise>
820 <xsl:value-of select="concat('/', name(.))"/>
821 <xsl:if test="@id">
822 <xsl:text>[@id=</xsl:text>
823 <xsl:value-of select="@id"/>
824 <xsl:text>]</xsl:text>
825 </xsl:if>
826 </xsl:otherwise>
827 </xsl:choose>
828 </xsl:for-each>
829 </xsl:for-each>
830 </xsl:template>
831
832 <!--
833 Debug/Diagnostics: Print list of nodes (by default all children of current node).
834 -->
835 <xsl:template name="list-nodes">
836 <xsl:param name="Nodes" select="node()"/>
837
838 <for-each select="$Nodes">
839 <xsl:if test="posision() != 1">
840 <xsl:text>, </xsl:text>
841 </xsl:if>
842 <xsl:choose>
843 <xsl:when test="name(.) = ''">
844 <xsl:text>text()</xsl:text>
845 </xsl:when>
846 <xsl:otherwise>
847 <xsl:value-of select="name(.)"/>
848 <xsl:if test="@id">
849 <xsl:text>[@id=</xsl:text>
850 <xsl:value-of select="@id"/>
851 <xsl:text>]</xsl:text>
852 </xsl:if>
853 </xsl:otherwise>
854 </xsl:choose>
855 </for-each>
856
857 </xsl:template>
858
859 <xsl:template name="check-children">
860 <xsl:param name="Node" select="."/>
861 <xsl:param name="UnsupportedNodes" select="*"/>
862 <xsl:param name="SupportedNames" select="'none'"/>
863 <xsl:if test="count($UnsupportedNodes) != 0">
864 <xsl:message terminate="yes">
865 <xsl:call-template name="get-node-path">
866 <xsl:with-param name="Node" select="$Node"/>
867 </xsl:call-template>
868 <!-- -->: error: Only <xsl:value-of select="$SupportedNames"/> are supported as children to <!-- -->
869 <xsl:value-of select="name($Node)"/>
870 <!-- -->Unsupported children: <!-- -->
871 <xsl:call-template name="list-nodes">
872 <xsl:with-param name="Nodes" select="$UnsupportedNodes"/>
873 </xsl:call-template>
874 </xsl:message>
875 </xsl:if>
876 </xsl:template>
877
878</xsl:stylesheet>
879
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