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 <!-- ********************************************************************
14 This file is part of the XSL DocBook Stylesheet distribution.
15 See ../README or http://cdn.docbook.org/release/xsl/current/ for
16 copyright and other information.
18 ******************************************************************** -->
20 <!-- put an xml:base attribute on the root element -->
21 <xsl:template match="/*" mode="stripNS">
23 <xsl:when test="self::ng:* or self::db:*">
24 <xsl:element name="{local-name(.)}">
25 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
26 and not(name(.) = 'version')]"/>
27 <xsl:if test="@xml:id">
28 <xsl:attribute name="id">
29 <xsl:value-of select="@xml:id"/>
33 <xsl:call-template name="add-xml-base"/>
35 <xsl:apply-templates mode="stripNS"/>
40 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
41 and not(name(.) = 'version')]"/>
42 <xsl:if test="@xml:id">
43 <xsl:attribute name="id">
44 <xsl:value-of select="@xml:id"/>
48 <xsl:call-template name="add-xml-base"/>
50 <xsl:apply-templates mode="stripNS"/>
56 <xsl:template match="*" mode="stripNS">
58 <xsl:when test="self::ng:* or self::db:*">
59 <xsl:element name="{local-name(.)}">
60 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
61 and not(name(.) = 'version')]"/>
62 <xsl:if test="@xml:id">
63 <xsl:attribute name="id">
64 <xsl:value-of select="@xml:id"/>
67 <xsl:apply-templates mode="stripNS"/>
72 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
73 and not(name(.) = 'version')]"/>
74 <xsl:if test="@xml:id">
75 <xsl:attribute name="id">
76 <xsl:value-of select="@xml:id"/>
79 <xsl:apply-templates mode="stripNS"/>
85 <xsl:template match="db:info" mode="stripNS">
86 <xsl:variable name="info">
88 <xsl:when test="parent::db:article
90 |parent::db:bibliography
102 |parent::db:refsection
103 |parent::db:refsynopsisdiv
113 |parent::db:sidebar">
114 <xsl:value-of select="local-name(parent::*)"/>
115 <xsl:text>info</xsl:text>
117 <xsl:when test="parent::db:audioobject
118 |parent::db:imageobject
119 |parent::db:inlinemediaobject
120 |parent::db:mediaobject
121 |parent::db:mediaobjectco
122 |parent::db:textobject
123 |parent::db:videoobject">
124 <xsl:text>objectinfo</xsl:text>
126 <xsl:otherwise>blockinfo</xsl:otherwise>
130 <xsl:element name="{$info}">
131 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
132 and not(name(.) = 'version')]"/>
133 <xsl:if test="@xml:id">
134 <xsl:attribute name="id">
135 <xsl:value-of select="@xml:id"/>
138 <xsl:apply-templates mode="stripNS"/>
141 <xsl:if test="(not(../db:title) and not(../ng:title))
142 and ($info = 'prefaceinfo'
143 or $info = 'chapterinfo'
144 or $info = 'sectioninfo'
145 or $info = 'sect1info'
146 or $info = 'sect2info'
147 or $info = 'sect3info'
148 or $info = 'sect4info'
149 or $info = 'sect5info'
150 or $info = 'refsectioninfo'
151 or $info = 'refsect1info'
152 or $info = 'refsect2info'
153 or $info = 'refsect3info'
154 or $info = 'blockinfo'
155 or $info = 'appendixinfo')">
156 <xsl:apply-templates select="db:title|ng:title" mode="stripNS"/>
161 <xsl:template match="ng:tag|db:tag" mode="stripNS">
163 <xsl:when test="@xlink:href">
164 <ulink url="{@xlink:href}">
166 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
167 and not(name(.) = 'version')
168 and not(local-name(.) = 'href')]"/>
169 <xsl:if test="@xml:id">
170 <xsl:attribute name="id">
171 <xsl:value-of select="@xml:id"/>
174 <xsl:apply-templates mode="stripNS"/>
180 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
181 and not(name(.) = 'version')]"/>
182 <xsl:if test="@xml:id">
183 <xsl:attribute name="id">
184 <xsl:value-of select="@xml:id"/>
187 <xsl:apply-templates mode="stripNS"/>
193 <xsl:template match="db:link[@xlink:href]" mode="stripNS">
194 <ulink url="{@xlink:href}">
195 <xsl:if test="@role">
196 <xsl:attribute name="role">
197 <xsl:value-of select="@role"/>
200 <xsl:apply-templates mode="stripNS"/>
204 <xsl:template match="db:citetitle[@xlink:href]" mode="stripNS">
205 <ulink url="{@xlink:href}">
207 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
208 and not(name(.) = 'version')
209 and not(local-name(.) = 'href')]"/>
210 <xsl:if test="@xml:id">
211 <xsl:attribute name="id">
212 <xsl:value-of select="@xml:id"/>
215 <xsl:apply-templates mode="stripNS"/>
220 <xsl:template match="db:citetitle[@linkend]" mode="stripNS">
222 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
223 and not(name(.) = 'version')
224 and not(name(.) = 'linkend')
225 and not(local-name(.) = 'href')]"/>
226 <xsl:if test="@xml:id">
227 <xsl:attribute name="id">
228 <xsl:value-of select="@xml:id"/>
231 <xsl:apply-templates mode="stripNS"/>
235 <xsl:template match="db:alt" mode="stripNS"/>
237 <xsl:template match="ng:textdata|db:textdata
238 |ng:imagedata|db:imagedata
239 |ng:videodata|db:videodata
240 |ng:audiodata|db:audiodata" mode="stripNS">
241 <xsl:element name="{local-name(.)}">
242 <xsl:copy-of select="@*[not(name(.) = 'xml:id')
243 and not(name(.) = 'version')
244 and not(name(.) = 'entityref')]"/>
245 <xsl:if test="@xml:id">
246 <xsl:attribute name="id">
247 <xsl:value-of select="@xml:id"/>
252 <xsl:when test="@entityref">
253 <xsl:attribute name="fileref">
254 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
259 <xsl:apply-templates mode="stripNS"/>
263 <xsl:template name="add-xml-base">
264 <xsl:if test="not(@xml:base)">
265 <xsl:variable name="base">
267 <xsl:when test="function-available('saxon:systemId')">
268 <xsl:value-of select="saxon:systemId()"/>
270 <xsl:when test="function-available('NodeInfo:systemId')">
271 <xsl:value-of select="NodeInfo:systemId()"/>
275 <xsl:text>WARNING: cannot add @xml:base to node </xsl:text>
276 <xsl:text>set root element. </xsl:text>
277 <xsl:text>Relative paths may not work.</xsl:text>
283 <xsl:message>base is <xsl:value-of select="$base"/></xsl:message>
285 <xsl:if test="$base != ''">
286 <xsl:attribute name="xml:base">
287 <xsl:call-template name="systemIdToBaseURI">
288 <xsl:with-param name="systemId">
289 <!-- file: seems to confuse some processors. -->
291 <!-- however, windows paths must use file:///c:/path -->
292 <xsl:when test="starts-with($base, 'file:///') and
293 substring($base, 10, 1) = ':'">
294 <xsl:value-of select="$base"/>
296 <xsl:when test="starts-with($base, 'file:/')
297 and substring($base, 8, 1) = ':'">
298 <xsl:value-of select="concat('file:///',
299 substring-after($base,'file:/'))"/>
301 <xsl:when test="starts-with($base, 'file:///')">
302 <xsl:value-of select="substring-after($base,'file://')"/>
304 <xsl:when test="starts-with($base, 'file://')">
305 <xsl:value-of select="substring-after($base,'file:/')"/>
307 <xsl:when test="starts-with($base, 'file:/')">
308 <xsl:value-of select="substring-after($base,'file:')"/>
311 <xsl:value-of select="$base"/>
321 <xsl:template name="systemIdToBaseURI">
322 <xsl:param name="systemId" select="''"/>
323 <xsl:if test="contains($systemId,'/')">
324 <xsl:value-of select="substring-before($systemId,'/')"/>
325 <xsl:text>/</xsl:text>
326 <xsl:call-template name="systemIdToBaseURI">
327 <xsl:with-param name="systemId"
328 select="substring-after($systemId,'/')"/>
333 <xsl:template match="comment()|processing-instruction()|text()" mode="stripNS">
337 <xsl:template match="/" priority="-1">
338 <!-- need a local version of this variable because this module imported many places-->
339 <xsl:variable name="local.exsl.node.set.available">
341 <xsl:when exsl:foo="" xmlns:exsl="http://exslt.org/common"
342 test="function-available('exsl:node-set') or
343 contains(system-property('xsl:vendor'),
344 'Apache Software Foundation')">1</xsl:when>
345 <xsl:otherwise>0</xsl:otherwise>
349 <xsl:when test="$local.exsl.node.set.available != 0
350 and (*/self::ng:* or */self::db:*)">
352 <xsl:text>Stripping namespace from DocBook 5 document. </xsl:text>
353 <xsl:text>It is suggested to use namespaced version of the stylesheets </xsl:text>
354 <xsl:text>available in distribution file 'docbook-xsl-ns' </xsl:text>
355 <xsl:text>at //http://sourceforge.net/projects/docbook/files/</xsl:text>
356 <xsl:text> which does not require namespace stripping step.</xsl:text>
358 <xsl:variable name="nons">
359 <xsl:apply-templates mode="stripNS"/>
361 <xsl:message>Processing stripped document.</xsl:message>
362 <xsl:apply-templates select="exsl:node-set($nons)"/>
365 <xsl:copy-of select="node()"/>