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 |
|
---|
27 | <xsl:output method="text" version="1.0" encoding="utf-8" indent="yes"/>
|
---|
28 | <xsl:strip-space elements="*"/>
|
---|
29 |
|
---|
30 |
|
---|
31 | <!-- Default action, do nothing. -->
|
---|
32 | <xsl:template match="node()|@*"/>
|
---|
33 |
|
---|
34 |
|
---|
35 | <!--
|
---|
36 | main() - because we need to order the output in a specific manner
|
---|
37 | that is contrary to the data flow in the refentry, this is
|
---|
38 | going to look a bit more like a C program than a stylesheet.
|
---|
39 | -->
|
---|
40 | <xsl:template match="refentry">
|
---|
41 | <!-- Assert refetry expectations. -->
|
---|
42 | <xsl:if test="not(./refsynopsisdiv)"> <xsl:message terminate="yes">refentry must have a refsynopsisdiv</xsl:message></xsl:if>
|
---|
43 | <xsl:if test="not(./refentryinfo/title)"> <xsl:message terminate="yes">refentry must have a refentryinfo with title</xsl:message></xsl:if>
|
---|
44 | <xsl:if test="not(./refsect1/title)"> <xsl:message terminate="yes">refentry must have a refsect1 with title</xsl:message></xsl:if>
|
---|
45 | <xsl:if test="not(@id) or @id = ''"> <xsl:message terminate="yes">refentry must have an id attribute</xsl:message></xsl:if>
|
---|
46 |
|
---|
47 | <!-- variables -->
|
---|
48 | <xsl:variable name="sBaseId" select="@id"/>
|
---|
49 | <xsl:variable name="sDataBaseSym" select="concat('g_', translate(@id, '-', '_'))"/>
|
---|
50 |
|
---|
51 |
|
---|
52 | <!--
|
---|
53 | Convert the refsynopsisdiv into REFENTRY::Synopsis data.
|
---|
54 | -->
|
---|
55 | <xsl:text>
|
---|
56 |
|
---|
57 | static const REFENTRYSTR </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis[] =
|
---|
58 | {</xsl:text>
|
---|
59 | <xsl:for-each select="./refsynopsisdiv/cmdsynopsis">
|
---|
60 | <!-- Assert synopsis expectations -->
|
---|
61 | <xsl:if test="not(@id) or substring-before(@id, '-') != 'synopsis'">
|
---|
62 | <xsl:message terminate="yes">The refsynopsisdiv/cmdsynopsis elements must have an id starting with 'synopsis-'.</xsl:message>
|
---|
63 | </xsl:if>
|
---|
64 | <xsl:if test="not(../../refsect1/refsect2[@id=./@id])">
|
---|
65 | <xsl:message terminate="yes">No refsect2 with id="<xsl:value-of select="@id"/>" found.</xsl:message>
|
---|
66 | </xsl:if>
|
---|
67 |
|
---|
68 | <!-- Do the work. -->
|
---|
69 | <xsl:apply-templates select="."/>
|
---|
70 |
|
---|
71 | </xsl:for-each>
|
---|
72 | <xsl:text>
|
---|
73 | };</xsl:text>
|
---|
74 |
|
---|
75 |
|
---|
76 | <!--
|
---|
77 | Convert the whole manpage to help text.
|
---|
78 | -->
|
---|
79 | <xsl:text>
|
---|
80 | static const REFENTRYSTR </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help[] =
|
---|
81 | {</xsl:text>
|
---|
82 | <!-- We start by combining the refentry title and the refpurpose into a short description. -->
|
---|
83 | <xsl:text>
|
---|
84 | { </xsl:text><xsl:call-template name="calc-scope"/><xsl:text>,
|
---|
85 | "</xsl:text>
|
---|
86 | <xsl:apply-templates select="./refentryinfo/title/node()"/>
|
---|
87 | <xsl:text> -- </xsl:text>
|
---|
88 | <xsl:call-template name="capitalize">
|
---|
89 | <xsl:with-param name="text">
|
---|
90 | <xsl:apply-templates select="./refnamediv/refpurpose/node()"/>
|
---|
91 | </xsl:with-param>
|
---|
92 | </xsl:call-template>
|
---|
93 | <xsl:text>." },
|
---|
94 | { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
|
---|
95 |
|
---|
96 | <!-- The follows the usage (synopsis) section. -->
|
---|
97 | <xsl:text>
|
---|
98 | { REFENTRYSTR_SCOPE_GLOBAL,
|
---|
99 | "Usage:" },</xsl:text>
|
---|
100 | <xsl:apply-templates select="./refsynopsisdiv/node()"/>
|
---|
101 |
|
---|
102 | <!-- Then comes the description and other refsect1 -->
|
---|
103 | <xsl:for-each select="./refsect1">
|
---|
104 | <xsl:if test="name(*[1]) != 'title'"><xsl:message terminate="yes">Expected title as the first element in refsect1.</xsl:message></xsl:if>
|
---|
105 | <xsl:if test="text()"><xsl:message terminate="yes">No text supported in refsect1.</xsl:message></xsl:if>
|
---|
106 | <xsl:if test="not(./remark[@role='help-skip'])">
|
---|
107 | <xsl:text>
|
---|
108 | { </xsl:text><xsl:call-template name="calc-scope-refsect1"/><xsl:text>, "" },
|
---|
109 | { REFENTRYSTR_SCOPE_SAME,
|
---|
110 | "</xsl:text><xsl:apply-templates select="title/node()"/><xsl:text>:" },</xsl:text>
|
---|
111 | <xsl:apply-templates select="./*[position() > 1]"/>
|
---|
112 | </xsl:if>
|
---|
113 | </xsl:for-each>
|
---|
114 |
|
---|
115 | <xsl:text>
|
---|
116 | };</xsl:text>
|
---|
117 |
|
---|
118 | <!--
|
---|
119 | Generate the refentry structure.
|
---|
120 | -->
|
---|
121 | <xsl:text>
|
---|
122 | static const REFENTRY </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text> =
|
---|
123 | {
|
---|
124 | /* .idinternal = */ HELP_CMD_</xsl:text>
|
---|
125 | <xsl:call-template name="str:to-upper">
|
---|
126 | <xsl:with-param name="text" select="translate(substring-after(@id, '-'), '-', '_')"/>
|
---|
127 | </xsl:call-template>
|
---|
128 | <xsl:text>,
|
---|
129 | /* .Synopsis = */ { </xsl:text>
|
---|
130 | <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis, RT_ELEMENTS(</xsl:text>
|
---|
131 | <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis) },
|
---|
132 | /* .Help = */ { </xsl:text>
|
---|
133 | <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help, RT_ELEMENTS(</xsl:text>
|
---|
134 | <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help) },
|
---|
135 | /* pszBrief = */ "</xsl:text>
|
---|
136 | <xsl:apply-templates select="./refnamediv/refpurpose/node()"/>
|
---|
137 | <xsl:text>"
|
---|
138 | };
|
---|
139 | </xsl:text>
|
---|
140 | </xsl:template>
|
---|
141 |
|
---|
142 |
|
---|
143 | <!--
|
---|
144 | Convert command synopsis to text.
|
---|
145 | -->
|
---|
146 | <xsl:template match="cmdsynopsis">
|
---|
147 | <xsl:if test="text()"><xsl:message terminate="yes">cmdsynopsis with text is not supported.</xsl:message></xsl:if>
|
---|
148 | <xsl:text>
|
---|
149 | { </xsl:text><xsl:call-template name="calc-scope-cmdsynopsis"/><xsl:text>,
|
---|
150 | "</xsl:text><xsl:call-template name="emit-indentation"/><xsl:apply-templates select="*|@*"/><xsl:text>" },</xsl:text>
|
---|
151 | </xsl:template>
|
---|
152 |
|
---|
153 | <xsl:template match="sbr">
|
---|
154 | <xsl:text>" },
|
---|
155 | { REFENTRYSTR_SCOPE_SAME,
|
---|
156 | " </xsl:text><xsl:call-template name="emit-indentation"/>
|
---|
157 | </xsl:template>
|
---|
158 |
|
---|
159 | <xsl:template match="command|option|computeroutput">
|
---|
160 | <xsl:apply-templates select="node()|@*"/>
|
---|
161 | </xsl:template>
|
---|
162 |
|
---|
163 | <xsl:template match="replaceable">
|
---|
164 | <xsl:text><</xsl:text>
|
---|
165 | <xsl:apply-templates select="node()|@*"/>
|
---|
166 | <xsl:text>></xsl:text>
|
---|
167 | </xsl:template>
|
---|
168 |
|
---|
169 | <xsl:template match="arg|group">
|
---|
170 | <!-- separator char if we're not the first child -->
|
---|
171 | <xsl:if test="position() > 1">
|
---|
172 | <xsl:choose>
|
---|
173 | <xsl:when test="ancestor-or-self::*/@sepchar"><xsl:value-of select="ancestor-or-self::*/@sepchar"/></xsl:when>
|
---|
174 | <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
|
---|
175 | </xsl:choose>
|
---|
176 | </xsl:if>
|
---|
177 | <!-- open wrapping -->
|
---|
178 | <xsl:choose>
|
---|
179 | <xsl:when test="@choice = 'opt' or not(@choice) or @choice = ''"> <xsl:text>[</xsl:text></xsl:when>
|
---|
180 | <xsl:when test="@choice = 'req'"> <xsl:text></xsl:text></xsl:when>
|
---|
181 | <xsl:when test="@choice = 'plain'"/>
|
---|
182 | <xsl:otherwise><xsl:message terminate="yes">Invalid arg choice: "<xsl:value-of select="@choice"/>"</xsl:message></xsl:otherwise>
|
---|
183 | </xsl:choose>
|
---|
184 | <!-- render the arg (TODO: may need to do more work here) -->
|
---|
185 | <xsl:apply-templates select="node()|@*"/>
|
---|
186 | <!-- repeat wrapping -->
|
---|
187 | <xsl:choose>
|
---|
188 | <xsl:when test="@rep = 'norepeat' or not(@rep) or @rep = ''"/>
|
---|
189 | <xsl:when test="@rep = 'repeat'"> <xsl:text>...</xsl:text></xsl:when>
|
---|
190 | <xsl:otherwise><xsl:message terminate="yes">Invalid rep choice: "<xsl:value-of select="@rep"/>"</xsl:message></xsl:otherwise>
|
---|
191 | </xsl:choose>
|
---|
192 | <!-- close wrapping -->
|
---|
193 | <xsl:choose>
|
---|
194 | <xsl:when test="@choice = 'opt' or not(@choice) or @choice = ''"> <xsl:text>]</xsl:text></xsl:when>
|
---|
195 | <xsl:when test="@choice = 'req'"> <xsl:text></xsl:text></xsl:when>
|
---|
196 | </xsl:choose>
|
---|
197 | </xsl:template>
|
---|
198 |
|
---|
199 |
|
---|
200 | <!--
|
---|
201 | refsect2
|
---|
202 | -->
|
---|
203 | <xsl:template match="refsect2">
|
---|
204 | <!-- assertions -->
|
---|
205 | <xsl:if test="text()"><xsl:message terminate="yes">refsect2 shouldn't contain text</xsl:message></xsl:if>
|
---|
206 | <xsl:if test="count(./cmdsynopsis) > 1"><xsl:message terminate="yes">Only a single cmdsynopsis is currently supported in a refsect2.</xsl:message></xsl:if>
|
---|
207 | <xsl:if test="count(./title) > 1"><xsl:message terminate="yes">Only a single title in refsect2</xsl:message></xsl:if>
|
---|
208 |
|
---|
209 | <!-- title / command synopsis - sets the scope. -->
|
---|
210 | <xsl:text>
|
---|
211 | { </xsl:text><xsl:call-template name="calc-scope-refsect2"/><xsl:text>,
|
---|
212 | "</xsl:text><xsl:call-template name="emit-indentation"/>
|
---|
213 | <xsl:choose>
|
---|
214 | <xsl:when test="name(./*[1]) = 'cmdsynopsis'">
|
---|
215 | <xsl:text> </xsl:text>
|
---|
216 | <xsl:apply-templates select="./cmdsynopsis/node()|./cmdsynopsis/@*"/>
|
---|
217 | </xsl:when>
|
---|
218 | <xsl:when test="name(./*[1]) = 'title'">
|
---|
219 | <xsl:apply-templates select="./title/text()"/>
|
---|
220 | </xsl:when>
|
---|
221 | <xsl:otherwise>
|
---|
222 | <xsl:message terminate="yes">Expected either a title or cmdsynopsis as the first element in a refsect2.
|
---|
223 | (Put scoping remarks after.)</xsl:message>
|
---|
224 | </xsl:otherwise>
|
---|
225 | </xsl:choose>
|
---|
226 | <xsl:text>" },</xsl:text>
|
---|
227 |
|
---|
228 | <!-- Format the text in the section -->
|
---|
229 | <xsl:apply-templates select="./*[position() > 1]"/>
|
---|
230 |
|
---|
231 | <!-- Add a blank line, unless we're the last element in this refsect1. -->
|
---|
232 | <xsl:if test="position() != last()">
|
---|
233 | <xsl:text>
|
---|
234 | { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
|
---|
235 | </xsl:if>
|
---|
236 | </xsl:template>
|
---|
237 |
|
---|
238 |
|
---|
239 | <!--
|
---|
240 | para
|
---|
241 | -->
|
---|
242 | <xsl:template match="para">
|
---|
243 | <xsl:if test="position() != 1 or not(parent::listitem)">
|
---|
244 | <xsl:text>
|
---|
245 | { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
|
---|
246 | </xsl:if>
|
---|
247 | <xsl:call-template name="process-mixed"/>
|
---|
248 | </xsl:template>
|
---|
249 |
|
---|
250 |
|
---|
251 | <!--
|
---|
252 | variablelist
|
---|
253 | -->
|
---|
254 | <xsl:template match="variablelist">
|
---|
255 | <xsl:if test="*[not(self::varlistentry)]|text()">
|
---|
256 | <xsl:message terminate="yes">Only varlistentry elements are supported in variablelist</xsl:message>
|
---|
257 | </xsl:if>
|
---|
258 | <xsl:for-each select="./varlistentry">
|
---|
259 | <xsl:if test="count(*) != 2 or not(term) or not(listitem)">
|
---|
260 | <xsl:message terminate="yes">Expected exactly one term and one listentry member in varlistentry element.</xsl:message>
|
---|
261 | </xsl:if>
|
---|
262 | <xsl:apply-templates select="*"/>
|
---|
263 | </xsl:for-each>
|
---|
264 | </xsl:template>
|
---|
265 |
|
---|
266 | <xsl:template match="varlistentry/term">
|
---|
267 | <xsl:call-template name="process-mixed"/>
|
---|
268 | </xsl:template>
|
---|
269 |
|
---|
270 | <xsl:template match="varlistentry/listitem">
|
---|
271 | <xsl:if test="text() or *[not(self::para)]">
|
---|
272 | <xsl:message terminate="yes">Expected varlistentry/listitem to only contain para elements</xsl:message>
|
---|
273 | </xsl:if>
|
---|
274 | <xsl:apply-templates select="*"/>
|
---|
275 | </xsl:template>
|
---|
276 |
|
---|
277 |
|
---|
278 | <!--
|
---|
279 | Text escaping for C.
|
---|
280 | -->
|
---|
281 | <xsl:template match="text()" name="escape_text">
|
---|
282 | <xsl:choose>
|
---|
283 |
|
---|
284 | <xsl:when test="contains(., '\') or contains(., '"')">
|
---|
285 | <xsl:variable name="sTmp">
|
---|
286 | <xsl:call-template name="str:subst">
|
---|
287 | <xsl:with-param name="text" select="normalize-space(.)"/>
|
---|
288 | <xsl:with-param name="replace" select="'\'"/>
|
---|
289 | <xsl:with-param name="with" select="'\\'"/>
|
---|
290 | <xsl:with-param name="disable-output-escaping" select="yes"/>
|
---|
291 | </xsl:call-template>
|
---|
292 | </xsl:variable>
|
---|
293 | <xsl:call-template name="str:subst">
|
---|
294 | <xsl:with-param name="text" select="$sTmp"/>
|
---|
295 | <xsl:with-param name="replace" select="'"'"/>
|
---|
296 | <xsl:with-param name="with" select="'\"'"/>
|
---|
297 | <xsl:with-param name="disable-output-escaping" select="yes"/>
|
---|
298 | </xsl:call-template>
|
---|
299 | </xsl:when>
|
---|
300 |
|
---|
301 | <xsl:otherwise>
|
---|
302 | <xsl:value-of select="normalize-space(.)"/>
|
---|
303 | </xsl:otherwise>
|
---|
304 | </xsl:choose>
|
---|
305 | </xsl:template>
|
---|
306 |
|
---|
307 | <!-- Elements producing non-breaking strings (single line). -->
|
---|
308 | <xsl:template match="command/text()|option/text()|computeroutput/text()" name="escape_fixed_text">
|
---|
309 | <xsl:choose>
|
---|
310 |
|
---|
311 | <xsl:when test="contains(., '\') or contains(., '"')">
|
---|
312 | <xsl:variable name="sTmp1">
|
---|
313 | <xsl:call-template name="str:subst">
|
---|
314 | <xsl:with-param name="text" select="."/>
|
---|
315 | <xsl:with-param name="replace" select="'\'"/>
|
---|
316 | <xsl:with-param name="with" select="'\\'"/>
|
---|
317 | <xsl:with-param name="disable-output-escaping" select="yes"/>
|
---|
318 | </xsl:call-template>
|
---|
319 | </xsl:variable>
|
---|
320 | <xsl:variable name="sTmp2">
|
---|
321 | <xsl:call-template name="str:subst">
|
---|
322 | <xsl:with-param name="text" select="$sTmp1"/>
|
---|
323 | <xsl:with-param name="replace" select="'"'"/>
|
---|
324 | <xsl:with-param name="with" select="'\"'"/>
|
---|
325 | <xsl:with-param name="disable-output-escaping" select="yes"/>
|
---|
326 | </xsl:call-template>
|
---|
327 | </xsl:variable>
|
---|
328 | <xsl:call-template name="str:subst">
|
---|
329 | <xsl:with-param name="text" select="$sTmp2"/>
|
---|
330 | <xsl:with-param name="replace" select="' '"/>
|
---|
331 | <xsl:with-param name="with" select="'\b'"/>
|
---|
332 | <xsl:with-param name="disable-output-escaping" select="yes"/>
|
---|
333 | </xsl:call-template>
|
---|
334 | </xsl:when>
|
---|
335 |
|
---|
336 | <xsl:when test="contains(., ' ')">
|
---|
337 | <xsl:call-template name="str:subst">
|
---|
338 | <xsl:with-param name="text" select="."/>
|
---|
339 | <xsl:with-param name="replace" select="' '"/>
|
---|
340 | <xsl:with-param name="with" select="'\b'"/>
|
---|
341 | <xsl:with-param name="disable-output-escaping" select="yes"/>
|
---|
342 | </xsl:call-template>
|
---|
343 | </xsl:when>
|
---|
344 |
|
---|
345 | <xsl:otherwise>
|
---|
346 | <xsl:value-of select="."/>
|
---|
347 | </xsl:otherwise>
|
---|
348 | </xsl:choose>
|
---|
349 | </xsl:template>
|
---|
350 |
|
---|
351 |
|
---|
352 | <!--
|
---|
353 | Unsupported elements and elements handled directly.
|
---|
354 | -->
|
---|
355 | <xsl:template match="synopfragment|synopfragmentref|title|refsect1">
|
---|
356 | <xsl:message terminate="yes">The <xsl:value-of select="name()"/> element is not supported</xsl:message>
|
---|
357 | </xsl:template>
|
---|
358 |
|
---|
359 | <!--
|
---|
360 | Fail on misplaced scoping remarks.
|
---|
361 | -->
|
---|
362 | <xsl:template match="remark[@role = 'help-scope']">
|
---|
363 | <xsl:choose>
|
---|
364 | <xsl:when test="parent::refsect1"/>
|
---|
365 | <xsl:when test="parent::refsect2"/>
|
---|
366 | <xsl:when test="parent::cmdsynopsis and ancestor::refsynopsisdiv"/>
|
---|
367 | <xsl:otherwise>
|
---|
368 | <xsl:message terminate="yes">Misplaced remark/@role=help-scope element.
|
---|
369 | Only supported on: refsect1, refsect2, refsynopsisdiv/cmdsynopsis</xsl:message>
|
---|
370 | </xsl:otherwise>
|
---|
371 | </xsl:choose>
|
---|
372 | </xsl:template>
|
---|
373 |
|
---|
374 | <!--
|
---|
375 | Warn about unhandled elements
|
---|
376 | -->
|
---|
377 | <xsl:template match="*">
|
---|
378 | <xsl:message terminate="no">Warning: Unhandled element: <xsl:value-of select="name(.)"/></xsl:message>
|
---|
379 | </xsl:template>
|
---|
380 |
|
---|
381 |
|
---|
382 | <!--
|
---|
383 | Functions
|
---|
384 | Functions
|
---|
385 | Functions
|
---|
386 | -->
|
---|
387 |
|
---|
388 | <!--
|
---|
389 | Processes mixed children, i.e. both text and regular elements.
|
---|
390 | Normalizes whitespace. -->
|
---|
391 | <xsl:template name="process-mixed">
|
---|
392 | <xsl:text>
|
---|
393 | { REFENTRYSTR_SCOPE_SAME,
|
---|
394 | "</xsl:text><xsl:call-template name="emit-indentation"/>
|
---|
395 |
|
---|
396 | <xsl:for-each select="node()[not(self::remark)]">
|
---|
397 | <xsl:if test="position() != 1">
|
---|
398 | <xsl:text> </xsl:text>
|
---|
399 | </xsl:if>
|
---|
400 | <xsl:choose>
|
---|
401 | <xsl:when test="name() = ''">
|
---|
402 | <xsl:call-template name="escape_text"/>
|
---|
403 | </xsl:when>
|
---|
404 | <xsl:otherwise>
|
---|
405 | <xsl:apply-templates select="."/>
|
---|
406 | </xsl:otherwise>
|
---|
407 | </xsl:choose>
|
---|
408 | </xsl:for-each>
|
---|
409 |
|
---|
410 | <xsl:text>" },</xsl:text>
|
---|
411 | </xsl:template>
|
---|
412 |
|
---|
413 |
|
---|
414 | <!-- TODO: scoping must be reworked! -->
|
---|
415 | <!-- Figures out the scope of a refsect1 element. -->
|
---|
416 | <xsl:template name="calc-scope-refsect1">
|
---|
417 | <xsl:choose>
|
---|
418 | <xsl:when test="title[text() = 'Description']">
|
---|
419 | <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
|
---|
420 | </xsl:when>
|
---|
421 | <xsl:otherwise>
|
---|
422 | <xsl:call-template name="calc-scope"/>
|
---|
423 | </xsl:otherwise>
|
---|
424 | </xsl:choose>
|
---|
425 | </xsl:template>
|
---|
426 |
|
---|
427 | <!-- Figures out the scope of a refsect2 element. -->
|
---|
428 | <xsl:template name="calc-scope-refsect2">
|
---|
429 | <xsl:choose>
|
---|
430 | <xsl:when test="0">
|
---|
431 | <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
|
---|
432 | </xsl:when>
|
---|
433 | <xsl:otherwise>
|
---|
434 | <xsl:call-template name="calc-scope"/>
|
---|
435 | </xsl:otherwise>
|
---|
436 | </xsl:choose>
|
---|
437 | </xsl:template>
|
---|
438 |
|
---|
439 | <!-- Figures out the scope of a refsect1 element. -->
|
---|
440 | <xsl:template name="calc-scope-cmdsynopsis">
|
---|
441 | <xsl:choose>
|
---|
442 | <xsl:when test="ancestor::refsynopsisdiv">
|
---|
443 | <xsl:call-template name="calc-scope"/>
|
---|
444 | </xsl:when>
|
---|
445 | <xsl:otherwise>
|
---|
446 | <xsl:text>REFENTRYSTR_SCOPE_SAME</xsl:text>
|
---|
447 | </xsl:otherwise>
|
---|
448 | </xsl:choose>
|
---|
449 | </xsl:template>
|
---|
450 |
|
---|
451 | <!-- Figures out the scope of an element. -->
|
---|
452 | <xsl:template name="calc-scope">
|
---|
453 | <xsl:param name="a_Element" select="."/>
|
---|
454 | <xsl:param name="a_cRecursions" select="'1'"/>
|
---|
455 | <xsl:variable name="ScopeRemark" select="$a_Element/remark[@role='help-scope']"/>
|
---|
456 |
|
---|
457 | <xsl:choose>
|
---|
458 | <!-- Check for an explicit scope remark: <remark role='scope' condition='uninstall'/> -->
|
---|
459 | <xsl:when test="$ScopeRemark">
|
---|
460 | <xsl:if test="not($ScopeRemark/@condition)">
|
---|
461 | <xsl:message terminate="yes">remark[role=scope] element must have a condition attribute.</xsl:message>
|
---|
462 | </xsl:if>
|
---|
463 |
|
---|
464 | <xsl:call-template name="calc-scope-const">
|
---|
465 | <xsl:with-param name="sId" select="concat(concat(ancestor::refentry[1]/@id, '-'), $ScopeRemark/@condition)"/>
|
---|
466 | </xsl:call-template>
|
---|
467 | </xsl:when>
|
---|
468 |
|
---|
469 | <!-- Try derive it from the @id tag, if any. -->
|
---|
470 | <xsl:when test="substring(@id, 1, 3) = 'vbox'">
|
---|
471 | <xsl:call-template name="calc-scope-const">
|
---|
472 | <xsl:with-param name="sId" select="$a_Element/@id"/>
|
---|
473 | </xsl:call-template>
|
---|
474 | </xsl:when>
|
---|
475 | <xsl:when test="@id">
|
---|
476 | <xsl:call-template name="calc-scope-const">
|
---|
477 | <xsl:with-param name="sId" select="substring-after($a_Element/@id, '-')"/>
|
---|
478 | </xsl:call-template>
|
---|
479 | </xsl:when>
|
---|
480 |
|
---|
481 | <!-- Recursively try the parent element. -->
|
---|
482 | <xsl:when test="($a_cRecursions) > 10">
|
---|
483 | <xsl:message terminal="yes">calc-scope recursion too deep.</xsl:message>
|
---|
484 | </xsl:when>
|
---|
485 | <xsl:otherwise>
|
---|
486 | <xsl:call-template name="calc-scope">
|
---|
487 | <xsl:with-param name="a_Element" select="$a_Element/.."/>
|
---|
488 | <xsl:with-param name="a_cRecursions" select="$a_cRecursions + 1"/>
|
---|
489 | </xsl:call-template>
|
---|
490 | </xsl:otherwise>
|
---|
491 | </xsl:choose>
|
---|
492 | </xsl:template>
|
---|
493 |
|
---|
494 | <!-- Calculates a scope constant from a ID like value. -->
|
---|
495 | <xsl:template name="calc-scope-const">
|
---|
496 | <xsl:param name="sId" select="@id"/>
|
---|
497 | <xsl:if test="$sId = ''"><xsl:message terminate="yes">refentry: command Missing </xsl:message></xsl:if>
|
---|
498 | <xsl:variable name="sTmp1" select="translate($sId, '-', '_')"/>
|
---|
499 | <xsl:variable name="sTmp2">
|
---|
500 | <xsl:call-template name="str:to-upper">
|
---|
501 | <xsl:with-param name="text" select="$sTmp1"/>
|
---|
502 | </xsl:call-template>
|
---|
503 | </xsl:variable>
|
---|
504 | <xsl:text>HELP_SCOPE_</xsl:text>
|
---|
505 | <xsl:value-of select="$sTmp2"/>
|
---|
506 | </xsl:template>
|
---|
507 |
|
---|
508 | <!-- Calculates and emits indentation. -->
|
---|
509 | <xsl:template name="emit-indentation">
|
---|
510 | <xsl:if test="ancestor::refsect1">
|
---|
511 | <xsl:text> </xsl:text>
|
---|
512 | </xsl:if>
|
---|
513 | <xsl:if test="ancestor::refsect2">
|
---|
514 | <xsl:text> </xsl:text>
|
---|
515 | </xsl:if>
|
---|
516 | <xsl:if test="ancestor::refsect3">
|
---|
517 | <xsl:text> </xsl:text>
|
---|
518 | </xsl:if>
|
---|
519 | <xsl:if test="ancestor::varlistentry">
|
---|
520 | <xsl:if test="ancestor-or-self::term">
|
---|
521 | <xsl:text> </xsl:text>
|
---|
522 | </xsl:if>
|
---|
523 | <xsl:if test="ancestor-or-self::listitem">
|
---|
524 | <xsl:text> </xsl:text>
|
---|
525 | </xsl:if>
|
---|
526 | </xsl:if>
|
---|
527 | </xsl:template>
|
---|
528 |
|
---|
529 | <!-- Captializes the given text. -->
|
---|
530 | <xsl:template name="capitalize">
|
---|
531 | <xsl:param name="text"/>
|
---|
532 | <xsl:call-template name="str:to-upper">
|
---|
533 | <xsl:with-param name="text" select="substring($text,1,1)"/>
|
---|
534 | </xsl:call-template>
|
---|
535 | <xsl:value-of select="substring($text,2)"/>
|
---|
536 | </xsl:template>
|
---|
537 |
|
---|
538 | </xsl:stylesheet>
|
---|
539 |
|
---|