Debian Codegraph @

xsl/main.xsl

raw
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="db ng exsl"
7 version="1.0">
8
9 <!--############################################################################
10 XSLT Stylesheet DocBook -> LaTeX
11 ############################################################################ -->
12
13 <xsl:template match="*" mode="info.copy">
14 <xsl:for-each select="(info
15 |referenceinfo
16 |refentryinfo
17 |articleinfo
18 |sectioninfo
19 |appendixinfo
20 |bibliographyinfo
21 |chapterinfo
22 |sect1info
23 |sect2info
24 |sect3info
25 |sect4info
26 |sect5info
27 |partinfo
28 |prefaceinfo
29 |docinfo)[1]/child::*">
30 <xsl:copy-of select=".|@*"/>
31 </xsl:for-each>
32 </xsl:template>
33
34 <xsl:template match="/" mode="doc-wrap-with">
35 <xsl:param name="root"/>
36 <xsl:variable name="rootnode" select="./*[1]"/>
37 <xsl:message>
38 <xsl:text>Warning: </xsl:text>
39 <xsl:value-of select="local-name($rootnode)"/>
40 <xsl:if test="$rootnode/@id or $rootnode/@xml:id">
41 <xsl:text>(</xsl:text>
42 <xsl:value-of select="($rootnode/@id|$rootnode/@xml:id)[1]"/>
43 <xsl:text>)</xsl:text>
44 </xsl:if>
45 <xsl:text> wrapped with </xsl:text>
46 <xsl:value-of select="$root"/>
47 </xsl:message>
48
49 <xsl:element name="{$root}">
50 <!-- Get the node attributes -->
51 <xsl:for-each select="node()/@*[name(.)!='id' and name(.)!='xml:id']">
52 <xsl:copy-of select="."/>
53 </xsl:for-each>
54
55 <!-- Get titles from the node -->
56 <xsl:for-each select="node()/title|node()/subtitle|node()/titleabbrev">
57 <xsl:copy-of select="."/>
58 </xsl:for-each>
59
60 <!-- Take the infos from the node -->
61 <xsl:element name="{$root}info">
62 <xsl:apply-templates select="node()" mode="info.copy"/>
63 </xsl:element>
64
65 <!-- Now the wrapped node -->
66 <xsl:copy-of select="node()|@*"/>
67 </xsl:element>
68 </xsl:template>
69
70
71 <xsl:template match="/" mode="doc-wrap">
72 <xsl:message>
73 <xsl:text>Warning: the root element is not an article nor a book</xsl:text>
74 </xsl:message>
75 <xsl:variable name="root">
76 <xsl:choose>
77 <xsl:when test="part|chapter">
78 <xsl:value-of select="'book'"/>
79 </xsl:when>
80 <xsl:otherwise>
81 <xsl:value-of select="'article'"/>
82 </xsl:otherwise>
83 </xsl:choose>
84 </xsl:variable>
85 <xsl:variable name="rnode">
86 <xsl:apply-templates select="." mode="doc-wrap-with">
87 <xsl:with-param name="root" select="$root"/>
88 </xsl:apply-templates>
89 </xsl:variable>
90
91 <!-- Process the DocBook document subset -->
92 <xsl:apply-templates select="exsl:node-set($rnode)/*" mode="wrapper"/>
93 </xsl:template>
94
95
96 <xsl:template match="/">
97 <xsl:param name="rfs" select="0"/>
98 <xsl:if test="$rfs = 0 and $output.quietly = 0">
99 <xsl:message>
100 <xsl:text>XSLT stylesheets DocBook - LaTeX 2e </xsl:text>
101 <xsl:text>(</xsl:text>
102 <xsl:value-of select="$version"/><xsl:text>)</xsl:text>
103 </xsl:message>
104 <xsl:message>===================================================</xsl:message>
105 </xsl:if>
106 <xsl:choose>
107 <xsl:when test="set|book|article">
108 <xsl:apply-templates/>
109 </xsl:when>
110 <xsl:when test="function-available('exsl:node-set')
111 and (*/self::ng:* or */self::db:*)">
112 <xsl:if test="$output.quietly = 0">
113 <xsl:message>Stripping NS from DocBook 5/NG document.</xsl:message>
114 </xsl:if>
115 <xsl:variable name="nons">
116 <xsl:apply-templates mode="stripNS"/>
117 </xsl:variable>
118 <xsl:if test="$output.quietly = 0">
119 <xsl:message>Processing stripped document.</xsl:message>
120 </xsl:if>
121 <xsl:apply-templates select="exsl:node-set($nons)">
122 <xsl:with-param name="rfs" select="1"/>
123 </xsl:apply-templates>
124 </xsl:when>
125 <xsl:otherwise>
126 <xsl:apply-templates select="." mode="doc-wrap"/>
127 </xsl:otherwise>
128 </xsl:choose>
129 </xsl:template>
130
131
132 <!-- DocBook NG/V5 translated to DocBook V4, taken from the
133 DocBook XSL Stylesheets
134 -->
135
136 <xsl:template match="*" mode="stripNS">
137 <xsl:choose>
138 <xsl:when test="self::ng:* or self::db:*">
139 <xsl:element name="{local-name(.)}">
140 <xsl:copy-of select="@*"/>
141 <xsl:apply-templates mode="stripNS"/>
142 </xsl:element>
143 </xsl:when>
144 <xsl:otherwise>
145 <xsl:copy>
146 <xsl:copy-of select="@*"/>
147 <xsl:apply-templates mode="stripNS"/>
148 </xsl:copy>
149 </xsl:otherwise>
150 </xsl:choose>
151 </xsl:template>
152
153 <xsl:template match="ng:link|db:link" mode="stripNS">
154 <xsl:variable xmlns:xlink="http://www.w3.org/1999/xlink"
155 name="href" select="@xlink:href|@href"/>
156 <xsl:choose>
157 <xsl:when test="$href != '' and not(starts-with($href,'#'))">
158 <ulink url="{$href}">
159 <xsl:for-each select="@*">
160 <xsl:if test="local-name(.) != 'href'">
161 <xsl:copy/>
162 </xsl:if>
163 </xsl:for-each>
164 <xsl:apply-templates mode="stripNS"/>
165 </ulink>
166 </xsl:when>
167 <xsl:when test="$href != '' and starts-with($href,'#')">
168 <link linkend="{substring-after($href,'#')}">
169 <xsl:for-each select="@*">
170 <xsl:if test="local-name(.) != 'href'">
171 <xsl:copy/>
172 </xsl:if>
173 </xsl:for-each>
174 <xsl:apply-templates mode="stripNS"/>
175 </link>
176 </xsl:when>
177 <xsl:otherwise>
178 <link>
179 <xsl:copy-of select="@*"/>
180 <xsl:apply-templates mode="stripNS"/>
181 </link>
182 </xsl:otherwise>
183 </xsl:choose>
184 </xsl:template>
185
186 <xsl:template match="comment()|processing-instruction()|text()" mode="stripNS">
187 <xsl:copy/>
188 </xsl:template>
189
190 </xsl:stylesheet>
191