root/docs/docbook-xsl/manpages/stripns.xsl

Revision 23dea7e00df87480acb58bb3398283c2bb227949, 4.2 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 8 years ago)

pull docs into master

  • Property mode set to 100644
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:exsl="http://exslt.org/common"
6                 exclude-result-prefixes="exsl db ng"
7                 version='1.0'>
8
9 <!-- ********************************************************************
10      $Id: stripns.xsl,v 1.2 2005/05/29 09:27:08 xmldoc Exp $
11      ********************************************************************
12
13      This file is part of the XSL DocBook Stylesheet distribution.
14      See ../README or http://docbook.sf.net/release/xsl/current/ for
15      copyright and other information.
16
17      ******************************************************************** -->
18
19 <!-- Standalone stylesheet for stripping namespaces from DocBook 5/NG -->
20 <!-- docs. You currently need to do two-pass processing to use this: First, -->
21 <!-- transform your DocBook 5/NG source doc using this, then transform the -->
22 <!-- result as usual with the manpages/docbook.xsl stylesheet. Of course -->
23 <!-- you can always run the process using a pipe if you want. Example: -->
24
25 <!--   xsltproc ./manpages/stripns.xsl myRefEntry.xml \ -->
26 <!--     | xsltproc ./manpages/docbook.xsl - -->
27
28 <!-- It may be that there is actually some way to set it up as a -->
29 <!-- single-pass XSLT process, as is done with the HTML stylesheets. But -->
30 <!-- I've not yet figured out how to get that towork... -Mike -->
31
32 <!-- ==================================================================== -->
33
34   <xsl:output method="xml"
35               encoding="ISO-8859-1"
36               indent="no"/>
37
38   <xsl:template match="node() | @*">
39     <xsl:copy>
40       <xsl:apply-templates select="@* | node()"/>
41     </xsl:copy>
42   </xsl:template>
43
44   <!-- ==================================================================== -->
45
46   <xsl:template match="/">
47     <xsl:choose>
48       <xsl:when test="function-available('exsl:node-set')
49                       and (*/self::ng:* or */self::db:*)">
50         <!-- see comment in html/docbook.xsl -->
51         <xsl:message>Stripping NS from DocBook 5/NG document.</xsl:message>
52         <xsl:variable name="nons">
53           <xsl:apply-templates mode="stripNS"/>
54         </xsl:variable>
55         <xsl:message>Processing stripped document.</xsl:message>
56         <xsl:apply-templates select="exsl:node-set($nons)"/>
57       </xsl:when>
58       <xsl:otherwise>
59         <xsl:apply-templates/>
60       </xsl:otherwise>
61     </xsl:choose>
62   </xsl:template>
63
64   <!-- ==================================================================== -->
65
66   <xsl:template match="*" mode="stripNS">
67     <xsl:choose>
68       <xsl:when test="self::ng:* or self::db:*">
69         <xsl:element name="{local-name(.)}">
70           <xsl:copy-of select="@*"/>
71           <xsl:apply-templates mode="stripNS"/>
72         </xsl:element>
73       </xsl:when>
74       <xsl:otherwise>
75         <xsl:copy>
76           <xsl:copy-of select="@*"/>
77           <xsl:apply-templates mode="stripNS"/>
78         </xsl:copy>
79       </xsl:otherwise>
80     </xsl:choose>
81   </xsl:template>
82
83   <xsl:template match="ng:link|db:link" mode="stripNS">
84     <xsl:variable xmlns:xlink="http://www.w3.org/1999/xlink"
85                   name="href" select="@xlink:href|@href"/>
86     <xsl:choose>
87       <xsl:when test="$href != '' and not(starts-with($href,'#'))">
88         <ulink url="{$href}">
89           <xsl:for-each select="@*">
90             <xsl:if test="local-name(.) != 'href'">
91               <xsl:copy/>
92             </xsl:if>
93           </xsl:for-each>
94           <xsl:apply-templates mode="stripNS"/>
95         </ulink>
96       </xsl:when>
97       <xsl:when test="$href != '' and starts-with($href,'#')">
98         <link linkend="{substring-after($href,'#')}">
99           <xsl:for-each select="@*">
100             <xsl:if test="local-name(.) != 'href'">
101               <xsl:copy/>
102             </xsl:if>
103           </xsl:for-each>
104           <xsl:apply-templates mode="stripNS"/>
105         </link>
106       </xsl:when>
107       <xsl:otherwise>
108         <link>
109           <xsl:copy-of select="@*"/>
110           <xsl:apply-templates mode="stripNS"/>
111         </link>
112       </xsl:otherwise>
113     </xsl:choose>
114   </xsl:template>
115
116   <xsl:template match="comment()|processing-instruction()|text()" mode="stripNS">
117     <xsl:copy/>
118   </xsl:template>
119
120 </xsl:stylesheet>
Note: See TracBrowser for help on using the browser.