Imported Upstream version 1.79.2
[platform/upstream/docbook-xsl-stylesheets.git] / roundtrip / sections2blocks.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 makeSubsections.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:appendix |&#10;  dbk:article |&#10;  dbk:book |&#10;  dbk:chapter |&#10;  dbk:part |&#10;  dbk:preface |&#10;  dbk:section |&#10;  dbk:sect1 |&#10;  dbk:sect2 |&#10;  dbk:sect3 |&#10;  dbk:sect4 |&#10;  dbk:sect5">
19     <axsl:variable name="subsections" select="dbk:para[@rnd:style = &quot;d:bibliography&quot; or @rnd:style = &quot;bibliography-title&quot; or @rnd:style = &quot;d:glossary&quot; or @rnd:style = &quot;glossary-title&quot; or @rnd:style = &quot;d:qandaset&quot; or @rnd:style = &quot;qandaset-title&quot;]"/>
20     <axsl:copy>
21       <axsl:apply-templates select="@*"/>
22       <axsl:choose>
23         <axsl:when test="$subsections">
24           <axsl:apply-templates select="$subsections[1]/preceding-sibling::node()"/>
25           <axsl:apply-templates select="$subsections[1]" mode="subsections">
26             <axsl:with-param name="subsections" select="$subsections[position() != 1]"/>
27           </axsl:apply-templates>
28         </axsl:when>
29         <axsl:when test="dbk:appendix |&#10;  dbk:article |&#10;  dbk:book |&#10;  dbk:chapter |&#10;  dbk:part |&#10;  dbk:preface |&#10;  dbk:section |&#10;  dbk:sect1 |&#10;  dbk:sect2 |&#10;  dbk:sect3 |&#10;  dbk:sect4 |&#10;  dbk:sect5">
30           <axsl:apply-templates select="*[self::dbk:appendix |&#10;  self::dbk:article |&#10;  self::dbk:book |&#10;  self::dbk:chapter |&#10;  self::dbk:part |&#10;  self::dbk:preface |&#10;  self::dbk:section |&#10;  self::dbk:sect1 |&#10;  self::dbk:sect2 |&#10;  self::dbk:sect3 |&#10;  self::dbk:sect4 |&#10;  self::dbk:sect5][1]/preceding-sibling::node()"/>
31           <axsl:apply-templates select="dbk:appendix |&#10;  dbk:article |&#10;  dbk:book |&#10;  dbk:chapter |&#10;  dbk:part |&#10;  dbk:preface |&#10;  dbk:section |&#10;  dbk:sect1 |&#10;  dbk:sect2 |&#10;  dbk:sect3 |&#10;  dbk:sect4 |&#10;  dbk:sect5"/>
32         </axsl:when>
33         <axsl:otherwise>
34           <axsl:apply-templates/>
35         </axsl:otherwise>
36       </axsl:choose>
37     </axsl:copy>
38     <axsl:choose>
39       <axsl:when test="following-sibling::*[self::dbk:appendix |&#10;  self::dbk:article |&#10;  self::dbk:book |&#10;  self::dbk:chapter |&#10;  self::dbk:part |&#10;  self::dbk:preface |&#10;  self::dbk:section |&#10;  self::dbk:sect1 |&#10;  self::dbk:sect2 |&#10;  self::dbk:sect3 |&#10;  self::dbk:sect4 |&#10;  self::dbk:sect5] | following-sibling::dbk:para[@rnd:style = &quot;d:bibliography&quot; or @rnd:style = &quot;bibliography-title&quot; or @rnd:style = &quot;d:glossary&quot; or @rnd:style = &quot;glossary-title&quot; or @rnd:style = &quot;d:qandaset&quot; or @rnd:style = &quot;qandaset-title&quot;]">
40         <axsl:variable name="nextComponent" select="following-sibling::*[self::dbk:appendix |&#10;  self::dbk:article |&#10;  self::dbk:book |&#10;  self::dbk:chapter |&#10;  self::dbk:part |&#10;  self::dbk:preface |&#10;  self::dbk:section |&#10;  self::dbk:sect1 |&#10;  self::dbk:sect2 |&#10;  self::dbk:sect3 |&#10;  self::dbk:sect4 |&#10;  self::dbk:sect5|self::dbk:para[@rnd:style = &quot;d:bibliography&quot; or @rnd:style = &quot;bibliography-title&quot; or @rnd:style = &quot;d:glossary&quot; or @rnd:style = &quot;glossary-title&quot; or @rnd:style = &quot;d:qandaset&quot; or @rnd:style = &quot;qandaset-title&quot;]][1]"/>
41         <axsl:apply-templates select="following-sibling::*[generate-id(following-sibling::*[self::dbk:appendix |&#10;  self::dbk:article |&#10;  self::dbk:book |&#10;  self::dbk:chapter |&#10;  self::dbk:part |&#10;  self::dbk:preface |&#10;  self::dbk:section |&#10;  self::dbk:sect1 |&#10;  self::dbk:sect2 |&#10;  self::dbk:sect3 |&#10;  self::dbk:sect4 |&#10;  self::dbk:sect5|self::dbk:para[@rnd:style = &quot;d:bibliography&quot; or @rnd:style = &quot;bibliography-title&quot; or @rnd:style = &quot;d:glossary&quot; or @rnd:style = &quot;glossary-title&quot; or @rnd:style = &quot;d:qandaset&quot; or @rnd:style = &quot;qandaset-title&quot;]][1]) = generate-id($nextComponent)]"/>
42       </axsl:when>
43       <axsl:otherwise>
44         <axsl:apply-templates select="following-sibling::*"/>
45       </axsl:otherwise>
46     </axsl:choose>
47   </axsl:template>
48   <axsl:template match="dbk:para" mode="subsections">
49     <axsl:param name="subsections" select="/.."/>
50     <axsl:choose>
51       <axsl:when test="@rnd:style = &quot;d:bibliography&quot; or @rnd:style = &quot;bibliography-title&quot;">
52         <bibliography xmlns="http://docbook.org/ns/docbook">
53           <axsl:call-template name="copy"/>
54           <axsl:variable name="bibliodivs" select="following-sibling::dbk:para[@rnd:style = &quot;d:bibliodiv&quot; or @rnd:style = &quot;bibliodiv-title&quot;]"/>
55           <axsl:choose>
56             <axsl:when test="$bibliodivs">
57               <axsl:apply-templates select="following-sibling::*[1]" mode="bibliodivs">
58                 <axsl:with-param name="nextSubsection" select="$subsections[1]"/>
59                 <axsl:with-param name="bibliodivs" select="$bibliodivs[position() != 1]"/>
60               </axsl:apply-templates>
61             </axsl:when>
62             <axsl:otherwise>
63               <axsl:apply-templates select="following-sibling::*[1]" mode="terminal">
64                 <axsl:with-param name="nextSubsection" select="$subsections[1]"/>
65               </axsl:apply-templates>
66             </axsl:otherwise>
67           </axsl:choose>
68         </bibliography>
69       </axsl:when>
70       <axsl:when test="@rnd:style = &quot;d:glossary&quot; or @rnd:style = &quot;glossary-title&quot;">
71         <glossary xmlns="http://docbook.org/ns/docbook">
72           <axsl:call-template name="copy"/>
73           <axsl:variable name="glossdivs" select="following-sibling::dbk:para[@rnd:style = &quot;d:glossdiv&quot; or @rnd:style = &quot;glossdiv-title&quot;]"/>
74           <axsl:choose>
75             <axsl:when test="$glossdivs">
76               <axsl:apply-templates select="following-sibling::*[1]" mode="glossdivs">
77                 <axsl:with-param name="nextSubsection" select="$subsections[1]"/>
78                 <axsl:with-param name="glossdivs" select="$glossdivs[position() != 1]"/>
79               </axsl:apply-templates>
80             </axsl:when>
81             <axsl:otherwise>
82               <axsl:apply-templates select="following-sibling::*[1]" mode="terminal">
83                 <axsl:with-param name="nextSubsection" select="$subsections[1]"/>
84               </axsl:apply-templates>
85             </axsl:otherwise>
86           </axsl:choose>
87         </glossary>
88       </axsl:when>
89       <axsl:when test="@rnd:style = &quot;d:qandaset&quot; or @rnd:style = &quot;qandaset-title&quot;">
90         <qandaset xmlns="http://docbook.org/ns/docbook">
91           <axsl:call-template name="copy"/>
92           <axsl:variable name="qandadivs" select="following-sibling::dbk:para[@rnd:style = &quot;d:qandadiv&quot; or @rnd:style = &quot;qandadiv-title&quot;]"/>
93           <axsl:choose>
94             <axsl:when test="$qandadivs">
95               <axsl:apply-templates select="following-sibling::*[1]" mode="qandadivs">
96                 <axsl:with-param name="nextSubsection" select="$subsections[1]"/>
97                 <axsl:with-param name="qandadivs" select="$qandadivs[position() != 1]"/>
98               </axsl:apply-templates>
99             </axsl:when>
100             <axsl:otherwise>
101               <axsl:apply-templates select="following-sibling::*[1]" mode="terminal">
102                 <axsl:with-param name="nextSubsection" select="$subsections[1]"/>
103               </axsl:apply-templates>
104             </axsl:otherwise>
105           </axsl:choose>
106         </qandaset>
107       </axsl:when>
108     </axsl:choose>
109   </axsl:template>
110   <axsl:template match="*" mode="subsections">
111     <axsl:param name="subsections" select="/.."/>
112     <axsl:copy>
113       <axsl:apply-templates select="@*"/>
114       <axsl:apply-templates mode="subsections"/>
115     </axsl:copy>
116   </axsl:template>
117   <axsl:template match="dbk:para" mode="bibliodivs">
118     <axsl:param name="nextSubsection" select="/.."/>
119     <axsl:param name="bibliodivs" select="/.."/>
120     <axsl:choose>
121       <axsl:when test="generate-id() = generate-id($nextSubsection)"/>
122       <axsl:when test="@rnd:style = &quot;d:bibliodiv&quot; or @rnd:style = &quot;bibliodiv-title&quot;">
123         <bibliodiv xmlns="http://docbook.org/ns/docbook">
124           <axsl:call-template name="copy"/>
125           <axsl:apply-templates select="following-sibling::*[1]" mode="terminal">
126             <axsl:with-param name="nextSubsection" select="$nextSubsection"/>
127             <axsl:with-param name="nextbibliodiv" select="$bibliodivs[1]"/>
128           </axsl:apply-templates>
129         </bibliodiv>
130         <axsl:choose>
131           <axsl:when test="$nextSubsection and         $bibliodivs and         count($nextSubsection/preceding-sibling::* | $bibliodivs[1]) = count($nextSubsection/preceding-sibling::*)">
132             <axsl:apply-templates select="$bibliodivs[1]" mode="bibliodivs">
133               <axsl:with-param name="nextSubsection" select="$nextSubsection"/>
134               <axsl:with-param name="bibliodivs" select="$bibliodivs[position() != 1]"/>
135             </axsl:apply-templates>
136           </axsl:when>
137           <axsl:when test="$bibliodivs">
138             <axsl:apply-templates select="$bibliodivs[1]" mode="bibliodivs">
139               <axsl:with-param name="bibliodivs" select="$bibliodivs[position() != 1]"/>
140             </axsl:apply-templates>
141           </axsl:when>
142         </axsl:choose>
143       </axsl:when>
144       <axsl:otherwise>
145         <axsl:call-template name="copy"/>
146         <axsl:apply-templates select="following-sibling::*[1]" mode="bibliodivs">
147           <axsl:with-param name="nextSubsection" select="$nextSubsection"/>
148         </axsl:apply-templates>
149       </axsl:otherwise>
150     </axsl:choose>
151   </axsl:template>
152   <axsl:template match="dbk:para" mode="glossdivs">
153     <axsl:param name="nextSubsection" select="/.."/>
154     <axsl:param name="glossdivs" select="/.."/>
155     <axsl:choose>
156       <axsl:when test="generate-id() = generate-id($nextSubsection)"/>
157       <axsl:when test="@rnd:style = &quot;d:glossdiv&quot; or @rnd:style = &quot;glossdiv-title&quot;">
158         <glossdiv xmlns="http://docbook.org/ns/docbook">
159           <axsl:call-template name="copy"/>
160           <axsl:apply-templates select="following-sibling::*[1]" mode="terminal">
161             <axsl:with-param name="nextSubsection" select="$nextSubsection"/>
162             <axsl:with-param name="nextglossdiv" select="$glossdivs[1]"/>
163           </axsl:apply-templates>
164         </glossdiv>
165         <axsl:choose>
166           <axsl:when test="$nextSubsection and         $glossdivs and         count($nextSubsection/preceding-sibling::* | $glossdivs[1]) = count($nextSubsection/preceding-sibling::*)">
167             <axsl:apply-templates select="$glossdivs[1]" mode="glossdivs">
168               <axsl:with-param name="nextSubsection" select="$nextSubsection"/>
169               <axsl:with-param name="glossdivs" select="$glossdivs[position() != 1]"/>
170             </axsl:apply-templates>
171           </axsl:when>
172           <axsl:when test="$glossdivs">
173             <axsl:apply-templates select="$glossdivs[1]" mode="glossdivs">
174               <axsl:with-param name="glossdivs" select="$glossdivs[position() != 1]"/>
175             </axsl:apply-templates>
176           </axsl:when>
177         </axsl:choose>
178       </axsl:when>
179       <axsl:otherwise>
180         <axsl:call-template name="copy"/>
181         <axsl:apply-templates select="following-sibling::*[1]" mode="glossdivs">
182           <axsl:with-param name="nextSubsection" select="$nextSubsection"/>
183         </axsl:apply-templates>
184       </axsl:otherwise>
185     </axsl:choose>
186   </axsl:template>
187   <axsl:template match="dbk:para" mode="qandadivs">
188     <axsl:param name="nextSubsection" select="/.."/>
189     <axsl:param name="qandadivs" select="/.."/>
190     <axsl:choose>
191       <axsl:when test="generate-id() = generate-id($nextSubsection)"/>
192       <axsl:when test="@rnd:style = &quot;d:qandadiv&quot; or @rnd:style = &quot;qandadiv-title&quot;">
193         <qandadiv xmlns="http://docbook.org/ns/docbook">
194           <axsl:call-template name="copy"/>
195           <axsl:apply-templates select="following-sibling::*[1]" mode="terminal">
196             <axsl:with-param name="nextSubsection" select="$nextSubsection"/>
197             <axsl:with-param name="nextqandadiv" select="$qandadivs[1]"/>
198           </axsl:apply-templates>
199         </qandadiv>
200         <axsl:choose>
201           <axsl:when test="$nextSubsection and         $qandadivs and         count($nextSubsection/preceding-sibling::* | $qandadivs[1]) = count($nextSubsection/preceding-sibling::*)">
202             <axsl:apply-templates select="$qandadivs[1]" mode="qandadivs">
203               <axsl:with-param name="nextSubsection" select="$nextSubsection"/>
204               <axsl:with-param name="qandadivs" select="$qandadivs[position() != 1]"/>
205             </axsl:apply-templates>
206           </axsl:when>
207           <axsl:when test="$qandadivs">
208             <axsl:apply-templates select="$qandadivs[1]" mode="qandadivs">
209               <axsl:with-param name="qandadivs" select="$qandadivs[position() != 1]"/>
210             </axsl:apply-templates>
211           </axsl:when>
212         </axsl:choose>
213       </axsl:when>
214       <axsl:otherwise>
215         <axsl:call-template name="copy"/>
216         <axsl:apply-templates select="following-sibling::*[1]" mode="qandadivs">
217           <axsl:with-param name="nextSubsection" select="$nextSubsection"/>
218         </axsl:apply-templates>
219       </axsl:otherwise>
220     </axsl:choose>
221   </axsl:template>
222   <axsl:template match="*" mode="terminal">
223     <axsl:param name="nextSubsection" select="/.."/>
224     <axsl:param name="nextbibliodiv" select="/.."/>
225     <axsl:param name="nextglossdiv" select="/.."/>
226     <axsl:param name="nextqandadiv" select="/.."/>
227     <axsl:choose>
228       <axsl:when test="generate-id() = generate-id($nextSubsection)"/>
229       <axsl:when test="generate-id() = generate-id($nextbibliodiv)"/>
230       <axsl:when test="generate-id() = generate-id($nextglossdiv)"/>
231       <axsl:when test="generate-id() = generate-id($nextqandadiv)"/>
232       <axsl:otherwise>
233         <axsl:call-template name="copy"/>
234         <axsl:apply-templates select="following-sibling::*[1]" mode="terminal">
235           <axsl:with-param name="nextSubsection" select="$nextSubsection"/>
236           <axsl:with-param name="nextbibliodiv" select="$nextbibliodiv"/>
237           <axsl:with-param name="nextglossdiv" select="$nextglossdiv"/>
238           <axsl:with-param name="nextqandadiv" select="$nextqandadiv"/>
239         </axsl:apply-templates>
240       </axsl:otherwise>
241     </axsl:choose>
242   </axsl:template>
243   <axsl:template match="*">
244     <axsl:copy>
245       <axsl:apply-templates select="@*"/>
246       <axsl:apply-templates/>
247     </axsl:copy>
248   </axsl:template>
249   <axsl:template name="copy">
250     <axsl:copy>
251       <axsl:apply-templates select="@*"/>
252       <axsl:apply-templates/>
253     </axsl:copy>
254   </axsl:template>
255   <axsl:template match="@*">
256     <axsl:copy/>
257   </axsl:template>
258 </axsl:stylesheet>