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(starts-with(substring-after(@id, '-'), $sBaseId))">
|
---|
65 | <xsl:message terminate="yes">The refsynopsisdiv/cmdsynopsis elements @id is expected to include the refentry @id.</xsl:message>
|
---|
66 | </xsl:if>
|
---|
67 | <xsl:if test="not(../../refsect1/refsect2[@id=./@id])">
|
---|
68 | <xsl:message terminate="yes">No refsect2 with id="<xsl:value-of select="@id"/>" found.</xsl:message>
|
---|
69 | </xsl:if>
|
---|
70 |
|
---|
71 | <!-- Do the work. -->
|
---|
72 | <xsl:apply-templates select="."/>
|
---|
73 |
|
---|
74 | </xsl:for-each>
|
---|
75 | <xsl:text>
|
---|
76 | };</xsl:text>
|
---|
77 |
|
---|
78 |
|
---|
79 | <!--
|
---|
80 | Convert the whole manpage to help text.
|
---|
81 | -->
|
---|
82 | <xsl:text>
|
---|
83 | static const REFENTRYSTR </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help[] =
|
---|
84 | {</xsl:text>
|
---|
85 | <!-- We start by combining the refentry title and the refpurpose into a short description. -->
|
---|
86 | <xsl:text>
|
---|
87 | { </xsl:text><xsl:call-template name="calc-scope-for-refentry"/><xsl:text>,
|
---|
88 | "</xsl:text>
|
---|
89 | <xsl:apply-templates select="./refentryinfo/title/node()"/>
|
---|
90 | <xsl:text> -- </xsl:text>
|
---|
91 | <xsl:call-template name="capitalize">
|
---|
92 | <xsl:with-param name="text">
|
---|
93 | <xsl:apply-templates select="./refnamediv/refpurpose/node()"/>
|
---|
94 | </xsl:with-param>
|
---|
95 | </xsl:call-template>
|
---|
96 | <xsl:text>." },
|
---|
97 | { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
|
---|
98 |
|
---|
99 | <!-- The follows the usage (synopsis) section. -->
|
---|
100 | <xsl:text>
|
---|
101 | { REFENTRYSTR_SCOPE_GLOBAL,
|
---|
102 | "Usage:" },</xsl:text>
|
---|
103 | <xsl:apply-templates select="./refsynopsisdiv/node()"/>
|
---|
104 |
|
---|
105 | <!-- Then comes the description and other refsect1 -->
|
---|
106 | <xsl:for-each select="./refsect1">
|
---|
107 | <xsl:if test="name(*[1]) != 'title'"><xsl:message terminate="yes">Expected title as the first element in refsect1.</xsl:message></xsl:if>
|
---|
108 | <xsl:if test="text()"><xsl:message terminate="yes">No text supported in refsect1.</xsl:message></xsl:if>
|
---|
109 | <xsl:if test="not(./remark[@role='help-skip'])">
|
---|
110 | <xsl:text>
|
---|
111 | { </xsl:text><xsl:call-template name="calc-scope-refsect1"/><xsl:text>, "" },
|
---|
112 | { REFENTRYSTR_SCOPE_SAME,
|
---|
113 | "</xsl:text><xsl:apply-templates select="title/node()"/><xsl:text>:" },</xsl:text>
|
---|
114 | <xsl:apply-templates select="./*[position() > 1]"/>
|
---|
115 | </xsl:if>
|
---|
116 | </xsl:for-each>
|
---|
117 |
|
---|
118 | <xsl:text>
|
---|
119 | };</xsl:text>
|
---|
120 |
|
---|
121 | <!--
|
---|
122 | Generate the refentry structure.
|
---|
123 | -->
|
---|
124 | <xsl:text>
|
---|
125 | static const REFENTRY </xsl:text><xsl:value-of select="$sDataBaseSym"/><xsl:text> =
|
---|
126 | {
|
---|
127 | /* .idInternal = */ HELP_CMD_</xsl:text>
|
---|
128 | <xsl:call-template name="str:to-upper">
|
---|
129 | <xsl:with-param name="text" select="translate(substring-after(@id, '-'), '-', '_')"/>
|
---|
130 | </xsl:call-template>
|
---|
131 | <xsl:text>,
|
---|
132 | /* .Synopsis = */ { RT_ELEMENTS(</xsl:text>
|
---|
133 | <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis), 0, </xsl:text>
|
---|
134 | <xsl:value-of select="$sDataBaseSym"/><xsl:text>_synopsis },
|
---|
135 | /* .Help = */ { RT_ELEMENTS(</xsl:text>
|
---|
136 | <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help), 0, </xsl:text>
|
---|
137 | <xsl:value-of select="$sDataBaseSym"/><xsl:text>_full_help },
|
---|
138 | /* pszBrief = */ "</xsl:text>
|
---|
139 | <xsl:apply-templates select="./refnamediv/refpurpose/node()"/>
|
---|
140 | <!-- TODO: Add the command name too. -->
|
---|
141 | <xsl:text>"
|
---|
142 | };
|
---|
143 | </xsl:text>
|
---|
144 | </xsl:template>
|
---|
145 |
|
---|
146 |
|
---|
147 | <!--
|
---|
148 | Convert command synopsis to text.
|
---|
149 | -->
|
---|
150 | <xsl:template match="cmdsynopsis">
|
---|
151 | <xsl:if test="text()"><xsl:message terminate="yes">cmdsynopsis with text is not supported.</xsl:message></xsl:if>
|
---|
152 | <xsl:text>
|
---|
153 | { </xsl:text><xsl:call-template name="calc-scope-cmdsynopsis"/><xsl:text>,
|
---|
154 | "</xsl:text><xsl:call-template name="emit-indentation"/><xsl:apply-templates select="*|@*"/><xsl:text>" },</xsl:text>
|
---|
155 | </xsl:template>
|
---|
156 |
|
---|
157 | <xsl:template match="sbr">
|
---|
158 | <xsl:text>" },
|
---|
159 | { REFENTRYSTR_SCOPE_SAME,
|
---|
160 | " </xsl:text><xsl:call-template name="emit-indentation"/>
|
---|
161 | </xsl:template>
|
---|
162 |
|
---|
163 | <xsl:template match="command|option|computeroutput">
|
---|
164 | <xsl:apply-templates select="node()|@*"/>
|
---|
165 | </xsl:template>
|
---|
166 |
|
---|
167 | <xsl:template match="replaceable">
|
---|
168 | <xsl:text><</xsl:text>
|
---|
169 | <xsl:apply-templates select="node()|@*"/>
|
---|
170 | <xsl:text>></xsl:text>
|
---|
171 | </xsl:template>
|
---|
172 |
|
---|
173 | <xsl:template match="arg|group">
|
---|
174 | <!-- separator char if we're not the first child -->
|
---|
175 | <xsl:if test="position() > 1">
|
---|
176 | <xsl:choose>
|
---|
177 | <xsl:when test="ancestor-or-self::*/@sepchar"><xsl:value-of select="ancestor-or-self::*/@sepchar"/></xsl:when>
|
---|
178 | <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
|
---|
179 | </xsl:choose>
|
---|
180 | </xsl:if>
|
---|
181 | <!-- open wrapping -->
|
---|
182 | <xsl:choose>
|
---|
183 | <xsl:when test="@choice = 'opt' or not(@choice) or @choice = ''"> <xsl:text>[</xsl:text></xsl:when>
|
---|
184 | <xsl:when test="@choice = 'req'"> <xsl:text></xsl:text></xsl:when>
|
---|
185 | <xsl:when test="@choice = 'plain'"/>
|
---|
186 | <xsl:otherwise><xsl:message terminate="yes">Invalid arg choice: "<xsl:value-of select="@choice"/>"</xsl:message></xsl:otherwise>
|
---|
187 | </xsl:choose>
|
---|
188 | <!-- render the arg (TODO: may need to do more work here) -->
|
---|
189 | <xsl:apply-templates select="node()|@*"/>
|
---|
190 | <!-- repeat wrapping -->
|
---|
191 | <xsl:choose>
|
---|
192 | <xsl:when test="@rep = 'norepeat' or not(@rep) or @rep = ''"/>
|
---|
193 | <xsl:when test="@rep = 'repeat'"> <xsl:text>...</xsl:text></xsl:when>
|
---|
194 | <xsl:otherwise><xsl:message terminate="yes">Invalid rep choice: "<xsl:value-of select="@rep"/>"</xsl:message></xsl:otherwise>
|
---|
195 | </xsl:choose>
|
---|
196 | <!-- close wrapping -->
|
---|
197 | <xsl:choose>
|
---|
198 | <xsl:when test="@choice = 'opt' or not(@choice) or @choice = ''"> <xsl:text>]</xsl:text></xsl:when>
|
---|
199 | <xsl:when test="@choice = 'req'"> <xsl:text></xsl:text></xsl:when>
|
---|
200 | </xsl:choose>
|
---|
201 | </xsl:template>
|
---|
202 |
|
---|
203 |
|
---|
204 | <!--
|
---|
205 | refsect2
|
---|
206 | -->
|
---|
207 | <xsl:template match="refsect2">
|
---|
208 | <!-- assertions -->
|
---|
209 | <xsl:if test="text()"><xsl:message terminate="yes">refsect2 shouldn't contain text</xsl:message></xsl:if>
|
---|
210 | <xsl:if test="count(./cmdsynopsis) > 1"><xsl:message terminate="yes">Only a single cmdsynopsis is currently supported in a refsect2.</xsl:message></xsl:if>
|
---|
211 | <xsl:if test="count(./title) > 1"><xsl:message terminate="yes">Only a single title in refsect2</xsl:message></xsl:if>
|
---|
212 |
|
---|
213 | <!-- title / command synopsis - sets the scope. -->
|
---|
214 | <xsl:text>
|
---|
215 | { </xsl:text><xsl:call-template name="calc-scope-refsect2"/><xsl:text>, "" },
|
---|
216 | { REFENTRYSTR_SCOPE_SAME,
|
---|
217 | "</xsl:text><xsl:call-template name="emit-indentation"/>
|
---|
218 | <xsl:choose>
|
---|
219 | <xsl:when test="name(./*[1]) = 'cmdsynopsis'">
|
---|
220 | <!--xsl:text>* </xsl:text-->
|
---|
221 | <xsl:apply-templates select="./cmdsynopsis/node()|./cmdsynopsis/@*"/>
|
---|
222 | </xsl:when>
|
---|
223 | <xsl:when test="name(./*[1]) = 'title'">
|
---|
224 | <xsl:apply-templates select="./title/text()"/>
|
---|
225 | </xsl:when>
|
---|
226 | <xsl:otherwise>
|
---|
227 | <xsl:message terminate="yes">Expected either a title or cmdsynopsis as the first element in a refsect2.
|
---|
228 | (Put scoping remarks after.)</xsl:message>
|
---|
229 | </xsl:otherwise>
|
---|
230 | </xsl:choose>
|
---|
231 | <xsl:text>" },</xsl:text>
|
---|
232 |
|
---|
233 | <!-- Format the text in the section -->
|
---|
234 | <xsl:apply-templates select="./*[position() > 1]"/>
|
---|
235 |
|
---|
236 | <!-- Add two blank lines, unless we're the last element in this refsect1. -->
|
---|
237 | <xsl:if test="position() != last()">
|
---|
238 | <xsl:text>
|
---|
239 | { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
|
---|
240 | </xsl:if>
|
---|
241 | </xsl:template>
|
---|
242 |
|
---|
243 |
|
---|
244 | <!--
|
---|
245 | para
|
---|
246 | -->
|
---|
247 | <xsl:template match="para">
|
---|
248 | <xsl:if test="position() != 1 or not(parent::listitem)">
|
---|
249 | <xsl:text>
|
---|
250 | { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
|
---|
251 | </xsl:if>
|
---|
252 | <xsl:call-template name="process-mixed"/>
|
---|
253 | </xsl:template>
|
---|
254 |
|
---|
255 |
|
---|
256 | <!--
|
---|
257 | variablelist
|
---|
258 | -->
|
---|
259 | <xsl:template match="variablelist">
|
---|
260 | <xsl:if test="*[not(self::varlistentry)]|text()">
|
---|
261 | <xsl:message terminate="yes">Only varlistentry elements are supported in variablelist</xsl:message>
|
---|
262 | </xsl:if>
|
---|
263 | <xsl:if test="position() != 1">
|
---|
264 | <xsl:text>
|
---|
265 | { REFENTRYSTR_SCOPE_SAME, "" },</xsl:text>
|
---|
266 | </xsl:if>
|
---|
267 | <xsl:for-each select="./varlistentry">
|
---|
268 | <xsl:if test="count(*) != 2 or not(term) or not(listitem)">
|
---|
269 | <xsl:message terminate="yes">Expected exactly one term and one listentry member in varlistentry element.</xsl:message>
|
---|
270 | </xsl:if>
|
---|
271 | <xsl:apply-templates select="*"/>
|
---|
272 | </xsl:for-each>
|
---|
273 | </xsl:template>
|
---|
274 |
|
---|
275 | <xsl:template match="varlistentry/term">
|
---|
276 | <xsl:call-template name="process-mixed"/>
|
---|
277 | </xsl:template>
|
---|
278 |
|
---|
279 | <xsl:template match="varlistentry/listitem">
|
---|
280 | <xsl:if test="text() or *[not(self::para)]">
|
---|
281 | <xsl:message terminate="yes">Expected varlistentry/listitem to only contain para elements</xsl:message>
|
---|
282 | </xsl:if>
|
---|
283 | <xsl:apply-templates select="*"/>
|
---|
284 | </xsl:template>
|
---|
285 |
|
---|
286 |
|
---|
287 | <!--
|
---|
288 | Screen
|
---|
289 | -->
|
---|
290 | <xsl:template match="screen">
|
---|
291 | <xsl:if test="ancestor::para">
|
---|
292 | <xsl:text>" },</xsl:text>
|
---|
293 | </xsl:if>
|
---|
294 |
|
---|
295 | <xsl:text>
|
---|
296 | { REFENTRYSTR_SCOPE_SAME,
|
---|
297 | "</xsl:text>
|
---|
298 |
|
---|
299 | <xsl:for-each select="node()">
|
---|
300 | <xsl:choose>
|
---|
301 | <xsl:when test="name() = ''">
|
---|
302 | <xsl:call-template name="screen_text_line">
|
---|
303 | <xsl:with-param name="sText" select="."/>
|
---|
304 | </xsl:call-template>
|
---|
305 | </xsl:when>
|
---|
306 | <xsl:otherwise>
|
---|
307 | <xsl:if test="*">
|
---|
308 | <xsl:message terminate="yes">Support for elements under screen has not been implemented: <xsl:value-of select="name()"/></xsl:message>
|
---|
309 | </xsl:if>
|
---|
310 | </xsl:otherwise>
|
---|
311 | </xsl:choose>
|
---|
312 | </xsl:for-each>
|
---|
313 |
|
---|
314 | <xsl:if test="not(ancestor::para)">
|
---|
315 | <xsl:text>" },</xsl:text>
|
---|
316 | </xsl:if>
|
---|
317 | </xsl:template>
|
---|
318 |
|
---|
319 | <xsl:template name="screen_text_line">
|
---|
320 | <xsl:param name="sText"/>
|
---|
321 | <xsl:call-template name="escape_fixed_text">
|
---|
322 | <xsl:with-param name="sText" select="substring-before($sText,'
')"/>
|
---|
323 | </xsl:call-template>
|
---|
324 |
|
---|
325 | <xsl:if test="substring-after($sText,'
')">
|
---|
326 | <xsl:text>" },
|
---|
327 | { REFENTRYSTR_SCOPE_SAME,
|
---|
328 | "</xsl:text>
|
---|
329 | <xsl:call-template name="screen_text_line">
|
---|
330 | <xsl:with-param name="sText" select="substring-after($sText,'
')"/>
|
---|
331 | </xsl:call-template>
|
---|
332 | </xsl:if>
|
---|
333 | </xsl:template>
|
---|
334 |
|
---|
335 |
|
---|
336 |
|
---|
337 | <!--
|
---|
338 | Text escaping for C.
|
---|
339 | -->
|
---|
340 | <xsl:template match="text()" name="escape_text">
|
---|
341 | <xsl:choose>
|
---|
342 |
|
---|
343 | <xsl:when test="contains(., '\') or contains(., '"')">
|
---|
344 | <xsl:variable name="sTmp">
|
---|
345 | <xsl:call-template name="str:subst">
|
---|
346 | <xsl:with-param name="text" select="normalize-space(.)"/>
|
---|
347 | <xsl:with-param name="replace" select="'\'"/>
|
---|
348 | <xsl:with-param name="with" select="'\\'"/>
|
---|
349 | <xsl:with-param name="disable-output-escaping" select="yes"/>
|
---|
350 | </xsl:call-template>
|
---|
351 | </xsl:variable>
|
---|
352 | <xsl:call-template name="str:subst">
|
---|
353 | <xsl:with-param name="text" select="$sTmp"/>
|
---|
354 | <xsl:with-param name="replace" select="'"'"/>
|
---|
355 | <xsl:with-param name="with" select="'\"'"/>
|
---|
356 | <xsl:with-param name="disable-output-escaping" select="yes"/>
|
---|
357 | </xsl:call-template>
|
---|
358 | </xsl:when>
|
---|
359 |
|
---|
360 | <xsl:otherwise>
|
---|
361 | <xsl:value-of select="normalize-space(.)"/>
|
---|
362 | </xsl:otherwise>
|
---|
363 | </xsl:choose>
|
---|
364 | </xsl:template>
|
---|
365 |
|
---|
366 | <!-- Elements producing non-breaking strings (single line). -->
|
---|
367 | <xsl:template match="command/text()|option/text()|computeroutput/text()" name="escape_fixed_text">
|
---|
368 | <xsl:param name="sText" select="."/>
|
---|
369 | <xsl:choose>
|
---|
370 |
|
---|
371 | <xsl:when test="contains($sText, '\') or contains($sText, '"')">
|
---|
372 | <xsl:variable name="sTmp1">
|
---|
373 | <xsl:call-template name="str:subst">
|
---|
374 | <xsl:with-param name="text" select="$sText"/>
|
---|
375 | <xsl:with-param name="replace" select="'\'"/>
|
---|
376 | <xsl:with-param name="with" select="'\\'"/>
|
---|
377 | <xsl:with-param name="disable-output-escaping" select="yes"/>
|
---|
378 | </xsl:call-template>
|
---|
379 | </xsl:variable>
|
---|
380 | <xsl:variable name="sTmp2">
|
---|
381 | <xsl:call-template name="str:subst">
|
---|
382 | <xsl:with-param name="text" select="$sTmp1"/>
|
---|
383 | <xsl:with-param name="replace" select="'"'"/>
|
---|
384 | <xsl:with-param name="with" select="'\"'"/>
|
---|
385 | <xsl:with-param name="disable-output-escaping" select="yes"/>
|
---|
386 | </xsl:call-template>
|
---|
387 | </xsl:variable>
|
---|
388 | <xsl:call-template name="str:subst">
|
---|
389 | <xsl:with-param name="text" select="$sTmp2"/>
|
---|
390 | <xsl:with-param name="replace" select="' '"/>
|
---|
391 | <xsl:with-param name="with" select="'\b'"/>
|
---|
392 | <xsl:with-param name="disable-output-escaping" select="yes"/>
|
---|
393 | </xsl:call-template>
|
---|
394 | </xsl:when>
|
---|
395 |
|
---|
396 | <xsl:when test="contains($sText, ' ')">
|
---|
397 | <xsl:call-template name="str:subst">
|
---|
398 | <xsl:with-param name="text" select="$sText"/>
|
---|
399 | <xsl:with-param name="replace" select="' '"/>
|
---|
400 | <xsl:with-param name="with" select="'\b'"/>
|
---|
401 | <xsl:with-param name="disable-output-escaping" select="yes"/>
|
---|
402 | </xsl:call-template>
|
---|
403 | </xsl:when>
|
---|
404 |
|
---|
405 | <xsl:otherwise>
|
---|
406 | <xsl:value-of select="$sText"/>
|
---|
407 | </xsl:otherwise>
|
---|
408 | </xsl:choose>
|
---|
409 | </xsl:template>
|
---|
410 |
|
---|
411 |
|
---|
412 | <!--
|
---|
413 | Unsupported elements and elements handled directly.
|
---|
414 | -->
|
---|
415 | <xsl:template match="synopfragment|synopfragmentref|title|refsect1">
|
---|
416 | <xsl:message terminate="yes">The <xsl:value-of select="name()"/> element is not supported</xsl:message>
|
---|
417 | </xsl:template>
|
---|
418 |
|
---|
419 | <!--
|
---|
420 | Fail on misplaced scoping remarks.
|
---|
421 | -->
|
---|
422 | <xsl:template match="remark[@role = 'help-scope']">
|
---|
423 | <xsl:choose>
|
---|
424 | <xsl:when test="parent::refsect1"/>
|
---|
425 | <xsl:when test="parent::refsect2"/>
|
---|
426 | <xsl:when test="parent::cmdsynopsis and ancestor::refsynopsisdiv"/>
|
---|
427 | <xsl:otherwise>
|
---|
428 | <xsl:message terminate="yes">Misplaced remark/@role=help-scope element.
|
---|
429 | Only supported on: refsect1, refsect2, refsynopsisdiv/cmdsynopsis</xsl:message>
|
---|
430 | </xsl:otherwise>
|
---|
431 | </xsl:choose>
|
---|
432 | </xsl:template>
|
---|
433 |
|
---|
434 | <!--
|
---|
435 | Warn about unhandled elements
|
---|
436 | -->
|
---|
437 | <xsl:template match="*">
|
---|
438 | <xsl:message terminate="no">Warning: Unhandled element: <xsl:value-of select="name(.)"/></xsl:message>
|
---|
439 | </xsl:template>
|
---|
440 |
|
---|
441 |
|
---|
442 | <!--
|
---|
443 | Functions
|
---|
444 | Functions
|
---|
445 | Functions
|
---|
446 | -->
|
---|
447 |
|
---|
448 | <!--
|
---|
449 | Processes mixed children, i.e. both text and regular elements.
|
---|
450 | Normalizes whitespace. -->
|
---|
451 | <xsl:template name="process-mixed">
|
---|
452 | <xsl:text>
|
---|
453 | { REFENTRYSTR_SCOPE_SAME,
|
---|
454 | "</xsl:text><xsl:call-template name="emit-indentation"/>
|
---|
455 |
|
---|
456 | <xsl:for-each select="node()[not(self::remark)]">
|
---|
457 | <xsl:if test="position() != 1">
|
---|
458 | <xsl:text> </xsl:text>
|
---|
459 | </xsl:if>
|
---|
460 | <xsl:choose>
|
---|
461 | <xsl:when test="name() = ''">
|
---|
462 | <xsl:call-template name="escape_text"/>
|
---|
463 | </xsl:when>
|
---|
464 | <xsl:otherwise>
|
---|
465 | <xsl:apply-templates select="."/>
|
---|
466 | </xsl:otherwise>
|
---|
467 | </xsl:choose>
|
---|
468 | </xsl:for-each>
|
---|
469 |
|
---|
470 | <xsl:text>" },</xsl:text>
|
---|
471 | </xsl:template>
|
---|
472 |
|
---|
473 |
|
---|
474 | <!--
|
---|
475 | Element specific scoping.
|
---|
476 | -->
|
---|
477 |
|
---|
478 | <xsl:template name="calc-scope-for-refentry">
|
---|
479 | <xsl:call-template name="calc-scope-const-from-id"/>
|
---|
480 | </xsl:template>
|
---|
481 |
|
---|
482 | <!-- Figures out the scope of a refsect1 element. -->
|
---|
483 | <xsl:template name="calc-scope-refsect1">
|
---|
484 | <xsl:choose>
|
---|
485 | <xsl:when test="title[text() = 'Description']">
|
---|
486 | <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
|
---|
487 | </xsl:when>
|
---|
488 | <xsl:when test="@id or remark[@role='help-scope']">
|
---|
489 | <xsl:call-template name="calc-scope-from-remark-or-id"/>
|
---|
490 | </xsl:when>
|
---|
491 | <xsl:otherwise>
|
---|
492 | <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
|
---|
493 | </xsl:otherwise>
|
---|
494 | </xsl:choose>
|
---|
495 | </xsl:template>
|
---|
496 |
|
---|
497 | <!-- Figures out the scope of a refsect2 element. -->
|
---|
498 | <xsl:template name="calc-scope-refsect2">
|
---|
499 | <xsl:choose>
|
---|
500 | <xsl:when test="@id or remark[@role='help-scope']">
|
---|
501 | <xsl:call-template name="calc-scope-from-remark-or-id"/>
|
---|
502 | </xsl:when>
|
---|
503 | <xsl:otherwise>
|
---|
504 | <xsl:text>REFENTRYSTR_SCOPE_SAME</xsl:text>
|
---|
505 | </xsl:otherwise>
|
---|
506 | </xsl:choose>
|
---|
507 | </xsl:template>
|
---|
508 |
|
---|
509 | <!-- Figures out the scope of a refsect1 element. -->
|
---|
510 | <xsl:template name="calc-scope-cmdsynopsis">
|
---|
511 | <xsl:choose>
|
---|
512 | <xsl:when test="ancestor::refsynopsisdiv">
|
---|
513 | <xsl:call-template name="calc-scope-from-remark-or-id">
|
---|
514 | <xsl:with-param name="sId" select="substring-after(@id, '-')"/>
|
---|
515 | </xsl:call-template>
|
---|
516 | </xsl:when>
|
---|
517 | <xsl:otherwise>
|
---|
518 | <xsl:text>REFENTRYSTR_SCOPE_SAME</xsl:text>
|
---|
519 | </xsl:otherwise>
|
---|
520 | </xsl:choose>
|
---|
521 | </xsl:template>
|
---|
522 |
|
---|
523 |
|
---|
524 | <!--
|
---|
525 | Scoping worker functions.
|
---|
526 | -->
|
---|
527 |
|
---|
528 | <!-- Calculates the current scope from the scope remark or @id. -->
|
---|
529 | <xsl:template name="calc-scope-from-remark-or-id">
|
---|
530 | <xsl:param name="sId" select="@id"/>
|
---|
531 | <xsl:choose>
|
---|
532 | <xsl:when test="remark[@role='help-scope']">
|
---|
533 | <xsl:call-template name="calc-scope-consts-from-remark"/>
|
---|
534 | </xsl:when>
|
---|
535 | <xsl:when test="$sId != ''">
|
---|
536 | <xsl:call-template name="calc-scope-const-from-id">
|
---|
537 | <xsl:with-param name="sId" select="$sId"/>
|
---|
538 | </xsl:call-template>
|
---|
539 | </xsl:when>
|
---|
540 | <xsl:otherwise>
|
---|
541 | <xsl:message terminate="yes">expected remark child or id attribute.</xsl:message>
|
---|
542 | </xsl:otherwise>
|
---|
543 | </xsl:choose>
|
---|
544 | </xsl:template>
|
---|
545 |
|
---|
546 | <!-- Turns a @id into a scope constant.
|
---|
547 | Some woodoo taking place here here that chops the everything up to and
|
---|
548 | including the first refentry/@id word from all IDs before turning them into
|
---|
549 | constants (word delimiter '-'). -->
|
---|
550 | <xsl:template name="calc-scope-const-from-id">
|
---|
551 | <xsl:param name="sId" select="@id"/>
|
---|
552 | <xsl:variable name="sPrefix" select="concat(substring-before(ancestor::refentry/@id, '-'), '-')"/>
|
---|
553 | <xsl:if test="not(contains($sId, sPrefix))">
|
---|
554 | <xsl:message terminate="yes">Expected sId (<xsl:value-of select="$sId"/>) to contain <xsl:value-of select="$sPrefix"/></xsl:message>
|
---|
555 | </xsl:if>
|
---|
556 | <xsl:text>HELP_SCOPE_</xsl:text>
|
---|
557 | <xsl:call-template name="str:to-upper">
|
---|
558 | <xsl:with-param name="text" select="translate(substring-after($sId, $sPrefix), '-', '_')"/>
|
---|
559 | </xsl:call-template>
|
---|
560 | </xsl:template>
|
---|
561 |
|
---|
562 | <!-- Turns a remark into one or more scope constant. -->
|
---|
563 | <xsl:template name="calc-scope-consts-from-remark">
|
---|
564 | <xsl:param name="sCondition" select="remark/@condition"/>
|
---|
565 | <xsl:variable name="sNormalized" select="concat(normalize-space(translate($sCondition, ',;:|', ' ')), ' ')"/>
|
---|
566 | <xsl:if test="$sNormalized = ' ' or $sNormalized = ''">
|
---|
567 | <xsl:message terminate="yes">Empty @condition for help-scope remark.</xsl:message>
|
---|
568 | </xsl:if>
|
---|
569 | <xsl:text>HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sNormalized, ' ')"/>
|
---|
570 | <xsl:call-template name="calc-scope-const-from-remark-worker">
|
---|
571 | <xsl:with-param name="sList" select="substring-after($sNormalized, ' ')"/>
|
---|
572 | </xsl:call-template>
|
---|
573 | </xsl:template>
|
---|
574 |
|
---|
575 | <xsl:template name="calc-scope-const-from-remark-worker">
|
---|
576 | <xsl:param name="sList"/>
|
---|
577 | <xsl:if test="$sList != ''">
|
---|
578 | <xsl:text> | HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sList, ' ')"/>
|
---|
579 | <xsl:call-template name="calc-scope-const-from-remark-worker">
|
---|
580 | <xsl:with-param name="sList" select="substring-after($sList, ' ')"/>
|
---|
581 | </xsl:call-template>
|
---|
582 | </xsl:if>
|
---|
583 | </xsl:template>
|
---|
584 |
|
---|
585 |
|
---|
586 | <!--
|
---|
587 | Calculates and emits indentation.
|
---|
588 | -->
|
---|
589 | <xsl:template name="emit-indentation">
|
---|
590 | <xsl:if test="ancestor::refsect1|ancestor::refsynopsisdiv">
|
---|
591 | <xsl:text> </xsl:text>
|
---|
592 | </xsl:if>
|
---|
593 | <xsl:if test="ancestor::refsect2">
|
---|
594 | <xsl:text> </xsl:text>
|
---|
595 | </xsl:if>
|
---|
596 | <xsl:if test="ancestor::refsect3">
|
---|
597 | <xsl:text> </xsl:text>
|
---|
598 | </xsl:if>
|
---|
599 | <xsl:if test="ancestor::varlistentry">
|
---|
600 | <xsl:if test="ancestor-or-self::term">
|
---|
601 | <xsl:text> </xsl:text>
|
---|
602 | </xsl:if>
|
---|
603 | <xsl:if test="ancestor-or-self::listitem">
|
---|
604 | <xsl:text> </xsl:text>
|
---|
605 | </xsl:if>
|
---|
606 | </xsl:if>
|
---|
607 | </xsl:template>
|
---|
608 |
|
---|
609 | <!--
|
---|
610 | Captializes the given text.
|
---|
611 | -->
|
---|
612 | <xsl:template name="capitalize">
|
---|
613 | <xsl:param name="text"/>
|
---|
614 | <xsl:call-template name="str:to-upper">
|
---|
615 | <xsl:with-param name="text" select="substring($text,1,1)"/>
|
---|
616 | </xsl:call-template>
|
---|
617 | <xsl:value-of select="substring($text,2)"/>
|
---|
618 | </xsl:template>
|
---|
619 |
|
---|
620 | </xsl:stylesheet>
|
---|
621 |
|
---|