Debian Codegraph @

xslt/docbook/common/db-chunk.xsl

raw
1 <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
2 <!--
3 This program is free software; you can redistribute it and/or modify it under
4 the terms of the GNU Lesser General Public License as published by the Free
5 Software Foundation; either version 2 of the License, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 details.
12
13 You should have received a copy of the GNU Lesser General Public License
14 along with this program; see the file COPYING.LGPL. If not, see <http://www.gnu.org/licenses/>.
15 -->
16 <!DOCTYPE xsl:stylesheet [
17 <!ENTITY % selectors SYSTEM "db-selectors.mod">
18 %selectors;
19 ]>
20
21 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22 xmlns:db="http://docbook.org/ns/docbook"
23 xmlns:set="http://exslt.org/sets"
24 xmlns:exsl="http://exslt.org/common"
25 extension-element-prefixes="exsl"
26 exclude-result-prefixes="db set"
27 version="1.0">
28
29 <!--!!==========================================================================
30 DocBook Chunking
31
32 REMARK: Describe this module
33 -->
34
35
36 <!--@@==========================================================================
37 db.chunk.max_depth
38 The maximum depth for chunking sections.
39
40 REMARK: Describe what this does
41 -->
42 <xsl:param name="db.chunk.max_depth">
43 <xsl:choose>
44 <xsl:when test="number(processing-instruction('db.chunk.max_depth'))">
45 <xsl:value-of
46 select="number(processing-instruction('db.chunk.max_depth'))"/>
47 </xsl:when>
48 <xsl:when test="/book | /db:book">
49 <xsl:value-of select="2"/>
50 </xsl:when>
51 <xsl:otherwise>
52 <xsl:value-of select="1"/>
53 </xsl:otherwise>
54 </xsl:choose>
55 </xsl:param>
56
57
58 <!--@@==========================================================================
59 db.chunk.basename
60 The base filename of the output file, without an extension.
61
62 REMARK: Describe what this does
63 -->
64 <xsl:param name="db.chunk.basename">
65 <xsl:choose>
66 <xsl:when test="/*/@xml:id">
67 <xsl:value-of select="/*/@xml:id"/>
68 </xsl:when>
69 <xsl:when test="/*/@id">
70 <xsl:value-of select="/*/@id"/>
71 </xsl:when>
72 <xsl:otherwise>
73 <xsl:text>index</xsl:text>
74 </xsl:otherwise>
75 </xsl:choose>
76 </xsl:param>
77
78
79 <!--@@==========================================================================
80 db.chunk.extension
81 The default file extension for new output documents.
82
83 REMARK: Describe what this does
84 -->
85 <xsl:param name="db.chunk.extension"/>
86
87
88 <!--**==========================================================================
89 db.chunk.depth-in-chunk
90 Determines the depth of an element in the containing chunk.
91
92 [xsl:params]
93 $node: The element to determine the depth of
94
95 REMARK: Explain how this works
96 -->
97 <xsl:template name="db.chunk.depth-in-chunk">
98 <xsl:param name="node" select="."/>
99 <xsl:variable name="divs" select="count($node/ancestor-or-self::&db_chunks;)"/>
100 <xsl:choose>
101 <xsl:when test="$divs &lt; ($db.chunk.max_depth + 1)">
102 <xsl:value-of select="count($node/ancestor-or-self::*) - $divs"/>
103 </xsl:when>
104 <xsl:otherwise>
105 <xsl:value-of select="count($node/ancestor::*) - $db.chunk.max_depth"/>
106 </xsl:otherwise>
107 </xsl:choose>
108 </xsl:template>
109
110
111 <!--**==========================================================================
112 db.chunk.depth-of-chunk
113 Determines the depth of the containing chunk in the document.
114
115 [xsl:params]
116 $node: The element to determine the depth of
117
118 REMARK: Explain how this works
119 -->
120 <xsl:template name="db.chunk.depth-of-chunk">
121 <xsl:param name="node" select="."/>
122 <xsl:variable name="divs" select="$node/ancestor-or-self::&db_chunks;"/>
123 <xsl:choose>
124 <xsl:when test="count($divs) - 1 &lt; $db.chunk.max_depth">
125 <xsl:value-of select="count($divs) - 1"/>
126 </xsl:when>
127 <xsl:otherwise>
128 <xsl:value-of select="$db.chunk.max_depth"/>
129 </xsl:otherwise>
130 </xsl:choose>
131 </xsl:template>
132
133
134 <!--**==========================================================================
135 db.chunk.chunk-id
136 Determines the id of the chunk that contains an element.
137
138 [xsl:params]
139 $id: The id of the element to determine the chunk id of
140 $node: The element to determine the chunk id of
141 $depth_in_chunk: The depth of $node in the containing chunk
142
143 REMARK: Explain how this works
144 -->
145 <xsl:template name="db.chunk.chunk-id">
146 <xsl:param name="id" select="@id | @xml:id"/>
147 <xsl:param name="node" select="key('db.id.key', $id)"/>
148 <xsl:param name="depth_in_chunk">
149 <xsl:call-template name="db.chunk.depth-in-chunk">
150 <xsl:with-param name="node" select="$node"/>
151 </xsl:call-template>
152 </xsl:param>
153 <xsl:param name="chunk" select="$node/ancestor-or-self::*[$depth_in_chunk + 1]"/>
154 <xsl:choose>
155 <xsl:when test="set:has-same-node($chunk, /*)">
156 <xsl:value-of select="$db.chunk.basename"/>
157 </xsl:when>
158 <xsl:when test="$chunk/@id">
159 <xsl:value-of select="string($chunk/@id)"/>
160 </xsl:when>
161 <xsl:when test="$chunk/@xml:id">
162 <xsl:value-of select="string($chunk/@xml:id)"/>
163 </xsl:when>
164 <xsl:otherwise>
165 <xsl:value-of select="generate-id($chunk)"/>
166 </xsl:otherwise>
167 </xsl:choose>
168 </xsl:template>
169
170
171 <!--**==========================================================================
172 db.chunk.chunk-id.axis
173 Determines the id of the first chunk along a specified axis.
174
175 [xsl:params]
176 $node: The base element
177 $node: The axis along which to find the first chunk
178 $depth_in_chunk: The depth of $node in the containing chunk
179 $depth_of_chunk: The depth of the containing chunk in the document
180
181 REMARK: Explain how this works, and what the axes are
182 -->
183 <xsl:template name="db.chunk.chunk-id.axis">
184 <xsl:param name="node" select="."/>
185 <xsl:param name="axis"/>
186 <xsl:param name="depth_in_chunk">
187 <xsl:call-template name="db.chunk.depth-in-chunk">
188 <xsl:with-param name="node" select="$node"/>
189 </xsl:call-template>
190 </xsl:param>
191 <xsl:param name="depth_of_chunk">
192 <xsl:call-template name="db.chunk.depth-of-chunk">
193 <xsl:with-param name="node" select="$node"/>
194 </xsl:call-template>
195 </xsl:param>
196 <xsl:choose>
197 <xsl:when test="depth_in_chunk != 0">
198 <xsl:call-template name="db.chunk.chunk-id.axis">
199 <xsl:with-param name="node" select="$node/ancestor::*[$depth_in_chunk]"/>
200 <xsl:with-param name="axis" select="$axis"/>
201 <xsl:with-param name="depth_in_chunk" select="0"/>
202 <xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
203 </xsl:call-template>
204 </xsl:when>
205 <!-- following -->
206 <xsl:when test="$axis = 'following'">
207 <xsl:variable name="divs"
208 select="$node/following-sibling::&db_chunks;"/>
209 <xsl:choose>
210 <xsl:when test="$divs">
211 <xsl:call-template name="db.chunk.chunk-id">
212 <xsl:with-param name="node" select="$divs[1]"/>
213 <xsl:with-param name="depth_in_chunk" select="0"/>
214 <xsl:with-param name="chunk" select="$divs[1]"/>
215 </xsl:call-template>
216 </xsl:when>
217 <xsl:when test="$node/..">
218 <xsl:call-template name="db.chunk.chunk-id.axis">
219 <xsl:with-param name="node" select="$node/.."/>
220 <xsl:with-param name="axis" select="'following'"/>
221 <xsl:with-param name="depth_in_chunk" select="0"/>
222 <xsl:with-param name="depth_of_chunk" select="$depth_of_chunk - 1"/>
223 </xsl:call-template>
224 </xsl:when>
225 </xsl:choose>
226 </xsl:when>
227 <!-- last-descendant -->
228 <xsl:when test="$axis = 'last-descendant'">
229 <xsl:variable name="divs" select="$node/&db_chunks;"/>
230 <xsl:choose>
231 <xsl:when test="($depth_of_chunk &gt;= $db.chunk.max_depth)">
232 <xsl:call-template name="db.chunk.chunk-id">
233 <xsl:with-param name="node" select="$node"/>
234 <xsl:with-param name="depth_in_chunk" select="0"/>
235 <xsl:with-param name="chunk" select="$node"/>
236 </xsl:call-template>
237 </xsl:when>
238 <xsl:when test="($depth_of_chunk + 1 = $db.chunk.max_depth) and $divs">
239 <xsl:call-template name="db.chunk.chunk-id">
240 <xsl:with-param name="node" select="$divs[last()]"/>
241 <xsl:with-param name="depth_in_chunk" select="0"/>
242 <xsl:with-param name="chunk" select="$divs[last()]"/>
243 </xsl:call-template>
244 </xsl:when>
245 <xsl:when test="$divs">
246 <xsl:call-template name="db.chunk.chunk-id.axis">
247 <xsl:with-param name="node" select="$divs[last()]"/>
248 <xsl:with-param name="axis" select="'last-descendant'"/>
249 <xsl:with-param name="depth_in_chunk" select="0"/>
250 <xsl:with-param name="depth_of_chunk" select="$depth_of_chunk + 1"/>
251 </xsl:call-template>
252 </xsl:when>
253 <xsl:otherwise>
254 <xsl:call-template name="db.chunk.chunk-id">
255 <xsl:with-param name="node" select="$node"/>
256 <xsl:with-param name="depth_in_chunk" select="0"/>
257 <xsl:with-param name="chunk" select="$node"/>
258 </xsl:call-template>
259 </xsl:otherwise>
260 </xsl:choose>
261 </xsl:when>
262 <!-- next -->
263 <xsl:when test="$axis = 'next'">
264 <xsl:variable name="divs" select="$node/&db_chunks;"/>
265 <xsl:choose>
266 <xsl:when test="($depth_of_chunk &lt; $db.chunk.max_depth) and $divs">
267 <xsl:call-template name="db.chunk.chunk-id">
268 <xsl:with-param name="node" select="$divs[1]"/>
269 <xsl:with-param name="depth_in_chunk" select="0"/>
270 <xsl:with-param name="chunk" select="$divs[1]"/>
271 </xsl:call-template>
272 </xsl:when>
273 <xsl:otherwise>
274 <xsl:call-template name="db.chunk.chunk-id.axis">
275 <xsl:with-param name="node" select="$node"/>
276 <xsl:with-param name="axis" select="'following'"/>
277 <xsl:with-param name="depth_in_chunk" select="$depth_in_chunk"/>
278 <xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
279 </xsl:call-template>
280 </xsl:otherwise>
281 </xsl:choose>
282 </xsl:when>
283 <!-- previous -->
284 <xsl:when test="$axis = 'previous'">
285 <xsl:variable name="divs" select="$node/preceding-sibling::&db_chunks;"/>
286 <xsl:choose>
287 <xsl:when test="$divs and ($depth_of_chunk &lt; $db.chunk.max_depth)">
288 <xsl:call-template name="db.chunk.chunk-id.axis">
289 <xsl:with-param name="node" select="$divs[last()]"/>
290 <xsl:with-param name="axis" select="'last-descendant'"/>
291 <xsl:with-param name="depth_in_chunk" select="$depth_in_chunk"/>
292 <xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
293 </xsl:call-template>
294 </xsl:when>
295 <xsl:when test="$divs">
296 <xsl:call-template name="db.chunk.chunk-id">
297 <xsl:with-param name="node" select="$divs[last()]"/>
298 <xsl:with-param name="depth_in_chunk" select="0"/>
299 <xsl:with-param name="chunk" select="$divs[last()]"/>
300 </xsl:call-template>
301 </xsl:when>
302 <xsl:when test="$node/..">
303 <xsl:call-template name="db.chunk.chunk-id">
304 <xsl:with-param name="node" select="$node/.."/>
305 <xsl:with-param name="depth_in_chunk" select="0"/>
306 <xsl:with-param name="chunk" select="$node/.."/>
307 </xsl:call-template>
308 </xsl:when>
309 </xsl:choose>
310 </xsl:when>
311 <!-- unsupported -->
312 <xsl:otherwise>
313 <xsl:message>
314 <xsl:text>Unsupported axis: </xsl:text>
315 <xsl:value-of select="$axis"/>
316 </xsl:message>
317 </xsl:otherwise>
318 </xsl:choose>
319 </xsl:template>
320
321 </xsl:stylesheet>