]> git.lyx.org Git - features.git/blob - lib/docbook/common/stripns.xsl
Unify wording for statistics
[features.git] / lib / docbook / common / stripns.xsl
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                 xmlns:xlink="http://www.w3.org/1999/xlink"
9                 exclude-result-prefixes="db ng exsl saxon NodeInfo xlink"
10                 version='1.0'>
11
12 <!-- ********************************************************************
13
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.
17
18      ******************************************************************** -->
19
20 <!-- put an xml:base attribute on the root element -->
21 <xsl:template match="/*" mode="stripNS">
22   <xsl:choose>
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"/>
30           </xsl:attribute>
31         </xsl:if>
32
33         <xsl:call-template name="add-xml-base"/>
34
35         <xsl:apply-templates mode="stripNS"/>
36       </xsl:element>
37     </xsl:when>
38     <xsl:otherwise>
39       <xsl:copy>
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"/>
45           </xsl:attribute>
46         </xsl:if>
47
48         <xsl:call-template name="add-xml-base"/>
49
50         <xsl:apply-templates mode="stripNS"/>
51       </xsl:copy>
52     </xsl:otherwise>
53   </xsl:choose>
54 </xsl:template>
55
56 <xsl:template match="*" mode="stripNS">
57   <xsl:choose>
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"/>
65           </xsl:attribute>
66         </xsl:if>
67         <xsl:apply-templates mode="stripNS"/>
68       </xsl:element>
69     </xsl:when>
70     <xsl:otherwise>
71       <xsl:copy>
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"/>
77           </xsl:attribute>
78         </xsl:if>
79         <xsl:apply-templates mode="stripNS"/>
80       </xsl:copy>
81     </xsl:otherwise>
82   </xsl:choose>
83 </xsl:template>
84
85 <xsl:template match="db:info" mode="stripNS">
86   <xsl:variable name="info">
87     <xsl:choose>
88       <xsl:when test="parent::db:article
89                       |parent::db:appendix
90                       |parent::db:bibliography
91                       |parent::db:book
92                       |parent::db:chapter
93                       |parent::db:glossary
94                       |parent::db:index
95                       |parent::db:part
96                       |parent::db:preface
97                       |parent::db:refentry
98                       |parent::db:reference
99                       |parent::db:refsect1
100                       |parent::db:refsect2
101                       |parent::db:refsect3
102                       |parent::db:refsection
103                       |parent::db:refsynopsisdiv
104                       |parent::db:sect1
105                       |parent::db:sect2
106                       |parent::db:sect3
107                       |parent::db:sect4
108                       |parent::db:sect5
109                       |parent::db:section
110                       |parent::db:setindex
111                       |parent::db:set
112                       |parent::db:slides
113                       |parent::db:sidebar">
114         <xsl:value-of select="local-name(parent::*)"/>
115         <xsl:text>info</xsl:text>
116       </xsl:when>
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>
125       </xsl:when>
126       <xsl:otherwise>blockinfo</xsl:otherwise>
127     </xsl:choose>
128   </xsl:variable>
129
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"/>
136       </xsl:attribute>
137     </xsl:if>
138     <xsl:apply-templates mode="stripNS"/>
139   </xsl:element>
140
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"/>
157   </xsl:if>
158
159 </xsl:template>
160
161 <xsl:template match="ng:tag|db:tag" mode="stripNS">
162   <xsl:choose>
163     <xsl:when test="@xlink:href">
164       <ulink url="{@xlink:href}">
165         <sgmltag>
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"/>
172             </xsl:attribute>
173           </xsl:if>
174           <xsl:apply-templates mode="stripNS"/>
175         </sgmltag>
176       </ulink>
177     </xsl:when>
178     <xsl:otherwise>
179       <sgmltag>
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"/>
185             </xsl:attribute>
186           </xsl:if>
187         <xsl:apply-templates mode="stripNS"/>
188       </sgmltag>
189     </xsl:otherwise>
190   </xsl:choose>
191 </xsl:template>
192
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"/>
198       </xsl:attribute>
199     </xsl:if>
200     <xsl:apply-templates mode="stripNS"/>
201   </ulink>
202 </xsl:template>
203
204 <xsl:template match="db:citetitle[@xlink:href]" mode="stripNS">
205   <ulink url="{@xlink:href}">
206     <citetitle>
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"/>
213         </xsl:attribute>
214       </xsl:if>
215       <xsl:apply-templates mode="stripNS"/>
216     </citetitle>
217   </ulink>
218 </xsl:template>
219
220 <xsl:template match="db:citetitle[@linkend]" mode="stripNS">
221   <citetitle>
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"/>
229       </xsl:attribute>
230     </xsl:if>
231       <xsl:apply-templates mode="stripNS"/>
232   </citetitle>
233 </xsl:template>
234
235 <xsl:template match="db:alt" mode="stripNS"/>
236
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"/>
248       </xsl:attribute>
249     </xsl:if>
250
251     <xsl:choose>
252       <xsl:when test="@entityref">
253         <xsl:attribute name="fileref">
254           <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
255         </xsl:attribute>
256       </xsl:when>
257     </xsl:choose>
258
259     <xsl:apply-templates mode="stripNS"/>
260   </xsl:element>
261 </xsl:template>
262
263 <xsl:template name="add-xml-base">
264   <xsl:if test="not(@xml:base)">
265     <xsl:variable name="base">
266       <xsl:choose>
267         <xsl:when test="function-available('saxon:systemId')">
268           <xsl:value-of select="saxon:systemId()"/>
269         </xsl:when>
270         <xsl:when test="function-available('NodeInfo:systemId')">
271           <xsl:value-of select="NodeInfo:systemId()"/>
272         </xsl:when>
273         <xsl:otherwise>
274           <xsl:message>
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>
278           </xsl:message>
279         </xsl:otherwise>
280       </xsl:choose>
281     </xsl:variable>
282     <!-- debug
283     <xsl:message>base is <xsl:value-of select="$base"/></xsl:message>
284     -->
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. -->
290             <xsl:choose>
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"/>
295               </xsl:when>
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:/'))"/>
300               </xsl:when>
301               <xsl:when test="starts-with($base, 'file:///')">
302                 <xsl:value-of select="substring-after($base,'file://')"/>
303               </xsl:when>
304               <xsl:when test="starts-with($base, 'file://')">
305                 <xsl:value-of select="substring-after($base,'file:/')"/>
306               </xsl:when>
307               <xsl:when test="starts-with($base, 'file:/')">
308                 <xsl:value-of select="substring-after($base,'file:')"/>
309               </xsl:when>
310               <xsl:otherwise>
311                 <xsl:value-of select="$base"/>
312               </xsl:otherwise>
313             </xsl:choose>
314           </xsl:with-param>
315         </xsl:call-template>
316       </xsl:attribute>
317     </xsl:if>
318   </xsl:if>
319 </xsl:template>
320
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,'/')"/>
329     </xsl:call-template>
330   </xsl:if>
331 </xsl:template>
332
333 <xsl:template match="comment()|processing-instruction()|text()" mode="stripNS">
334   <xsl:copy/>
335 </xsl:template>
336
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">
340     <xsl:choose>
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>
346     </xsl:choose>
347   </xsl:variable>
348   <xsl:choose>
349     <xsl:when test="$local.exsl.node.set.available != 0
350                     and (*/self::ng:* or */self::db:*)">
351       <xsl:message>
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>
357       </xsl:message>
358       <xsl:variable name="nons">
359         <xsl:apply-templates mode="stripNS"/>
360       </xsl:variable>
361       <xsl:message>Processing stripped document.</xsl:message>
362       <xsl:apply-templates select="exsl:node-set($nons)"/>
363     </xsl:when>
364     <xsl:otherwise>
365       <xsl:copy-of select="node()"/>
366     </xsl:otherwise>
367   </xsl:choose>
368 </xsl:template>
369
370 </xsl:stylesheet>