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 8488 2009-07-15 19:45:55Z nwalsh $
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:apply-templates mode="stripNS"/>
191 <xsl:template match="db:citetitle[@xlink:href]" mode="stripNS">
192 <ulink url="{@xlink:href}">
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"/>
202 <xsl:template match="db:citetitle[@linkend]" mode="stripNS">
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"/>
212 <xsl:template match="db:alt" mode="stripNS"/>
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"/>
229 <xsl:when test="@entityref">
230 <xsl:attribute name="fileref">
231 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
236 <xsl:apply-templates mode="stripNS"/>
240 <xsl:template name="add-xml-base">
241 <xsl:if test="not(@xml:base)">
242 <xsl:variable name="base">
244 <xsl:when test="function-available('saxon:systemId')">
245 <xsl:value-of select="saxon:systemId()"/>
247 <xsl:when test="function-available('NodeInfo:systemId')">
248 <xsl:value-of select="NodeInfo:systemId()"/>
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>
260 <xsl:message>base is <xsl:value-of select="$base"/></xsl:message>
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. -->
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"/>
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:/'))"/>
278 <xsl:when test="starts-with($base, 'file:///')">
279 <xsl:value-of select="substring-after($base,'file://')"/>
281 <xsl:when test="starts-with($base, 'file://')">
282 <xsl:value-of select="substring-after($base,'file:/')"/>
284 <xsl:when test="starts-with($base, 'file:/')">
285 <xsl:value-of select="substring-after($base,'file:')"/>
288 <xsl:value-of select="$base"/>
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,'/')"/>
310 <xsl:template match="comment()|processing-instruction()|text()" mode="stripNS">
314 <xsl:template match="/" priority="-1">
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"/>
321 <xsl:message>Processing stripped document.</xsl:message>
322 <xsl:apply-templates select="exsl:node-set($nons)"/>
325 <xsl:copy-of select="node()"/>