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> | REFENTRYSTR_FLAGS_SYNOPSIS,
|
---|
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 | REFENTRYSTR_FLAGS_SYNOPSIS,
|
---|
174 | " </xsl:text><xsl:call-template name="emit-indentation"/> <!-- hardcoded in VBoxManageHelp.cpp too -->
|
---|
175 | </xsl:template>
|
---|
176 |
|
---|
177 | <xsl:template match="cmdsynopsis/command">
|
---|
178 | <xsl:text>" },
|
---|
179 | { REFENTRYSTR_SCOPE_SAME | REFENTRYSTR_FLAGS_SYNOPSIS,
|
---|
180 | "</xsl:text><xsl:call-template name="emit-indentation"/>
|
---|
181 | <xsl:apply-templates select="node()|@*"/>
|
---|
182 | </xsl:template>
|
---|
183 |
|
---|
184 | <xsl:template match="cmdsynopsis/command[1]" priority="2">
|
---|
185 | <xsl:apply-templates select="node()|@*"/>
|
---|
186 | </xsl:template>
|
---|
187 |
|
---|
188 | <xsl:template match="command|option|computeroutput">
|
---|
189 | <xsl:apply-templates select="node()|@*"/>
|
---|
190 | </xsl:template>
|
---|
191 |
|
---|
192 | <xsl:template match="replaceable">
|
---|
193 | <xsl:text><</xsl:text>
|
---|
194 | <xsl:apply-templates select="node()|@*"/>
|
---|
195 | <xsl:text>></xsl:text>
|
---|
196 | </xsl:template>
|
---|
197 |
|
---|
198 | <xsl:template match="arg|group">
|
---|
199 | <!-- separator char if we're not the first child -->
|
---|
200 | <xsl:if test="position() > 1">
|
---|
201 | <xsl:choose>
|
---|
202 | <xsl:when test="ancestor-or-self::*/@sepchar"><xsl:value-of select="ancestor-or-self::*/@sepchar"/></xsl:when>
|
---|
203 | <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
|
---|
204 | </xsl:choose>
|
---|
205 | </xsl:if>
|
---|
206 | <!-- open wrapping -->
|
---|
207 | <xsl:choose>
|
---|
208 | <xsl:when test="@choice = 'opt' or not(@choice) or @choice = ''"> <xsl:text>[</xsl:text></xsl:when>
|
---|
209 | <xsl:when test="@choice = 'req'"> <xsl:text></xsl:text></xsl:when>
|
---|
210 | <xsl:when test="@choice = 'plain'"/>
|
---|
211 | <xsl:otherwise><xsl:message terminate="yes">Invalid arg choice: "<xsl:value-of select="@choice"/>"</xsl:message></xsl:otherwise>
|
---|
212 | </xsl:choose>
|
---|
213 | <!-- render the arg (TODO: may need to do more work here) -->
|
---|
214 | <xsl:apply-templates select="node()|@*"/>
|
---|
215 | <!-- repeat wrapping -->
|
---|
216 | <xsl:choose>
|
---|
217 | <xsl:when test="@rep = 'norepeat' or not(@rep) or @rep = ''"/>
|
---|
218 | <xsl:when test="@rep = 'repeat'"> <xsl:text>...</xsl:text></xsl:when>
|
---|
219 | <xsl:otherwise><xsl:message terminate="yes">Invalid rep choice: "<xsl:value-of select="@rep"/>"</xsl:message></xsl:otherwise>
|
---|
220 | </xsl:choose>
|
---|
221 | <!-- close wrapping -->
|
---|
222 | <xsl:choose>
|
---|
223 | <xsl:when test="@choice = 'opt' or not(@choice) or @choice = ''"> <xsl:text>]</xsl:text></xsl:when>
|
---|
224 | <xsl:when test="@choice = 'req'"> <xsl:text></xsl:text></xsl:when>
|
---|
225 | </xsl:choose>
|
---|
226 | </xsl:template>
|
---|
227 |
|
---|
228 |
|
---|
229 | <!--
|
---|
230 | refsect2
|
---|
231 | -->
|
---|
232 | <xsl:template match="refsect2">
|
---|
233 | <!-- assertions -->
|
---|
234 | <xsl:if test="text()"><xsl:message terminate="yes">refsect2 shouldn't contain text</xsl:message></xsl:if>
|
---|
235 | <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>
|
---|
236 |
|
---|
237 | <!-- title / command synopsis - sets the scope. -->
|
---|
238 | <xsl:text>
|
---|
239 | { </xsl:text><xsl:call-template name="calc-scope-refsect2"/><xsl:text>, "" },
|
---|
240 | { REFENTRYSTR_SCOPE_SAME,
|
---|
241 | "</xsl:text><xsl:call-template name="emit-indentation"/>
|
---|
242 | <xsl:apply-templates select="./title/text()"/>
|
---|
243 | <xsl:text>" },</xsl:text>
|
---|
244 |
|
---|
245 | <!-- Format the text in the section -->
|
---|
246 | <xsl:for-each select="./*[name() != 'title']">
|
---|
247 | <xsl:apply-templates select="."/>
|
---|
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 | Execute synopsis copy remark (avoids duplication for complicated xml).
|
---|
450 | -->
|
---|
451 | <xsl:template match="remark[@role = 'help-copy-synopsis']">
|
---|
452 | <xsl:message terminate="yes">remark/@role=help-copy-synopsis is not supported by this stylesheet. Must preprocess input!</xsl:message>
|
---|
453 | </xsl:template>
|
---|
454 |
|
---|
455 | <!--
|
---|
456 | Warn about unhandled elements
|
---|
457 | -->
|
---|
458 | <xsl:template match="*">
|
---|
459 | <xsl:message terminate="no">Warning: Unhandled element: <!-- no newline -->
|
---|
460 | <xsl:for-each select="ancestor-or-self::*">
|
---|
461 | <xsl:text>/</xsl:text>
|
---|
462 | <xsl:value-of select="name(.)"/>
|
---|
463 | <xsl:if test="@id">
|
---|
464 | <xsl:value-of select="concat('[id=', @id ,']')"/>
|
---|
465 | </xsl:if>
|
---|
466 | </xsl:for-each>
|
---|
467 | </xsl:message>
|
---|
468 | </xsl:template>
|
---|
469 |
|
---|
470 |
|
---|
471 | <!--
|
---|
472 | Functions
|
---|
473 | Functions
|
---|
474 | Functions
|
---|
475 | -->
|
---|
476 |
|
---|
477 | <!--
|
---|
478 | Processes mixed children, i.e. both text and regular elements.
|
---|
479 | Normalizes whitespace. -->
|
---|
480 | <xsl:template name="process-mixed">
|
---|
481 | <xsl:text>
|
---|
482 | { REFENTRYSTR_SCOPE_SAME,
|
---|
483 | "</xsl:text><xsl:call-template name="emit-indentation"/>
|
---|
484 |
|
---|
485 | <xsl:for-each select="node()[not(self::remark)]">
|
---|
486 | <xsl:if test="position() != 1">
|
---|
487 | <xsl:text> </xsl:text>
|
---|
488 | </xsl:if>
|
---|
489 | <xsl:choose>
|
---|
490 | <xsl:when test="name() = ''">
|
---|
491 | <xsl:call-template name="escape_text"/>
|
---|
492 | </xsl:when>
|
---|
493 | <xsl:otherwise>
|
---|
494 | <xsl:apply-templates select="."/>
|
---|
495 | </xsl:otherwise>
|
---|
496 | </xsl:choose>
|
---|
497 | </xsl:for-each>
|
---|
498 |
|
---|
499 | <xsl:text>" },</xsl:text>
|
---|
500 | </xsl:template>
|
---|
501 |
|
---|
502 |
|
---|
503 | <!--
|
---|
504 | Element specific scoping.
|
---|
505 | -->
|
---|
506 |
|
---|
507 | <xsl:template name="calc-scope-for-refentry">
|
---|
508 | <xsl:call-template name="calc-scope-const-from-id"/>
|
---|
509 | </xsl:template>
|
---|
510 |
|
---|
511 | <!-- Figures out the scope of a refsect1 element. -->
|
---|
512 | <xsl:template name="calc-scope-refsect1">
|
---|
513 | <xsl:choose>
|
---|
514 | <xsl:when test="title[text() = 'Description']">
|
---|
515 | <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
|
---|
516 | </xsl:when>
|
---|
517 | <xsl:when test="@id or remark[@role='help-scope']">
|
---|
518 | <xsl:call-template name="calc-scope-from-remark-or-id"/>
|
---|
519 | </xsl:when>
|
---|
520 | <xsl:otherwise>
|
---|
521 | <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
|
---|
522 | </xsl:otherwise>
|
---|
523 | </xsl:choose>
|
---|
524 | </xsl:template>
|
---|
525 |
|
---|
526 | <!-- Figures out the scope of a refsect2 element. -->
|
---|
527 | <xsl:template name="calc-scope-refsect2">
|
---|
528 | <xsl:choose>
|
---|
529 | <xsl:when test="@id or remark[@role='help-scope']">
|
---|
530 | <xsl:call-template name="calc-scope-from-remark-or-id"/>
|
---|
531 | </xsl:when>
|
---|
532 | <xsl:otherwise>
|
---|
533 | <xsl:text>REFENTRYSTR_SCOPE_SAME</xsl:text>
|
---|
534 | </xsl:otherwise>
|
---|
535 | </xsl:choose>
|
---|
536 | </xsl:template>
|
---|
537 |
|
---|
538 | <!-- Figures out the scope of a refsect1 element. -->
|
---|
539 | <xsl:template name="calc-scope-cmdsynopsis">
|
---|
540 | <xsl:choose>
|
---|
541 | <xsl:when test="ancestor::refsynopsisdiv">
|
---|
542 | <xsl:call-template name="calc-scope-from-remark-or-id">
|
---|
543 | <xsl:with-param name="sId" select="substring-after(@id, '-')"/>
|
---|
544 | </xsl:call-template>
|
---|
545 | </xsl:when>
|
---|
546 | <xsl:otherwise>
|
---|
547 | <xsl:text>REFENTRYSTR_SCOPE_SAME</xsl:text>
|
---|
548 | </xsl:otherwise>
|
---|
549 | </xsl:choose>
|
---|
550 | </xsl:template>
|
---|
551 |
|
---|
552 |
|
---|
553 | <!--
|
---|
554 | Scoping worker functions.
|
---|
555 | -->
|
---|
556 |
|
---|
557 | <!-- Calculates the current scope from the scope remark or @id. -->
|
---|
558 | <xsl:template name="calc-scope-from-remark-or-id">
|
---|
559 | <xsl:param name="sId" select="@id"/>
|
---|
560 | <xsl:choose>
|
---|
561 | <xsl:when test="remark[@role='help-scope']">
|
---|
562 | <xsl:call-template name="calc-scope-consts-from-remark"/>
|
---|
563 | </xsl:when>
|
---|
564 | <xsl:when test="$sId != ''">
|
---|
565 | <xsl:call-template name="calc-scope-const-from-id">
|
---|
566 | <xsl:with-param name="sId" select="$sId"/>
|
---|
567 | </xsl:call-template>
|
---|
568 | </xsl:when>
|
---|
569 | <xsl:otherwise>
|
---|
570 | <xsl:message terminate="yes">expected remark child or id attribute.</xsl:message>
|
---|
571 | </xsl:otherwise>
|
---|
572 | </xsl:choose>
|
---|
573 | </xsl:template>
|
---|
574 |
|
---|
575 | <!-- Turns a @id into a scope constant.
|
---|
576 | Some woodoo taking place here here that chops the everything up to and
|
---|
577 | including the first refentry/@id word from all IDs before turning them into
|
---|
578 | constants (word delimiter '-'). -->
|
---|
579 | <xsl:template name="calc-scope-const-from-id">
|
---|
580 | <xsl:param name="sId" select="@id"/>
|
---|
581 | <xsl:variable name="sPrefix" select="concat(substring-before(ancestor::refentry/@id, '-'), '-')"/>
|
---|
582 | <xsl:if test="not(contains($sId, sPrefix))">
|
---|
583 | <xsl:message terminate="yes">Expected sId (<xsl:value-of select="$sId"/>) to contain <xsl:value-of select="$sPrefix"/></xsl:message>
|
---|
584 | </xsl:if>
|
---|
585 | <xsl:text>HELP_SCOPE_</xsl:text>
|
---|
586 | <xsl:call-template name="str:to-upper">
|
---|
587 | <xsl:with-param name="text" select="translate(substring-after($sId, $sPrefix), '-', '_')"/>
|
---|
588 | </xsl:call-template>
|
---|
589 | </xsl:template>
|
---|
590 |
|
---|
591 | <!-- Turns a remark into one or more scope constant. -->
|
---|
592 | <xsl:template name="calc-scope-consts-from-remark">
|
---|
593 | <xsl:param name="sCondition" select="remark/@condition"/>
|
---|
594 | <xsl:variable name="sNormalized" select="concat(normalize-space(translate($sCondition, ',;:|', ' ')), ' ')"/>
|
---|
595 | <xsl:if test="$sNormalized = ' ' or $sNormalized = ''">
|
---|
596 | <xsl:message terminate="yes">Empty @condition for help-scope remark.</xsl:message>
|
---|
597 | </xsl:if>
|
---|
598 | <xsl:choose>
|
---|
599 | <xsl:when test="substring-before($sNormalized, ' ') = 'GLOBAL'">
|
---|
600 | <xsl:text>REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
|
---|
601 | </xsl:when>
|
---|
602 | <xsl:otherwise>
|
---|
603 | <xsl:text>HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sNormalized, ' ')"/>
|
---|
604 | </xsl:otherwise>
|
---|
605 | </xsl:choose>
|
---|
606 | <xsl:call-template name="calc-scope-const-from-remark-worker">
|
---|
607 | <xsl:with-param name="sList" select="substring-after($sNormalized, ' ')"/>
|
---|
608 | </xsl:call-template>
|
---|
609 | </xsl:template>
|
---|
610 |
|
---|
611 | <xsl:template name="calc-scope-const-from-remark-worker">
|
---|
612 | <xsl:param name="sList"/>
|
---|
613 | <xsl:if test="$sList != ''">
|
---|
614 | <xsl:choose>
|
---|
615 | <xsl:when test="substring-before($sList, ' ') = 'GLOBAL'">
|
---|
616 | <xsl:text>| REFENTRYSTR_SCOPE_GLOBAL</xsl:text>
|
---|
617 | </xsl:when>
|
---|
618 | <xsl:otherwise>
|
---|
619 | <xsl:text> | HELP_SCOPE_</xsl:text><xsl:value-of select="substring-before($sList, ' ')"/>
|
---|
620 | </xsl:otherwise>
|
---|
621 | </xsl:choose>
|
---|
622 | <xsl:call-template name="calc-scope-const-from-remark-worker">
|
---|
623 | <xsl:with-param name="sList" select="substring-after($sList, ' ')"/>
|
---|
624 | </xsl:call-template>
|
---|
625 | </xsl:if>
|
---|
626 | </xsl:template>
|
---|
627 |
|
---|
628 |
|
---|
629 | <!--
|
---|
630 | Calculates and emits indentation.
|
---|
631 | -->
|
---|
632 | <xsl:template name="emit-indentation">
|
---|
633 | <xsl:if test="ancestor::refsect1|ancestor::refsynopsisdiv">
|
---|
634 | <xsl:text> </xsl:text>
|
---|
635 | </xsl:if>
|
---|
636 | <xsl:if test="ancestor::refsect2">
|
---|
637 | <xsl:text> </xsl:text>
|
---|
638 | </xsl:if>
|
---|
639 | <xsl:if test="ancestor::refsect3">
|
---|
640 | <xsl:text> </xsl:text>
|
---|
641 | </xsl:if>
|
---|
642 | <xsl:if test="ancestor::varlistentry">
|
---|
643 | <xsl:if test="ancestor-or-self::term">
|
---|
644 | <xsl:text> </xsl:text>
|
---|
645 | </xsl:if>
|
---|
646 | <xsl:if test="ancestor-or-self::listitem">
|
---|
647 | <xsl:text> </xsl:text>
|
---|
648 | </xsl:if>
|
---|
649 | </xsl:if>
|
---|
650 | </xsl:template>
|
---|
651 |
|
---|
652 | <!--
|
---|
653 | Captializes the given text.
|
---|
654 | -->
|
---|
655 | <xsl:template name="capitalize">
|
---|
656 | <xsl:param name="text"/>
|
---|
657 | <xsl:call-template name="str:to-upper">
|
---|
658 | <xsl:with-param name="text" select="substring($text,1,1)"/>
|
---|
659 | </xsl:call-template>
|
---|
660 | <xsl:value-of select="substring($text,2)"/>
|
---|
661 | </xsl:template>
|
---|
662 |
|
---|
663 | </xsl:stylesheet>
|
---|
664 |
|
---|