source: clfs-embedded/BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/common/stripns.xsl @ 9642843

Last change on this file since 9642843 was 9642843, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Updated DocBook?-XSL code to version 1.73.2

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