1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4                exclude-result-prefixes="doc"
5                version='1.0'>
6
7<!-- ============================================================ -->
8
9<xsl:template match="*" mode="object.title.template">
10  <xsl:call-template name="gentext.template">
11    <xsl:with-param name="context" select="'title'"/>
12    <xsl:with-param name="name" select="local-name(.)"/>
13  </xsl:call-template>
14</xsl:template>
15
16<xsl:template match="section|sect1|sect2|sect3|sect4|sect5|simplesect"
17              mode="object.title.template">
18  <xsl:choose>
19    <xsl:when test="$section.autolabel != 0">
20      <xsl:call-template name="gentext.template">
21        <xsl:with-param name="context" select="'section-title-numbered'"/>
22        <xsl:with-param name="name" select="local-name(.)"/>
23      </xsl:call-template>
24    </xsl:when>
25    <xsl:otherwise>
26      <xsl:call-template name="gentext.template">
27        <xsl:with-param name="context" select="'section-title'"/>
28        <xsl:with-param name="name" select="local-name(.)"/>
29      </xsl:call-template>
30    </xsl:otherwise>
31  </xsl:choose>
32</xsl:template>
33
34<xsl:template match="article/appendix"
35              mode="object.title.template">
36  <!-- FIXME: HACK HACK HACK! -->
37  <xsl:text>%n. %t</xsl:text>
38</xsl:template>
39
40<!-- ============================================================ -->
41
42<xsl:template match="*" mode="object.subtitle.template">
43  <xsl:call-template name="gentext.template">
44    <xsl:with-param name="context" select="'subtitle'"/>
45    <xsl:with-param name="name" select="local-name(.)"/>
46  </xsl:call-template>
47</xsl:template>
48
49<!-- ============================================================ -->
50
51<xsl:template match="*" mode="object.xref.template">
52  <xsl:call-template name="gentext.template">
53    <xsl:with-param name="context" select="'xref'"/>
54    <xsl:with-param name="name" select="local-name(.)"/>
55  </xsl:call-template>
56</xsl:template>
57
58<xsl:template match="section|simplesect
59                     |sect1|sect2|sect3|sect4|sect5
60                     |refsect1|refsect2|refsect3"
61              mode="object.xref.template">
62  <xsl:choose>
63    <xsl:when test="$section.autolabel != 0">
64      <xsl:call-template name="gentext.template">
65        <xsl:with-param name="context" select="'section-xref-numbered'"/>
66        <xsl:with-param name="name" select="local-name(.)"/>
67      </xsl:call-template>
68    </xsl:when>
69    <xsl:otherwise>
70      <xsl:call-template name="gentext.template">
71        <xsl:with-param name="context" select="'section-xref'"/>
72        <xsl:with-param name="name" select="local-name(.)"/>
73      </xsl:call-template>
74    </xsl:otherwise>
75  </xsl:choose>
76</xsl:template>
77
78<!-- ============================================================ -->
79
80<xsl:template match="*" mode="object.title.markup">
81  <xsl:variable name="template">
82    <xsl:apply-templates select="." mode="object.title.template"/>
83  </xsl:variable>
84
85<!--
86  <xsl:message>
87    <xsl:text>object.title.markup: </xsl:text>
88    <xsl:value-of select="local-name(.)"/>
89    <xsl:text>: </xsl:text>
90    <xsl:value-of select="$template"/>
91  </xsl:message>
92-->
93
94  <xsl:call-template name="substitute-markup">
95    <xsl:with-param name="allow-anchors" select="1"/>
96    <xsl:with-param name="template" select="$template"/>
97  </xsl:call-template>
98</xsl:template>
99
100<xsl:template match="*" mode="object.title.markup.textonly">
101  <xsl:variable name="title">
102    <xsl:apply-templates select="." mode="object.title.markup"/>
103  </xsl:variable>
104  <xsl:value-of select="$title"/>
105</xsl:template>
106
107<!-- ============================================================ -->
108
109<xsl:template match="*" mode="object.subtitle.markup">
110  <xsl:variable name="template">
111    <xsl:apply-templates select="." mode="object.subtitle.template"/>
112  </xsl:variable>
113
114  <xsl:call-template name="substitute-markup">
115    <xsl:with-param name="template" select="$template"/>
116  </xsl:call-template>
117</xsl:template>
118
119<!-- ============================================================ -->
120
121<xsl:template match="*" mode="object.xref.markup">
122  <xsl:variable name="template">
123    <xsl:apply-templates select="." mode="object.xref.template"/>
124  </xsl:variable>
125
126<!--
127  <xsl:message>
128    <xsl:text>object.xref.markup: </xsl:text>
129    <xsl:value-of select="local-name(.)"/>
130    <xsl:text>: </xsl:text>
131    <xsl:value-of select="$template"/>
132  </xsl:message>
133-->
134
135  <xsl:call-template name="substitute-markup">
136    <xsl:with-param name="template" select="$template"/>
137  </xsl:call-template>
138</xsl:template>
139
140<xsl:template match="section|simplesect
141                     |sect1|sect2|sect3|sect4|sect5
142                     |refsect1|refsect2|refsect3"
143              mode="object.xref.markup">
144  <xsl:variable name="template">
145    <xsl:apply-templates select="." mode="object.xref.template"/>
146  </xsl:variable>
147
148<!--
149  <xsl:message>
150    <xsl:text>object.xref.markup: </xsl:text>
151    <xsl:value-of select="local-name(.)"/>
152    <xsl:text>: </xsl:text>
153    <xsl:value-of select="$template"/>
154  </xsl:message>
155-->
156
157  <xsl:call-template name="substitute-markup">
158    <xsl:with-param name="template" select="$template"/>
159  </xsl:call-template>
160</xsl:template>
161
162<!-- ============================================================ -->
163
164<xsl:template name="substitute-markup">
165  <xsl:param name="template" select="''"/>
166  <xsl:param name="allow-anchors" select="'0'"/>
167  <xsl:variable name="bef-n" select="substring-before($template, '%n')"/>
168  <xsl:variable name="bef-s" select="substring-before($template, '%s')"/>
169  <xsl:variable name="bef-t" select="substring-before($template, '%t')"/>
170
171<!--
172  <xsl:message>
173    <xsl:text>sm: </xsl:text>
174    <xsl:value-of select="name(.)"/>
175    <xsl:text> </xsl:text>
176    <xsl:value-of select="$allow-anchors"/>
177  </xsl:message>
178-->
179
180  <xsl:choose>
181    <!-- n=1 -->
182    <xsl:when test="starts-with($template, '%n')">
183      <xsl:apply-templates select="." mode="label.markup"/>
184      <xsl:call-template name="substitute-markup">
185        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
186        <xsl:with-param name="template"
187                        select="substring-after($template, '%n')"/>
188      </xsl:call-template>
189    </xsl:when>
190
191    <!-- t=1 -->
192    <xsl:when test="starts-with($template, '%t')">
193      <xsl:apply-templates select="." mode="title.markup">
194        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
195      </xsl:apply-templates>
196      <xsl:call-template name="substitute-markup">
197        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
198        <xsl:with-param name="template"
199                        select="substring-after($template, '%t')"/>
200      </xsl:call-template>
201    </xsl:when>
202
203    <!-- s=1 -->
204    <xsl:when test="starts-with($template, '%s')">
205      <xsl:apply-templates select="." mode="subtitle.markup"/>
206      <xsl:call-template name="substitute-markup">
207        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
208        <xsl:with-param name="template"
209                        select="substring-after($template, '%s')"/>
210      </xsl:call-template>
211    </xsl:when>
212
213    <!-- n and t and s -->
214    <xsl:when test="contains($template, '%n')
215                    and contains($template, '%t')
216                    and contains($template, '%s')">
217      <xsl:choose>
218        <!-- n is first -->
219        <xsl:when test="string-length($bef-n) &lt; string-length($bef-s)
220                        and string-length($bef-n) &lt; string-length($bef-t)">
221          <xsl:value-of select="$bef-n"/>
222          <xsl:apply-templates select="." mode="label.markup"/>
223          <xsl:call-template name="substitute-markup">
224            <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
225            <xsl:with-param name="template"
226                            select="substring-after($template, '%n')"/>
227          </xsl:call-template>
228        </xsl:when>
229        <!-- s is first -->
230        <xsl:when test="string-length($bef-s) &lt; string-length($bef-n)
231                        and string-length($bef-s) &lt; string-length($bef-t)">
232          <xsl:value-of select="$bef-s"/>
233          <xsl:apply-templates select="." mode="subtitle.markup"/>
234          <xsl:call-template name="substitute-markup">
235            <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
236            <xsl:with-param name="template"
237                            select="substring-after($template, '%s')"/>
238          </xsl:call-template>
239        </xsl:when>
240        <!-- t must be first -->
241        <xsl:otherwise>
242          <xsl:value-of select="$bef-t"/>
243          <xsl:apply-templates select="." mode="title.markup">
244            <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
245          </xsl:apply-templates>
246          <xsl:call-template name="substitute-markup">
247            <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
248            <xsl:with-param name="template"
249                            select="substring-after($template, '%t')"/>
250          </xsl:call-template>
251        </xsl:otherwise>
252      </xsl:choose>
253    </xsl:when>
254
255    <!-- n and t -->
256    <xsl:when test="contains($template, '%n')
257                    and contains($template, '%t')">
258      <xsl:choose>
259        <!-- n is first -->
260        <xsl:when test="string-length($bef-n) &lt; string-length($bef-t)">
261          <xsl:value-of select="$bef-n"/>
262          <xsl:apply-templates select="." mode="label.markup"/>
263          <xsl:call-template name="substitute-markup">
264            <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
265            <xsl:with-param name="template"
266                            select="substring-after($template, '%n')"/>
267          </xsl:call-template>
268        </xsl:when>
269        <!-- t is first -->
270        <xsl:otherwise>
271          <xsl:value-of select="$bef-t"/>
272          <xsl:apply-templates select="." mode="title.markup">
273            <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
274          </xsl:apply-templates>
275          <xsl:call-template name="substitute-markup">
276            <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
277            <xsl:with-param name="template"
278                            select="substring-after($template, '%t')"/>
279          </xsl:call-template>
280        </xsl:otherwise>
281      </xsl:choose>
282    </xsl:when>
283
284    <!-- n and s -->
285    <xsl:when test="contains($template, '%n')
286                    and contains($template, '%s')">
287      <xsl:choose>
288        <!-- n is first -->
289        <xsl:when test="string-length($bef-n) &lt; string-length($bef-s)">
290          <xsl:value-of select="$bef-n"/>
291          <xsl:apply-templates select="." mode="label.markup"/>
292          <xsl:call-template name="substitute-markup">
293            <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
294            <xsl:with-param name="template"
295                            select="substring-after($template, '%n')"/>
296          </xsl:call-template>
297        </xsl:when>
298        <!-- s is first -->
299        <xsl:otherwise>
300          <xsl:value-of select="$bef-s"/>
301          <xsl:apply-templates select="." mode="subtitle.markup"/>
302          <xsl:call-template name="substitute-markup">
303            <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
304            <xsl:with-param name="template"
305                            select="substring-after($template, '%s')"/>
306          </xsl:call-template>
307        </xsl:otherwise>
308      </xsl:choose>
309    </xsl:when>
310
311    <!-- t and s -->
312    <xsl:when test="contains($template, '%t')
313                    and contains($template, '%s')">
314      <xsl:choose>
315        <!-- t is first -->
316        <xsl:when test="string-length($bef-t) &lt; string-length($bef-s)">
317          <xsl:value-of select="$bef-t"/>
318          <xsl:apply-templates select="." mode="title.markup">
319            <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
320          </xsl:apply-templates>
321          <xsl:call-template name="substitute-markup">
322            <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
323            <xsl:with-param name="template"
324                            select="substring-after($template, '%t')"/>
325          </xsl:call-template>
326        </xsl:when>
327        <!-- s is first -->
328        <xsl:otherwise>
329          <xsl:value-of select="$bef-s"/>
330          <xsl:apply-templates select="." mode="subtitle.markup"/>
331          <xsl:call-template name="substitute-markup">
332            <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
333            <xsl:with-param name="template"
334                            select="substring-after($template, '%s')"/>
335          </xsl:call-template>
336        </xsl:otherwise>
337      </xsl:choose>
338    </xsl:when>
339
340    <!-- n -->
341    <xsl:when test="contains($template, '%n')">
342      <xsl:value-of select="$bef-n"/>
343      <xsl:apply-templates select="." mode="label.markup"/>
344      <xsl:call-template name="substitute-markup">
345        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
346        <xsl:with-param name="template"
347                        select="substring-after($template, '%n')"/>
348      </xsl:call-template>
349    </xsl:when>
350
351    <!-- t -->
352    <xsl:when test="contains($template, '%t')">
353      <xsl:value-of select="$bef-t"/>
354      <xsl:apply-templates select="." mode="title.markup">
355        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
356      </xsl:apply-templates>
357      <xsl:call-template name="substitute-markup">
358        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
359        <xsl:with-param name="template"
360                        select="substring-after($template, '%t')"/>
361      </xsl:call-template>
362    </xsl:when>
363
364    <!-- s -->
365    <xsl:when test="contains($template, '%s')">
366      <xsl:value-of select="$bef-s"/>
367      <xsl:apply-templates select="." mode="subtitle.markup"/>
368      <xsl:call-template name="substitute-markup">
369        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
370        <xsl:with-param name="template"
371                        select="substring-after($template, '%s')"/>
372      </xsl:call-template>
373    </xsl:when>
374
375    <!-- neither n nor t nor s -->
376    <xsl:otherwise>
377      <xsl:value-of select="$template"/>
378    </xsl:otherwise>
379  </xsl:choose>
380</xsl:template>
381
382<!-- ============================================================ -->
383
384</xsl:stylesheet>
385
386