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