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"
12 <!-- ********************************************************************
13 $Id: stripns.xsl 8728 2010-07-15 14:37:33Z mzjn $
14 ********************************************************************
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.
20 ******************************************************************** -->
22 <!-- put an xml:base attribute on the root element -->
23 <xsl:template match="/*" mode="stripNS">
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"/>
35 <xsl:call-template name="add-xml-base"/>
37 <xsl:apply-templates mode="stripNS"/>
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"/>
50 <xsl:call-template name="add-xml-base"/>
52 <xsl:apply-templates mode="stripNS"/>
58 <xsl:template match="*" mode="stripNS">
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"/>
69 <xsl:apply-templates mode="stripNS"/>
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"/>
81 <xsl:apply-templates mode="stripNS"/>
87 <xsl:template match="db:info" mode="stripNS">
88 <xsl:variable name="info">
90 <xsl:when test="parent::db:article
92 |parent::db:bibliography
100 |parent::db:reference
104 |parent::db:refsection
105 |parent::db:refsynopsisdiv
115 |parent::db:sidebar">
116 <xsl:value-of select="local-name(parent::*)"/>
117 <xsl:text>info</xsl:text>
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>
128 <xsl:otherwise>blockinfo</xsl:otherwise>
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"/>
140 <xsl:apply-templates mode="stripNS"/>
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"/>
163 <xsl:template match="ng:tag|db:tag" mode="stripNS">
165 <xsl:when test="@xlink:href">
166 <ulink url="{@xlink:href}">
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"/>
177 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
178 and not(name(.) = 'version')]"/>
179 <xsl:apply-templates mode="stripNS"/>
185 <xsl:template match="db:link[@xlink:href]" mode="stripNS">
186 <ulink url="{@xlink:href}">
187 <xsl:if test="@role">
188 <xsl:attribute name="role">
189 <xsl:value-of select="@role"/>
192 <xsl:apply-templates mode="stripNS"/>
196 <xsl:template match="db:citetitle[@xlink:href]" mode="stripNS">
197 <ulink url="{@xlink:href}">
199 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
200 and not(name(.) = 'version')
201 and not(local-name(.) = 'href')]"/>
202 <xsl:apply-templates mode="stripNS"/>
207 <xsl:template match="db:citetitle[@linkend]" mode="stripNS">
209 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
210 and not(name(.) = 'version')
211 and not(name(.) = 'linkend')
212 and not(local-name(.) = 'href')]"/>
213 <xsl:apply-templates mode="stripNS"/>
217 <xsl:template match="db:alt" mode="stripNS"/>
219 <xsl:template match="ng:textdata|db:textdata
220 |ng:imagedata|db:imagedata
221 |ng:videodata|db:videodata
222 |ng:audiodata|db:audiodata" mode="stripNS">
223 <xsl:element name="{local-name(.)}">
224 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
225 and not(name(.) = 'version')
226 and not(name(.) = 'entityref')]"/>
227 <xsl:if test="@xml:id">
228 <xsl:attribute name="id">
229 <xsl:value-of select="@xml:id"/>
234 <xsl:when test="@entityref">
235 <xsl:attribute name="fileref">
236 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
241 <xsl:apply-templates mode="stripNS"/>
245 <xsl:template name="add-xml-base">
246 <xsl:if test="not(@xml:base)">
247 <xsl:variable name="base">
249 <xsl:when test="function-available('saxon:systemId')">
250 <xsl:value-of select="saxon:systemId()"/>
252 <xsl:when test="function-available('NodeInfo:systemId')">
253 <xsl:value-of select="NodeInfo:systemId()"/>
257 <xsl:text>WARNING: cannot add @xml:base to node </xsl:text>
258 <xsl:text>set root element. </xsl:text>
259 <xsl:text>Relative paths may not work.</xsl:text>
265 <xsl:message>base is <xsl:value-of select="$base"/></xsl:message>
267 <xsl:if test="$base != ''">
268 <xsl:attribute name="xml:base">
269 <xsl:call-template name="systemIdToBaseURI">
270 <xsl:with-param name="systemId">
271 <!-- file: seems to confuse some processors. -->
273 <!-- however, windows paths must use file:///c:/path -->
274 <xsl:when test="starts-with($base, 'file:///') and
275 substring($base, 10, 1) = ':'">
276 <xsl:value-of select="$base"/>
278 <xsl:when test="starts-with($base, 'file:/')
279 and substring($base, 8, 1) = ':'">
280 <xsl:value-of select="concat('file:///',
281 substring-after($base,'file:/'))"/>
283 <xsl:when test="starts-with($base, 'file:///')">
284 <xsl:value-of select="substring-after($base,'file://')"/>
286 <xsl:when test="starts-with($base, 'file://')">
287 <xsl:value-of select="substring-after($base,'file:/')"/>
289 <xsl:when test="starts-with($base, 'file:/')">
290 <xsl:value-of select="substring-after($base,'file:')"/>
293 <xsl:value-of select="$base"/>
303 <xsl:template name="systemIdToBaseURI">
304 <xsl:param name="systemId" select="''"/>
305 <xsl:if test="contains($systemId,'/')">
306 <xsl:value-of select="substring-before($systemId,'/')"/>
307 <xsl:text>/</xsl:text>
308 <xsl:call-template name="systemIdToBaseURI">
309 <xsl:with-param name="systemId"
310 select="substring-after($systemId,'/')"/>
315 <xsl:template match="comment()|processing-instruction()|text()" mode="stripNS">
319 <xsl:template match="/" priority="-1">
320 <!-- need a local version of this variable because this module imported many places-->
321 <xsl:variable name="local.exsl.node.set.available">
323 <xsl:when exsl:foo="" xmlns:exsl="http://exslt.org/common"
324 test="function-available('exsl:node-set') or
325 contains(system-property('xsl:vendor'),
326 'Apache Software Foundation')">1</xsl:when>
327 <xsl:otherwise>0</xsl:otherwise>
331 <xsl:when test="$local.exsl.node.set.available != 0
332 and (*/self::ng:* or */self::db:*)">
334 <xsl:text>Stripping namespace from DocBook 5 document. </xsl:text>
335 <xsl:text>It is suggested to use namespaced version of the stylesheets </xsl:text>
336 <xsl:text>available in distribution file 'docbook-xsl-ns' </xsl:text>
337 <xsl:text>at //http://sourceforge.net/projects/docbook/files/</xsl:text>
338 <xsl:text> which does not require namespace stripping step.</xsl:text>
340 <xsl:variable name="nons">
341 <xsl:apply-templates mode="stripNS"/>
343 <xsl:message>Processing stripped document.</xsl:message>
344 <xsl:apply-templates select="exsl:node-set($nons)"/>
347 <xsl:copy-of select="node()"/>