VirtualBox

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

Last change on this file since 56571 was 56571, checked in by vboxsync, 9 years ago

fixes and better debug.

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