source: BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/common/stripns.xsl@ ff103efa

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since ff103efa was f8c4e94, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Added LFS XSL Stylesheets.

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