VirtualBox

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

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

Implemented itemizedlist; fixed lost space between arg and replaceable; underlined refsect1 and refsect2 titles.

  • 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: 27.1 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:variable name="g_sUnderlineRefSect1">
32 <xsl:text>===================================================================================================================</xsl:text>
33 </xsl:variable>
34 <xsl:variable name="g_sUnderlineRefSect2">
35 <xsl:text>-------------------------------------------------------------------------------------------------------------------</xsl:text>
36 </xsl:variable>
37
38
39 <!-- Default action, do nothing. -->
40 <xsl:template match="node()|@*"/>
41
42 <!--
43 main() - because we need to order the output in a specific manner
44 that is contrary to the data flow in the refentry, this is
45 going to look a bit more like a C program than a stylesheet.
46 -->
47 <xsl:template match="refentry">
48 <!-- Assert refetry expectations. -->
49 <xsl:if test="not(./refsynopsisdiv)">
50 <xsl:message terminate="yes">refentry must have a refsynopsisdiv</xsl:message>
51 </xsl:if>
52 <xsl:if test="not(./refentryinfo/title)">
53 <xsl:message terminate="yes">refentry must have a refentryinfo with title</xsl:message>
54 </xsl:if>
55 <xsl:if test="not(./refmeta/refentrytitle)">
56 <xsl:message terminate="yes">refentry must have a refentryinfo with title</xsl:message>
57 </xsl:if>
58 <xsl:if test="./refmeta/refentrytitle != ./refnamediv/refname">
59 <xsl:message terminate="yes">The refmeta/refentrytitle and the refnamediv/refname must be identical</xsl:message>
60 </xsl:if>
61 <xsl:if test="not(./refsect1/title)">
62 <xsl:message terminate="yes">refentry must have a refsect1 with title</xsl:message>
63 </xsl:if>
64 <xsl:if test="not(@id) or @id = ''">
65 <xsl:message terminate="yes">refentry must have an id attribute</xsl:message>
66 </xsl:if>
67
68 <!-- variables -->
69 <xsl:variable name="sBaseId" select="@id"/>
70 <xsl:variable name="sDataBaseSym" select="concat('g_', translate(@id, '-', '_'))"/>
71
72
73 <!--
74 Convert the refsynopsisdiv into REFENTRY::Synopsis data.
75 -->
76 <xsl:text>
77
78static const REFENTRYSTR </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis[] =
79{</xsl:text>
80 <xsl:for-each select="./refsynopsisdiv/cmdsynopsis">
81 <!-- Assert synopsis expectations -->
82 <xsl:if test="not(@id) or substring-before(@id, '-') != 'synopsis'">
83 <xsl:message terminate="yes">The refsynopsisdiv/cmdsynopsis elements must have an id starting with 'synopsis-'.</xsl:message>
84 </xsl:if>
85 <xsl:if test="not(starts-with(substring-after(@id, '-'), $sBaseId))">
86 <xsl:message terminate="yes">The refsynopsisdiv/cmdsynopsis elements @id is expected to include the refentry @id.</xsl:message>
87 </xsl:if>
88 <xsl:if test="not(../../refsect1/refsect2[@id=./@id])">
89 <xsl:message terminate="yes">No refsect2 with id="<xsl:value-of select="@id"/>" found.</xsl:message>
90 </xsl:if>
91
92 <!-- Do the work. -->
93 <xsl:apply-templates select="."/>
94
95 </xsl:for-each>
96 <xsl:text>
97};</xsl:text>
98
99
100 <!--
101 Convert the whole manpage to help text.
102 -->
103 <xsl:text>
104static const REFENTRYSTR </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help[] =
105{</xsl:text>
106 <!-- We start by combining the refentry title and the refpurpose into a short description. -->
107 <xsl:text>
108 { </xsl:text><xsl:call-template name="calc-scope-for-refentry"/><xsl:text>,
109 "</xsl:text>
110 <xsl:apply-templates select="./refentryinfo/title/node()"/>
111 <xsl:text> -- </xsl:text>
112 <xsl:call-template name="capitalize">
113 <xsl:with-param name="text">
114 <xsl:apply-templates select="./refnamediv/refpurpose/node()"/>
115 </xsl:with-param>
116 </xsl:call-template>
117 <xsl:text>." },
118 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
119
120 <!-- The follows the usage (synopsis) section. -->
121 <xsl:text>
122 { REFENTRYSTR_SCOPE_GLOBAL,
123 "Usage" },
124 { REFENTRYSTR_SCOPE_SAME,
125 "=====" },
126 { REFENTRYSTR_SCOPE_SAME,
127 "" },</xsl:text>
128 <xsl:apply-templates select="./refsynopsisdiv/node()"/>
129
130 <!-- Then comes the description and other refsect1 -->
131 <xsl:for-each select="./refsect1">
132 <xsl:if test="name(*[1]) != 'title'"><xsl:message terminate="yes">Expected title as the first element in refsect1.</xsl:message></xsl:if>
133 <xsl:if test="text()"><xsl:message terminate="yes">No text supported in refsect1.</xsl:message></xsl:if>
134 <xsl:if test="not(./remark[@role='help-skip'])">
135 <xsl:variable name="sTitle">
136 <xsl:apply-templates select="./title/node()"/>
137 </xsl:variable>
138 <xsl:text>
139 { </xsl:text><xsl:call-template name="calc-scope-refsect1"/><xsl:text>, "" },
140 { REFENTRYSTR_SCOPE_SAME,
141 "</xsl:text><xsl:value-of select="$sTitle"/><xsl:text>" },
142 { REFENTRYSTR_SCOPE_SAME,
143 "</xsl:text>
144 <xsl:value-of select="substring($g_sUnderlineRefSect1, 1, string-length($sTitle))"/>
145 <xsl:text>" },</xsl:text>
146
147 <xsl:apply-templates select="./*[name() != 'title']"/>
148 </xsl:if>
149 </xsl:for-each>
150
151 <xsl:text>
152};</xsl:text>
153
154 <!--
155 Generate the refentry structure.
156 -->
157 <xsl:text>
158static const REFENTRY </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text> =
159{
160 /* .idInternal = */ HELP_CMD_</xsl:text>
161 <xsl:call-template name="str:to-upper">
162 <xsl:with-param name="text" select="translate(substring-after(@id, '-'), '-', '_')"/>
163 </xsl:call-template>
164 <xsl:text>,
165 /* .Synopsis = */ { RT_ELEMENTS(</xsl:text>
166 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis), 0, </xsl:text>
167 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis },
168 /* .Help = */ { RT_ELEMENTS(</xsl:text>
169 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help), 0, </xsl:text>
170 <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help },
171 /* pszBrief = */ "</xsl:text>
172 <xsl:apply-templates select="./refnamediv/refpurpose/node()"/>
173 <!-- TODO: Add the command name too. -->
174 <xsl:text>"
175};
176</xsl:text>
177 </xsl:template>
178
179
180 <!--
181 Convert command synopsis to text.
182 -->
183 <xsl:template match="cmdsynopsis">
184 <xsl:if test="text()"><xsl:message terminate="yes">cmdsynopsis with text is not supported.</xsl:message></xsl:if>
185 <xsl:text>
186 { </xsl:text><xsl:call-template name="calc-scope-cmdsynopsis"/><xsl:text> | REFENTRYSTR_FLAGS_SYNOPSIS,
187 "</xsl:text><xsl:call-template name="emit-indentation"/><xsl:apply-templates select="*|@*"/><xsl:text>" },</xsl:text>
188 </xsl:template>
189
190 <xsl:template match="sbr">
191 <xsl:text>" },
192 { REFENTRYSTR_SCOPE_SAME | REFENTRYSTR_FLAGS_SYNOPSIS,
193 " </xsl:text><xsl:call-template name="emit-indentation"/> <!-- hardcoded in VBoxManageHelp.cpp too -->
194 </xsl:template>
195
196 <xsl:template match="cmdsynopsis/command">
197 <xsl:text>" },
198 { REFENTRYSTR_SCOPE_SAME | REFENTRYSTR_FLAGS_SYNOPSIS,
199 "</xsl:text><xsl:call-template name="emit-indentation"/>
200 <xsl:apply-templates select="node()|@*"/>
201 </xsl:template>
202
203 <xsl:template match="cmdsynopsis/command[1]" priority="2">
204 <xsl:apply-templates select="node()|@*"/>
205 </xsl:template>
206
207 <xsl:template match="command|option|computeroutput">
208 <xsl:apply-templates select="node()|@*"/>
209 </xsl:template>
210
211 <xsl:template match="replaceable">
212 <xsl:choose>
213 <xsl:when test="not(ancestor::cmdsynopsis) or ancestor::arg">
214 <xsl:apply-templates />
215 </xsl:when>
216 <xsl:otherwise>
217 <xsl:text>&lt;</xsl:text>
218 <xsl:apply-templates />
219 <xsl:text>&gt;</xsl:text>
220 </xsl:otherwise>
221 </xsl:choose>
222 </xsl:template>
223
224 <!-- duplicated in docbook2latex.xsl -->
225 <xsl:template match="arg|group">
226 <!-- separator char if we're not the first child -->
227 <xsl:if test="position() > 1">
228 <xsl:choose>
229 <xsl:when test="parent::group"><xsl:value-of select="$arg.or.sep"/></xsl:when>
230 <xsl:when test="ancestor-or-self::*/@sepchar"><xsl:value-of select="ancestor-or-self::*/@sepchar"/></xsl:when>
231 <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
232 </xsl:choose>
233 </xsl:if>
234 <!-- open wrapping -->
235 <xsl:choose>
236 <xsl:when test="not(@choice) or @choice = ''"> <xsl:value-of select="$arg.choice.def.open.str"/></xsl:when>
237 <xsl:when test="@choice = 'opt'"> <xsl:value-of select="$arg.choice.opt.open.str"/></xsl:when>
238 <xsl:when test="@choice = 'req'"> <xsl:value-of select="$arg.choice.req.open.str"/></xsl:when>
239 <xsl:when test="@choice = 'plain'"/>
240 <xsl:otherwise><xsl:message terminate="yes">Invalid arg choice: "<xsl:value-of select="@choice"/>"</xsl:message></xsl:otherwise>
241 </xsl:choose>
242
243 <!-- render the arg (TODO: may need to do more work here) -->
244 <xsl:apply-templates />
245
246 <!-- repeat wrapping -->
247 <xsl:choose>
248 <xsl:when test="@rep = 'norepeat' or not(@rep) or @rep = ''"/>
249 <xsl:when test="@rep = 'repeat'"> <xsl:value-of select="$arg.rep.repeat.str"/></xsl:when>
250 <xsl:otherwise><xsl:message terminate="yes">Invalid rep choice: "<xsl:value-of select="@rep"/>"</xsl:message></xsl:otherwise>
251 </xsl:choose>
252 <!-- close wrapping -->
253 <xsl:choose>
254 <xsl:when test="not(@choice) or @choice = ''"> <xsl:value-of select="$arg.choice.def.close.str"/></xsl:when>
255 <xsl:when test="@choice = 'opt'"> <xsl:value-of select="$arg.choice.opt.close.str"/></xsl:when>
256 <xsl:when test="@choice = 'req'"> <xsl:value-of select="$arg.choice.req.close.str"/></xsl:when>
257 </xsl:choose>
258 </xsl:template>
259
260
261 <!--
262 refsect2
263 -->
264 <xsl:template match="refsect2">
265 <!-- assertions -->
266 <xsl:if test="text()"><xsl:message terminate="yes">refsect2 shouldn't contain text</xsl:message></xsl:if>
267 <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>
268
269 <!-- title / command synopsis - sets the scope. -->
270 <xsl:variable name="sTitle">
271 <xsl:apply-templates select="./title/text()"/>
272 </xsl:variable>
273 <xsl:text>
274 { </xsl:text><xsl:call-template name="calc-scope-refsect2"/><xsl:text>, "" },
275 { REFENTRYSTR_SCOPE_SAME,
276 "</xsl:text><xsl:call-template name="emit-indentation"/>
277 <xsl:value-of select="$sTitle"/>
278 <xsl:text>" },
279 { REFENTRYSTR_SCOPE_SAME,
280 "</xsl:text><xsl:call-template name="emit-indentation"/>
281 <xsl:value-of select="substring($g_sUnderlineRefSect2, 1, string-length($sTitle))"/>
282 <xsl:text>" },
283 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
284
285 <!-- Format the text in the section -->
286 <xsl:for-each select="./*[name() != 'title']">
287 <xsl:apply-templates select="."/>
288 </xsl:for-each>
289
290 <!-- Add two blank lines, unless we're the last element in this refsect1. -->
291 <xsl:if test="position() != last()">
292 <xsl:text>
293 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
294 </xsl:if>
295 </xsl:template>
296
297
298 <!--
299 para
300 -->
301 <xsl:template match="para">
302 <xsl:if test="position() != 1 or not(parent::listitem)">
303 <xsl:text>
304 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
305 </xsl:if>
306 <xsl:call-template name="process-mixed"/>
307 </xsl:template>
308
309
310 <!--
311 variablelist
312 -->
313 <xsl:template match="variablelist">
314 <xsl:if test="*[not(self::varlistentry)]|text()">
315 <xsl:message terminate="yes">Only varlistentry elements are supported in variablelist</xsl:message>
316 </xsl:if>
317 <xsl:for-each select="./varlistentry">
318 <xsl:if test="count(*) != 2 or not(term) or not(listitem)">
319 <xsl:message terminate="yes">Expected exactly one term and one listentry member in varlistentry element.</xsl:message>
320 </xsl:if>
321 <xsl:if test="not(@spacing) or @spacing != 'compact'">
322 <xsl:text>
323 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
324 </xsl:if>
325 <xsl:apply-templates select="*"/>
326 </xsl:for-each>
327 </xsl:template>
328
329 <xsl:template match="varlistentry/term">
330 <xsl:call-template name="process-mixed"/>
331 </xsl:template>
332
333 <xsl:template match="varlistentry/listitem">
334 <xsl:if test="text() or *[not(self::para or self::itemizedlist)]">
335 <xsl:message terminate="yes">Expected varlistentry/listitem to only contain para elements</xsl:message>
336 </xsl:if>
337 <xsl:apply-templates select="*"/>
338 </xsl:template>
339
340
341 <!--
342 itemizedlist
343 -->
344 <xsl:template match="itemizedlist">
345 <xsl:if test="*[not(self::listitem)]|text()">
346 <xsl:message terminate="yes">Only listitem elements are supported in itemizedlist.</xsl:message>
347 </xsl:if>
348 <xsl:if test="parent::para">
349 <xsl:message terminate="yes">itemizedlist inside a para is current not supported. <!-- no newline
350 -->Close the para before the list, it makes no difference to html and latex/pdf output.</xsl:message>
351 </xsl:if>
352 <xsl:if test="position() != 1 and (not(@spacing) or @spacing != 'compact')">
353 <xsl:text>
354 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
355 </xsl:if>
356 <xsl:for-each select="./listitem">
357 <xsl:apply-templates select="*"/>
358 </xsl:for-each>
359 </xsl:template>
360
361 <xsl:template match="itemizedlist/listitem">
362 <xsl:if test="text() or *[not(self::para)]">
363 <xsl:message terminate="yes">Expected itemizedlist/listitem to only contain para elements</xsl:message>
364 </xsl:if>
365 <xsl:if test="position() != 1 and @spaceing != 'compact'">
366 <xsl:text>
367 { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
368 </xsl:if>
369 <xsl:apply-templates select="*"/>
370 </xsl:template>
371
372
373 <!--
374 Screen
375 -->
376 <xsl:template match="screen">
377 <xsl:if test="ancestor::para">
378 <xsl:text>" },</xsl:text>
379 </xsl:if>
380
381 <xsl:text>
382 { REFENTRYSTR_SCOPE_SAME,
383 "</xsl:text>
384
385 <xsl:for-each select="node()">
386 <xsl:choose>
387 <xsl:when test="name() = ''">
388 <xsl:call-template name="screen_text_line">
389 <xsl:with-param name="sText" select="."/>
390 </xsl:call-template>
391 </xsl:when>
392 <xsl:otherwise>
393 <xsl:if test="*">
394 <xsl:message terminate="yes">Support for elements under screen has not been implemented: <xsl:value-of select="name()"/></xsl:message>
395 </xsl:if>
396 </xsl:otherwise>
397 </xsl:choose>
398 </xsl:for-each>
399
400 <xsl:if test="not(ancestor::para)">
401 <xsl:text>" },</xsl:text>
402 </xsl:if>
403 </xsl:template>
404
405 <xsl:template name="screen_text_line">
406 <xsl:param name="sText"/>
407 <xsl:call-template name="escape_fixed_text">
408 <xsl:with-param name="sText" select="substring-before($sText,'&#x0a;')"/>
409 </xsl:call-template>
410
411 <xsl:if test="substring-after($sText,'&#x0a;')">
412 <xsl:text>" },
413 { REFENTRYSTR_SCOPE_SAME,
414 "</xsl:text>
415 <xsl:call-template name="screen_text_line">
416 <xsl:with-param name="sText" select="substring-after($sText,'&#x0a;')"/>
417 </xsl:call-template>
418 </xsl:if>
419 </xsl:template>
420
421
422
423 <!--
424 Text escaping for C.
425 -->
426 <xsl:template match="text()" name="escape_text">
427 <xsl:choose>
428
429 <xsl:when test="contains(., '\') or contains(., '&quot;')">
430 <xsl:variable name="sTmp">
431 <xsl:call-template name="str:subst">
432 <xsl:with-param name="text" select="normalize-space(.)"/>
433 <xsl:with-param name="replace" select="'\'"/>
434 <xsl:with-param name="with" select="'\\'"/>
435 <xsl:with-param name="disable-output-escaping" select="yes"/>
436 </xsl:call-template>
437 </xsl:variable>
438 <xsl:call-template name="str:subst">
439 <xsl:with-param name="text" select="$sTmp"/>
440 <xsl:with-param name="replace" select="'&quot;'"/>
441 <xsl:with-param name="with" select="'\&quot;'"/>
442 <xsl:with-param name="disable-output-escaping" select="yes"/>
443 </xsl:call-template>
444 </xsl:when>
445
446 <xsl:otherwise>
447 <xsl:value-of select="normalize-space(.)"/>
448 </xsl:otherwise>
449 </xsl:choose>
450
451 <!-- Ugly whitespace hack! Mainly for <arg>-_-cpu <replaceable>id</replaceable></arg> -->
452 <xsl:if test="substring(.,string-length(.)) = ' ' and position() != last()">
453 <xsl:text> </xsl:text>
454 </xsl:if>
455
456 </xsl:template>
457
458 <!-- Elements producing non-breaking strings (single line). -->
459 <xsl:template match="command/text()|option/text()|computeroutput/text()|arg/text()" name="escape_fixed_text">
460 <xsl:param name="sText" select="."/>
461 <xsl:choose>
462
463 <xsl:when test="contains($sText, '\') or contains($sText, '&quot;')">
464 <xsl:variable name="sTmp1">
465 <xsl:call-template name="str:subst">
466 <xsl:with-param name="text" select="$sText"/>
467 <xsl:with-param name="replace" select="'\'"/>
468 <xsl:with-param name="with" select="'\\'"/>
469 <xsl:with-param name="disable-output-escaping" select="yes"/>
470 </xsl:call-template>
471 </xsl:variable>
472 <xsl:variable name="sTmp2">
473 <xsl:call-template name="str:subst">
474 <xsl:with-param name="text" select="$sTmp1"/>
475 <xsl:with-param name="replace" select="'&quot;'"/>
476 <xsl:with-param name="with" select="'\&quot;'"/>
477 <xsl:with-param name="disable-output-escaping" select="yes"/>
478 </xsl:call-template>
479 </xsl:variable>
480 <xsl:call-template name="str:subst">
481 <xsl:with-param name="text" select="$sTmp2"/>
482 <xsl:with-param name="replace" select="' '"/>
483 <xsl:with-param name="with" select="'\b'"/>
484 <xsl:with-param name="disable-output-escaping" select="yes"/>
485 </xsl:call-template>
486 </xsl:when>
487
488 <xsl:when test="contains($sText, ' ')">
489 <xsl:call-template name="str:subst">
490 <xsl:with-param name="text" select="$sText"/>
491 <xsl:with-param name="replace" select="' '"/>
492 <xsl:with-param name="with" select="'\b'"/>
493 <xsl:with-param name="disable-output-escaping" select="yes"/>
494 </xsl:call-template>
495 </xsl:when>
496
497 <xsl:otherwise>
498 <xsl:value-of select="$sText"/>
499 </xsl:otherwise>
500 </xsl:choose>
501 </xsl:template>
502
503
504 <!--
505 Unsupported elements and elements handled directly.
506 -->
507 <xsl:template match="synopfragment|synopfragmentref|title|refsect1">
508 <xsl:message terminate="yes">The <xsl:value-of select="name()"/> element is not supported</xsl:message>
509 </xsl:template>
510
511 <!--
512 Fail on misplaced scoping remarks.
513 -->
514 <xsl:template match="remark[@role = 'help-scope']">
515 <xsl:choose>
516 <xsl:when test="parent::refsect1"/>
517 <xsl:when test="parent::refsect2"/>
518 <xsl:when test="parent::cmdsynopsis and ancestor::refsynopsisdiv"/>
519 <xsl:otherwise>
520 <xsl:message terminate="yes">Misplaced remark/@role=help-scope element.
521Only supported on: refsect1, refsect2, refsynopsisdiv/cmdsynopsis</xsl:message>
522 </xsl:otherwise>
523 </xsl:choose>
524 </xsl:template>
525
526 <!--
527 Execute synopsis copy remark (avoids duplication for complicated xml).
528 -->
529 <xsl:template match="remark[@role = 'help-copy-synopsis']">
530 <xsl:message terminate="yes">remark/@role=help-copy-synopsis is not supported by this stylesheet. Must preprocess input!</xsl:message>
531 </xsl:template>
532
533 <!--
534 Warn about unhandled elements
535 -->
536 <xsl:template match="*">
537 <xsl:message terminate="no">Warning: Unhandled element: <!-- no newline -->
538 <xsl:for-each select="ancestor-or-self::*">
539 <xsl:text>/</xsl:text>
540 <xsl:value-of select="name(.)"/>
541 <xsl:if test="@id">
542 <xsl:value-of select="concat('[id=', @id ,']')"/>
543 </xsl:if>
544 </xsl:for-each>
545 </xsl:message>
546 </xsl:template>
547
548
549 <!--
550 Functions
551 Functions
552 Functions
553 -->
554
555 <!--
556 Processes mixed children, i.e. both text and regular elements.
557 Normalizes whitespace. -->
558 <xsl:template name="process-mixed">
559 <xsl:text>
560 { REFENTRYSTR_SCOPE_SAME,
561 "</xsl:text><xsl:call-template name="emit-indentation"/>
562
563 <xsl:for-each select="node()[not(self::remark)]">
564 <xsl:if test="position() != 1">
565 <xsl:text> </xsl:text>
566 </xsl:if>
567 <xsl:choose>
568 <xsl:when test="name() = ''">
569 <xsl:call-template name="escape_text"/>
570 </xsl:when>
571 <xsl:otherwise>
572 <xsl:apply-templates select="."/>
573 </xsl:otherwise>
574 </xsl:choose>
575 </xsl:for-each>
576
577 <xsl:text>" },</xsl:text>
578 </xsl:template>
579
580
581 <!--
582 Element specific scoping.
583 -->
584
585 <xsl:template name="calc-scope-for-refentry">
586 <xsl:call-template name="calc-scope-const-from-id"/>
587 </xsl:template>
588
589 <!-- Figures out the scope of a refsect1 element. -->
590 <xsl:template name="calc-scope-refsect1">
591 <xsl:choose>
592 <xsl:when test="title[text() = 'Description']">
593 <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
594 </xsl:when>
595 <xsl:when test="@id or remark[@role='help-scope']">
596 <xsl:call-template name="calc-scope-from-remark-or-id"/>
597 </xsl:when>
598 <xsl:otherwise>
599 <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
600 </xsl:otherwise>
601 </xsl:choose>
602 </xsl:template>
603
604 <!-- Figures out the scope of a refsect2 element. -->
605 <xsl:template name="calc-scope-refsect2">
606 <xsl:choose>
607 <xsl:when test="@id or remark[@role='help-scope']">
608 <xsl:call-template name="calc-scope-from-remark-or-id"/>
609 </xsl:when>
610 <xsl:otherwise>
611 <xsl:text>REFENTRYSTR_SCOPE_SAME</xsl:text>
612 </xsl:otherwise>
613 </xsl:choose>
614 </xsl:template>
615
616 <!-- Figures out the scope of a refsect1 element. -->
617 <xsl:template name="calc-scope-cmdsynopsis">
618 <xsl:choose>
619 <xsl:when test="ancestor::refsynopsisdiv">
620 <xsl:call-template name="calc-scope-from-remark-or-id">
621 <xsl:with-param name="sId" select="substring-after(@id, '-')"/>
622 </xsl:call-template>
623 </xsl:when>
624 <xsl:otherwise>
625 <xsl:text>REFENTRYSTR_SCOPE_SAME</xsl:text>
626 </xsl:otherwise>
627 </xsl:choose>
628 </xsl:template>
629
630
631 <!--
632 Scoping worker functions.
633 -->
634
635 <!-- Calculates the current scope from the scope remark or @id. -->
636 <xsl:template name="calc-scope-from-remark-or-id">
637 <xsl:param name="sId" select="@id"/>
638 <xsl:choose>
639 <xsl:when test="remark[@role='help-scope']">
640 <xsl:call-template name="calc-scope-consts-from-remark"/>
641 </xsl:when>
642 <xsl:when test="$sId != ''">
643 <xsl:call-template name="calc-scope-const-from-id">
644 <xsl:with-param name="sId" select="$sId"/>
645 </xsl:call-template>
646 </xsl:when>
647 <xsl:otherwise>
648 <xsl:message terminate="yes">expected remark child or id attribute.</xsl:message>
649 </xsl:otherwise>
650 </xsl:choose>
651 </xsl:template>
652
653 <!-- Turns a @id into a scope constant.
654 Some woodoo taking place here here that chops the everything up to and
655 including the first refentry/@id word from all IDs before turning them into
656 constants (word delimiter '-'). -->
657 <xsl:template name="calc-scope-const-from-id">
658 <xsl:param name="sId" select="@id"/>
659 <xsl:variable name="sPrefix" select="concat(substring-before(ancestor::refentry/@id, '-'), '-')"/>
660 <xsl:if test="not(contains($sId, sPrefix))">
661 <xsl:message terminate="yes">Expected sId (<xsl:value-of select="$sId"/>) to contain <xsl:value-of select="$sPrefix"/></xsl:message>
662 </xsl:if>
663 <xsl:text>HELP_SCOPE_</xsl:text>
664 <xsl:call-template name="str:to-upper">
665 <xsl:with-param name="text" select="translate(substring-after($sId, $sPrefix), '-', '_')"/>
666 </xsl:call-template>
667 </xsl:template>
668
669 <!-- Turns a remark into one or more scope constant. -->
670 <xsl:template name="calc-scope-consts-from-remark">
671 <xsl:param name="sCondition" select="remark/@condition"/>
672 <xsl:variable name="sNormalized" select="concat(normalize-space(translate($sCondition, ',;:|', ' ')), ' ')"/>
673 <xsl:if test="$sNormalized = ' ' or $sNormalized = ''">
674 <xsl:message terminate="yes">Empty @condition for help-scope remark.</xsl:message>
675 </xsl:if>
676 <xsl:choose>
677 <xsl:when test="substring-before($sNormalized, ' ') = 'GLOBAL'">
678 <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
679 </xsl:when>
680 <xsl:otherwise>
681 <xsl:text>HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sNormalized, ' ')"/>
682 </xsl:otherwise>
683 </xsl:choose>
684 <xsl:call-template name="calc-scope-const-from-remark-worker">
685 <xsl:with-param name="sList" select="substring-after($sNormalized, ' ')"/>
686 </xsl:call-template>
687 </xsl:template>
688
689 <xsl:template name="calc-scope-const-from-remark-worker">
690 <xsl:param name="sList"/>
691 <xsl:if test="$sList != ''">
692 <xsl:choose>
693 <xsl:when test="substring-before($sList, ' ') = 'GLOBAL'">
694 <xsl:text>| REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
695 </xsl:when>
696 <xsl:otherwise>
697 <xsl:text> | HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sList, ' ')"/>
698 </xsl:otherwise>
699 </xsl:choose>
700 <xsl:call-template name="calc-scope-const-from-remark-worker">
701 <xsl:with-param name="sList" select="substring-after($sList, ' ')"/>
702 </xsl:call-template>
703 </xsl:if>
704 </xsl:template>
705
706
707 <!--
708 Calculates and emits indentation list markup.
709 -->
710 <xsl:template name="emit-indentation">
711 <xsl:variable name="iDepth" select="count(ancestor-or-self::*)"/>
712 <xsl:for-each select="ancestor-or-self::*">
713 <xsl:choose>
714 <xsl:when test="self::refsect1
715 | self::refsect2
716 | self::refsect3
717 | self::refsynopsisdiv">
718 <xsl:text> </xsl:text>
719 </xsl:when>
720 <xsl:when test="self::term"/> <!-- currently no indent. -->
721 <xsl:when test="self::listitem and parent::varlistentry">
722 <xsl:text> </xsl:text>
723 </xsl:when>
724 <xsl:when test="self::listitem and parent::itemizedlist and (position() + 1) = $iDepth">
725 <xsl:text> * </xsl:text>
726 </xsl:when>
727 <xsl:when test="self::listitem and parent::itemizedlist">
728 <xsl:text> </xsl:text>
729 </xsl:when>
730 </xsl:choose>
731 </xsl:for-each>
732 </xsl:template>
733
734 <!--
735 Captializes the given text.
736 -->
737 <xsl:template name="capitalize">
738 <xsl:param name="text"/>
739 <xsl:call-template name="str:to-upper">
740 <xsl:with-param name="text" select="substring($text,1,1)"/>
741 </xsl:call-template>
742 <xsl:value-of select="substring($text,2)"/>
743 </xsl:template>
744
745</xsl:stylesheet>
746
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