-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmap-to-MAIN.xsl
180 lines (162 loc) · 6.42 KB
/
map-to-MAIN.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE xsl:stylesheet
[
<!ENTITY dbns "http://docbook.org/ns/docbook">
]>
<xsl:stylesheet version="1.0"
xmlns="&dbns;"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:param name="prefix" select="''"/>
<xsl:param name="entityfile" select="'entities.xml'"/>
<xsl:param name="replace" select="''"/>
<xsl:param name="remove" select="''"/>
<xsl:template match="/">
<xsl:processing-instruction name="xml-stylesheet">href="urn:x-suse:xslt:profiling:docbook51-profile.xsl"
type="text/xml"
title="Profiling step"</xsl:processing-instruction>
<xsl:text disable-output-escaping="yes"> <!DOCTYPE </xsl:text>
<!-- <xsl:value-of select="local-name(/*[1])"/>-->
<xsl:text>book</xsl:text>
<xsl:text disable-output-escaping="yes"> [ <!ENTITY % entities SYSTEM "</xsl:text>
<xsl:value-of select="$entityfile"/>
<xsl:text disable-output-escaping="yes">"> %entities; ]> </xsl:text>
<xsl:apply-templates select="@*|node()"/>
</xsl:template>
<xsl:template match="@*|node()" priority="-1">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Kill whitespace -->
<xsl:template match="text()[not(normalize-space(.))]">
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="*" priority="0">
<xsl:message>WARNING: Unhandled element <xsl:value-of select="local-name(.)"/>, ignored.</xsl:message>
</xsl:template>
<!-- Keep the element as is. -->
<xsl:template match="title">
<title>
<xsl:apply-templates/>
</title>
</xsl:template>
<!-- Step over the element. -->
<xsl:template match="prodinfo|vrmlist|frontmatter|backmatter">
<xsl:apply-templates/>
</xsl:template>
<!-- Ignore the element. -->
<!-- FIXME: ignoring prodname makes me feel a bit uneasy... -->
<xsl:template match="bookmeta|bookrights|bookid|series|component|brand|prodname|vrm"/>
<!-- Any other types of maps necessary? -->
<xsl:template match="bookmap|map">
<book>
<xsl:apply-templates select="@*|node()"/>
</book>
</xsl:template>
<xsl:template match="@*[local-name(.)='lang']">
<xsl:attribute name="xml:lang"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>
<xsl:template match="bookmeta">
<info>
<xsl:apply-templates/>
</info>
</xsl:template>
<!-- The Fujitsu docs use both prodname ("ServerView") and Prognum ("CMM
V1.3"). Using the one that said CMM seemed more fitting here. And we'll
have to change that anyway before the conversion. -->
<xsl:template match="prognum">
<productname>
<xsl:apply-templates/>
</productname>
</xsl:template>
<!-- I think I have misunderstood the meaning of the vrm element... -->
<!-- <xsl:template match="vrm">
<productnumber>
<xsl:value-of select="@version"/>
</productnumber>
</xsl:template> -->
<!-- XIncludes directly in MAIN. -->
<xsl:template match="*[@href]">
<xsl:variable name="file">
<xsl:call-template name="mangle-filename">
<xsl:with-param name="input" select="@href"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="removal">
<xsl:if test="contains($remove, concat(' ', normalize-space(@href), ' '))">1</xsl:if>
</xsl:variable>
<xsl:variable name="replacement">
<xsl:if test="contains($replace, concat(' ', normalize-space(@href), '='))">
<xsl:value-of select="substring-before(substring-after($replace, concat(' ', normalize-space(@href), '=')),' ')"/>
</xsl:if>
</xsl:variable>
<xsl:choose>
<xsl:when test="$removal = 1">
<xsl:message>file-removal:<xsl:value-of select="@href"/></xsl:message>
</xsl:when>
<xsl:when test="not($replacement = '')">
<xsl:message>source-file-replaced:<xsl:value-of select="$replacement"/></xsl:message>
<xsl:choose>
<xsl:when test="ancestor::*[@href]">
<xsl:variable name="parentfile">
<xsl:call-template name="mangle-filename">
<xsl:with-param name="input" select="ancestor::*[1]/@href"/>
</xsl:call-template>
</xsl:variable>
<xsl:message>append-to:<xsl:value-of select="$parentfile"/>,generate-include:<xsl:value-of select="$replacement"/></xsl:message>
</xsl:when>
<xsl:otherwise>
<xi:include href="{$replacement}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:message>source-file:<xsl:value-of select="@href"/></xsl:message>
<xsl:choose>
<xsl:when test="ancestor::*[@href]">
<xsl:variable name="parentfile">
<xsl:call-template name="mangle-filename">
<xsl:with-param name="input" select="ancestor::*[1]/@href"/>
</xsl:call-template>
</xsl:variable>
<xsl:message>append-to:<xsl:value-of select="$parentfile"/>,generate-include:<xsl:value-of select="$file"/></xsl:message>
</xsl:when>
<xsl:otherwise>
<xi:include href="{$file}"/>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="changeroot">
<xsl:with-param name="file" select="$file"/>
</xsl:call-template>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="mangle-filename">
<xsl:param name="input" select="'NOINPUT'"/>
<xsl:value-of select="concat($prefix, '-', translate($input,'/,_ ','---'))"/>
</xsl:template>
<xsl:template name="changeroot">
<xsl:param name="file" select="'NOINPUT'"/>
<xsl:param name="node" select="."/>
<xsl:variable name="root">
<xsl:choose>
<xsl:when
test="local-name($node) = 'preface' or
local-name($node) = 'appendix' or
local-name($node)='chapter'">
<xsl:value-of select="local-name($node)"/>
</xsl:when>
<xsl:when test="local-name($node) = 'topicref'">
<xsl:text>section</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:message>WARNING: Unhandled element <xsl:value-of select="local-name(.)"/> (with @href), replaced with section.</xsl:message>
<xsl:text>section</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:message>file:<xsl:value-of select="$file"/>,root:<xsl:value-of select="$root"/></xsl:message>
</xsl:template>
</xsl:stylesheet>