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"
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">
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"/>
36 <xsl:call-template name=
"add-xml-base"/>
38 <xsl:apply-templates mode=
"stripNS"/>
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"/>
51 <xsl:call-template name=
"add-xml-base"/>
53 <xsl:apply-templates mode=
"stripNS"/>
59 <xsl:template match=
"*" mode=
"stripNS">
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"/>
70 <xsl:apply-templates mode=
"stripNS"/>
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"/>
82 <xsl:apply-templates mode=
"stripNS"/>
88 <xsl:template match=
"db:info" mode=
"stripNS">
89 <xsl:variable name=
"info">
91 <xsl:when test=
"parent::db:article
93 |parent::db:bibliography
101 |parent::db:reference
105 |parent::db:refsection
106 |parent::db:refsynopsisdiv
116 |parent::db:sidebar">
117 <xsl:value-of select=
"local-name(parent::*)"/>
118 <xsl:text>info
</xsl:text>
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>
129 <xsl:otherwise>blockinfo
</xsl:otherwise>
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"/>
141 <xsl:apply-templates mode=
"stripNS"/>
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"/>
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"/>
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'">
177 <xsl:if test=
"@xml:id">
178 <xsl:attribute name=
"id">
179 <xsl:value-of select=
"@xml:id"/>
182 <xsl:apply-templates mode=
"stripNS"/>
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'">
194 <xsl:if test=
"@xml:id">
195 <xsl:attribute name=
"id">
196 <xsl:value-of select=
"@xml:id"/>
199 <xsl:apply-templates mode=
"stripNS"/>
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"/>
211 <xsl:apply-templates mode=
"stripNS"/>
217 <xsl:template match=
"ng:tag|db:tag" mode=
"stripNS">
219 <xsl:copy-of select=
"@*[not(name(.) = 'xml:id')
220 and not(name(.) = 'version')]"/>
221 <xsl:apply-templates mode=
"stripNS"/>
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"/>
240 <xsl:when test=
"@entityref">
241 <xsl:attribute name=
"fileref">
242 <xsl:value-of select=
"unparsed-entity-uri(@entityref)"/>
247 <xsl:apply-templates mode=
"stripNS"/>
251 <xsl:template name=
"add-xml-base">
252 <xsl:if test=
"not(@xml:base)">
253 <xsl:variable name=
"base">
255 <xsl:when test=
"function-available('saxon:systemId')">
256 <xsl:value-of select=
"saxon:systemId()"/>
258 <xsl:when test=
"function-available('NodeInfo:systemId')">
259 <xsl:value-of select=
"NodeInfo:systemId()"/>
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>
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. -->
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"/>
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:/'))"/>
289 <xsl:when test=
"starts-with($base, 'file:///')">
290 <xsl:value-of select=
"substring-after($base,'file://')"/>
292 <xsl:when test=
"starts-with($base, 'file://')">
293 <xsl:value-of select=
"substring-after($base,'file:/')"/>
295 <xsl:when test=
"starts-with($base, 'file:/')">
296 <xsl:value-of select=
"substring-after($base,'file:')"/>
299 <xsl:value-of select=
"$base"/>
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,'/')"/>
321 <xsl:template match=
"comment()|processing-instruction()|text()" mode=
"stripNS">
325 <xsl:template match=
"/" priority=
"-1">
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"/>
335 <xsl:message>Processing stripped document.
</xsl:message>
336 <xsl:apply-templates select=
"exsl:node-set($nons)"/>
339 <xsl:copy-of select=
"@* | node()"/>