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