1 | <?xml version="1.0"?>
|
---|
2 | <!--
|
---|
3 | docbook-refentry-to-manual-sect1.xsl:
|
---|
4 | XSLT stylesheet for converting a refentry (manpage)
|
---|
5 | to dita for use in the user manual.
|
---|
6 | -->
|
---|
7 | <!--
|
---|
8 | Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
9 |
|
---|
10 | This file is part of VirtualBox base platform packages, as
|
---|
11 | available from https://www.virtualbox.org.
|
---|
12 |
|
---|
13 | This program is free software; you can redistribute it and/or
|
---|
14 | modify it under the terms of the GNU General Public License
|
---|
15 | as published by the Free Software Foundation, in version 3 of the
|
---|
16 | License.
|
---|
17 |
|
---|
18 | This program is distributed in the hope that it will be useful, but
|
---|
19 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | General Public License for more details.
|
---|
22 |
|
---|
23 | You should have received a copy of the GNU General Public License
|
---|
24 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
25 |
|
---|
26 | SPDX-License-Identifier: GPL-3.0-only
|
---|
27 | -->
|
---|
28 |
|
---|
29 | <xsl:stylesheet
|
---|
30 | version="1.0"
|
---|
31 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
---|
32 | xmlns:str="http://xsltsl.org/string"
|
---|
33 | >
|
---|
34 |
|
---|
35 | <xsl:import href="string.xsl"/>
|
---|
36 | <xsl:import href="common-formatcfg.xsl"/>
|
---|
37 |
|
---|
38 | <xsl:output method="xml" version="1.0" encoding="utf-8" indent="no"/>
|
---|
39 | <xsl:preserve-space elements="*"/>
|
---|
40 | <!-- xsl:strip-space elements="*"/ - never -->
|
---|
41 |
|
---|
42 |
|
---|
43 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
44 | parameters
|
---|
45 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
46 | <!-- Replace dashes with non-breaking dashes.
|
---|
47 | Note! If the monospace font used in the PDF doesn't support it,
|
---|
48 | then '#' shows up instead for instance. This is currently
|
---|
49 | the case, so it's disabled by default. When we switch to
|
---|
50 | 4.0.x with the latest com.elovirta.pdf plugin (2023-03-xx
|
---|
51 | or later), we can enable this by default again. -->
|
---|
52 | <xsl:param name="g_fReplaceHypens">false</xsl:param>
|
---|
53 |
|
---|
54 | <!-- Render the syntax diagram more as text than as proper markup. -->
|
---|
55 | <xsl:param name="g_fRenderSyntaxAsText">true</xsl:param>
|
---|
56 |
|
---|
57 | <!-- Convert to reference if true, to topic structure if not. -->
|
---|
58 | <xsl:param name="g_fToReference">false</xsl:param>
|
---|
59 |
|
---|
60 |
|
---|
61 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
62 | global XSLT variables
|
---|
63 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
64 |
|
---|
65 |
|
---|
66 |
|
---|
67 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
68 | base operation is to fail on nodes w/o explicit matching.
|
---|
69 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
70 |
|
---|
71 | <xsl:template match="*">
|
---|
72 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>unhandled element</xsl:message>
|
---|
73 | </xsl:template>
|
---|
74 |
|
---|
75 |
|
---|
76 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
77 | transformations starting with root and going deeper.
|
---|
78 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
79 |
|
---|
80 | <!-- Rename refentry to reference.
|
---|
81 | Also we need to wrap the refsync and refsect1 elements in a refbody. -->
|
---|
82 | <xsl:template match="refentry">
|
---|
83 | <xsl:variable name="sRootElement">
|
---|
84 | <xsl:choose>
|
---|
85 | <xsl:when test="$g_fToReference = 'true'">reference</xsl:when>
|
---|
86 | <xsl:otherwise>topic</xsl:otherwise>
|
---|
87 | </xsl:choose>
|
---|
88 | </xsl:variable>
|
---|
89 |
|
---|
90 | <!-- !DOCTYPE -->
|
---|
91 | <xsl:choose>
|
---|
92 | <xsl:when test="$g_fToReference = 'true'">
|
---|
93 | <xsl:text disable-output-escaping='yes'><!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd"></xsl:text>
|
---|
94 | </xsl:when>
|
---|
95 | <xsl:otherwise>
|
---|
96 | <xsl:text disable-output-escaping='yes'><!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd"></xsl:text>
|
---|
97 | </xsl:otherwise>
|
---|
98 | </xsl:choose>
|
---|
99 | <xsl:text>
|
---|
100 | </xsl:text>
|
---|
101 |
|
---|
102 | <!-- Root element -->
|
---|
103 | <xsl:element name="{$sRootElement}">
|
---|
104 | <xsl:if test="not(@id)">
|
---|
105 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have an id attribute!</xsl:message>
|
---|
106 | </xsl:if>
|
---|
107 | <xsl:attribute name="rev">refentry</xsl:attribute>
|
---|
108 | <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
|
---|
109 |
|
---|
110 | <!-- Copy title element from refentryinfo -->
|
---|
111 | <xsl:if test="./refentryinfo/title">
|
---|
112 | <xsl:copy-of select="./refentryinfo/title"/>
|
---|
113 | </xsl:if>
|
---|
114 |
|
---|
115 | <!-- Create a shortdesc element from the text in refnamediv/refpurpose -->
|
---|
116 | <xsl:if test="./refnamediv/refpurpose">
|
---|
117 | <xsl:element name="shortdesc">
|
---|
118 | <xsl:attribute name="rev">refnamediv/refpurpose</xsl:attribute>
|
---|
119 | <xsl:call-template name="capitalize">
|
---|
120 | <xsl:with-param name="text" select="normalize-space(./refnamediv/refpurpose)"/>
|
---|
121 | </xsl:call-template>
|
---|
122 | </xsl:element>
|
---|
123 | </xsl:if>
|
---|
124 |
|
---|
125 | <!-- Put everything else side a refbody element if in 'reference' mode, otherwise no body. -->
|
---|
126 | <xsl:choose>
|
---|
127 | <xsl:when test="$g_fToReference = 'true'">
|
---|
128 | <xsl:element name="refbody">
|
---|
129 | <xsl:apply-templates />
|
---|
130 | </xsl:element>
|
---|
131 | </xsl:when>
|
---|
132 |
|
---|
133 | <xsl:otherwise>
|
---|
134 | <xsl:apply-templates />
|
---|
135 | </xsl:otherwise>
|
---|
136 | </xsl:choose>
|
---|
137 |
|
---|
138 | </xsl:element>
|
---|
139 | </xsl:template>
|
---|
140 |
|
---|
141 | <!-- Remove refentryinfo (we extracted the title element already). -->
|
---|
142 | <xsl:template match="refentryinfo" />
|
---|
143 |
|
---|
144 | <!-- Remove refmeta (manpage info). -->
|
---|
145 | <xsl:template match="refmeta"/>
|
---|
146 |
|
---|
147 | <!-- Remove the refnamediv (we extracted a shortdesc from it already). -->
|
---|
148 | <xsl:template match="refnamediv"/>
|
---|
149 |
|
---|
150 | <!-- Morph the refsynopsisdiv part into a refsyn section. -->
|
---|
151 | <xsl:template match="refsynopsisdiv">
|
---|
152 | <xsl:if test="name(*[1]) != 'cmdsynopsis'"><xsl:message terminate="yes">Expected refsynopsisdiv to start with cmdsynopsis</xsl:message></xsl:if>
|
---|
153 | <xsl:if test="title"><xsl:message terminate="yes">No title element supported in refsynopsisdiv</xsl:message></xsl:if>
|
---|
154 |
|
---|
155 | <xsl:choose>
|
---|
156 | <xsl:when test="$g_fToReference = 'true'">
|
---|
157 | <xsl:element name="refsyn">
|
---|
158 | <xsl:attribute name="rev">refsynopsisdiv</xsl:attribute>
|
---|
159 | <xsl:element name="title">
|
---|
160 | <xsl:text>Synopsis</xsl:text>
|
---|
161 | </xsl:element>
|
---|
162 | <xsl:apply-templates />
|
---|
163 | </xsl:element>
|
---|
164 | </xsl:when>
|
---|
165 |
|
---|
166 | <xsl:otherwise>
|
---|
167 | <xsl:element name="topic">
|
---|
168 | <xsl:attribute name="rev">refsynopsisdiv</xsl:attribute>
|
---|
169 | <!-- <xsl:attribute name="toc">no</xsl:attribute> - topicref only. sigh -->
|
---|
170 | <xsl:attribute name="id"><xsl:value-of select="concat(../@id,'-synopsis')"/></xsl:attribute>
|
---|
171 | <xsl:element name="title">
|
---|
172 | <xsl:text>Synopsis</xsl:text>
|
---|
173 | </xsl:element>
|
---|
174 |
|
---|
175 | <xsl:element name="body">
|
---|
176 | <xsl:apply-templates />
|
---|
177 | </xsl:element>
|
---|
178 | </xsl:element>
|
---|
179 | </xsl:otherwise>
|
---|
180 |
|
---|
181 | </xsl:choose>
|
---|
182 | </xsl:template>
|
---|
183 |
|
---|
184 | <!-- refsect1 -> section or topic -->
|
---|
185 | <xsl:template match="refsect1">
|
---|
186 | <xsl:if test="not(title)"><xsl:message terminate="yes">refsect1 requires title</xsl:message></xsl:if>
|
---|
187 |
|
---|
188 | <xsl:choose>
|
---|
189 | <xsl:when test="$g_fToReference = 'true'">
|
---|
190 | <xsl:element name="section">
|
---|
191 | <xsl:attribute name="rev">refsect1</xsl:attribute>
|
---|
192 | <xsl:if test="@id">
|
---|
193 | <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
|
---|
194 | </xsl:if>
|
---|
195 | <xsl:apply-templates />
|
---|
196 | </xsl:element>
|
---|
197 | </xsl:when>
|
---|
198 |
|
---|
199 | <xsl:otherwise>
|
---|
200 | <xsl:element name="topic">
|
---|
201 | <xsl:attribute name="rev">refsect1</xsl:attribute>
|
---|
202 | <!-- <xsl:attribute name="toc">no</xsl:attribute> - topicref only. sigh -->
|
---|
203 | <xsl:attribute name="id">
|
---|
204 | <xsl:choose>
|
---|
205 | <xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when>
|
---|
206 | <xsl:otherwise><xsl:value-of select="concat(../@id, '-no', count(./preceding-sibling::refsect1))"/></xsl:otherwise>
|
---|
207 | </xsl:choose>
|
---|
208 | </xsl:attribute>
|
---|
209 |
|
---|
210 | <xsl:apply-templates select="title"/>
|
---|
211 |
|
---|
212 | <!-- Must put cmdsynopsis in a paragraph or it'll get too close to any preceeding section title -->
|
---|
213 | <xsl:element name="body">
|
---|
214 | <xsl:for-each select="node()">
|
---|
215 | <xsl:choose>
|
---|
216 | <xsl:when test="self::title"/>
|
---|
217 | <xsl:when test="self::refsect2"/>
|
---|
218 | <xsl:when test="self::cmdsynopsis">
|
---|
219 | <xsl:element name="p">
|
---|
220 | <xsl:attribute name="rev">refsect1/cmdsynopsis</xsl:attribute>
|
---|
221 | <xsl:apply-templates select="." />
|
---|
222 | </xsl:element>
|
---|
223 | </xsl:when>
|
---|
224 | <xsl:otherwise>
|
---|
225 | <xsl:apply-templates select="." />
|
---|
226 | </xsl:otherwise>
|
---|
227 | </xsl:choose>
|
---|
228 | </xsl:for-each>
|
---|
229 | </xsl:element>
|
---|
230 |
|
---|
231 | <xsl:apply-templates select="refsect2"/>
|
---|
232 | </xsl:element>
|
---|
233 | </xsl:otherwise>
|
---|
234 |
|
---|
235 | </xsl:choose>
|
---|
236 | </xsl:template>
|
---|
237 |
|
---|
238 | <!-- refsect2 -> sectiondiv or topic. -->
|
---|
239 | <xsl:template match="refsect2">
|
---|
240 | <xsl:if test="not(title)"><xsl:message terminate="yes">refsect2 requires title</xsl:message></xsl:if>
|
---|
241 |
|
---|
242 | <xsl:choose>
|
---|
243 | <xsl:when test="$g_fToReference = 'true'">
|
---|
244 | <xsl:element name="sectiondiv">
|
---|
245 | <xsl:attribute name="rev">refsect2</xsl:attribute>
|
---|
246 | <xsl:attribute name="outputclass">refsect2</xsl:attribute> <!-- how to make xhtml pass these thru... -->
|
---|
247 | <xsl:if test="@id">
|
---|
248 | <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
|
---|
249 | </xsl:if>
|
---|
250 |
|
---|
251 | <xsl:apply-templates />
|
---|
252 |
|
---|
253 | </xsl:element>
|
---|
254 | </xsl:when>
|
---|
255 |
|
---|
256 | <xsl:otherwise>
|
---|
257 | <xsl:element name="topic">
|
---|
258 | <xsl:attribute name="rev">refsect2</xsl:attribute>
|
---|
259 | <!-- <xsl:attribute name="toc">no</xsl:attribute> - topicref only. sigh -->
|
---|
260 | <xsl:attribute name="id">
|
---|
261 | <xsl:choose>
|
---|
262 | <xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when>
|
---|
263 | <xsl:otherwise>
|
---|
264 | <xsl:if test="not(../@id)">
|
---|
265 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>both refsect2 and parent refsect1 are missing an @id attribute! Please fix add at least one of these to facilitate proper dita topic splitting.</xsl:message>
|
---|
266 | </xsl:if>
|
---|
267 | <xsl:value-of select="concat(../@id, '-no', count(./preceding-sibling::refsect2))"/>
|
---|
268 | </xsl:otherwise>
|
---|
269 | </xsl:choose>
|
---|
270 | </xsl:attribute>
|
---|
271 |
|
---|
272 | <xsl:apply-templates select="title"/>
|
---|
273 |
|
---|
274 | <xsl:element name="body">
|
---|
275 | <xsl:for-each select="node()">
|
---|
276 | <xsl:choose>
|
---|
277 | <xsl:when test="self::title"/>
|
---|
278 | <xsl:when test="self::refsect3"/>
|
---|
279 | <xsl:when test="self::cmdsynopsis">
|
---|
280 | <xsl:element name="p">
|
---|
281 | <xsl:attribute name="rev">refsect2/cmdsynopsis</xsl:attribute>
|
---|
282 | <xsl:apply-templates select="." />
|
---|
283 | </xsl:element>
|
---|
284 | <xsl:element name="p">
|
---|
285 | <xsl:attribute name="rev">space hack</xsl:attribute>
|
---|
286 | <xsl:text> </xsl:text>
|
---|
287 | </xsl:element>
|
---|
288 | </xsl:when>
|
---|
289 | <xsl:otherwise>
|
---|
290 | <xsl:apply-templates select="." />
|
---|
291 | </xsl:otherwise>
|
---|
292 | </xsl:choose>
|
---|
293 | </xsl:for-each>
|
---|
294 | </xsl:element>
|
---|
295 |
|
---|
296 | <xsl:apply-templates select="refsect3"/>
|
---|
297 | </xsl:element>
|
---|
298 | </xsl:otherwise>
|
---|
299 |
|
---|
300 | </xsl:choose>
|
---|
301 | </xsl:template>
|
---|
302 |
|
---|
303 | <!-- refsect1/title -> title -->
|
---|
304 | <xsl:template match="refsect1/title">
|
---|
305 | <xsl:copy>
|
---|
306 | <xsl:apply-templates />
|
---|
307 | </xsl:copy>
|
---|
308 | </xsl:template>
|
---|
309 |
|
---|
310 | <!-- refsect2/title -> b or title -->
|
---|
311 | <xsl:template match="refsect2/title">
|
---|
312 | <xsl:choose>
|
---|
313 | <xsl:when test="$g_fToReference = 'true'">
|
---|
314 | <xsl:element name="b">
|
---|
315 | <xsl:attribute name="rev">refsect2/title</xsl:attribute>
|
---|
316 | <xsl:attribute name="outputclass">refsect2title</xsl:attribute> <!-- how to make xhtml pass these thru... -->
|
---|
317 | <xsl:apply-templates />
|
---|
318 | </xsl:element>
|
---|
319 | </xsl:when>
|
---|
320 |
|
---|
321 | <xsl:otherwise>
|
---|
322 | <xsl:copy>
|
---|
323 | <xsl:apply-templates />
|
---|
324 | </xsl:copy>
|
---|
325 | </xsl:otherwise>
|
---|
326 |
|
---|
327 | </xsl:choose>
|
---|
328 | </xsl:template>
|
---|
329 |
|
---|
330 | <!-- para -> p -->
|
---|
331 | <xsl:template match="para">
|
---|
332 | <xsl:element name="p">
|
---|
333 | <xsl:attribute name="rev">para</xsl:attribute>
|
---|
334 | <xsl:apply-templates />
|
---|
335 | </xsl:element>
|
---|
336 | </xsl:template>
|
---|
337 |
|
---|
338 | <!-- note in a section -> note (no change needed) -->
|
---|
339 | <xsl:template match="refsect1/note | refsect2/note">
|
---|
340 | <xsl:copy>
|
---|
341 | <xsl:apply-templates />
|
---|
342 | </xsl:copy>
|
---|
343 | </xsl:template>
|
---|
344 |
|
---|
345 | <!-- variablelist -> parml -->
|
---|
346 | <xsl:template match="variablelist">
|
---|
347 | <xsl:element name="parml">
|
---|
348 | <xsl:attribute name="rev">variablelist</xsl:attribute>
|
---|
349 | <xsl:apply-templates />
|
---|
350 | </xsl:element>
|
---|
351 | </xsl:template>
|
---|
352 |
|
---|
353 | <!-- varlistentry -> plentry -->
|
---|
354 | <xsl:template match="varlistentry">
|
---|
355 | <xsl:element name="plentry">
|
---|
356 | <xsl:attribute name="rev">varlistentry</xsl:attribute>
|
---|
357 | <xsl:apply-templates />
|
---|
358 | </xsl:element>
|
---|
359 | </xsl:template>
|
---|
360 |
|
---|
361 | <!-- term (in varlistentry) -> pt -->
|
---|
362 | <xsl:template match="varlistentry/term">
|
---|
363 | <xsl:element name="pt">
|
---|
364 | <xsl:attribute name="rev">term</xsl:attribute>
|
---|
365 | <xsl:apply-templates />
|
---|
366 | </xsl:element>
|
---|
367 | </xsl:template>
|
---|
368 |
|
---|
369 | <!-- listitem (in varlistentry) -> pd -->
|
---|
370 | <xsl:template match="varlistentry/listitem">
|
---|
371 | <xsl:element name="pd">
|
---|
372 | <xsl:attribute name="rev">listitem</xsl:attribute>
|
---|
373 | <xsl:apply-templates />
|
---|
374 | </xsl:element>
|
---|
375 | </xsl:template>
|
---|
376 |
|
---|
377 | <!-- itemizedlist -> ul -->
|
---|
378 | <xsl:template match="itemizedlist">
|
---|
379 | <xsl:element name="ul">
|
---|
380 | <xsl:attribute name="rev">itemizedlist</xsl:attribute>
|
---|
381 | <xsl:apply-templates />
|
---|
382 | </xsl:element>
|
---|
383 | </xsl:template>
|
---|
384 |
|
---|
385 | <!-- listitem in itemizedlist -> li -->
|
---|
386 | <xsl:template match="itemizedlist/listitem">
|
---|
387 | <xsl:element name="li">
|
---|
388 | <xsl:attribute name="rev">listitem</xsl:attribute>
|
---|
389 | <xsl:apply-templates />
|
---|
390 | </xsl:element>
|
---|
391 | </xsl:template>
|
---|
392 |
|
---|
393 | <!-- orderedlist -> ol -->
|
---|
394 | <xsl:template match="orderedlist">
|
---|
395 | <xsl:element name="ol">
|
---|
396 | <xsl:attribute name="rev">orderedlist</xsl:attribute>
|
---|
397 | <xsl:apply-templates />
|
---|
398 | </xsl:element>
|
---|
399 | </xsl:template>
|
---|
400 |
|
---|
401 | <!-- listitem in orderedlist -> li -->
|
---|
402 | <xsl:template match="orderedlist/listitem">
|
---|
403 | <xsl:element name="li">
|
---|
404 | <xsl:attribute name="rev">listitem</xsl:attribute>
|
---|
405 | <xsl:apply-templates />
|
---|
406 | </xsl:element>
|
---|
407 | </xsl:template>
|
---|
408 |
|
---|
409 | <!-- cmdsynopsis -> syntaxdiagram
|
---|
410 | If sbr is used, this gets a bit more complicated... -->
|
---|
411 | <xsl:template match="cmdsynopsis[not(sbr)]">
|
---|
412 | <xsl:element name="syntaxdiagram">
|
---|
413 | <xsl:attribute name="rev">cmdsynopsis</xsl:attribute>
|
---|
414 | <xsl:if test="@id">
|
---|
415 | <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
|
---|
416 | </xsl:if>
|
---|
417 | <xsl:choose>
|
---|
418 | <xsl:when test="$g_fRenderSyntaxAsText = 'true'">
|
---|
419 | <xsl:element name="groupseq">
|
---|
420 | <xsl:apply-templates />
|
---|
421 | </xsl:element>
|
---|
422 | </xsl:when>
|
---|
423 |
|
---|
424 | <xsl:otherwise>
|
---|
425 | <xsl:apply-templates />
|
---|
426 | </xsl:otherwise>
|
---|
427 | </xsl:choose>
|
---|
428 | </xsl:element>
|
---|
429 |
|
---|
430 | <!-- HACK ALERT! Add an empty paragraph to keep syntax diagrams apart in the
|
---|
431 | PDF output, otherwise the commands becomes hard to tell apart. -->
|
---|
432 | <xsl:if test="position() < last()">
|
---|
433 | <xsl:element name="p">
|
---|
434 | <xsl:attribute name="platform">ohc</xsl:attribute> <!-- 'och', so it gets filtered out from the html(help) docs. -->
|
---|
435 | <xsl:attribute name="rev">pdf space hack</xsl:attribute>
|
---|
436 | <xsl:text> </xsl:text>
|
---|
437 | </xsl:element>
|
---|
438 | </xsl:if>
|
---|
439 | </xsl:template>
|
---|
440 |
|
---|
441 | <!-- TODO: sbr cannot be translated, it seems. Whether we wrap things in
|
---|
442 | synblk, groupcomp or groupseq elements, the result is always the same:
|
---|
443 | - HTML: ignored.
|
---|
444 | - PDF: condensed arguments w/o spaces between. 4.0.2 doesn't seem
|
---|
445 | to condense stuff any more inside synblk elements, but then the
|
---|
446 | rending isn't much changed for PDFs anyway since its one element
|
---|
447 | per line.
|
---|
448 | Update: Turns out the condensing was because we stripped element
|
---|
449 | whitespace instead of preserving it. svn copy. sigh. -->
|
---|
450 | <xsl:template match="cmdsynopsis[sbr]">
|
---|
451 | <xsl:variable name="sWrapperElement">
|
---|
452 | <xsl:choose>
|
---|
453 | <xsl:when test="$g_fRenderSyntaxAsText = 'true'"><xsl:text>groupseq</xsl:text></xsl:when>
|
---|
454 | <xsl:otherwise><!--synblk--></xsl:otherwise>
|
---|
455 | </xsl:choose>
|
---|
456 | </xsl:variable>
|
---|
457 |
|
---|
458 | <xsl:element name="syntaxdiagram">
|
---|
459 | <xsl:attribute name="rev">cmdsynopsis</xsl:attribute>
|
---|
460 | <xsl:if test="@id">
|
---|
461 | <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
|
---|
462 | </xsl:if>
|
---|
463 | <xsl:for-each select="sbr">
|
---|
464 | <xsl:variable name="idxSbr" select="position()"/>
|
---|
465 |
|
---|
466 | <xsl:choose>
|
---|
467 | <xsl:when test="$sWrapperElement != ''">
|
---|
468 | <xsl:element name="{$sWrapperElement}">
|
---|
469 | <xsl:attribute name="rev">sbr/<xsl:value-of select="position()"/></xsl:attribute>
|
---|
470 |
|
---|
471 | <xsl:if test="$idxSbr = 1">
|
---|
472 | <xsl:apply-templates select="preceding-sibling::node()"/>
|
---|
473 | </xsl:if>
|
---|
474 | <xsl:if test="$idxSbr != 1">
|
---|
475 | <xsl:apply-templates select="preceding-sibling::node()[ count(. | ../sbr[$idxSbr - 1]/following-sibling::node())
|
---|
476 | = count(../sbr[$idxSbr - 1]/following-sibling::node())]"/>
|
---|
477 | </xsl:if>
|
---|
478 | </xsl:element>
|
---|
479 | </xsl:when>
|
---|
480 |
|
---|
481 | <xsl:otherwise>
|
---|
482 | <xsl:if test="$idxSbr = 1">
|
---|
483 | <xsl:apply-templates select="preceding-sibling::node()"/>
|
---|
484 | </xsl:if>
|
---|
485 | <xsl:if test="$idxSbr != 1">
|
---|
486 | <xsl:apply-templates select="preceding-sibling::node()[ count(. | ../sbr[$idxSbr - 1]/following-sibling::node())
|
---|
487 | = count(../sbr[$idxSbr - 1]/following-sibling::node())]"/>
|
---|
488 | </xsl:if>
|
---|
489 | </xsl:otherwise>
|
---|
490 | </xsl:choose>
|
---|
491 |
|
---|
492 | <!-- Ensure some space between these.-->
|
---|
493 | <xsl:text>
|
---|
494 | </xsl:text>
|
---|
495 |
|
---|
496 | <xsl:if test="$idxSbr = last()">
|
---|
497 | <xsl:choose>
|
---|
498 | <xsl:when test="$sWrapperElement != ''">
|
---|
499 | <xsl:element name="{$sWrapperElement}">
|
---|
500 | <xsl:attribute name="rev">sbr/<xsl:value-of select="position()"/></xsl:attribute>
|
---|
501 | <xsl:apply-templates select="following-sibling::node()"/>
|
---|
502 | </xsl:element>
|
---|
503 | </xsl:when>
|
---|
504 |
|
---|
505 | <xsl:otherwise>
|
---|
506 | <xsl:apply-templates select="following-sibling::node()"/>
|
---|
507 | </xsl:otherwise>
|
---|
508 | </xsl:choose>
|
---|
509 | </xsl:if>
|
---|
510 | </xsl:for-each>
|
---|
511 | </xsl:element>
|
---|
512 |
|
---|
513 | <!-- HACK ALERT! Add an empty paragraph to keep syntax diagrams apart in the
|
---|
514 | PDF output, otherwise the commands becomes hard to tell apart. -->
|
---|
515 | <xsl:if test="position() < last()">
|
---|
516 | <xsl:element name="p">
|
---|
517 | <xsl:attribute name="platform">ohc</xsl:attribute> <!-- 'och', so it gets filtered out from the html(help) docs. -->
|
---|
518 | <xsl:attribute name="rev">pdf space hack</xsl:attribute>
|
---|
519 | <xsl:text> </xsl:text>
|
---|
520 | </xsl:element>
|
---|
521 | </xsl:if>
|
---|
522 | </xsl:template>
|
---|
523 |
|
---|
524 | <!-- text (whitespace) under synopsis may need removing. -->
|
---|
525 | <xsl:template match="cmdsynopsis/text()">
|
---|
526 | <xsl:if test="normalize-space(.) != ''">
|
---|
527 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>text in cmdsynopsis '<xsl:value-of select="."/>'</xsl:message>
|
---|
528 | </xsl:if>
|
---|
529 |
|
---|
530 | <xsl:choose>
|
---|
531 | <xsl:when test="$g_fRenderSyntaxAsText = 'true'">
|
---|
532 | </xsl:when>
|
---|
533 |
|
---|
534 | <xsl:otherwise>
|
---|
535 | <xsl:value-of select="."/>
|
---|
536 | </xsl:otherwise>
|
---|
537 | </xsl:choose>
|
---|
538 | </xsl:template>
|
---|
539 |
|
---|
540 |
|
---|
541 | <!-- command with text and/or replaceable in cmdsynopsis -> groupseq + kwd -->
|
---|
542 | <xsl:template match="cmdsynopsis/command | cmdsynopsis/*/command" >
|
---|
543 | <xsl:element name="groupseq">
|
---|
544 | <xsl:attribute name="rev">command</xsl:attribute>
|
---|
545 | <xsl:apply-templates />
|
---|
546 | </xsl:element>
|
---|
547 | </xsl:template>
|
---|
548 |
|
---|
549 | <xsl:template match="cmdsynopsis/command/text() | cmdsynopsis/*/command/text()" >
|
---|
550 | <xsl:element name="kwd">
|
---|
551 | <xsl:attribute name="rev">command/text</xsl:attribute>
|
---|
552 | <xsl:call-template name="emit-text-with-replacements"/>
|
---|
553 | </xsl:element>
|
---|
554 | </xsl:template>
|
---|
555 |
|
---|
556 | <xsl:template match="cmdsynopsis/command/replaceable | cmdsynopsis/*/command/replaceable" >
|
---|
557 | <xsl:call-template name="check-children"/>
|
---|
558 | <xsl:element name="var">
|
---|
559 | <xsl:attribute name="rev">command/replaceable</xsl:attribute>
|
---|
560 | <xsl:apply-templates />
|
---|
561 | </xsl:element>
|
---|
562 | </xsl:template>
|
---|
563 |
|
---|
564 | <!-- command with text and/or replaceable in not cmdsynopsis -> userinput + cmdname -->
|
---|
565 | <xsl:template match="command[not(ancestor::cmdsynopsis)]">
|
---|
566 | <xsl:element name="userinput">
|
---|
567 | <xsl:attribute name="rev">command</xsl:attribute>
|
---|
568 | <xsl:apply-templates />
|
---|
569 | </xsl:element>
|
---|
570 | </xsl:template>
|
---|
571 |
|
---|
572 | <xsl:template match="command[not(ancestor::cmdsynopsis)]/text()">
|
---|
573 | <xsl:element name="cmdname">
|
---|
574 | <xsl:attribute name="rev">command/text</xsl:attribute>
|
---|
575 | <xsl:value-of select="."/>
|
---|
576 | </xsl:element>
|
---|
577 | </xsl:template>
|
---|
578 |
|
---|
579 | <xsl:template match="command[not(ancestor::cmdsynopsis)]/replaceable">
|
---|
580 | <xsl:call-template name="check-children"/>
|
---|
581 | <xsl:element name="varname">
|
---|
582 | <xsl:attribute name="rev">command/replaceable</xsl:attribute>
|
---|
583 | <xsl:value-of select="."/>
|
---|
584 | </xsl:element>
|
---|
585 | </xsl:template>
|
---|
586 |
|
---|
587 | <!--
|
---|
588 | arg -> groupseq; A bit complicated though, because text needs to be wrapping
|
---|
589 | in 'kwd' and any nested arguments needs explicit 'sep' elements containing a
|
---|
590 | space or the nested arguments gets bunched up tight.
|
---|
591 | Examples:
|
---|
592 | {arg}-output={replaceable}file{/replaceable}{/arg}
|
---|
593 | = {groupcomp importance="optional"}{kwd}-output{/kwd}{sep}={/sep}{var}file{/var}{/groupcomp}
|
---|
594 |
|
---|
595 | {arg}-output {replaceable}file{/replaceable}{/arg}
|
---|
596 | = {groupcomp importance="optional"}{kwd}-output{/kwd}{sep} {/sep}{var}file{/var}{/groupcomp}
|
---|
597 |
|
---|
598 | {arg}-R {arg}-L{/arg}{/arg}
|
---|
599 | = {groupseq importance="optional"}{groupcomp}{kwd}-R{/groupcomp}{sep} {/sep}
|
---|
600 | or {groupseq importance="optional"}{kwd}-R{sep} {/sep}{groupcomp}{kwd}-L{/groupcomp}{/groupseq}
|
---|
601 | note: Important to specify {sep} here as whitespace might otherwise be squashed.
|
---|
602 | -->
|
---|
603 |
|
---|
604 | <!-- Plaintext within arg is generally translated to kwd, but value separators
|
---|
605 | like '=' and ',' should be wrapped in a delim element. -->
|
---|
606 | <xsl:template match="arg/text()">
|
---|
607 | <xsl:choose>
|
---|
608 | <!-- put trailing '=' inside <sep> -->
|
---|
609 | <xsl:when test="substring(., string-length(.)) = '='">
|
---|
610 | <xsl:element name="kwd">
|
---|
611 | <xsl:attribute name="rev">arg=</xsl:attribute>
|
---|
612 | <xsl:call-template name="emit-text-with-replacements">
|
---|
613 | <xsl:with-param name="a_sText" select="substring(., 1, string-length(.) - 1)"/>
|
---|
614 | </xsl:call-template>
|
---|
615 | </xsl:element>
|
---|
616 | <xsl:element name="delim">
|
---|
617 | <xsl:attribute name="rev">arg=</xsl:attribute>
|
---|
618 | <xsl:text>=</xsl:text>
|
---|
619 | </xsl:element>
|
---|
620 | </xsl:when>
|
---|
621 |
|
---|
622 | <!-- Special case, single space, assuming it's deliberate so put in inside a sep element. -->
|
---|
623 | <xsl:when test=". = ' '">
|
---|
624 | <xsl:element name="sep">
|
---|
625 | <xsl:attribute name="rev">arg-space</xsl:attribute>
|
---|
626 | <xsl:text> </xsl:text>
|
---|
627 | </xsl:element>
|
---|
628 | </xsl:when>
|
---|
629 |
|
---|
630 | <!-- Don't wrap other pure whitespace kwd sequences, but emit single space 'sep'
|
---|
631 | element if a arg or groups follows. If the whitespace includes a newline
|
---|
632 | we'll emit it, but otherways we'll generally suppress it to avoid
|
---|
633 | accidentally padding spaces between arguments. -->
|
---|
634 | <xsl:when test="normalize-space(.) = ''">
|
---|
635 | <xsl:if test="following::*[position() = 1 and (self::arg or self::group)] and not(ancestor-or-self::*[@role='compact'])">
|
---|
636 | <xsl:element name="sep">
|
---|
637 | <xsl:attribute name="rev">arg-whitespace</xsl:attribute>
|
---|
638 | <xsl:text> </xsl:text>
|
---|
639 | </xsl:element>
|
---|
640 | </xsl:if>
|
---|
641 | <xsl:if test="contains(., ' ') and $g_fRenderSyntaxAsText != 'true'">
|
---|
642 | <xsl:value-of select="."/>
|
---|
643 | </xsl:if>
|
---|
644 | </xsl:when>
|
---|
645 |
|
---|
646 | <!-- Remainder is all wrapped in kwd, after space normalization. -->
|
---|
647 | <xsl:otherwise>
|
---|
648 | <xsl:element name="kwd">
|
---|
649 | <xsl:attribute name="rev">arg</xsl:attribute>
|
---|
650 | <xsl:call-template name="emit-text-with-replacements">
|
---|
651 | <xsl:with-param name="a_sText" select="normalize-space(.)"/>
|
---|
652 | </xsl:call-template>
|
---|
653 | </xsl:element>
|
---|
654 | <xsl:if test="normalize-space(substring(., string-length(.), 1)) = ''
|
---|
655 | and following::*[position() = 1 and (self::arg or self::group)]
|
---|
656 | and not(ancestor-or-self::*[@role='compact'])">
|
---|
657 | <xsl:element name="sep">
|
---|
658 | <xsl:attribute name="rev">arg-trailing</xsl:attribute>
|
---|
659 | <xsl:text> </xsl:text>
|
---|
660 | </xsl:element>
|
---|
661 | </xsl:if>
|
---|
662 | </xsl:otherwise>
|
---|
663 | </xsl:choose>
|
---|
664 | </xsl:template>
|
---|
665 |
|
---|
666 | <!-- arg -> groupseq or groupcomp and optionally a repsep element if repeatable. -->
|
---|
667 | <xsl:template match="arg" >
|
---|
668 | <xsl:choose>
|
---|
669 | <xsl:when test="$g_fRenderSyntaxAsText = 'true'">
|
---|
670 | <xsl:call-template name="arg_or_group_as_text"/>
|
---|
671 | </xsl:when>
|
---|
672 |
|
---|
673 | <xsl:otherwise>
|
---|
674 | <!-- If it's a tighly packed arg, we use groupcomp instead of groupseq to try
|
---|
675 | avoid it being split in the middle. -->
|
---|
676 | <xsl:variable name="sGroupType">
|
---|
677 | <xsl:call-template name="determine_arg_wrapper_element"/>
|
---|
678 | </xsl:variable>
|
---|
679 | <xsl:element name="{$sGroupType}">
|
---|
680 | <xsl:attribute name="rev">arg[<xsl:value-of select="concat(@choice,',',@rep)"/>]</xsl:attribute>
|
---|
681 | <xsl:choose>
|
---|
682 | <xsl:when test="not(@choice) or @choice = 'opt'">
|
---|
683 | <xsl:attribute name="importance">optional</xsl:attribute>
|
---|
684 | </xsl:when>
|
---|
685 | <xsl:when test="@choice = 'req'">
|
---|
686 | <xsl:attribute name="importance">required</xsl:attribute>
|
---|
687 | </xsl:when>
|
---|
688 | <xsl:when test="@choice = 'plain'"/>
|
---|
689 | <xsl:otherwise>
|
---|
690 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Unexpected @choice value: <xsl:value-of select="@choice"/></xsl:message>
|
---|
691 | </xsl:otherwise>
|
---|
692 | </xsl:choose>
|
---|
693 |
|
---|
694 | <xsl:apply-templates />
|
---|
695 |
|
---|
696 | <xsl:if test="@rep = 'repeat'">
|
---|
697 | <!-- repsep can only be placed at the start of a groupseq/whatever and
|
---|
698 | the documenation and examples of the element is very sparse. The
|
---|
699 | PDF output plugin will place the '...' where it finds it and do
|
---|
700 | nothing if it's empty. The XHTML output plugin ignores it, it seems. -->
|
---|
701 | <xsl:element name="sep">
|
---|
702 | <xsl:attribute name="rev">arg[<xsl:value-of select="@choice"/>,repeat]</xsl:attribute>
|
---|
703 | <xsl:text> </xsl:text>
|
---|
704 | </xsl:element>
|
---|
705 | <xsl:element name="groupcomp">
|
---|
706 | <xsl:attribute name="importance">optional</xsl:attribute>
|
---|
707 | <xsl:attribute name="rev">arg[<xsl:value-of select="@choice"/>,repeat]</xsl:attribute>
|
---|
708 | <xsl:attribute name="outputclass">repeatarg</xsl:attribute> <!-- how to make xhtml pass these thru... -->
|
---|
709 | <xsl:element name="repsep">
|
---|
710 | <xsl:attribute name="rev">arg[<xsl:value-of select="@choice"/>,repeat]</xsl:attribute>
|
---|
711 | <xsl:text>...</xsl:text>
|
---|
712 | </xsl:element>
|
---|
713 | </xsl:element>
|
---|
714 | </xsl:if>
|
---|
715 |
|
---|
716 | </xsl:element>
|
---|
717 | </xsl:otherwise>
|
---|
718 | </xsl:choose>
|
---|
719 |
|
---|
720 | <xsl:if test="parent::group and @choice != 'plain'">
|
---|
721 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Expected arg in group to be plain, not optional.</xsl:message>
|
---|
722 | </xsl:if>
|
---|
723 | </xsl:template>
|
---|
724 |
|
---|
725 | <xsl:template name="determine_arg_wrapper_element">
|
---|
726 | <xsl:choose>
|
---|
727 | <xsl:when test="not(descendant::group) and not(descendant::text()[contains(.,' ') or normalize-space(.) != .])">
|
---|
728 | <xsl:text>groupcomp</xsl:text>
|
---|
729 | </xsl:when>
|
---|
730 | <xsl:otherwise>
|
---|
731 | <xsl:text>groupseq</xsl:text>
|
---|
732 | </xsl:otherwise>
|
---|
733 | </xsl:choose>
|
---|
734 | </xsl:template>
|
---|
735 |
|
---|
736 | <!-- replaceable under arg -> var -->
|
---|
737 | <xsl:template match="arg/replaceable" >
|
---|
738 | <xsl:element name="var">
|
---|
739 | <xsl:attribute name="rev">replaceable</xsl:attribute>
|
---|
740 | <xsl:apply-templates />
|
---|
741 | </xsl:element>
|
---|
742 | </xsl:template>
|
---|
743 |
|
---|
744 | <!-- replaceable in para or term -> synph+var -->
|
---|
745 | <xsl:template match="para/replaceable | term/replaceable | screen/replaceable" >
|
---|
746 | <xsl:element name="synph">
|
---|
747 | <xsl:attribute name="rev">replaceable</xsl:attribute>
|
---|
748 | <xsl:element name="var">
|
---|
749 | <xsl:attribute name="rev">replaceable</xsl:attribute>
|
---|
750 | <xsl:apply-templates />
|
---|
751 | </xsl:element>
|
---|
752 | </xsl:element>
|
---|
753 | </xsl:template>
|
---|
754 |
|
---|
755 | <!-- replaceable in option -> var -->
|
---|
756 | <xsl:template match="option/replaceable" >
|
---|
757 | <xsl:element name="var">
|
---|
758 | <xsl:attribute name="rev">option/replaceable</xsl:attribute>
|
---|
759 | <xsl:apply-templates />
|
---|
760 | </xsl:element>
|
---|
761 | </xsl:template>
|
---|
762 |
|
---|
763 | <!-- replaceable in computeroutput or filename -> varname -->
|
---|
764 | <xsl:template match="computeroutput/replaceable | filename/replaceable" >
|
---|
765 | <xsl:element name="varname">
|
---|
766 | <xsl:attribute name="rev">computeroutput/replaceable</xsl:attribute>
|
---|
767 | <xsl:apply-templates />
|
---|
768 | </xsl:element>
|
---|
769 | </xsl:template>
|
---|
770 |
|
---|
771 | <!-- replaceable/text() in a cmdsynopsis should have hypens replaced. -->
|
---|
772 | <xsl:template match="replaceable/text()[ancestor::cmdsynopsis]" >
|
---|
773 | <xsl:call-template name="emit-text-with-replacements"/>
|
---|
774 | </xsl:template>
|
---|
775 |
|
---|
776 | <!--
|
---|
777 | DocBook 'group' elements are only ever used for multiple choice options
|
---|
778 | in our refentry XML, it is never used for argument groupings. For
|
---|
779 | grouping arguments we use nested 'arg' elements.
|
---|
780 |
|
---|
781 | This is because 'group' with 'group' parent is poorly defned/handled.
|
---|
782 | Whether the DocBook HTML formatters uses ' | ' separators depends on what
|
---|
783 | other elements are in the group and their order. arg1+group2+group3 won't
|
---|
784 | get any, but group1+arg2+group3 will get one between the first two.
|
---|
785 | -->
|
---|
786 |
|
---|
787 | <xsl:template match="group[group]" priority="3.0">
|
---|
788 | <xsl:message terminate="yes">
|
---|
789 | <xsl:call-template name="error-prefix"/>Immediate group nesting is not allowed! Put nested group inside arg element.
|
---|
790 | </xsl:message>
|
---|
791 | </xsl:template>
|
---|
792 |
|
---|
793 | <xsl:template match="group[count(arg) < 2]" priority="3.0">
|
---|
794 | <xsl:message terminate="yes">
|
---|
795 | <xsl:call-template name="error-prefix"/>Group with fewer than two 'arg' elements is not allowed!
|
---|
796 | </xsl:message>
|
---|
797 | </xsl:template>
|
---|
798 |
|
---|
799 | <!-- group -> groupchoice w/attrib -->
|
---|
800 | <xsl:template match="group">
|
---|
801 | <xsl:choose>
|
---|
802 | <xsl:when test="$g_fRenderSyntaxAsText = 'true'">
|
---|
803 | <xsl:call-template name="arg_or_group_as_text"/>
|
---|
804 | </xsl:when>
|
---|
805 | <xsl:otherwise>
|
---|
806 |
|
---|
807 | <xsl:element name="groupchoice">
|
---|
808 | <xsl:choose>
|
---|
809 | <xsl:when test="@choice = 'req'">
|
---|
810 | <xsl:attribute name="rev">group[req]</xsl:attribute>
|
---|
811 | <xsl:attribute name="importance">required</xsl:attribute>
|
---|
812 | </xsl:when>
|
---|
813 | <xsl:when test="@choice = 'plain'">
|
---|
814 | <xsl:attribute name="rev">group[plain]</xsl:attribute>
|
---|
815 | <!-- We don't set the importance here. @todo Check what it does to the output formatting -->
|
---|
816 | </xsl:when>
|
---|
817 | <xsl:otherwise>
|
---|
818 | <xsl:attribute name="rev">group[opt]</xsl:attribute>
|
---|
819 | <xsl:attribute name="importance">optional</xsl:attribute>
|
---|
820 | </xsl:otherwise>
|
---|
821 | </xsl:choose>
|
---|
822 |
|
---|
823 | <xsl:apply-templates />
|
---|
824 |
|
---|
825 | <xsl:if test="@rep = 'repeat'">
|
---|
826 | <!-- repsep can only be placed at the start of a groupseq/whatever and
|
---|
827 | the documenation and examples of the element is very sparse. The
|
---|
828 | PDF output plugin will place the '...' where it finds it and do
|
---|
829 | nothing if it's empty. The XHTML output plugin ignores it, it seems. -->
|
---|
830 | <xsl:message terminate="no"><xsl:call-template name="error-prefix"/>Repeating group is not a good idea...</xsl:message>
|
---|
831 | <xsl:element name="sep">
|
---|
832 | <xsl:attribute name="rev">arg[<xsl:value-of select="@choice"/>,repeat]</xsl:attribute>
|
---|
833 | <xsl:text> </xsl:text>
|
---|
834 | </xsl:element>
|
---|
835 | <xsl:element name="groupcomp">
|
---|
836 | <xsl:attribute name="importance">optional</xsl:attribute>
|
---|
837 | <xsl:attribute name="rev">arg[<xsl:value-of select="@choice"/>,repeat]</xsl:attribute>
|
---|
838 | <xsl:attribute name="outputclass">repeatarg</xsl:attribute> <!-- how to make xhtml pass these thru... -->
|
---|
839 | <xsl:element name="repsep">
|
---|
840 | <xsl:attribute name="rev">arg[<xsl:value-of select="@choice"/>,repeat]</xsl:attribute>
|
---|
841 | <xsl:text>...</xsl:text>
|
---|
842 | </xsl:element>
|
---|
843 | </xsl:element>
|
---|
844 | </xsl:if>
|
---|
845 | </xsl:element>
|
---|
846 |
|
---|
847 | </xsl:otherwise>
|
---|
848 | </xsl:choose>
|
---|
849 | </xsl:template>
|
---|
850 |
|
---|
851 | <!-- text under a group may need removing. -->
|
---|
852 | <xsl:template match="group/text()">
|
---|
853 | <xsl:if test="normalize-space(.) != ''">
|
---|
854 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>text in group: '<xsl:value-of select="."/>'</xsl:message>
|
---|
855 | </xsl:if>
|
---|
856 |
|
---|
857 | <xsl:choose>
|
---|
858 | <xsl:when test="$g_fRenderSyntaxAsText = 'true'">
|
---|
859 | </xsl:when>
|
---|
860 |
|
---|
861 | <xsl:otherwise>
|
---|
862 | <xsl:value-of select="."/>
|
---|
863 | </xsl:otherwise>
|
---|
864 | </xsl:choose>
|
---|
865 | </xsl:template>
|
---|
866 |
|
---|
867 |
|
---|
868 | <!--
|
---|
869 | arg or group -> kwd + text
|
---|
870 | (Code duplicated in docbook-refentry-to-C-help.xsl & docbook2latex.xsl, with local differences.)
|
---|
871 | -->
|
---|
872 | <xsl:template name="arg_or_group_as_text" >
|
---|
873 | <xsl:variable name="fWrappers" select="not(ancestor::group)"/>
|
---|
874 |
|
---|
875 | <!-- lead separators -->
|
---|
876 | <xsl:variable name="sLeadSeps">
|
---|
877 | <xsl:call-template name="arg_or_group_as_text_calc_lead_seps">
|
---|
878 | <xsl:with-param name="a_fWrappers" select="$fWrappers"/>
|
---|
879 | </xsl:call-template>
|
---|
880 | </xsl:variable>
|
---|
881 | <xsl:if test="$sLeadSeps != ''">
|
---|
882 | <xsl:element name="sep">
|
---|
883 | <xsl:value-of select="$sLeadSeps"/>
|
---|
884 | </xsl:element>
|
---|
885 | </xsl:if>
|
---|
886 |
|
---|
887 | <!-- render the arg (TODO: may need to do more work here) -->
|
---|
888 | <xsl:apply-templates />
|
---|
889 |
|
---|
890 | <!-- repeat wrapping -->
|
---|
891 | <xsl:choose>
|
---|
892 | <xsl:when test="@rep = 'norepeat' or not(@rep) or @rep = ''"/>
|
---|
893 | <xsl:when test="@rep = 'repeat'"> <xsl:element name="sep"><xsl:value-of select="$arg.rep.repeat.str"/></xsl:element></xsl:when>
|
---|
894 | <xsl:otherwise><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Invalid rep choice: "<xsl:value-of select="@rep"/>"</xsl:message></xsl:otherwise>
|
---|
895 | </xsl:choose>
|
---|
896 |
|
---|
897 | <!-- close wrapping -->
|
---|
898 | <xsl:if test="$fWrappers">
|
---|
899 | <xsl:choose>
|
---|
900 | <xsl:when test="not(@choice) or @choice = ''"> <xsl:element name="sep"><xsl:value-of select="$arg.choice.def.close.str"/></xsl:element></xsl:when>
|
---|
901 | <xsl:when test="@choice = 'opt'"> <xsl:element name="sep"><xsl:value-of select="$arg.choice.opt.close.str"/></xsl:element></xsl:when>
|
---|
902 | <xsl:when test="@choice = 'req'"> <xsl:element name="sep"><xsl:value-of select="$arg.choice.req.close.str"/></xsl:element></xsl:when>
|
---|
903 | </xsl:choose>
|
---|
904 | <!-- Add a space padding if we're the last element in a repeating arg or group -->
|
---|
905 | <!-- 2023-03-22 bird: This is incorrectly written. Fix as needed...
|
---|
906 | <xsl:if test="(parent::arg or parent::group) and not(following-sibiling) and not(ancestor::*[@role='compact'])">
|
---|
907 | <xsl:text> </xsl:text>
|
---|
908 | </xsl:if>
|
---|
909 | -->
|
---|
910 | </xsl:if>
|
---|
911 |
|
---|
912 | </xsl:template>
|
---|
913 |
|
---|
914 | <!-- Helper for arg_or_group_as_text. -->
|
---|
915 | <xsl:template name="arg_or_group_as_text_calc_lead_seps">
|
---|
916 | <xsl:param name="a_fWrappers"/>
|
---|
917 | <xsl:variable name="idSelf" select="generate-id(.)"/>
|
---|
918 |
|
---|
919 | <!-- separator char if we're not the first child -->
|
---|
920 | <xsl:if test="../*[generate-id(.) = $idSelf and position() > 1]">
|
---|
921 | <!--<xsl:value-of select="concat('*',name(),'=', position(),'#')"/>-->
|
---|
922 | <xsl:choose>
|
---|
923 | <xsl:when test="parent::group and ancestor::*[@role='compact']"><xsl:value-of select="$arg.or.sep.compact"/></xsl:when>
|
---|
924 | <xsl:when test="parent::group"><xsl:value-of select="$arg.or.sep"/></xsl:when>
|
---|
925 | <xsl:when test="ancestor::*[@role='compact']"></xsl:when>
|
---|
926 | <xsl:when test="ancestor::*/@sepchar"><xsl:value-of select="ancestor::*/@sepchar"/></xsl:when>
|
---|
927 | <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
|
---|
928 | </xsl:choose>
|
---|
929 | </xsl:if>
|
---|
930 |
|
---|
931 | <!-- open wrapping -->
|
---|
932 | <xsl:if test="$a_fWrappers">
|
---|
933 | <xsl:choose>
|
---|
934 | <xsl:when test="not(@choice) or @choice = ''"> <xsl:value-of select="$arg.choice.def.open.str"/></xsl:when>
|
---|
935 | <xsl:when test="@choice = 'opt'"> <xsl:value-of select="$arg.choice.opt.open.str"/></xsl:when>
|
---|
936 | <xsl:when test="@choice = 'req'"> <xsl:value-of select="$arg.choice.req.open.str"/></xsl:when>
|
---|
937 | <xsl:when test="@choice = 'plain'"/>
|
---|
938 | <xsl:otherwise><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Invalid arg choice: "<xsl:value-of select="@choice"/>"</xsl:message></xsl:otherwise>
|
---|
939 | </xsl:choose>
|
---|
940 | </xsl:if>
|
---|
941 |
|
---|
942 | </xsl:template>
|
---|
943 |
|
---|
944 |
|
---|
945 | <!-- option -->
|
---|
946 | <xsl:template match="option/text()" >
|
---|
947 | <xsl:element name="kwd">
|
---|
948 | <xsl:attribute name="rev">option</xsl:attribute>
|
---|
949 | <xsl:value-of select="."/>
|
---|
950 | </xsl:element>
|
---|
951 | </xsl:template>
|
---|
952 |
|
---|
953 | <xsl:template match="option" >
|
---|
954 | <xsl:element name="synph">
|
---|
955 | <xsl:attribute name="rev">option</xsl:attribute>
|
---|
956 | <xsl:apply-templates />
|
---|
957 | </xsl:element>
|
---|
958 | </xsl:template>
|
---|
959 |
|
---|
960 | <!-- literal w/o sub-elements -> codeph -->
|
---|
961 | <xsl:template match="literal[not(*)]" >
|
---|
962 | <xsl:element name="codeph">
|
---|
963 | <xsl:attribute name="rev">literal</xsl:attribute>
|
---|
964 | <xsl:apply-templates />
|
---|
965 | </xsl:element>
|
---|
966 | </xsl:template>
|
---|
967 |
|
---|
968 | <!-- literal with replaceable sub-elements -> synph -->
|
---|
969 | <xsl:template match="literal[replaceable]" >
|
---|
970 | <xsl:element name="synph">
|
---|
971 | <xsl:attribute name="rev">literal/replaceable</xsl:attribute>
|
---|
972 | <xsl:for-each select="node()">
|
---|
973 | <xsl:choose>
|
---|
974 | <xsl:when test="self::text()">
|
---|
975 | <xsl:element name="kwd">
|
---|
976 | <xsl:value-of select="."/>
|
---|
977 | </xsl:element>
|
---|
978 | </xsl:when>
|
---|
979 | <xsl:when test="self::replaceable">
|
---|
980 | <xsl:if test="./*">
|
---|
981 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Unexpected literal/replaceable child</xsl:message>
|
---|
982 | </xsl:if>
|
---|
983 | <xsl:element name="var">
|
---|
984 | <xsl:value-of select="."/>
|
---|
985 | </xsl:element>
|
---|
986 | </xsl:when>
|
---|
987 | <xsl:otherwise>
|
---|
988 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Unexpected literal child:
|
---|
989 | <xsl:value-of select="name(.)" />
|
---|
990 | </xsl:message>
|
---|
991 | </xsl:otherwise>
|
---|
992 | </xsl:choose>
|
---|
993 | </xsl:for-each>
|
---|
994 | </xsl:element>
|
---|
995 | </xsl:template>
|
---|
996 |
|
---|
997 | <!-- filename -> filepath -->
|
---|
998 | <xsl:template match="filename" >
|
---|
999 | <xsl:element name="filepath">
|
---|
1000 | <xsl:attribute name="rev">filename</xsl:attribute>
|
---|
1001 | <xsl:apply-templates />
|
---|
1002 | </xsl:element>
|
---|
1003 | </xsl:template>
|
---|
1004 |
|
---|
1005 | <!-- screen - pass thru -->
|
---|
1006 | <xsl:template match="screen" >
|
---|
1007 | <xsl:copy>
|
---|
1008 | <xsl:apply-templates />
|
---|
1009 | </xsl:copy>
|
---|
1010 | </xsl:template>
|
---|
1011 |
|
---|
1012 | <!-- computeroutput -> systemoutput-->
|
---|
1013 | <xsl:template match="computeroutput">
|
---|
1014 | <xsl:element name="systemoutput">
|
---|
1015 | <xsl:attribute name="rev">computeroutput</xsl:attribute>
|
---|
1016 | <xsl:apply-templates />
|
---|
1017 | </xsl:element>
|
---|
1018 | </xsl:template>
|
---|
1019 |
|
---|
1020 | <!-- xref -> xref, but attributes differ. -->
|
---|
1021 | <xsl:template match="xref">
|
---|
1022 | <xsl:element name="xref">
|
---|
1023 | <xsl:attribute name="href"><xsl:value-of select="@linkend"/></xsl:attribute>
|
---|
1024 | <xsl:if test="contains(@linkend, 'http')"><xsl:message terminate="yes">xref/linkend with http</xsl:message></xsl:if>
|
---|
1025 | </xsl:element>
|
---|
1026 | </xsl:template>
|
---|
1027 |
|
---|
1028 | <!-- ulink -> xref -->
|
---|
1029 | <xsl:template match="ulink">
|
---|
1030 | <xsl:element name="xref">
|
---|
1031 | <xsl:attribute name="rev">ulink</xsl:attribute>
|
---|
1032 | <xsl:attribute name="scope">external</xsl:attribute> <!-- Just assumes this is external. -->
|
---|
1033 | <xsl:attribute name="href"><xsl:value-of select="@url"/></xsl:attribute>
|
---|
1034 | <xsl:attribute name="format">html</xsl:attribute>
|
---|
1035 | <xsl:if test="not(starts-with(@url, 'http'))"><xsl:message terminate="yes">ulink url is not http: <xsl:value-of select="@url"/></xsl:message></xsl:if>
|
---|
1036 | </xsl:element>
|
---|
1037 | </xsl:template>
|
---|
1038 |
|
---|
1039 | <!-- emphasis -> i -->
|
---|
1040 | <xsl:template match="emphasis">
|
---|
1041 | <xsl:if test="*">
|
---|
1042 | <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Did not expect emphasis to have children!</xsl:message>
|
---|
1043 | </xsl:if>
|
---|
1044 | <xsl:element name="i">
|
---|
1045 | <xsl:attribute name="rev">emphasis</xsl:attribute>
|
---|
1046 | <xsl:apply-templates />
|
---|
1047 | </xsl:element>
|
---|
1048 | </xsl:template>
|
---|
1049 |
|
---|
1050 | <!-- note -> note -->
|
---|
1051 | <xsl:template match="note">
|
---|
1052 | <xsl:copy>
|
---|
1053 | <xsl:apply-templates />
|
---|
1054 | </xsl:copy>
|
---|
1055 | </xsl:template>
|
---|
1056 |
|
---|
1057 | <!-- citetitle -> cite -->
|
---|
1058 | <xsl:template match="citetitle">
|
---|
1059 | <xsl:element name="cite">
|
---|
1060 | <xsl:attribute name="rev">citetitle</xsl:attribute>
|
---|
1061 | <xsl:apply-templates />
|
---|
1062 | </xsl:element>
|
---|
1063 | </xsl:template>
|
---|
1064 |
|
---|
1065 | <!--
|
---|
1066 | remark extensions:
|
---|
1067 | -->
|
---|
1068 | <!-- Default: remove all remarks. -->
|
---|
1069 | <xsl:template match="remark"/>
|
---|
1070 |
|
---|
1071 |
|
---|
1072 | <!--
|
---|
1073 | Captializes the given text.
|
---|
1074 | -->
|
---|
1075 | <xsl:template name="capitalize">
|
---|
1076 | <xsl:param name="text"/>
|
---|
1077 | <xsl:call-template name="str:to-upper">
|
---|
1078 | <xsl:with-param name="text" select="substring($text,1,1)"/>
|
---|
1079 | </xsl:call-template>
|
---|
1080 | <xsl:value-of select="substring($text,2)"/>
|
---|
1081 | </xsl:template>
|
---|
1082 |
|
---|
1083 |
|
---|
1084 | <!--
|
---|
1085 | Maybe replace hypens (dashes) with non-breaking ones.
|
---|
1086 | -->
|
---|
1087 | <xsl:template name="emit-text-with-replacements">
|
---|
1088 | <xsl:param name="a_sText" select="."/>
|
---|
1089 | <xsl:choose>
|
---|
1090 | <xsl:when test="$g_fReplaceHypens = 'true'">
|
---|
1091 | <xsl:call-template name="str:subst">
|
---|
1092 | <xsl:with-param name="text" select="$a_sText"/>
|
---|
1093 | <xsl:with-param name="replace">-</xsl:with-param>
|
---|
1094 | <xsl:with-param name="with">‑</xsl:with-param> <!-- U+2011 / ‑ -->
|
---|
1095 | </xsl:call-template>
|
---|
1096 | </xsl:when>
|
---|
1097 | <xsl:otherwise>
|
---|
1098 | <xsl:value-of select="$a_sText"/>
|
---|
1099 | </xsl:otherwise>
|
---|
1100 | </xsl:choose>
|
---|
1101 | </xsl:template>
|
---|
1102 |
|
---|
1103 |
|
---|
1104 | <!--
|
---|
1105 | Debug/Diagnostics: Return the path to the specified node (by default the current).
|
---|
1106 | -->
|
---|
1107 | <xsl:template name="get-node-path">
|
---|
1108 | <xsl:param name="Node" select="."/>
|
---|
1109 | <xsl:for-each select="$Node">
|
---|
1110 | <xsl:for-each select="ancestor-or-self::node()">
|
---|
1111 | <xsl:choose>
|
---|
1112 | <xsl:when test="name(.) = ''">
|
---|
1113 | <xsl:value-of select="concat('/text(',')')"/>
|
---|
1114 | </xsl:when>
|
---|
1115 | <xsl:otherwise>
|
---|
1116 | <xsl:value-of select="concat('/', name(.))"/>
|
---|
1117 | <xsl:choose>
|
---|
1118 | <xsl:when test="@id">
|
---|
1119 | <xsl:text>[@id=</xsl:text>
|
---|
1120 | <xsl:value-of select="@id"/>
|
---|
1121 | <xsl:text>]</xsl:text>
|
---|
1122 | </xsl:when>
|
---|
1123 | <xsl:otherwise>
|
---|
1124 | <!-- Use generate-id() to find the current node position among its siblings. -->
|
---|
1125 | <xsl:variable name="id" select="generate-id(.)"/>
|
---|
1126 | <xsl:for-each select="../node()">
|
---|
1127 | <xsl:if test="generate-id(.) = $id">
|
---|
1128 | <xsl:text>[</xsl:text><xsl:value-of select="position()"/><xsl:text>]</xsl:text>
|
---|
1129 | </xsl:if>
|
---|
1130 | </xsl:for-each>
|
---|
1131 | </xsl:otherwise>
|
---|
1132 | </xsl:choose>
|
---|
1133 | </xsl:otherwise>
|
---|
1134 | </xsl:choose>
|
---|
1135 | </xsl:for-each>
|
---|
1136 | </xsl:for-each>
|
---|
1137 | </xsl:template>
|
---|
1138 |
|
---|
1139 | <!--
|
---|
1140 | Debug/Diagnostics: Return error message prefix.
|
---|
1141 | -->
|
---|
1142 | <xsl:template name="error-prefix">
|
---|
1143 | <xsl:param name="Node" select="."/>
|
---|
1144 | <xsl:text>error: </xsl:text>
|
---|
1145 | <xsl:call-template name="get-node-path">
|
---|
1146 | <xsl:with-param name="Node" select="$Node"/>
|
---|
1147 | </xsl:call-template>
|
---|
1148 | <xsl:text>: </xsl:text>
|
---|
1149 | </xsl:template>
|
---|
1150 |
|
---|
1151 | <!--
|
---|
1152 | Debug/Diagnostics: Print list of nodes (by default all children of current node).
|
---|
1153 | -->
|
---|
1154 | <xsl:template name="list-nodes">
|
---|
1155 | <xsl:param name="Nodes" select="node()"/>
|
---|
1156 | <xsl:for-each select="$Nodes">
|
---|
1157 | <xsl:if test="position() != 1">
|
---|
1158 | <xsl:text>, </xsl:text>
|
---|
1159 | </xsl:if>
|
---|
1160 | <xsl:choose>
|
---|
1161 | <xsl:when test="name(.) = ''">
|
---|
1162 | <xsl:text>text:text()</xsl:text>
|
---|
1163 | </xsl:when>
|
---|
1164 | <xsl:otherwise>
|
---|
1165 | <xsl:value-of select="name(.)"/>
|
---|
1166 | <xsl:if test="@id">
|
---|
1167 | <xsl:text>[@id=</xsl:text>
|
---|
1168 | <xsl:value-of select="@id"/>
|
---|
1169 | <xsl:text>]</xsl:text>
|
---|
1170 | </xsl:if>
|
---|
1171 | </xsl:otherwise>
|
---|
1172 | </xsl:choose>
|
---|
1173 | </xsl:for-each>
|
---|
1174 | </xsl:template>
|
---|
1175 |
|
---|
1176 | <xsl:template name="check-children">
|
---|
1177 | <xsl:param name="Node" select="."/>
|
---|
1178 | <xsl:param name="UnsupportedNodes" select="*"/>
|
---|
1179 | <xsl:param name="SupportedNames" select="'none'"/>
|
---|
1180 | <xsl:if test="count($UnsupportedNodes) != 0">
|
---|
1181 | <xsl:message terminate="yes">
|
---|
1182 | <xsl:call-template name="get-node-path">
|
---|
1183 | <xsl:with-param name="Node" select="$Node"/>
|
---|
1184 | </xsl:call-template>
|
---|
1185 | <!-- -->: error: Only <xsl:value-of select="$SupportedNames"/> are supported as children to <!-- -->
|
---|
1186 | <xsl:value-of select="name($Node)"/>
|
---|
1187 | <!-- -->
|
---|
1188 | Unsupported children: <!-- -->
|
---|
1189 | <xsl:call-template name="list-nodes">
|
---|
1190 | <xsl:with-param name="Nodes" select="$UnsupportedNodes"/>
|
---|
1191 | </xsl:call-template>
|
---|
1192 | </xsl:message>
|
---|
1193 | </xsl:if>
|
---|
1194 | </xsl:template>
|
---|
1195 |
|
---|
1196 | </xsl:stylesheet>
|
---|
1197 |
|
---|