1
|
<?xml version='1.0'?>
|
2
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
3
|
xmlns:ng="http://docbook.org/docbook-ng"
|
4
|
xmlns:db="http://docbook.org/ns/docbook"
|
5
|
xmlns:saxon="http://icl.com/saxon"
|
6
|
xmlns:NodeInfo="http://org.apache.xalan.lib.NodeInfo"
|
7
|
xmlns:exsl="http://exslt.org/common"
|
8
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
9
|
exclude-result-prefixes="db ng exsl saxon NodeInfo xlink"
|
10
|
version='1.0'>
|
11
|
|
12
|
<!-- ********************************************************************
|
13
|
$Id: stripns.xsl 8488 2009-07-15 19:45:55Z nwalsh $
|
14
|
********************************************************************
|
15
|
|
16
|
This file is part of the XSL DocBook Stylesheet distribution.
|
17
|
See ../README or http://docbook.sf.net/release/xsl/current/ for
|
18
|
copyright and other information.
|
19
|
|
20
|
******************************************************************** -->
|
21
|
|
22
|
<!-- put an xml:base attribute on the root element -->
|
23
|
<xsl:template match="/*" mode="stripNS">
|
24
|
<xsl:choose>
|
25
|
<xsl:when test="self::ng:* or self::db:*">
|
26
|
<xsl:element name="{local-name(.)}">
|
27
|
<xsl:copy-of select="@*[not(name(.) = 'xml:id')
|
28
|
and not(name(.) = 'version')]"/>
|
29
|
<xsl:if test="@xml:id">
|
30
|
<xsl:attribute name="id">
|
31
|
<xsl:value-of select="@xml:id"/>
|
32
|
</xsl:attribute>
|
33
|
</xsl:if>
|
34
|
|
35
|
<xsl:call-template name="add-xml-base"/>
|
36
|
|
37
|
<xsl:apply-templates mode="stripNS"/>
|
38
|
</xsl:element>
|
39
|
</xsl:when>
|
40
|
<xsl:otherwise>
|
41
|
<xsl:copy>
|
42
|
<xsl:copy-of select="@*[not(name(.) = 'xml:id')
|
43
|
and not(name(.) = 'version')]"/>
|
44
|
<xsl:if test="@xml:id">
|
45
|
<xsl:attribute name="id">
|
46
|
<xsl:value-of select="@xml:id"/>
|
47
|
</xsl:attribute>
|
48
|
</xsl:if>
|
49
|
|
50
|
<xsl:call-template name="add-xml-base"/>
|
51
|
|
52
|
<xsl:apply-templates mode="stripNS"/>
|
53
|
</xsl:copy>
|
54
|
</xsl:otherwise>
|
55
|
</xsl:choose>
|
56
|
</xsl:template>
|
57
|
|
58
|
<xsl:template match="*" mode="stripNS">
|
59
|
<xsl:choose>
|
60
|
<xsl:when test="self::ng:* or self::db:*">
|
61
|
<xsl:element name="{local-name(.)}">
|
62
|
<xsl:copy-of select="@*[not(name(.) = 'xml:id')
|
63
|
and not(name(.) = 'version')]"/>
|
64
|
<xsl:if test="@xml:id">
|
65
|
<xsl:attribute name="id">
|
66
|
<xsl:value-of select="@xml:id"/>
|
67
|
</xsl:attribute>
|
68
|
</xsl:if>
|
69
|
<xsl:apply-templates mode="stripNS"/>
|
70
|
</xsl:element>
|
71
|
</xsl:when>
|
72
|
<xsl:otherwise>
|
73
|
<xsl:copy>
|
74
|
<xsl:copy-of select="@*[not(name(.) = 'xml:id')
|
75
|
and not(name(.) = 'version')]"/>
|
76
|
<xsl:if test="@xml:id">
|
77
|
<xsl:attribute name="id">
|
78
|
<xsl:value-of select="@xml:id"/>
|
79
|
</xsl:attribute>
|
80
|
</xsl:if>
|
81
|
<xsl:apply-templates mode="stripNS"/>
|
82
|
</xsl:copy>
|
83
|
</xsl:otherwise>
|
84
|
</xsl:choose>
|
85
|
</xsl:template>
|
86
|
|
87
|
<xsl:template match="db:info" mode="stripNS">
|
88
|
<xsl:variable name="info">
|
89
|
<xsl:choose>
|
90
|
<xsl:when test="parent::db:article
|
91
|
|parent::db:appendix
|
92
|
|parent::db:bibliography
|
93
|
|parent::db:book
|
94
|
|parent::db:chapter
|
95
|
|parent::db:glossary
|
96
|
|parent::db:index
|
97
|
|parent::db:part
|
98
|
|parent::db:preface
|
99
|
|parent::db:refentry
|
100
|
|parent::db:reference
|
101
|
|parent::db:refsect1
|
102
|
|parent::db:refsect2
|
103
|
|parent::db:refsect3
|
104
|
|parent::db:refsection
|
105
|
|parent::db:refsynopsisdiv
|
106
|
|parent::db:sect1
|
107
|
|parent::db:sect2
|
108
|
|parent::db:sect3
|
109
|
|parent::db:sect4
|
110
|
|parent::db:sect5
|
111
|
|parent::db:section
|
112
|
|parent::db:setindex
|
113
|
|parent::db:set
|
114
|
|parent::db:slides
|
115
|
|parent::db:sidebar">
|
116
|
<xsl:value-of select="local-name(parent::*)"/>
|
117
|
<xsl:text>info</xsl:text>
|
118
|
</xsl:when>
|
119
|
<xsl:when test="parent::db:audioobject
|
120
|
|parent::db:imageobject
|
121
|
|parent::db:inlinemediaobject
|
122
|
|parent::db:mediaobject
|
123
|
|parent::db:mediaobjectco
|
124
|
|parent::db:textobject
|
125
|
|parent::db:videoobject">
|
126
|
<xsl:text>objectinfo</xsl:text>
|
127
|
</xsl:when>
|
128
|
<xsl:otherwise>blockinfo</xsl:otherwise>
|
129
|
</xsl:choose>
|
130
|
</xsl:variable>
|
131
|
|
132
|
<xsl:element name="{$info}">
|
133
|
<xsl:copy-of select="@*[not(name(.) = 'xml:id')
|
134
|
and not(name(.) = 'version')]"/>
|
135
|
<xsl:if test="@xml:id">
|
136
|
<xsl:attribute name="id">
|
137
|
<xsl:value-of select="@xml:id"/>
|
138
|
</xsl:attribute>
|
139
|
</xsl:if>
|
140
|
<xsl:apply-templates mode="stripNS"/>
|
141
|
</xsl:element>
|
142
|
|
143
|
<xsl:if test="(not(../db:title) and not(../ng:title))
|
144
|
and ($info = 'prefaceinfo'
|
145
|
or $info = 'chapterinfo'
|
146
|
or $info = 'sectioninfo'
|
147
|
or $info = 'sect1info'
|
148
|
or $info = 'sect2info'
|
149
|
or $info = 'sect3info'
|
150
|
or $info = 'sect4info'
|
151
|
or $info = 'sect5info'
|
152
|
or $info = 'refsectioninfo'
|
153
|
or $info = 'refsect1info'
|
154
|
or $info = 'refsect2info'
|
155
|
or $info = 'refsect3info'
|
156
|
or $info = 'blockinfo'
|
157
|
or $info = 'appendixinfo')">
|
158
|
<xsl:apply-templates select="db:title|ng:title" mode="stripNS"/>
|
159
|
</xsl:if>
|
160
|
|
161
|
</xsl:template>
|
162
|
|
163
|
<xsl:template match="ng:tag|db:tag" mode="stripNS">
|
164
|
<xsl:choose>
|
165
|
<xsl:when test="@xlink:href">
|
166
|
<ulink url="{@xlink:href}">
|
167
|
<sgmltag>
|
168
|
<xsl:copy-of select="@*[not(name(.) = 'xml:id')
|
169
|
and not(name(.) = 'version')
|
170
|
and not(local-name(.) = 'href')]"/>
|
171
|
<xsl:apply-templates mode="stripNS"/>
|
172
|
</sgmltag>
|
173
|
</ulink>
|
174
|
</xsl:when>
|
175
|
<xsl:otherwise>
|
176
|
<sgmltag>
|
177
|
<xsl:copy-of select="@*[not(name(.) = 'xml:id')
|
178
|
and not(name(.) = 'version')]"/>
|
179
|
<xsl:apply-templates mode="stripNS"/>
|
180
|
</sgmltag>
|
181
|
</xsl:otherwise>
|
182
|
</xsl:choose>
|
183
|
</xsl:template>
|
184
|
|
185
|
<xsl:template match="db:link[@xlink:href]" mode="stripNS">
|
186
|
<ulink url="{@xlink:href}">
|
187
|
<xsl:apply-templates mode="stripNS"/>
|
188
|
</ulink>
|
189
|
</xsl:template>
|
190
|
|
191
|
<xsl:template match="db:citetitle[@xlink:href]" mode="stripNS">
|
192
|
<ulink url="{@xlink:href}">
|
193
|
<citetitle>
|
194
|
<xsl:copy-of select="@*[not(name(.) = 'xml:id')
|
195
|
and not(name(.) = 'version')
|
196
|
and not(local-name(.) = 'href')]"/>
|
197
|
<xsl:apply-templates mode="stripNS"/>
|
198
|
</citetitle>
|
199
|
</ulink>
|
200
|
</xsl:template>
|
201
|
|
202
|
<xsl:template match="db:citetitle[@linkend]" mode="stripNS">
|
203
|
<citetitle>
|
204
|
<xsl:copy-of select="@*[not(name(.) = 'xml:id')
|
205
|
and not(name(.) = 'version')
|
206
|
and not(name(.) = 'linkend')
|
207
|
and not(local-name(.) = 'href')]"/>
|
208
|
<xsl:apply-templates mode="stripNS"/>
|
209
|
</citetitle>
|
210
|
</xsl:template>
|
211
|
|
212
|
<xsl:template match="db:alt" mode="stripNS"/>
|
213
|
|
214
|
<xsl:template match="ng:textdata|db:textdata
|
215
|
|ng:imagedata|db:imagedata
|
216
|
|ng:videodata|db:videodata
|
217
|
|ng:audiodata|db:audiodata" mode="stripNS">
|
218
|
<xsl:element name="{local-name(.)}">
|
219
|
<xsl:copy-of select="@*[not(name(.) = 'xml:id')
|
220
|
and not(name(.) = 'version')
|
221
|
and not(name(.) = 'entityref')]"/>
|
222
|
<xsl:if test="@xml:id">
|
223
|
<xsl:attribute name="id">
|
224
|
<xsl:value-of select="@xml:id"/>
|
225
|
</xsl:attribute>
|
226
|
</xsl:if>
|
227
|
|
228
|
<xsl:choose>
|
229
|
<xsl:when test="@entityref">
|
230
|
<xsl:attribute name="fileref">
|
231
|
<xsl:value-of select="unparsed-entity-uri(@entityref)"/>
|
232
|
</xsl:attribute>
|
233
|
</xsl:when>
|
234
|
</xsl:choose>
|
235
|
|
236
|
<xsl:apply-templates mode="stripNS"/>
|
237
|
</xsl:element>
|
238
|
</xsl:template>
|
239
|
|
240
|
<xsl:template name="add-xml-base">
|
241
|
<xsl:if test="not(@xml:base)">
|
242
|
<xsl:variable name="base">
|
243
|
<xsl:choose>
|
244
|
<xsl:when test="function-available('saxon:systemId')">
|
245
|
<xsl:value-of select="saxon:systemId()"/>
|
246
|
</xsl:when>
|
247
|
<xsl:when test="function-available('NodeInfo:systemId')">
|
248
|
<xsl:value-of select="NodeInfo:systemId()"/>
|
249
|
</xsl:when>
|
250
|
<xsl:otherwise>
|
251
|
<xsl:message>
|
252
|
<xsl:text>WARNING: cannot add @xml:base to node </xsl:text>
|
253
|
<xsl:text>set root element. </xsl:text>
|
254
|
<xsl:text>Relative paths may not work.</xsl:text>
|
255
|
</xsl:message>
|
256
|
</xsl:otherwise>
|
257
|
</xsl:choose>
|
258
|
</xsl:variable>
|
259
|
<!-- debug
|
260
|
<xsl:message>base is <xsl:value-of select="$base"/></xsl:message>
|
261
|
-->
|
262
|
<xsl:if test="$base != ''">
|
263
|
<xsl:attribute name="xml:base">
|
264
|
<xsl:call-template name="systemIdToBaseURI">
|
265
|
<xsl:with-param name="systemId">
|
266
|
<!-- file: seems to confuse some processors. -->
|
267
|
<xsl:choose>
|
268
|
<!-- however, windows paths must use file:///c:/path -->
|
269
|
<xsl:when test="starts-with($base, 'file:///') and
|
270
|
substring($base, 10, 1) = ':'">
|
271
|
<xsl:value-of select="$base"/>
|
272
|
</xsl:when>
|
273
|
<xsl:when test="starts-with($base, 'file:/')
|
274
|
and substring($base, 8, 1) = ':'">
|
275
|
<xsl:value-of select="concat('file:///',
|
276
|
substring-after($base,'file:/'))"/>
|
277
|
</xsl:when>
|
278
|
<xsl:when test="starts-with($base, 'file:///')">
|
279
|
<xsl:value-of select="substring-after($base,'file://')"/>
|
280
|
</xsl:when>
|
281
|
<xsl:when test="starts-with($base, 'file://')">
|
282
|
<xsl:value-of select="substring-after($base,'file:/')"/>
|
283
|
</xsl:when>
|
284
|
<xsl:when test="starts-with($base, 'file:/')">
|
285
|
<xsl:value-of select="substring-after($base,'file:')"/>
|
286
|
</xsl:when>
|
287
|
<xsl:otherwise>
|
288
|
<xsl:value-of select="$base"/>
|
289
|
</xsl:otherwise>
|
290
|
</xsl:choose>
|
291
|
</xsl:with-param>
|
292
|
</xsl:call-template>
|
293
|
</xsl:attribute>
|
294
|
</xsl:if>
|
295
|
</xsl:if>
|
296
|
</xsl:template>
|
297
|
|
298
|
<xsl:template name="systemIdToBaseURI">
|
299
|
<xsl:param name="systemId" select="''"/>
|
300
|
<xsl:if test="contains($systemId,'/')">
|
301
|
<xsl:value-of select="substring-before($systemId,'/')"/>
|
302
|
<xsl:text>/</xsl:text>
|
303
|
<xsl:call-template name="systemIdToBaseURI">
|
304
|
<xsl:with-param name="systemId"
|
305
|
select="substring-after($systemId,'/')"/>
|
306
|
</xsl:call-template>
|
307
|
</xsl:if>
|
308
|
</xsl:template>
|
309
|
|
310
|
<xsl:template match="comment()|processing-instruction()|text()" mode="stripNS">
|
311
|
<xsl:copy/>
|
312
|
</xsl:template>
|
313
|
|
314
|
<xsl:template match="/" priority="-1">
|
315
|
<xsl:choose>
|
316
|
<xsl:when test="(*/self::ng:* or */self::db:*)">
|
317
|
<xsl:message>Stripping namespace from DocBook 5 document.</xsl:message>
|
318
|
<xsl:variable name="nons">
|
319
|
<xsl:apply-templates mode="stripNS"/>
|
320
|
</xsl:variable>
|
321
|
<xsl:message>Processing stripped document.</xsl:message>
|
322
|
<xsl:apply-templates select="exsl:node-set($nons)"/>
|
323
|
</xsl:when>
|
324
|
<xsl:otherwise>
|
325
|
<xsl:copy-of select="node()"/>
|
326
|
</xsl:otherwise>
|
327
|
</xsl:choose>
|
328
|
</xsl:template>
|
329
|
|
330
|
</xsl:stylesheet>
|