VirtualBox

source: vbox/trunk/doc/manual/docbook-refentry-to-manual-dita.xsl

Last change on this file was 99629, checked in by vboxsync, 12 months ago

manual: Corrected dita-refentry-flat-to-single-topic.xsl so that it preserves spaces and does not indent the xml, just like docbook-refentry-to-manual-dita.xsl. bugref:10302

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.9 KB
Line 
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'>&lt;!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd"&gt;</xsl:text>
94 </xsl:when>
95 <xsl:otherwise>
96 <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd"&gt;</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() &lt; 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() &lt; 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(., '&#10;') 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) &lt; 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:attribute name="rev"><xsl:value-of select="concat(local-name(.), '-leadseps')"/></xsl:attribute>
884 <xsl:value-of select="$sLeadSeps"/>
885 </xsl:element>
886 </xsl:if>
887
888 <!-- render the arg (TODO: may need to do more work here) -->
889 <xsl:apply-templates />
890
891 <!-- repeat wrapping -->
892 <xsl:choose>
893 <xsl:when test="@rep = 'norepeat' or not(@rep) or @rep = ''"/>
894 <xsl:when test="@rep = 'repeat'"> <xsl:element name="sep"><xsl:value-of select="$arg.rep.repeat.str"/></xsl:element></xsl:when>
895 <xsl:otherwise><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Invalid rep choice: "<xsl:value-of select="@rep"/>"</xsl:message></xsl:otherwise>
896 </xsl:choose>
897
898 <!-- close wrapping -->
899 <xsl:if test="$fWrappers">
900 <xsl:choose>
901 <xsl:when test="not(@choice) or @choice = ''"> <xsl:element name="sep"><xsl:value-of select="$arg.choice.def.close.str"/></xsl:element></xsl:when>
902 <xsl:when test="@choice = 'opt'"> <xsl:element name="sep"><xsl:value-of select="$arg.choice.opt.close.str"/></xsl:element></xsl:when>
903 <xsl:when test="@choice = 'req'"> <xsl:element name="sep"><xsl:value-of select="$arg.choice.req.close.str"/></xsl:element></xsl:when>
904 </xsl:choose>
905 <!-- Add a space padding if we're the last element in a repeating arg or group -->
906 <!-- 2023-03-22 bird: This is incorrectly written. Fix as needed...
907 <xsl:if test="(parent::arg or parent::group) and not(following-sibiling) and not(ancestor::*[@role='compact'])">
908 <xsl:text> </xsl:text>
909 </xsl:if>
910 -->
911 </xsl:if>
912
913</xsl:template>
914
915<!-- Helper for arg_or_group_as_text. -->
916<xsl:template name="arg_or_group_as_text_calc_lead_seps">
917 <xsl:param name="a_fWrappers"/>
918 <xsl:variable name="idSelf" select="generate-id(.)"/>
919
920 <!-- separator char if we're not the first child -->
921 <xsl:if test="../*[generate-id(.) = $idSelf and position() > 1]">
922 <!--<xsl:value-of select="concat('*',name(),'=', position(),'#')"/>-->
923 <xsl:choose>
924 <xsl:when test="parent::group and ancestor::*[@role='compact']"><xsl:value-of select="$arg.or.sep.compact"/></xsl:when>
925 <xsl:when test="parent::group"><xsl:value-of select="$arg.or.sep"/></xsl:when>
926 <xsl:when test="ancestor::*[@role='compact']"></xsl:when>
927 <xsl:when test="ancestor::*/@sepchar"><xsl:value-of select="ancestor::*/@sepchar"/></xsl:when>
928 <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
929 </xsl:choose>
930 </xsl:if>
931
932 <!-- open wrapping -->
933 <xsl:if test="$a_fWrappers">
934 <xsl:choose>
935 <xsl:when test="not(@choice) or @choice = ''"> <xsl:value-of select="$arg.choice.def.open.str"/></xsl:when>
936 <xsl:when test="@choice = 'opt'"> <xsl:value-of select="$arg.choice.opt.open.str"/></xsl:when>
937 <xsl:when test="@choice = 'req'"> <xsl:value-of select="$arg.choice.req.open.str"/></xsl:when>
938 <xsl:when test="@choice = 'plain'"/>
939 <xsl:otherwise><xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Invalid arg choice: "<xsl:value-of select="@choice"/>"</xsl:message></xsl:otherwise>
940 </xsl:choose>
941 </xsl:if>
942
943</xsl:template>
944
945
946<!-- option -->
947<xsl:template match="option/text()" >
948 <xsl:element name="kwd">
949 <xsl:attribute name="rev">option</xsl:attribute>
950 <xsl:value-of select="."/>
951 </xsl:element>
952</xsl:template>
953
954<xsl:template match="option" >
955 <xsl:element name="synph">
956 <xsl:attribute name="rev">option</xsl:attribute>
957 <xsl:apply-templates />
958 </xsl:element>
959</xsl:template>
960
961<!-- literal w/o sub-elements -> codeph -->
962<xsl:template match="literal[not(*)]" >
963 <xsl:element name="codeph">
964 <xsl:attribute name="rev">literal</xsl:attribute>
965 <xsl:apply-templates />
966 </xsl:element>
967</xsl:template>
968
969<!-- literal with replaceable sub-elements -> synph -->
970<xsl:template match="literal[replaceable]" >
971 <xsl:element name="synph">
972 <xsl:attribute name="rev">literal/replaceable</xsl:attribute>
973 <xsl:for-each select="node()">
974 <xsl:choose>
975 <xsl:when test="self::text()">
976 <xsl:element name="kwd">
977 <xsl:value-of select="."/>
978 </xsl:element>
979 </xsl:when>
980 <xsl:when test="self::replaceable">
981 <xsl:if test="./*">
982 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Unexpected literal/replaceable child</xsl:message>
983 </xsl:if>
984 <xsl:element name="var">
985 <xsl:value-of select="."/>
986 </xsl:element>
987 </xsl:when>
988 <xsl:otherwise>
989 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Unexpected literal child:
990 <xsl:value-of select="name(.)" />
991 </xsl:message>
992 </xsl:otherwise>
993 </xsl:choose>
994 </xsl:for-each>
995 </xsl:element>
996</xsl:template>
997
998<!-- filename -> filepath -->
999<xsl:template match="filename" >
1000 <xsl:element name="filepath">
1001 <xsl:attribute name="rev">filename</xsl:attribute>
1002 <xsl:apply-templates />
1003 </xsl:element>
1004</xsl:template>
1005
1006<!-- screen - pass thru -->
1007<xsl:template match="screen" >
1008 <xsl:copy>
1009 <xsl:apply-templates />
1010 </xsl:copy>
1011</xsl:template>
1012
1013<!-- computeroutput -> systemoutput-->
1014<xsl:template match="computeroutput">
1015 <xsl:element name="systemoutput">
1016 <xsl:attribute name="rev">computeroutput</xsl:attribute>
1017 <xsl:apply-templates />
1018 </xsl:element>
1019</xsl:template>
1020
1021<!-- xref -> xref, but attributes differ. -->
1022<xsl:template match="xref">
1023 <xsl:element name="xref">
1024 <xsl:attribute name="href"><xsl:value-of select="@linkend"/></xsl:attribute>
1025 <xsl:if test="contains(@linkend, 'http')"><xsl:message terminate="yes">xref/linkend with http</xsl:message></xsl:if>
1026 </xsl:element>
1027</xsl:template>
1028
1029<!-- ulink -> xref -->
1030<xsl:template match="ulink">
1031 <xsl:element name="xref">
1032 <xsl:attribute name="rev">ulink</xsl:attribute>
1033 <xsl:attribute name="scope">external</xsl:attribute> <!-- Just assumes this is external. -->
1034 <xsl:attribute name="href"><xsl:value-of select="@url"/></xsl:attribute>
1035 <xsl:attribute name="format">html</xsl:attribute>
1036 <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>
1037 </xsl:element>
1038</xsl:template>
1039
1040<!-- emphasis -> i -->
1041<xsl:template match="emphasis">
1042 <xsl:if test="*">
1043 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Did not expect emphasis to have children!</xsl:message>
1044 </xsl:if>
1045 <xsl:element name="i">
1046 <xsl:attribute name="rev">emphasis</xsl:attribute>
1047 <xsl:apply-templates />
1048 </xsl:element>
1049</xsl:template>
1050
1051<!-- note -> note -->
1052<xsl:template match="note">
1053 <xsl:copy>
1054 <xsl:apply-templates />
1055 </xsl:copy>
1056</xsl:template>
1057
1058<!-- citetitle -> cite -->
1059<xsl:template match="citetitle">
1060 <xsl:element name="cite">
1061 <xsl:attribute name="rev">citetitle</xsl:attribute>
1062 <xsl:apply-templates />
1063 </xsl:element>
1064</xsl:template>
1065
1066<!--
1067 remark extensions:
1068 -->
1069<!-- Default: remove all remarks. -->
1070<xsl:template match="remark"/>
1071
1072
1073<!--
1074 Captializes the given text.
1075 -->
1076<xsl:template name="capitalize">
1077 <xsl:param name="text"/>
1078 <xsl:call-template name="str:to-upper">
1079 <xsl:with-param name="text" select="substring($text,1,1)"/>
1080 </xsl:call-template>
1081 <xsl:value-of select="substring($text,2)"/>
1082</xsl:template>
1083
1084
1085<!--
1086 Maybe replace hypens (dashes) with non-breaking ones.
1087 -->
1088<xsl:template name="emit-text-with-replacements">
1089 <xsl:param name="a_sText" select="."/>
1090 <xsl:choose>
1091 <xsl:when test="$g_fReplaceHypens = 'true'">
1092 <xsl:call-template name="str:subst">
1093 <xsl:with-param name="text" select="$a_sText"/>
1094 <xsl:with-param name="replace">-</xsl:with-param>
1095 <xsl:with-param name="with"></xsl:with-param> <!-- U+2011 / &#8209; -->
1096 </xsl:call-template>
1097 </xsl:when>
1098 <xsl:otherwise>
1099 <xsl:value-of select="$a_sText"/>
1100 </xsl:otherwise>
1101 </xsl:choose>
1102</xsl:template>
1103
1104
1105<!--
1106 Debug/Diagnostics: Return the path to the specified node (by default the current).
1107 -->
1108<xsl:template name="get-node-path">
1109 <xsl:param name="Node" select="."/>
1110 <xsl:for-each select="$Node">
1111 <xsl:for-each select="ancestor-or-self::node()">
1112 <xsl:choose>
1113 <xsl:when test="name(.) = ''">
1114 <xsl:value-of select="concat('/text(',')')"/>
1115 </xsl:when>
1116 <xsl:otherwise>
1117 <xsl:value-of select="concat('/', name(.))"/>
1118 <xsl:choose>
1119 <xsl:when test="@id">
1120 <xsl:text>[@id=</xsl:text>
1121 <xsl:value-of select="@id"/>
1122 <xsl:text>]</xsl:text>
1123 </xsl:when>
1124 <xsl:otherwise>
1125 <!-- Use generate-id() to find the current node position among its siblings. -->
1126 <xsl:variable name="id" select="generate-id(.)"/>
1127 <xsl:for-each select="../node()">
1128 <xsl:if test="generate-id(.) = $id">
1129 <xsl:text>[</xsl:text><xsl:value-of select="position()"/><xsl:text>]</xsl:text>
1130 </xsl:if>
1131 </xsl:for-each>
1132 </xsl:otherwise>
1133 </xsl:choose>
1134 </xsl:otherwise>
1135 </xsl:choose>
1136 </xsl:for-each>
1137 </xsl:for-each>
1138</xsl:template>
1139
1140<!--
1141 Debug/Diagnostics: Return error message prefix.
1142 -->
1143<xsl:template name="error-prefix">
1144 <xsl:param name="Node" select="."/>
1145 <xsl:text>error: </xsl:text>
1146 <xsl:call-template name="get-node-path">
1147 <xsl:with-param name="Node" select="$Node"/>
1148 </xsl:call-template>
1149 <xsl:text>: </xsl:text>
1150</xsl:template>
1151
1152<!--
1153 Debug/Diagnostics: Print list of nodes (by default all children of current node).
1154 -->
1155<xsl:template name="list-nodes">
1156 <xsl:param name="Nodes" select="node()"/>
1157 <xsl:for-each select="$Nodes">
1158 <xsl:if test="position() != 1">
1159 <xsl:text>, </xsl:text>
1160 </xsl:if>
1161 <xsl:choose>
1162 <xsl:when test="name(.) = ''">
1163 <xsl:text>text:text()</xsl:text>
1164 </xsl:when>
1165 <xsl:otherwise>
1166 <xsl:value-of select="name(.)"/>
1167 <xsl:if test="@id">
1168 <xsl:text>[@id=</xsl:text>
1169 <xsl:value-of select="@id"/>
1170 <xsl:text>]</xsl:text>
1171 </xsl:if>
1172 </xsl:otherwise>
1173 </xsl:choose>
1174 </xsl:for-each>
1175</xsl:template>
1176
1177<xsl:template name="check-children">
1178 <xsl:param name="Node" select="."/>
1179 <xsl:param name="UnsupportedNodes" select="*"/>
1180 <xsl:param name="SupportedNames" select="'none'"/>
1181 <xsl:if test="count($UnsupportedNodes) != 0">
1182 <xsl:message terminate="yes">
1183 <xsl:call-template name="get-node-path">
1184 <xsl:with-param name="Node" select="$Node"/>
1185 </xsl:call-template>
1186 <!-- -->: error: Only <xsl:value-of select="$SupportedNames"/> are supported as children to <!-- -->
1187 <xsl:value-of select="name($Node)"/>
1188 <!-- -->
1189Unsupported children: <!-- -->
1190 <xsl:call-template name="list-nodes">
1191 <xsl:with-param name="Nodes" select="$UnsupportedNodes"/>
1192 </xsl:call-template>
1193 </xsl:message>
1194 </xsl:if>
1195</xsl:template>
1196
1197</xsl:stylesheet>
1198
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use