1 | <?xml version="1.0"?>
|
---|
2 | <!--
|
---|
3 | dita-refentry-flat-to-single-topic.xsl:
|
---|
4 | XSLT stylesheet for help converting a flat DITA manual page with nested
|
---|
5 | topic elements into individual topics and a map file for including them
|
---|
6 | in the right order.
|
---|
7 | -->
|
---|
8 | <!--
|
---|
9 | Copyright (C) 2023 Oracle and/or its affiliates.
|
---|
10 |
|
---|
11 | This file is part of VirtualBox base platform packages, as
|
---|
12 | available from https://www.virtualbox.org.
|
---|
13 |
|
---|
14 | This program is free software; you can redistribute it and/or
|
---|
15 | modify it under the terms of the GNU General Public License
|
---|
16 | as published by the Free Software Foundation, in version 3 of the
|
---|
17 | License.
|
---|
18 |
|
---|
19 | This program is distributed in the hope that it will be useful, but
|
---|
20 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
22 | General Public License for more details.
|
---|
23 |
|
---|
24 | You should have received a copy of the GNU General Public License
|
---|
25 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
26 |
|
---|
27 | SPDX-License-Identifier: GPL-3.0-only
|
---|
28 | -->
|
---|
29 |
|
---|
30 | <xsl:stylesheet
|
---|
31 | version="1.0"
|
---|
32 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
---|
33 | >
|
---|
34 |
|
---|
35 | <xsl:output method="xml" version="1.0" encoding="utf-8" indent="no"/>
|
---|
36 | <xsl:preserve-space elements="*"/>
|
---|
37 | <!-- xsl:strip-space elements="*"/ - never -->
|
---|
38 |
|
---|
39 | <!-- Script parameters: -->
|
---|
40 | <xsl:param name="g_sMode" select="not-specified"/>
|
---|
41 | <xsl:param name="g_idTopic" select="not-specified"/>
|
---|
42 |
|
---|
43 | <!--
|
---|
44 | Process root element according to g_sMode.
|
---|
45 | -->
|
---|
46 | <xsl:template match="/">
|
---|
47 | <xsl:choose>
|
---|
48 | <!-- map file -->
|
---|
49 | <xsl:when test="$g_sMode = 'map'">
|
---|
50 | <xsl:text disable-output-escaping='yes'><!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
|
---|
51 | </xsl:text>
|
---|
52 | <xsl:element name="map" >
|
---|
53 | <xsl:element name="title">
|
---|
54 | <xsl:value-of select="/topic/title"/>
|
---|
55 | </xsl:element>
|
---|
56 | <xsl:apply-templates mode="map"/>
|
---|
57 | </xsl:element>
|
---|
58 | </xsl:when>
|
---|
59 |
|
---|
60 | <!-- topic extraction -->
|
---|
61 | <xsl:when test="$g_sMode = 'topic'">
|
---|
62 | <xsl:text disable-output-escaping='yes'><!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
|
---|
63 | </xsl:text>
|
---|
64 | <xsl:apply-templates mode="topic" select="//topic[@id = $g_idTopic]"/>
|
---|
65 | </xsl:when>
|
---|
66 |
|
---|
67 |
|
---|
68 | <!-- Bad mode parameter: -->
|
---|
69 | <xsl:otherwise>
|
---|
70 | <xsl:message terminate="yes">Invalid g_sMode value!"</xsl:message>
|
---|
71 | </xsl:otherwise>
|
---|
72 | </xsl:choose>
|
---|
73 | </xsl:template>
|
---|
74 |
|
---|
75 | <!--
|
---|
76 | map: Default operation is to supress all output, except for topic elements
|
---|
77 | which are transformed to topicref.
|
---|
78 | -->
|
---|
79 | <xsl:template match="node()|@*" mode="map">
|
---|
80 | <xsl:apply-templates mode="map"/>
|
---|
81 | </xsl:template>
|
---|
82 |
|
---|
83 | <xsl:template match="topic" mode="map">
|
---|
84 | <xsl:element name="topicref">
|
---|
85 | <xsl:attribute name="href">
|
---|
86 | <xsl:value-of select="concat(@id,'.dita')"/>
|
---|
87 | </xsl:attribute>
|
---|
88 | <xsl:if test="count(./ancestor::*) != 0">
|
---|
89 | <xsl:attribute name="toc">no</xsl:attribute>
|
---|
90 | </xsl:if>
|
---|
91 | <xsl:apply-templates mode="map"/>
|
---|
92 | </xsl:element>
|
---|
93 | </xsl:template>
|
---|
94 |
|
---|
95 | <!--
|
---|
96 | topic: Default action is to copy everything except non-matching topic elements
|
---|
97 | We suppress class, domains and xmlns attributes in a hackish way here,
|
---|
98 | because the xmlns:ditaarch stuff confuses 1.8.5 (making it hang)...
|
---|
99 | -->
|
---|
100 | <xsl:template match="node()" mode="topic">
|
---|
101 | <xsl:copy>
|
---|
102 | <xsl:apply-templates mode="topic" select="@*|node()"/>
|
---|
103 | </xsl:copy>
|
---|
104 | </xsl:template>
|
---|
105 |
|
---|
106 | <xsl:template match="@*" mode="topic">
|
---|
107 | <!-- xsl:message>dbg: @*: name()='<xsl:value-of select="name()"/></xsl:message -->
|
---|
108 | <xsl:if test="name() != 'class' and name() != 'ditaarch:DITAArchVersion' and name() != 'domains' ">
|
---|
109 | <xsl:copy/>
|
---|
110 | </xsl:if>
|
---|
111 | </xsl:template>
|
---|
112 |
|
---|
113 | <xsl:template match="topic" mode="topic">
|
---|
114 | <xsl:if test="@id = $g_idTopic">
|
---|
115 | <xsl:element name="topic">
|
---|
116 | <xsl:apply-templates mode="topic" select="node()|@*"/>
|
---|
117 | </xsl:element>
|
---|
118 | </xsl:if>
|
---|
119 | </xsl:template>
|
---|
120 |
|
---|
121 |
|
---|
122 | </xsl:stylesheet>
|
---|
123 |
|
---|