Bump to docbook-xsl-stylesheets 1.79.2
[platform/upstream/docbook-xsl-stylesheets.git] / roundtrip / normalise2sections.xsl
1 <?xml version="1.0"?>
2 <axsl:stylesheet xmlns:axsl="http://www.w3.org/1999/XSL/Transform"
3                  xmlns:dbk="http://docbook.org/ns/docbook"
4                  xmlns:rnd="http://docbook.org/ns/docbook/roundtrip"
5                  version="1.0">
6 <!--====================================-->
7 <!--=                                  =-->
8 <!--=   DO NOT EDIT THIS STYLESHEET    =-->
9 <!--=                                  =-->
10 <!--= This stylesheet is generated     =-->
11 <!--= by makeSections.xsl and a        =-->
12 <!--= mapping specification.           =-->
13 <!--=                                  =-->
14 <!--====================================-->
15   <axsl:output indent="yes"/>
16   <axsl:strip-space elements="*"/>
17   <axsl:preserve-space elements="dbk:para dbk:emphasis"/>
18   <axsl:template match="dbk:article">
19     <axsl:copy>
20       <axsl:for-each select="@*">
21         <axsl:copy/>
22       </axsl:for-each>
23       <axsl:variable name="books" select="dbk:para[@rnd:style = &quot;d:book&quot; or @rnd:style = &quot;book-title&quot;]"/>
24       <axsl:variable name="toplevel-components" select="dbk:para[@rnd:style = &quot;d:article&quot; or @rnd:style = &quot;article-title&quot; or @rnd:style = &quot;d:appendix&quot; or @rnd:style = &quot;appendix-title&quot; or @rnd:style = &quot;d:chapter&quot; or @rnd:style = &quot;chapter-title&quot; or @rnd:style = &quot;d:preface&quot; or @rnd:style = &quot;preface-title&quot;]"/>
25       <axsl:choose>
26         <axsl:when test="$books">
27           <axsl:apply-templates select="$books[1]/preceding-sibling::*"/>
28           <axsl:apply-templates select="$books[1]" mode="book">
29             <axsl:with-param name="books" select="$books[position() != 1]"/>
30           </axsl:apply-templates>
31         </axsl:when>
32         <axsl:when test="$toplevel-components">
33           <axsl:apply-templates select="$toplevel-components[1]/preceding-sibling::*"/>
34           <axsl:apply-templates select="$toplevel-components[1]" mode="toplevel-component">
35             <axsl:with-param name="toplevel-components" select="$toplevel-components[position() != 1]"/>
36           </axsl:apply-templates>
37         </axsl:when>
38         <axsl:otherwise>
39           <axsl:apply-templates/>
40         </axsl:otherwise>
41       </axsl:choose>
42     </axsl:copy>
43   </axsl:template>
44   <axsl:template match="dbk:para" mode="book">
45     <axsl:param name="books" select="/.."/>
46     <axsl:choose>
47       <axsl:when test="$books and (@rnd:style = &quot;d:book&quot; or @rnd:style = &quot;book-title&quot;)">
48         <axsl:call-template name="make-book">
49           <axsl:with-param name="books" select="$books"/>
50           <axsl:with-param name="book-components" select="$books[1]/preceding-sibling::dbk:para[@rnd:style = &quot;d:part&quot; or @rnd:style = &quot;part-title&quot; or @rnd:style = &quot;d:article&quot; or @rnd:style = &quot;article-title&quot; or @rnd:style = &quot;d:appendix&quot; or @rnd:style = &quot;appendix-title&quot; or @rnd:style = &quot;d:chapter&quot; or @rnd:style = &quot;chapter-title&quot; or @rnd:style = &quot;d:preface&quot; or @rnd:style = &quot;preface-title&quot;]"/>
51         </axsl:call-template>
52       </axsl:when>
53       <axsl:otherwise>
54         <axsl:call-template name="make-book">
55           <axsl:with-param name="books" select="$books"/>
56           <axsl:with-param name="book-components" select="following-sibling::dbk:para[@rnd:style = &quot;d:part&quot; or @rnd:style = &quot;part-title&quot; or @rnd:style = &quot;d:article&quot; or @rnd:style = &quot;article-title&quot; or @rnd:style = &quot;d:appendix&quot; or @rnd:style = &quot;appendix-title&quot; or @rnd:style = &quot;d:chapter&quot; or @rnd:style = &quot;chapter-title&quot; or @rnd:style = &quot;d:preface&quot; or @rnd:style = &quot;preface-title&quot;]"/>
57         </axsl:call-template>
58       </axsl:otherwise>
59     </axsl:choose>
60   </axsl:template>
61   <axsl:template name="make-book">
62     <axsl:param name="books" select="/.."/>
63     <axsl:param name="book-components" select="/.."/>
64 <!-- mode toplevel-templates -->
65     <book xmlns="http://docbook.org/ns/docbook">
66       <axsl:call-template name="copy"/>
67       <axsl:apply-templates select="following-sibling::*[1]" mode="book-component">
68         <axsl:with-param name="nextbook" select="$books[1]"/>
69         <axsl:with-param name="book-components" select="$book-components"/>
70       </axsl:apply-templates>
71     </book>
72     <axsl:apply-templates select="$books[1]" mode="book">
73       <axsl:with-param name="books" select="$books[position() != 1]"/>
74     </axsl:apply-templates>
75   </axsl:template>
76   <axsl:template match="dbk:para" mode="toplevel-component">
77     <axsl:param name="toplevel-components" select="/.."/>
78     <axsl:choose>
79       <axsl:when test="$toplevel-components and (@rnd:style = &quot;d:article&quot; or @rnd:style = &quot;article-title&quot; or @rnd:style = &quot;d:appendix&quot; or @rnd:style = &quot;appendix-title&quot; or @rnd:style = &quot;d:chapter&quot; or @rnd:style = &quot;chapter-title&quot; or @rnd:style = &quot;d:preface&quot; or @rnd:style = &quot;preface-title&quot;)">
80         <axsl:call-template name="make-toplevel-component">
81           <axsl:with-param name="toplevel-components" select="$toplevel-components"/>
82           <axsl:with-param name="sect1s" select="$toplevel-components[1]/preceding-sibling::dbk:para[@rnd:style = &quot;d:sect1&quot; or @rnd:style = &quot;sect1-title&quot;]"/>
83         </axsl:call-template>
84       </axsl:when>
85       <axsl:otherwise>
86         <axsl:call-template name="make-toplevel-component">
87           <axsl:with-param name="toplevel-components" select="$toplevel-components"/>
88           <axsl:with-param name="sect1s" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect1&quot; or @rnd:style = &quot;sect1-title&quot;]"/>
89         </axsl:call-template>
90       </axsl:otherwise>
91     </axsl:choose>
92   </axsl:template>
93   <axsl:template name="make-toplevel-component">
94     <axsl:param name="toplevel-components" select="/.."/>
95     <axsl:param name="sect1s" select="/.."/>
96 <!-- mode toplevel-templates: group:level - do not create element -->
97     <axsl:call-template name="copy"/>
98     <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect1">
99       <axsl:with-param name="nexttoplevel-component" select="$toplevel-components[1]"/>
100       <axsl:with-param name="sect1s" select="$sect1s"/>
101     </axsl:apply-templates>
102     <axsl:apply-templates select="$toplevel-components[1]" mode="toplevel-component">
103       <axsl:with-param name="toplevel-components" select="$toplevel-components[position() != 1]"/>
104     </axsl:apply-templates>
105   </axsl:template>
106   <axsl:template match="dbk:para" mode="book-component">
107     <axsl:param name="nextbook" select="/.."/>
108     <axsl:param select="/.." name="book-components"/>
109     <axsl:choose>
110       <axsl:when test="generate-id() = generate-id($nextbook)"/>
111       <axsl:when test="@rnd:style = &quot;d:part&quot; or @rnd:style = &quot;part-title&quot; or @rnd:style = &quot;d:article&quot; or @rnd:style = &quot;article-title&quot; or @rnd:style = &quot;d:appendix&quot; or @rnd:style = &quot;appendix-title&quot; or @rnd:style = &quot;d:chapter&quot; or @rnd:style = &quot;chapter-title&quot; or @rnd:style = &quot;d:preface&quot; or @rnd:style = &quot;preface-title&quot;">
112         <axsl:variable name="nextbook-component" select="following-sibling::dbk:para[@rnd:style = &quot;d:part&quot; or @rnd:style = &quot;part-title&quot; or @rnd:style = &quot;d:article&quot; or @rnd:style = &quot;article-title&quot; or @rnd:style = &quot;d:appendix&quot; or @rnd:style = &quot;appendix-title&quot; or @rnd:style = &quot;d:chapter&quot; or @rnd:style = &quot;chapter-title&quot; or @rnd:style = &quot;d:preface&quot; or @rnd:style = &quot;preface-title&quot;][1]"/>
113         <axsl:choose>
114           <axsl:when test="$nextbook-component">
115             <axsl:variable name="sect1s" select="$nextbook-component/preceding-sibling::dbk:para[@rnd:style = &quot;d:sect1&quot; or @rnd:style = &quot;sect1-title&quot;]"/>
116 <!-- mode sections 1 -->
117             <book-component xmlns="http://docbook.org/ns/docbook">
118               <axsl:call-template name="copy"/>
119               <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect1">
120                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
121                 <axsl:with-param name="nextbook" select="$nextbook"/>
122                 <axsl:with-param name="sect1s" select="$sect1s"/>
123                 <axsl:with-param name="book-components" select="$book-components"/>
124               </axsl:apply-templates>
125             </book-component>
126             <axsl:if test="count($book-components|$nextbook-component) = count($book-components)">
127               <axsl:apply-templates select="$nextbook-component" mode="book-component">
128                 <axsl:with-param name="nextbook" select="$nextbook"/>
129                 <axsl:with-param name="book-components" select="$book-components"/>
130               </axsl:apply-templates>
131             </axsl:if>
132           </axsl:when>
133           <axsl:otherwise>
134             <axsl:variable name="sect1s" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect1&quot; or @rnd:style = &quot;sect1-title&quot;]"/>
135 <!-- mode sections 2 -->
136             <book-component xmlns="http://docbook.org/ns/docbook">
137               <axsl:call-template name="copy"/>
138               <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect1">
139                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
140                 <axsl:with-param name="nextbook" select="$nextbook"/>
141                 <axsl:with-param name="sect1s" select="$sect1s"/>
142                 <axsl:with-param name="book-components" select="$book-components"/>
143               </axsl:apply-templates>
144             </book-component>
145             <axsl:if test="count($book-components|$nextbook-component) = count($book-components)">
146               <axsl:apply-templates select="$nextbook-component" mode="book-component">
147                 <axsl:with-param name="nextbook" select="$nextbook"/>
148                 <axsl:with-param name="book-components" select="$book-components"/>
149               </axsl:apply-templates>
150             </axsl:if>
151           </axsl:otherwise>
152         </axsl:choose>
153       </axsl:when>
154       <axsl:otherwise>
155         <axsl:call-template name="copy"/>
156         <axsl:apply-templates select="following-sibling::*[1]" mode="book-component">
157           <axsl:with-param name="nextbook" select="$nextbook"/>
158           <axsl:with-param name="book-components" select="$book-components"/>
159         </axsl:apply-templates>
160       </axsl:otherwise>
161     </axsl:choose>
162   </axsl:template>
163   <axsl:template match="dbk:para" mode="book-sect1">
164     <axsl:param name="nextbook-component" select="/.."/>
165     <axsl:param name="nextbook" select="/.."/>
166     <axsl:param select="/.." name="sect1s"/>
167     <axsl:param select="/.." name="book-components"/>
168     <axsl:choose>
169       <axsl:when test="generate-id() = generate-id($nextbook-component)"/>
170       <axsl:when test="generate-id() = generate-id($nextbook)"/>
171       <axsl:when test="@rnd:style = &quot;d:sect1&quot; or @rnd:style = &quot;sect1-title&quot;">
172         <axsl:variable name="nextsect1" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect1&quot; or @rnd:style = &quot;sect1-title&quot;][1]"/>
173         <axsl:choose>
174           <axsl:when test="$nextsect1">
175             <axsl:variable name="sect2s" select="$nextsect1/preceding-sibling::dbk:para[@rnd:style = &quot;d:sect2&quot; or @rnd:style = &quot;sect2-title&quot;]"/>
176 <!-- mode sections 1 -->
177             <sect1 xmlns="http://docbook.org/ns/docbook">
178               <axsl:call-template name="copy"/>
179               <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect2">
180                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
181                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
182                 <axsl:with-param name="nextbook" select="$nextbook"/>
183                 <axsl:with-param name="sect2s" select="$sect2s"/>
184                 <axsl:with-param name="sect1s" select="$sect1s"/>
185                 <axsl:with-param name="book-components" select="$book-components"/>
186               </axsl:apply-templates>
187             </sect1>
188             <axsl:if test="$nextsect1 and (not($book-components) or count($sect1s|$nextsect1) = count($sect1s))">
189               <axsl:apply-templates select="$nextsect1" mode="book-sect1">
190                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
191                 <axsl:with-param name="nextbook" select="$nextbook"/>
192                 <axsl:with-param name="sect1s" select="$sect1s"/>
193                 <axsl:with-param name="book-components" select="$book-components"/>
194               </axsl:apply-templates>
195             </axsl:if>
196           </axsl:when>
197           <axsl:otherwise>
198             <axsl:variable name="sect2s" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect2&quot; or @rnd:style = &quot;sect2-title&quot;]"/>
199 <!-- mode sections 2 -->
200             <sect1 xmlns="http://docbook.org/ns/docbook">
201               <axsl:call-template name="copy"/>
202               <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect2">
203                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
204                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
205                 <axsl:with-param name="nextbook" select="$nextbook"/>
206                 <axsl:with-param name="sect2s" select="$sect2s"/>
207                 <axsl:with-param name="sect1s" select="$sect1s"/>
208                 <axsl:with-param name="book-components" select="$book-components"/>
209               </axsl:apply-templates>
210             </sect1>
211             <axsl:if test="$nextsect1 and (not($book-components) or count($sect1s|$nextsect1) = count($sect1s))">
212               <axsl:apply-templates select="$nextsect1" mode="book-sect1">
213                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
214                 <axsl:with-param name="nextbook" select="$nextbook"/>
215                 <axsl:with-param name="sect1s" select="$sect1s"/>
216                 <axsl:with-param name="book-components" select="$book-components"/>
217               </axsl:apply-templates>
218             </axsl:if>
219           </axsl:otherwise>
220         </axsl:choose>
221       </axsl:when>
222       <axsl:otherwise>
223         <axsl:call-template name="copy"/>
224         <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect1">
225           <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
226           <axsl:with-param name="nextbook" select="$nextbook"/>
227           <axsl:with-param name="sect1s" select="$sect1s"/>
228           <axsl:with-param name="book-components" select="$book-components"/>
229         </axsl:apply-templates>
230       </axsl:otherwise>
231     </axsl:choose>
232   </axsl:template>
233   <axsl:template match="dbk:para" mode="book-sect2">
234     <axsl:param name="nextsect1" select="/.."/>
235     <axsl:param name="nextbook-component" select="/.."/>
236     <axsl:param name="nextbook" select="/.."/>
237     <axsl:param select="/.." name="sect2s"/>
238     <axsl:param select="/.." name="sect1s"/>
239     <axsl:param select="/.." name="book-components"/>
240     <axsl:choose>
241       <axsl:when test="generate-id() = generate-id($nextsect1)"/>
242       <axsl:when test="generate-id() = generate-id($nextbook-component)"/>
243       <axsl:when test="generate-id() = generate-id($nextbook)"/>
244       <axsl:when test="@rnd:style = &quot;d:sect2&quot; or @rnd:style = &quot;sect2-title&quot;">
245         <axsl:variable name="nextsect2" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect2&quot; or @rnd:style = &quot;sect2-title&quot;][1]"/>
246         <axsl:choose>
247           <axsl:when test="$nextsect2">
248             <axsl:variable name="sect3s" select="$nextsect2/preceding-sibling::dbk:para[@rnd:style = &quot;d:sect3&quot; or @rnd:style = &quot;sect3-title&quot;]"/>
249 <!-- mode sections 1 -->
250             <sect2 xmlns="http://docbook.org/ns/docbook">
251               <axsl:call-template name="copy"/>
252               <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect3">
253                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
254                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
255                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
256                 <axsl:with-param name="nextbook" select="$nextbook"/>
257                 <axsl:with-param name="sect3s" select="$sect3s"/>
258                 <axsl:with-param name="sect2s" select="$sect2s"/>
259                 <axsl:with-param name="sect1s" select="$sect1s"/>
260                 <axsl:with-param name="book-components" select="$book-components"/>
261               </axsl:apply-templates>
262             </sect2>
263             <axsl:if test="$nextsect2 and (not($sect1s) or count($sect2s|$nextsect2) = count($sect2s))">
264               <axsl:apply-templates select="$nextsect2" mode="book-sect2">
265                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
266                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
267                 <axsl:with-param name="nextbook" select="$nextbook"/>
268                 <axsl:with-param name="sect2s" select="$sect2s"/>
269                 <axsl:with-param name="sect1s" select="$sect1s"/>
270                 <axsl:with-param name="book-components" select="$book-components"/>
271               </axsl:apply-templates>
272             </axsl:if>
273           </axsl:when>
274           <axsl:otherwise>
275             <axsl:variable name="sect3s" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect3&quot; or @rnd:style = &quot;sect3-title&quot;]"/>
276 <!-- mode sections 2 -->
277             <sect2 xmlns="http://docbook.org/ns/docbook">
278               <axsl:call-template name="copy"/>
279               <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect3">
280                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
281                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
282                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
283                 <axsl:with-param name="nextbook" select="$nextbook"/>
284                 <axsl:with-param name="sect3s" select="$sect3s"/>
285                 <axsl:with-param name="sect2s" select="$sect2s"/>
286                 <axsl:with-param name="sect1s" select="$sect1s"/>
287                 <axsl:with-param name="book-components" select="$book-components"/>
288               </axsl:apply-templates>
289             </sect2>
290             <axsl:if test="$nextsect2 and (not($sect1s) or count($sect2s|$nextsect2) = count($sect2s))">
291               <axsl:apply-templates select="$nextsect2" mode="book-sect2">
292                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
293                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
294                 <axsl:with-param name="nextbook" select="$nextbook"/>
295                 <axsl:with-param name="sect2s" select="$sect2s"/>
296                 <axsl:with-param name="sect1s" select="$sect1s"/>
297                 <axsl:with-param name="book-components" select="$book-components"/>
298               </axsl:apply-templates>
299             </axsl:if>
300           </axsl:otherwise>
301         </axsl:choose>
302       </axsl:when>
303       <axsl:otherwise>
304         <axsl:call-template name="copy"/>
305         <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect2">
306           <axsl:with-param name="nextsect1" select="$nextsect1"/>
307           <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
308           <axsl:with-param name="nextbook" select="$nextbook"/>
309           <axsl:with-param name="sect2s" select="$sect2s"/>
310           <axsl:with-param name="sect1s" select="$sect1s"/>
311           <axsl:with-param name="book-components" select="$book-components"/>
312         </axsl:apply-templates>
313       </axsl:otherwise>
314     </axsl:choose>
315   </axsl:template>
316   <axsl:template match="dbk:para" mode="book-sect3">
317     <axsl:param name="nextsect2" select="/.."/>
318     <axsl:param name="nextsect1" select="/.."/>
319     <axsl:param name="nextbook-component" select="/.."/>
320     <axsl:param name="nextbook" select="/.."/>
321     <axsl:param select="/.." name="sect3s"/>
322     <axsl:param select="/.." name="sect2s"/>
323     <axsl:param select="/.." name="sect1s"/>
324     <axsl:param select="/.." name="book-components"/>
325     <axsl:choose>
326       <axsl:when test="generate-id() = generate-id($nextsect2)"/>
327       <axsl:when test="generate-id() = generate-id($nextsect1)"/>
328       <axsl:when test="generate-id() = generate-id($nextbook-component)"/>
329       <axsl:when test="generate-id() = generate-id($nextbook)"/>
330       <axsl:when test="@rnd:style = &quot;d:sect3&quot; or @rnd:style = &quot;sect3-title&quot;">
331         <axsl:variable name="nextsect3" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect3&quot; or @rnd:style = &quot;sect3-title&quot;][1]"/>
332         <axsl:choose>
333           <axsl:when test="$nextsect3">
334             <axsl:variable name="sect4s" select="$nextsect3/preceding-sibling::dbk:para[@rnd:style = &quot;d:sect4&quot; or @rnd:style = &quot;sect4-title&quot;]"/>
335 <!-- mode sections 1 -->
336             <sect3 xmlns="http://docbook.org/ns/docbook">
337               <axsl:call-template name="copy"/>
338               <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect4">
339                 <axsl:with-param name="nextsect3" select="$nextsect3"/>
340                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
341                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
342                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
343                 <axsl:with-param name="nextbook" select="$nextbook"/>
344                 <axsl:with-param name="sect4s" select="$sect4s"/>
345                 <axsl:with-param name="sect3s" select="$sect3s"/>
346                 <axsl:with-param name="sect2s" select="$sect2s"/>
347                 <axsl:with-param name="sect1s" select="$sect1s"/>
348                 <axsl:with-param name="book-components" select="$book-components"/>
349               </axsl:apply-templates>
350             </sect3>
351             <axsl:if test="$nextsect3 and (not($sect2s) or count($sect3s|$nextsect3) = count($sect3s))">
352               <axsl:apply-templates select="$nextsect3" mode="book-sect3">
353                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
354                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
355                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
356                 <axsl:with-param name="nextbook" select="$nextbook"/>
357                 <axsl:with-param name="sect3s" select="$sect3s"/>
358                 <axsl:with-param name="sect2s" select="$sect2s"/>
359                 <axsl:with-param name="sect1s" select="$sect1s"/>
360                 <axsl:with-param name="book-components" select="$book-components"/>
361               </axsl:apply-templates>
362             </axsl:if>
363           </axsl:when>
364           <axsl:otherwise>
365             <axsl:variable name="sect4s" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect4&quot; or @rnd:style = &quot;sect4-title&quot;]"/>
366 <!-- mode sections 2 -->
367             <sect3 xmlns="http://docbook.org/ns/docbook">
368               <axsl:call-template name="copy"/>
369               <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect4">
370                 <axsl:with-param name="nextsect3" select="$nextsect3"/>
371                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
372                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
373                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
374                 <axsl:with-param name="nextbook" select="$nextbook"/>
375                 <axsl:with-param name="sect4s" select="$sect4s"/>
376                 <axsl:with-param name="sect3s" select="$sect3s"/>
377                 <axsl:with-param name="sect2s" select="$sect2s"/>
378                 <axsl:with-param name="sect1s" select="$sect1s"/>
379                 <axsl:with-param name="book-components" select="$book-components"/>
380               </axsl:apply-templates>
381             </sect3>
382             <axsl:if test="$nextsect3 and (not($sect2s) or count($sect3s|$nextsect3) = count($sect3s))">
383               <axsl:apply-templates select="$nextsect3" mode="book-sect3">
384                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
385                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
386                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
387                 <axsl:with-param name="nextbook" select="$nextbook"/>
388                 <axsl:with-param name="sect3s" select="$sect3s"/>
389                 <axsl:with-param name="sect2s" select="$sect2s"/>
390                 <axsl:with-param name="sect1s" select="$sect1s"/>
391                 <axsl:with-param name="book-components" select="$book-components"/>
392               </axsl:apply-templates>
393             </axsl:if>
394           </axsl:otherwise>
395         </axsl:choose>
396       </axsl:when>
397       <axsl:otherwise>
398         <axsl:call-template name="copy"/>
399         <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect3">
400           <axsl:with-param name="nextsect2" select="$nextsect2"/>
401           <axsl:with-param name="nextsect1" select="$nextsect1"/>
402           <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
403           <axsl:with-param name="nextbook" select="$nextbook"/>
404           <axsl:with-param name="sect3s" select="$sect3s"/>
405           <axsl:with-param name="sect2s" select="$sect2s"/>
406           <axsl:with-param name="sect1s" select="$sect1s"/>
407           <axsl:with-param name="book-components" select="$book-components"/>
408         </axsl:apply-templates>
409       </axsl:otherwise>
410     </axsl:choose>
411   </axsl:template>
412   <axsl:template match="dbk:para" mode="book-sect4">
413     <axsl:param name="nextsect3" select="/.."/>
414     <axsl:param name="nextsect2" select="/.."/>
415     <axsl:param name="nextsect1" select="/.."/>
416     <axsl:param name="nextbook-component" select="/.."/>
417     <axsl:param name="nextbook" select="/.."/>
418     <axsl:param select="/.." name="sect4s"/>
419     <axsl:param select="/.." name="sect3s"/>
420     <axsl:param select="/.." name="sect2s"/>
421     <axsl:param select="/.." name="sect1s"/>
422     <axsl:param select="/.." name="book-components"/>
423     <axsl:choose>
424       <axsl:when test="generate-id() = generate-id($nextsect3)"/>
425       <axsl:when test="generate-id() = generate-id($nextsect2)"/>
426       <axsl:when test="generate-id() = generate-id($nextsect1)"/>
427       <axsl:when test="generate-id() = generate-id($nextbook-component)"/>
428       <axsl:when test="generate-id() = generate-id($nextbook)"/>
429       <axsl:when test="@rnd:style = &quot;d:sect4&quot; or @rnd:style = &quot;sect4-title&quot;">
430         <axsl:variable name="nextsect4" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect4&quot; or @rnd:style = &quot;sect4-title&quot;][1]"/>
431         <axsl:choose>
432           <axsl:when test="$nextsect4">
433             <axsl:variable name="sect5s" select="$nextsect4/preceding-sibling::dbk:para[@rnd:style = &quot;d:sect5&quot; or @rnd:style = &quot;sect5-title&quot;]"/>
434 <!-- mode sections 1 -->
435             <sect4 xmlns="http://docbook.org/ns/docbook">
436               <axsl:call-template name="copy"/>
437               <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect5">
438                 <axsl:with-param name="nextsect4" select="$nextsect4"/>
439                 <axsl:with-param name="nextsect3" select="$nextsect3"/>
440                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
441                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
442                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
443                 <axsl:with-param name="nextbook" select="$nextbook"/>
444                 <axsl:with-param name="sect5s" select="$sect5s"/>
445                 <axsl:with-param name="sect4s" select="$sect4s"/>
446                 <axsl:with-param name="sect3s" select="$sect3s"/>
447                 <axsl:with-param name="sect2s" select="$sect2s"/>
448                 <axsl:with-param name="sect1s" select="$sect1s"/>
449                 <axsl:with-param name="book-components" select="$book-components"/>
450               </axsl:apply-templates>
451             </sect4>
452             <axsl:if test="$nextsect4 and (not($sect3s) or count($sect4s|$nextsect4) = count($sect4s))">
453               <axsl:apply-templates select="$nextsect4" mode="book-sect4">
454                 <axsl:with-param name="nextsect3" select="$nextsect3"/>
455                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
456                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
457                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
458                 <axsl:with-param name="nextbook" select="$nextbook"/>
459                 <axsl:with-param name="sect4s" select="$sect4s"/>
460                 <axsl:with-param name="sect3s" select="$sect3s"/>
461                 <axsl:with-param name="sect2s" select="$sect2s"/>
462                 <axsl:with-param name="sect1s" select="$sect1s"/>
463                 <axsl:with-param name="book-components" select="$book-components"/>
464               </axsl:apply-templates>
465             </axsl:if>
466           </axsl:when>
467           <axsl:otherwise>
468             <axsl:variable name="sect5s" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect5&quot; or @rnd:style = &quot;sect5-title&quot;]"/>
469 <!-- mode sections 2 -->
470             <sect4 xmlns="http://docbook.org/ns/docbook">
471               <axsl:call-template name="copy"/>
472               <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect5">
473                 <axsl:with-param name="nextsect4" select="$nextsect4"/>
474                 <axsl:with-param name="nextsect3" select="$nextsect3"/>
475                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
476                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
477                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
478                 <axsl:with-param name="nextbook" select="$nextbook"/>
479                 <axsl:with-param name="sect5s" select="$sect5s"/>
480                 <axsl:with-param name="sect4s" select="$sect4s"/>
481                 <axsl:with-param name="sect3s" select="$sect3s"/>
482                 <axsl:with-param name="sect2s" select="$sect2s"/>
483                 <axsl:with-param name="sect1s" select="$sect1s"/>
484                 <axsl:with-param name="book-components" select="$book-components"/>
485               </axsl:apply-templates>
486             </sect4>
487             <axsl:if test="$nextsect4 and (not($sect3s) or count($sect4s|$nextsect4) = count($sect4s))">
488               <axsl:apply-templates select="$nextsect4" mode="book-sect4">
489                 <axsl:with-param name="nextsect3" select="$nextsect3"/>
490                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
491                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
492                 <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
493                 <axsl:with-param name="nextbook" select="$nextbook"/>
494                 <axsl:with-param name="sect4s" select="$sect4s"/>
495                 <axsl:with-param name="sect3s" select="$sect3s"/>
496                 <axsl:with-param name="sect2s" select="$sect2s"/>
497                 <axsl:with-param name="sect1s" select="$sect1s"/>
498                 <axsl:with-param name="book-components" select="$book-components"/>
499               </axsl:apply-templates>
500             </axsl:if>
501           </axsl:otherwise>
502         </axsl:choose>
503       </axsl:when>
504       <axsl:otherwise>
505         <axsl:call-template name="copy"/>
506         <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect4">
507           <axsl:with-param name="nextsect3" select="$nextsect3"/>
508           <axsl:with-param name="nextsect2" select="$nextsect2"/>
509           <axsl:with-param name="nextsect1" select="$nextsect1"/>
510           <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
511           <axsl:with-param name="nextbook" select="$nextbook"/>
512           <axsl:with-param name="sect4s" select="$sect4s"/>
513           <axsl:with-param name="sect3s" select="$sect3s"/>
514           <axsl:with-param name="sect2s" select="$sect2s"/>
515           <axsl:with-param name="sect1s" select="$sect1s"/>
516           <axsl:with-param name="book-components" select="$book-components"/>
517         </axsl:apply-templates>
518       </axsl:otherwise>
519     </axsl:choose>
520   </axsl:template>
521   <axsl:template match="dbk:para" mode="book-sect5">
522     <axsl:param name="nextsect4" select="/.."/>
523     <axsl:param name="nextsect3" select="/.."/>
524     <axsl:param name="nextsect2" select="/.."/>
525     <axsl:param name="nextsect1" select="/.."/>
526     <axsl:param name="nextbook-component" select="/.."/>
527     <axsl:param name="nextbook" select="/.."/>
528     <axsl:param select="/.." name="sect5s"/>
529     <axsl:param select="/.." name="sect4s"/>
530     <axsl:param select="/.." name="sect3s"/>
531     <axsl:param select="/.." name="sect2s"/>
532     <axsl:param select="/.." name="sect1s"/>
533     <axsl:param select="/.." name="book-components"/>
534     <axsl:choose>
535       <axsl:when test="generate-id() = generate-id($nextsect4)"/>
536       <axsl:when test="generate-id() = generate-id($nextsect3)"/>
537       <axsl:when test="generate-id() = generate-id($nextsect2)"/>
538       <axsl:when test="generate-id() = generate-id($nextsect1)"/>
539       <axsl:when test="generate-id() = generate-id($nextbook-component)"/>
540       <axsl:when test="generate-id() = generate-id($nextbook)"/>
541       <axsl:when test="@rnd:style = &quot;d:sect5&quot; or @rnd:style = &quot;sect5-title&quot;">
542         <axsl:variable name="nextsect5" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect5&quot; or @rnd:style = &quot;sect5-title&quot;][1]"/>
543 <!-- mode sections 3 -->
544         <sect5 xmlns="http://docbook.org/ns/docbook">
545           <axsl:call-template name="copy"/>
546           <axsl:apply-templates select="following-sibling::*[1]" mode="book-terminal">
547             <axsl:with-param name="nextsect5" select="$nextsect5"/>
548             <axsl:with-param name="nextsect4" select="$nextsect4"/>
549             <axsl:with-param name="nextsect3" select="$nextsect3"/>
550             <axsl:with-param name="nextsect2" select="$nextsect2"/>
551             <axsl:with-param name="nextsect1" select="$nextsect1"/>
552             <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
553             <axsl:with-param name="nextbook" select="$nextbook"/>
554             <axsl:with-param name="sect5s" select="$sect5s"/>
555             <axsl:with-param name="sect4s" select="$sect4s"/>
556             <axsl:with-param name="sect3s" select="$sect3s"/>
557             <axsl:with-param name="sect2s" select="$sect2s"/>
558             <axsl:with-param name="sect1s" select="$sect1s"/>
559             <axsl:with-param name="book-components" select="$book-components"/>
560           </axsl:apply-templates>
561         </sect5>
562         <axsl:if test="$nextsect5 and (not($sect4s) or count($sect5s|$nextsect5) = count($sect5s))">
563           <axsl:apply-templates select="$nextsect5" mode="book-sect5">
564             <axsl:with-param name="nextsect4" select="$nextsect4"/>
565             <axsl:with-param name="nextsect3" select="$nextsect3"/>
566             <axsl:with-param name="nextsect2" select="$nextsect2"/>
567             <axsl:with-param name="nextsect1" select="$nextsect1"/>
568             <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
569             <axsl:with-param name="nextbook" select="$nextbook"/>
570             <axsl:with-param name="sect5s" select="$sect5s"/>
571             <axsl:with-param name="sect4s" select="$sect4s"/>
572             <axsl:with-param name="sect3s" select="$sect3s"/>
573             <axsl:with-param name="sect2s" select="$sect2s"/>
574             <axsl:with-param name="sect1s" select="$sect1s"/>
575             <axsl:with-param name="book-components" select="$book-components"/>
576           </axsl:apply-templates>
577         </axsl:if>
578       </axsl:when>
579       <axsl:otherwise>
580         <axsl:call-template name="copy"/>
581         <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect5">
582           <axsl:with-param name="nextsect4" select="$nextsect4"/>
583           <axsl:with-param name="nextsect3" select="$nextsect3"/>
584           <axsl:with-param name="nextsect2" select="$nextsect2"/>
585           <axsl:with-param name="nextsect1" select="$nextsect1"/>
586           <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
587           <axsl:with-param name="nextbook" select="$nextbook"/>
588           <axsl:with-param name="sect5s" select="$sect5s"/>
589           <axsl:with-param name="sect4s" select="$sect4s"/>
590           <axsl:with-param name="sect3s" select="$sect3s"/>
591           <axsl:with-param name="sect2s" select="$sect2s"/>
592           <axsl:with-param name="sect1s" select="$sect1s"/>
593           <axsl:with-param name="book-components" select="$book-components"/>
594         </axsl:apply-templates>
595       </axsl:otherwise>
596     </axsl:choose>
597   </axsl:template>
598   <axsl:template match="dbk:para" mode="toplevel-sect1">
599     <axsl:param name="nexttoplevel-component" select="/.."/>
600     <axsl:param select="/.." name="sect1s"/>
601     <axsl:choose>
602       <axsl:when test="generate-id() = generate-id($nexttoplevel-component)"/>
603       <axsl:when test="@rnd:style = &quot;d:sect1&quot; or @rnd:style = &quot;sect1-title&quot;">
604         <axsl:variable name="nextsect1" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect1&quot; or @rnd:style = &quot;sect1-title&quot;][1]"/>
605         <axsl:choose>
606           <axsl:when test="$nextsect1">
607             <axsl:variable name="sect2s" select="$nextsect1/preceding-sibling::dbk:para[@rnd:style = &quot;d:sect2&quot; or @rnd:style = &quot;sect2-title&quot;]"/>
608 <!-- mode sections 1 -->
609             <sect1 xmlns="http://docbook.org/ns/docbook">
610               <axsl:call-template name="copy"/>
611               <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect2">
612                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
613                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
614                 <axsl:with-param name="sect2s" select="$sect2s"/>
615                 <axsl:with-param name="sect1s" select="$sect1s"/>
616               </axsl:apply-templates>
617             </sect1>
618             <axsl:if test="count($sect1s|$nextsect1) = count($sect1s)">
619               <axsl:apply-templates select="$nextsect1" mode="toplevel-sect1">
620                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
621                 <axsl:with-param name="sect1s" select="$sect1s"/>
622               </axsl:apply-templates>
623             </axsl:if>
624           </axsl:when>
625           <axsl:otherwise>
626             <axsl:variable name="sect2s" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect2&quot; or @rnd:style = &quot;sect2-title&quot;]"/>
627 <!-- mode sections 2 -->
628             <sect1 xmlns="http://docbook.org/ns/docbook">
629               <axsl:call-template name="copy"/>
630               <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect2">
631                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
632                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
633                 <axsl:with-param name="sect2s" select="$sect2s"/>
634                 <axsl:with-param name="sect1s" select="$sect1s"/>
635               </axsl:apply-templates>
636             </sect1>
637             <axsl:if test="count($sect1s|$nextsect1) = count($sect1s)">
638               <axsl:apply-templates select="$nextsect1" mode="toplevel-sect1">
639                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
640                 <axsl:with-param name="sect1s" select="$sect1s"/>
641               </axsl:apply-templates>
642             </axsl:if>
643           </axsl:otherwise>
644         </axsl:choose>
645       </axsl:when>
646       <axsl:otherwise>
647         <axsl:call-template name="copy"/>
648         <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect1">
649           <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
650           <axsl:with-param name="sect1s" select="$sect1s"/>
651         </axsl:apply-templates>
652       </axsl:otherwise>
653     </axsl:choose>
654   </axsl:template>
655   <axsl:template match="dbk:para" mode="toplevel-sect2">
656     <axsl:param name="nextsect1" select="/.."/>
657     <axsl:param name="nexttoplevel-component" select="/.."/>
658     <axsl:param select="/.." name="sect2s"/>
659     <axsl:param select="/.." name="sect1s"/>
660     <axsl:choose>
661       <axsl:when test="generate-id() = generate-id($nextsect1)"/>
662       <axsl:when test="generate-id() = generate-id($nexttoplevel-component)"/>
663       <axsl:when test="@rnd:style = &quot;d:sect2&quot; or @rnd:style = &quot;sect2-title&quot;">
664         <axsl:variable name="nextsect2" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect2&quot; or @rnd:style = &quot;sect2-title&quot;][1]"/>
665         <axsl:choose>
666           <axsl:when test="$nextsect2">
667             <axsl:variable name="sect3s" select="$nextsect2/preceding-sibling::dbk:para[@rnd:style = &quot;d:sect3&quot; or @rnd:style = &quot;sect3-title&quot;]"/>
668 <!-- mode sections 1 -->
669             <sect2 xmlns="http://docbook.org/ns/docbook">
670               <axsl:call-template name="copy"/>
671               <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect3">
672                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
673                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
674                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
675                 <axsl:with-param name="sect3s" select="$sect3s"/>
676                 <axsl:with-param name="sect2s" select="$sect2s"/>
677                 <axsl:with-param name="sect1s" select="$sect1s"/>
678               </axsl:apply-templates>
679             </sect2>
680             <axsl:if test="$nextsect2 and (not($sect1s) or count($sect2s|$nextsect2) = count($sect2s))">
681               <axsl:apply-templates select="$nextsect2" mode="toplevel-sect2">
682                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
683                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
684                 <axsl:with-param name="sect2s" select="$sect2s"/>
685                 <axsl:with-param name="sect1s" select="$sect1s"/>
686               </axsl:apply-templates>
687             </axsl:if>
688           </axsl:when>
689           <axsl:otherwise>
690             <axsl:variable name="sect3s" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect3&quot; or @rnd:style = &quot;sect3-title&quot;]"/>
691 <!-- mode sections 2 -->
692             <sect2 xmlns="http://docbook.org/ns/docbook">
693               <axsl:call-template name="copy"/>
694               <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect3">
695                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
696                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
697                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
698                 <axsl:with-param name="sect3s" select="$sect3s"/>
699                 <axsl:with-param name="sect2s" select="$sect2s"/>
700                 <axsl:with-param name="sect1s" select="$sect1s"/>
701               </axsl:apply-templates>
702             </sect2>
703             <axsl:if test="$nextsect2 and (not($sect1s) or count($sect2s|$nextsect2) = count($sect2s))">
704               <axsl:apply-templates select="$nextsect2" mode="toplevel-sect2">
705                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
706                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
707                 <axsl:with-param name="sect2s" select="$sect2s"/>
708                 <axsl:with-param name="sect1s" select="$sect1s"/>
709               </axsl:apply-templates>
710             </axsl:if>
711           </axsl:otherwise>
712         </axsl:choose>
713       </axsl:when>
714       <axsl:otherwise>
715         <axsl:call-template name="copy"/>
716         <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect2">
717           <axsl:with-param name="nextsect1" select="$nextsect1"/>
718           <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
719           <axsl:with-param name="sect2s" select="$sect2s"/>
720           <axsl:with-param name="sect1s" select="$sect1s"/>
721         </axsl:apply-templates>
722       </axsl:otherwise>
723     </axsl:choose>
724   </axsl:template>
725   <axsl:template match="dbk:para" mode="toplevel-sect3">
726     <axsl:param name="nextsect2" select="/.."/>
727     <axsl:param name="nextsect1" select="/.."/>
728     <axsl:param name="nexttoplevel-component" select="/.."/>
729     <axsl:param select="/.." name="sect3s"/>
730     <axsl:param select="/.." name="sect2s"/>
731     <axsl:param select="/.." name="sect1s"/>
732     <axsl:choose>
733       <axsl:when test="generate-id() = generate-id($nextsect2)"/>
734       <axsl:when test="generate-id() = generate-id($nextsect1)"/>
735       <axsl:when test="generate-id() = generate-id($nexttoplevel-component)"/>
736       <axsl:when test="@rnd:style = &quot;d:sect3&quot; or @rnd:style = &quot;sect3-title&quot;">
737         <axsl:variable name="nextsect3" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect3&quot; or @rnd:style = &quot;sect3-title&quot;][1]"/>
738         <axsl:choose>
739           <axsl:when test="$nextsect3">
740             <axsl:variable name="sect4s" select="$nextsect3/preceding-sibling::dbk:para[@rnd:style = &quot;d:sect4&quot; or @rnd:style = &quot;sect4-title&quot;]"/>
741 <!-- mode sections 1 -->
742             <sect3 xmlns="http://docbook.org/ns/docbook">
743               <axsl:call-template name="copy"/>
744               <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect4">
745                 <axsl:with-param name="nextsect3" select="$nextsect3"/>
746                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
747                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
748                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
749                 <axsl:with-param name="sect4s" select="$sect4s"/>
750                 <axsl:with-param name="sect3s" select="$sect3s"/>
751                 <axsl:with-param name="sect2s" select="$sect2s"/>
752                 <axsl:with-param name="sect1s" select="$sect1s"/>
753               </axsl:apply-templates>
754             </sect3>
755             <axsl:if test="$nextsect3 and (not($sect2s) or count($sect3s|$nextsect3) = count($sect3s))">
756               <axsl:apply-templates select="$nextsect3" mode="toplevel-sect3">
757                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
758                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
759                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
760                 <axsl:with-param name="sect3s" select="$sect3s"/>
761                 <axsl:with-param name="sect2s" select="$sect2s"/>
762                 <axsl:with-param name="sect1s" select="$sect1s"/>
763               </axsl:apply-templates>
764             </axsl:if>
765           </axsl:when>
766           <axsl:otherwise>
767             <axsl:variable name="sect4s" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect4&quot; or @rnd:style = &quot;sect4-title&quot;]"/>
768 <!-- mode sections 2 -->
769             <sect3 xmlns="http://docbook.org/ns/docbook">
770               <axsl:call-template name="copy"/>
771               <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect4">
772                 <axsl:with-param name="nextsect3" select="$nextsect3"/>
773                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
774                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
775                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
776                 <axsl:with-param name="sect4s" select="$sect4s"/>
777                 <axsl:with-param name="sect3s" select="$sect3s"/>
778                 <axsl:with-param name="sect2s" select="$sect2s"/>
779                 <axsl:with-param name="sect1s" select="$sect1s"/>
780               </axsl:apply-templates>
781             </sect3>
782             <axsl:if test="$nextsect3 and (not($sect2s) or count($sect3s|$nextsect3) = count($sect3s))">
783               <axsl:apply-templates select="$nextsect3" mode="toplevel-sect3">
784                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
785                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
786                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
787                 <axsl:with-param name="sect3s" select="$sect3s"/>
788                 <axsl:with-param name="sect2s" select="$sect2s"/>
789                 <axsl:with-param name="sect1s" select="$sect1s"/>
790               </axsl:apply-templates>
791             </axsl:if>
792           </axsl:otherwise>
793         </axsl:choose>
794       </axsl:when>
795       <axsl:otherwise>
796         <axsl:call-template name="copy"/>
797         <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect3">
798           <axsl:with-param name="nextsect2" select="$nextsect2"/>
799           <axsl:with-param name="nextsect1" select="$nextsect1"/>
800           <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
801           <axsl:with-param name="sect3s" select="$sect3s"/>
802           <axsl:with-param name="sect2s" select="$sect2s"/>
803           <axsl:with-param name="sect1s" select="$sect1s"/>
804         </axsl:apply-templates>
805       </axsl:otherwise>
806     </axsl:choose>
807   </axsl:template>
808   <axsl:template match="dbk:para" mode="toplevel-sect4">
809     <axsl:param name="nextsect3" select="/.."/>
810     <axsl:param name="nextsect2" select="/.."/>
811     <axsl:param name="nextsect1" select="/.."/>
812     <axsl:param name="nexttoplevel-component" select="/.."/>
813     <axsl:param select="/.." name="sect4s"/>
814     <axsl:param select="/.." name="sect3s"/>
815     <axsl:param select="/.." name="sect2s"/>
816     <axsl:param select="/.." name="sect1s"/>
817     <axsl:choose>
818       <axsl:when test="generate-id() = generate-id($nextsect3)"/>
819       <axsl:when test="generate-id() = generate-id($nextsect2)"/>
820       <axsl:when test="generate-id() = generate-id($nextsect1)"/>
821       <axsl:when test="generate-id() = generate-id($nexttoplevel-component)"/>
822       <axsl:when test="@rnd:style = &quot;d:sect4&quot; or @rnd:style = &quot;sect4-title&quot;">
823         <axsl:variable name="nextsect4" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect4&quot; or @rnd:style = &quot;sect4-title&quot;][1]"/>
824         <axsl:choose>
825           <axsl:when test="$nextsect4">
826             <axsl:variable name="sect5s" select="$nextsect4/preceding-sibling::dbk:para[@rnd:style = &quot;d:sect5&quot; or @rnd:style = &quot;sect5-title&quot;]"/>
827 <!-- mode sections 1 -->
828             <sect4 xmlns="http://docbook.org/ns/docbook">
829               <axsl:call-template name="copy"/>
830               <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect5">
831                 <axsl:with-param name="nextsect4" select="$nextsect4"/>
832                 <axsl:with-param name="nextsect3" select="$nextsect3"/>
833                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
834                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
835                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
836                 <axsl:with-param name="sect5s" select="$sect5s"/>
837                 <axsl:with-param name="sect4s" select="$sect4s"/>
838                 <axsl:with-param name="sect3s" select="$sect3s"/>
839                 <axsl:with-param name="sect2s" select="$sect2s"/>
840                 <axsl:with-param name="sect1s" select="$sect1s"/>
841               </axsl:apply-templates>
842             </sect4>
843             <axsl:if test="$nextsect4 and (not($sect3s) or count($sect4s|$nextsect4) = count($sect4s))">
844               <axsl:apply-templates select="$nextsect4" mode="toplevel-sect4">
845                 <axsl:with-param name="nextsect3" select="$nextsect3"/>
846                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
847                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
848                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
849                 <axsl:with-param name="sect4s" select="$sect4s"/>
850                 <axsl:with-param name="sect3s" select="$sect3s"/>
851                 <axsl:with-param name="sect2s" select="$sect2s"/>
852                 <axsl:with-param name="sect1s" select="$sect1s"/>
853               </axsl:apply-templates>
854             </axsl:if>
855           </axsl:when>
856           <axsl:otherwise>
857             <axsl:variable name="sect5s" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect5&quot; or @rnd:style = &quot;sect5-title&quot;]"/>
858 <!-- mode sections 2 -->
859             <sect4 xmlns="http://docbook.org/ns/docbook">
860               <axsl:call-template name="copy"/>
861               <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect5">
862                 <axsl:with-param name="nextsect4" select="$nextsect4"/>
863                 <axsl:with-param name="nextsect3" select="$nextsect3"/>
864                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
865                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
866                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
867                 <axsl:with-param name="sect5s" select="$sect5s"/>
868                 <axsl:with-param name="sect4s" select="$sect4s"/>
869                 <axsl:with-param name="sect3s" select="$sect3s"/>
870                 <axsl:with-param name="sect2s" select="$sect2s"/>
871                 <axsl:with-param name="sect1s" select="$sect1s"/>
872               </axsl:apply-templates>
873             </sect4>
874             <axsl:if test="$nextsect4 and (not($sect3s) or count($sect4s|$nextsect4) = count($sect4s))">
875               <axsl:apply-templates select="$nextsect4" mode="toplevel-sect4">
876                 <axsl:with-param name="nextsect3" select="$nextsect3"/>
877                 <axsl:with-param name="nextsect2" select="$nextsect2"/>
878                 <axsl:with-param name="nextsect1" select="$nextsect1"/>
879                 <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
880                 <axsl:with-param name="sect4s" select="$sect4s"/>
881                 <axsl:with-param name="sect3s" select="$sect3s"/>
882                 <axsl:with-param name="sect2s" select="$sect2s"/>
883                 <axsl:with-param name="sect1s" select="$sect1s"/>
884               </axsl:apply-templates>
885             </axsl:if>
886           </axsl:otherwise>
887         </axsl:choose>
888       </axsl:when>
889       <axsl:otherwise>
890         <axsl:call-template name="copy"/>
891         <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect4">
892           <axsl:with-param name="nextsect3" select="$nextsect3"/>
893           <axsl:with-param name="nextsect2" select="$nextsect2"/>
894           <axsl:with-param name="nextsect1" select="$nextsect1"/>
895           <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
896           <axsl:with-param name="sect4s" select="$sect4s"/>
897           <axsl:with-param name="sect3s" select="$sect3s"/>
898           <axsl:with-param name="sect2s" select="$sect2s"/>
899           <axsl:with-param name="sect1s" select="$sect1s"/>
900         </axsl:apply-templates>
901       </axsl:otherwise>
902     </axsl:choose>
903   </axsl:template>
904   <axsl:template match="dbk:para" mode="toplevel-sect5">
905     <axsl:param name="nextsect4" select="/.."/>
906     <axsl:param name="nextsect3" select="/.."/>
907     <axsl:param name="nextsect2" select="/.."/>
908     <axsl:param name="nextsect1" select="/.."/>
909     <axsl:param name="nexttoplevel-component" select="/.."/>
910     <axsl:param select="/.." name="sect5s"/>
911     <axsl:param select="/.." name="sect4s"/>
912     <axsl:param select="/.." name="sect3s"/>
913     <axsl:param select="/.." name="sect2s"/>
914     <axsl:param select="/.." name="sect1s"/>
915     <axsl:choose>
916       <axsl:when test="generate-id() = generate-id($nextsect4)"/>
917       <axsl:when test="generate-id() = generate-id($nextsect3)"/>
918       <axsl:when test="generate-id() = generate-id($nextsect2)"/>
919       <axsl:when test="generate-id() = generate-id($nextsect1)"/>
920       <axsl:when test="generate-id() = generate-id($nexttoplevel-component)"/>
921       <axsl:when test="@rnd:style = &quot;d:sect5&quot; or @rnd:style = &quot;sect5-title&quot;">
922         <axsl:variable name="nextsect5" select="following-sibling::dbk:para[@rnd:style = &quot;d:sect5&quot; or @rnd:style = &quot;sect5-title&quot;][1]"/>
923 <!-- mode sections 3 -->
924         <sect5 xmlns="http://docbook.org/ns/docbook">
925           <axsl:call-template name="copy"/>
926           <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-terminal">
927             <axsl:with-param name="nextsect5" select="$nextsect5"/>
928             <axsl:with-param name="nextsect4" select="$nextsect4"/>
929             <axsl:with-param name="nextsect3" select="$nextsect3"/>
930             <axsl:with-param name="nextsect2" select="$nextsect2"/>
931             <axsl:with-param name="nextsect1" select="$nextsect1"/>
932             <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
933             <axsl:with-param name="sect5s" select="$sect5s"/>
934             <axsl:with-param name="sect4s" select="$sect4s"/>
935             <axsl:with-param name="sect3s" select="$sect3s"/>
936             <axsl:with-param name="sect2s" select="$sect2s"/>
937             <axsl:with-param name="sect1s" select="$sect1s"/>
938           </axsl:apply-templates>
939         </sect5>
940         <axsl:if test="$nextsect5 and (not($sect4s) or count($sect5s|$nextsect5) = count($sect5s))">
941           <axsl:apply-templates select="$nextsect5" mode="toplevel-sect5">
942             <axsl:with-param name="nextsect4" select="$nextsect4"/>
943             <axsl:with-param name="nextsect3" select="$nextsect3"/>
944             <axsl:with-param name="nextsect2" select="$nextsect2"/>
945             <axsl:with-param name="nextsect1" select="$nextsect1"/>
946             <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
947             <axsl:with-param name="sect5s" select="$sect5s"/>
948             <axsl:with-param name="sect4s" select="$sect4s"/>
949             <axsl:with-param name="sect3s" select="$sect3s"/>
950             <axsl:with-param name="sect2s" select="$sect2s"/>
951             <axsl:with-param name="sect1s" select="$sect1s"/>
952           </axsl:apply-templates>
953         </axsl:if>
954       </axsl:when>
955       <axsl:otherwise>
956         <axsl:call-template name="copy"/>
957         <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect5">
958           <axsl:with-param name="nextsect4" select="$nextsect4"/>
959           <axsl:with-param name="nextsect3" select="$nextsect3"/>
960           <axsl:with-param name="nextsect2" select="$nextsect2"/>
961           <axsl:with-param name="nextsect1" select="$nextsect1"/>
962           <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
963           <axsl:with-param name="sect5s" select="$sect5s"/>
964           <axsl:with-param name="sect4s" select="$sect4s"/>
965           <axsl:with-param name="sect3s" select="$sect3s"/>
966           <axsl:with-param name="sect2s" select="$sect2s"/>
967           <axsl:with-param name="sect1s" select="$sect1s"/>
968         </axsl:apply-templates>
969       </axsl:otherwise>
970     </axsl:choose>
971   </axsl:template>
972   <axsl:template match="dbk:para" mode="book-terminal">
973     <axsl:param name="nextsect5" select="/.."/>
974     <axsl:param name="nextsect4" select="/.."/>
975     <axsl:param name="nextsect3" select="/.."/>
976     <axsl:param name="nextsect2" select="/.."/>
977     <axsl:param name="nextsect1" select="/.."/>
978     <axsl:param name="nextbook-component" select="/.."/>
979     <axsl:param name="nextbook" select="/.."/>
980     <axsl:param select="/.." name="sect5s"/>
981     <axsl:param select="/.." name="sect4s"/>
982     <axsl:param select="/.." name="sect3s"/>
983     <axsl:param select="/.." name="sect2s"/>
984     <axsl:param select="/.." name="sect1s"/>
985     <axsl:param select="/.." name="book-components"/>
986     <axsl:choose>
987       <axsl:when test="generate-id() = generate-id($nextsect5)"/>
988       <axsl:when test="generate-id() = generate-id($nextsect4)"/>
989       <axsl:when test="generate-id() = generate-id($nextsect3)"/>
990       <axsl:when test="generate-id() = generate-id($nextsect2)"/>
991       <axsl:when test="generate-id() = generate-id($nextsect1)"/>
992       <axsl:when test="generate-id() = generate-id($nextbook-component)"/>
993       <axsl:when test="generate-id() = generate-id($nextbook)"/>
994       <axsl:otherwise>
995         <axsl:call-template name="copy"/>
996         <axsl:apply-templates select="following-sibling::*[1]" mode="book-terminal">
997           <axsl:with-param name="nextsect5" select="$nextsect5"/>
998           <axsl:with-param name="nextsect4" select="$nextsect4"/>
999           <axsl:with-param name="nextsect3" select="$nextsect3"/>
1000           <axsl:with-param name="nextsect2" select="$nextsect2"/>
1001           <axsl:with-param name="nextsect1" select="$nextsect1"/>
1002           <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
1003           <axsl:with-param name="nextbook" select="$nextbook"/>
1004           <axsl:with-param name="sect5s" select="$sect5s"/>
1005           <axsl:with-param name="sect4s" select="$sect4s"/>
1006           <axsl:with-param name="sect3s" select="$sect3s"/>
1007           <axsl:with-param name="sect2s" select="$sect2s"/>
1008           <axsl:with-param name="sect1s" select="$sect1s"/>
1009           <axsl:with-param name="book-components" select="$book-components"/>
1010         </axsl:apply-templates>
1011       </axsl:otherwise>
1012     </axsl:choose>
1013   </axsl:template>
1014   <axsl:template match="dbk:para" mode="toplevel-terminal">
1015     <axsl:param name="nextsect5" select="/.."/>
1016     <axsl:param name="nextsect4" select="/.."/>
1017     <axsl:param name="nextsect3" select="/.."/>
1018     <axsl:param name="nextsect2" select="/.."/>
1019     <axsl:param name="nextsect1" select="/.."/>
1020     <axsl:param name="nexttoplevel-component" select="/.."/>
1021     <axsl:param select="/.." name="sect5s"/>
1022     <axsl:param select="/.." name="sect4s"/>
1023     <axsl:param select="/.." name="sect3s"/>
1024     <axsl:param select="/.." name="sect2s"/>
1025     <axsl:param select="/.." name="sect1s"/>
1026     <axsl:choose>
1027       <axsl:when test="generate-id() = generate-id($nextsect5)"/>
1028       <axsl:when test="generate-id() = generate-id($nextsect4)"/>
1029       <axsl:when test="generate-id() = generate-id($nextsect3)"/>
1030       <axsl:when test="generate-id() = generate-id($nextsect2)"/>
1031       <axsl:when test="generate-id() = generate-id($nextsect1)"/>
1032       <axsl:when test="generate-id() = generate-id($nexttoplevel-component)"/>
1033       <axsl:otherwise>
1034         <axsl:call-template name="copy"/>
1035         <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-terminal">
1036           <axsl:with-param name="nextsect5" select="$nextsect5"/>
1037           <axsl:with-param name="nextsect4" select="$nextsect4"/>
1038           <axsl:with-param name="nextsect3" select="$nextsect3"/>
1039           <axsl:with-param name="nextsect2" select="$nextsect2"/>
1040           <axsl:with-param name="nextsect1" select="$nextsect1"/>
1041           <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
1042           <axsl:with-param name="sect5s" select="$sect5s"/>
1043           <axsl:with-param name="sect4s" select="$sect4s"/>
1044           <axsl:with-param name="sect3s" select="$sect3s"/>
1045           <axsl:with-param name="sect2s" select="$sect2s"/>
1046           <axsl:with-param name="sect1s" select="$sect1s"/>
1047         </axsl:apply-templates>
1048       </axsl:otherwise>
1049     </axsl:choose>
1050   </axsl:template>
1051   <axsl:template match="*">
1052     <axsl:call-template name="copy"/>
1053   </axsl:template>
1054   <axsl:template match="*" mode="book">
1055     <axsl:call-template name="copy"/>
1056     <axsl:apply-templates select="following-sibling::*[1]" mode="book"/>
1057   </axsl:template>
1058   <axsl:template match="*" mode="book-component">
1059     <axsl:param name="nextbook" select="/.."/>
1060     <axsl:param select="/.." name="book-components"/>
1061     <axsl:call-template name="copy"/>
1062     <axsl:apply-templates select="following-sibling::*[1]" mode="book-component">
1063       <axsl:with-param name="nextbook" select="$nextbook"/>
1064       <axsl:with-param name="book-components" select="$book-components"/>
1065     </axsl:apply-templates>
1066   </axsl:template>
1067   <axsl:template match="*" mode="book-sect1">
1068     <axsl:param name="nextbook-component" select="/.."/>
1069     <axsl:param name="nextbook" select="/.."/>
1070     <axsl:param select="/.." name="sect1s"/>
1071     <axsl:param select="/.." name="book-components"/>
1072     <axsl:call-template name="copy"/>
1073     <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect1">
1074       <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
1075       <axsl:with-param name="nextbook" select="$nextbook"/>
1076       <axsl:with-param name="sect1s" select="$sect1s"/>
1077       <axsl:with-param name="book-components" select="$book-components"/>
1078     </axsl:apply-templates>
1079   </axsl:template>
1080   <axsl:template match="*" mode="book-sect2">
1081     <axsl:param name="nextsect1" select="/.."/>
1082     <axsl:param name="nextbook-component" select="/.."/>
1083     <axsl:param name="nextbook" select="/.."/>
1084     <axsl:param select="/.." name="sect2s"/>
1085     <axsl:param select="/.." name="sect1s"/>
1086     <axsl:param select="/.." name="book-components"/>
1087     <axsl:call-template name="copy"/>
1088     <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect2">
1089       <axsl:with-param name="nextsect1" select="$nextsect1"/>
1090       <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
1091       <axsl:with-param name="nextbook" select="$nextbook"/>
1092       <axsl:with-param name="sect2s" select="$sect2s"/>
1093       <axsl:with-param name="sect1s" select="$sect1s"/>
1094       <axsl:with-param name="book-components" select="$book-components"/>
1095     </axsl:apply-templates>
1096   </axsl:template>
1097   <axsl:template match="*" mode="book-sect3">
1098     <axsl:param name="nextsect2" select="/.."/>
1099     <axsl:param name="nextsect1" select="/.."/>
1100     <axsl:param name="nextbook-component" select="/.."/>
1101     <axsl:param name="nextbook" select="/.."/>
1102     <axsl:param select="/.." name="sect3s"/>
1103     <axsl:param select="/.." name="sect2s"/>
1104     <axsl:param select="/.." name="sect1s"/>
1105     <axsl:param select="/.." name="book-components"/>
1106     <axsl:call-template name="copy"/>
1107     <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect3">
1108       <axsl:with-param name="nextsect2" select="$nextsect2"/>
1109       <axsl:with-param name="nextsect1" select="$nextsect1"/>
1110       <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
1111       <axsl:with-param name="nextbook" select="$nextbook"/>
1112       <axsl:with-param name="sect3s" select="$sect3s"/>
1113       <axsl:with-param name="sect2s" select="$sect2s"/>
1114       <axsl:with-param name="sect1s" select="$sect1s"/>
1115       <axsl:with-param name="book-components" select="$book-components"/>
1116     </axsl:apply-templates>
1117   </axsl:template>
1118   <axsl:template match="*" mode="book-sect4">
1119     <axsl:param name="nextsect3" select="/.."/>
1120     <axsl:param name="nextsect2" select="/.."/>
1121     <axsl:param name="nextsect1" select="/.."/>
1122     <axsl:param name="nextbook-component" select="/.."/>
1123     <axsl:param name="nextbook" select="/.."/>
1124     <axsl:param select="/.." name="sect4s"/>
1125     <axsl:param select="/.." name="sect3s"/>
1126     <axsl:param select="/.." name="sect2s"/>
1127     <axsl:param select="/.." name="sect1s"/>
1128     <axsl:param select="/.." name="book-components"/>
1129     <axsl:call-template name="copy"/>
1130     <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect4">
1131       <axsl:with-param name="nextsect3" select="$nextsect3"/>
1132       <axsl:with-param name="nextsect2" select="$nextsect2"/>
1133       <axsl:with-param name="nextsect1" select="$nextsect1"/>
1134       <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
1135       <axsl:with-param name="nextbook" select="$nextbook"/>
1136       <axsl:with-param name="sect4s" select="$sect4s"/>
1137       <axsl:with-param name="sect3s" select="$sect3s"/>
1138       <axsl:with-param name="sect2s" select="$sect2s"/>
1139       <axsl:with-param name="sect1s" select="$sect1s"/>
1140       <axsl:with-param name="book-components" select="$book-components"/>
1141     </axsl:apply-templates>
1142   </axsl:template>
1143   <axsl:template match="*" mode="book-sect5">
1144     <axsl:param name="nextsect4" select="/.."/>
1145     <axsl:param name="nextsect3" select="/.."/>
1146     <axsl:param name="nextsect2" select="/.."/>
1147     <axsl:param name="nextsect1" select="/.."/>
1148     <axsl:param name="nextbook-component" select="/.."/>
1149     <axsl:param name="nextbook" select="/.."/>
1150     <axsl:param select="/.." name="sect5s"/>
1151     <axsl:param select="/.." name="sect4s"/>
1152     <axsl:param select="/.." name="sect3s"/>
1153     <axsl:param select="/.." name="sect2s"/>
1154     <axsl:param select="/.." name="sect1s"/>
1155     <axsl:param select="/.." name="book-components"/>
1156     <axsl:call-template name="copy"/>
1157     <axsl:apply-templates select="following-sibling::*[1]" mode="book-sect5">
1158       <axsl:with-param name="nextsect4" select="$nextsect4"/>
1159       <axsl:with-param name="nextsect3" select="$nextsect3"/>
1160       <axsl:with-param name="nextsect2" select="$nextsect2"/>
1161       <axsl:with-param name="nextsect1" select="$nextsect1"/>
1162       <axsl:with-param name="nextbook-component" select="$nextbook-component"/>
1163       <axsl:with-param name="nextbook" select="$nextbook"/>
1164       <axsl:with-param name="sect5s" select="$sect5s"/>
1165       <axsl:with-param name="sect4s" select="$sect4s"/>
1166       <axsl:with-param name="sect3s" select="$sect3s"/>
1167       <axsl:with-param name="sect2s" select="$sect2s"/>
1168       <axsl:with-param name="sect1s" select="$sect1s"/>
1169       <axsl:with-param name="book-components" select="$book-components"/>
1170     </axsl:apply-templates>
1171   </axsl:template>
1172   <axsl:template match="*" mode="toplevel-component">
1173     <axsl:call-template name="copy"/>
1174     <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-component"/>
1175   </axsl:template>
1176   <axsl:template match="*" mode="toplevel-sect1">
1177     <axsl:param name="nexttoplevel-component" select="/.."/>
1178     <axsl:param select="/.." name="sect1s"/>
1179     <axsl:call-template name="copy"/>
1180     <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect1">
1181       <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
1182       <axsl:with-param name="sect1s" select="$sect1s"/>
1183     </axsl:apply-templates>
1184   </axsl:template>
1185   <axsl:template match="*" mode="toplevel-sect2">
1186     <axsl:param name="nextsect1" select="/.."/>
1187     <axsl:param name="nexttoplevel-component" select="/.."/>
1188     <axsl:param select="/.." name="sect2s"/>
1189     <axsl:param select="/.." name="sect1s"/>
1190     <axsl:call-template name="copy"/>
1191     <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect2">
1192       <axsl:with-param name="nextsect1" select="$nextsect1"/>
1193       <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
1194       <axsl:with-param name="sect2s" select="$sect2s"/>
1195       <axsl:with-param name="sect1s" select="$sect1s"/>
1196     </axsl:apply-templates>
1197   </axsl:template>
1198   <axsl:template match="*" mode="toplevel-sect3">
1199     <axsl:param name="nextsect2" select="/.."/>
1200     <axsl:param name="nextsect1" select="/.."/>
1201     <axsl:param name="nexttoplevel-component" select="/.."/>
1202     <axsl:param select="/.." name="sect3s"/>
1203     <axsl:param select="/.." name="sect2s"/>
1204     <axsl:param select="/.." name="sect1s"/>
1205     <axsl:call-template name="copy"/>
1206     <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect3">
1207       <axsl:with-param name="nextsect2" select="$nextsect2"/>
1208       <axsl:with-param name="nextsect1" select="$nextsect1"/>
1209       <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
1210       <axsl:with-param name="sect3s" select="$sect3s"/>
1211       <axsl:with-param name="sect2s" select="$sect2s"/>
1212       <axsl:with-param name="sect1s" select="$sect1s"/>
1213     </axsl:apply-templates>
1214   </axsl:template>
1215   <axsl:template match="*" mode="toplevel-sect4">
1216     <axsl:param name="nextsect3" select="/.."/>
1217     <axsl:param name="nextsect2" select="/.."/>
1218     <axsl:param name="nextsect1" select="/.."/>
1219     <axsl:param name="nexttoplevel-component" select="/.."/>
1220     <axsl:param select="/.." name="sect4s"/>
1221     <axsl:param select="/.." name="sect3s"/>
1222     <axsl:param select="/.." name="sect2s"/>
1223     <axsl:param select="/.." name="sect1s"/>
1224     <axsl:call-template name="copy"/>
1225     <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect4">
1226       <axsl:with-param name="nextsect3" select="$nextsect3"/>
1227       <axsl:with-param name="nextsect2" select="$nextsect2"/>
1228       <axsl:with-param name="nextsect1" select="$nextsect1"/>
1229       <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
1230       <axsl:with-param name="sect4s" select="$sect4s"/>
1231       <axsl:with-param name="sect3s" select="$sect3s"/>
1232       <axsl:with-param name="sect2s" select="$sect2s"/>
1233       <axsl:with-param name="sect1s" select="$sect1s"/>
1234     </axsl:apply-templates>
1235   </axsl:template>
1236   <axsl:template match="*" mode="toplevel-sect5">
1237     <axsl:param name="nextsect4" select="/.."/>
1238     <axsl:param name="nextsect3" select="/.."/>
1239     <axsl:param name="nextsect2" select="/.."/>
1240     <axsl:param name="nextsect1" select="/.."/>
1241     <axsl:param name="nexttoplevel-component" select="/.."/>
1242     <axsl:param select="/.." name="sect5s"/>
1243     <axsl:param select="/.." name="sect4s"/>
1244     <axsl:param select="/.." name="sect3s"/>
1245     <axsl:param select="/.." name="sect2s"/>
1246     <axsl:param select="/.." name="sect1s"/>
1247     <axsl:call-template name="copy"/>
1248     <axsl:apply-templates select="following-sibling::*[1]" mode="toplevel-sect5">
1249       <axsl:with-param name="nextsect4" select="$nextsect4"/>
1250       <axsl:with-param name="nextsect3" select="$nextsect3"/>
1251       <axsl:with-param name="nextsect2" select="$nextsect2"/>
1252       <axsl:with-param name="nextsect1" select="$nextsect1"/>
1253       <axsl:with-param name="nexttoplevel-component" select="$nexttoplevel-component"/>
1254       <axsl:with-param name="sect5s" select="$sect5s"/>
1255       <axsl:with-param name="sect4s" select="$sect4s"/>
1256       <axsl:with-param name="sect3s" select="$sect3s"/>
1257       <axsl:with-param name="sect2s" select="$sect2s"/>
1258       <axsl:with-param name="sect1s" select="$sect1s"/>
1259     </axsl:apply-templates>
1260   </axsl:template>
1261   <axsl:template name="copy">
1262     <axsl:copy>
1263       <axsl:for-each select="@*">
1264         <axsl:copy/>
1265       </axsl:for-each>
1266       <axsl:apply-templates/>
1267     </axsl:copy>
1268   </axsl:template>
1269 </axsl:stylesheet>