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"
7 <!-- ********************************************************************
8 $Id: gentext.xsl,v 1.4 2004/01/04 09:26:24 j-devenish Exp $
9 ********************************************************************
11 This file is part of the XSL DocBook Stylesheet distribution.
13 Copyright (C) 1999, 2000, 2001, 2002 Norman Walsh.
14 ******************************************************************** -->
16 <!-- ==================================================================== -->
18 <xsl:param name="appendix.autolabel" select="0"/>
20 <xsl:template match="*" mode="object.title.template">
21 <xsl:call-template name="gentext.template">
22 <xsl:with-param name="context" select="'title'"/>
23 <xsl:with-param name="name">
24 <xsl:call-template name="xpath.location"/>
29 <xsl:template match="chapter" mode="object.title.template">
31 <xsl:when test="$chapter.autolabel != 0">
32 <xsl:call-template name="gentext.template">
33 <xsl:with-param name="context" select="'title-numbered'"/>
34 <xsl:with-param name="name">
35 <xsl:call-template name="xpath.location"/>
40 <xsl:call-template name="gentext.template">
41 <xsl:with-param name="context" select="'title-unnumbered'"/>
42 <xsl:with-param name="name">
43 <xsl:call-template name="xpath.location"/>
50 <xsl:template match="appendix" mode="object.title.template">
52 <xsl:when test="$appendix.autolabel != 0">
53 <xsl:call-template name="gentext.template">
54 <xsl:with-param name="context" select="'title-numbered'"/>
55 <xsl:with-param name="name">
56 <xsl:call-template name="xpath.location"/>
61 <xsl:call-template name="gentext.template">
62 <xsl:with-param name="context" select="'title-unnumbered'"/>
63 <xsl:with-param name="name">
64 <xsl:call-template name="xpath.location"/>
71 <xsl:template match="section|sect1|sect2|sect3|sect4|sect5|simplesect
73 mode="object.title.template">
75 <xsl:when test="$section.autolabel != 0">
76 <xsl:call-template name="gentext.template">
77 <xsl:with-param name="context" select="'title-numbered'"/>
78 <xsl:with-param name="name">
79 <xsl:call-template name="xpath.location"/>
84 <xsl:call-template name="gentext.template">
85 <xsl:with-param name="context" select="'title-unnumbered'"/>
86 <xsl:with-param name="name">
87 <xsl:call-template name="xpath.location"/>
94 <xsl:template match="procedure" mode="object.title.template">
96 <xsl:when test="$formal.procedures != 0">
97 <xsl:call-template name="gentext.template">
98 <xsl:with-param name="context" select="'title'"/>
99 <xsl:with-param name="name">
100 <xsl:call-template name="xpath.location"/>
101 <xsl:text>.formal</xsl:text>
106 <xsl:call-template name="gentext.template">
107 <xsl:with-param name="context" select="'title'"/>
108 <xsl:with-param name="name">
109 <xsl:call-template name="xpath.location"/>
116 <!-- ============================================================ -->
118 <xsl:template match="*" mode="object.subtitle.template">
119 <xsl:call-template name="gentext.template">
120 <xsl:with-param name="context" select="'subtitle'"/>
121 <xsl:with-param name="name">
122 <xsl:call-template name="xpath.location"/>
127 <!-- ============================================================ -->
129 <xsl:template match="*" mode="is.autonumber">
130 <xsl:value-of select="'0'"/>
133 <xsl:template match="section|sect1|sect2|sect3|sect4|sect5"
134 mode="is.autonumber">
135 <xsl:value-of select="$section.autolabel"/>
138 <xsl:template match="figure|example|table|equation" mode="is.autonumber">
139 <xsl:value-of select="'1'"/>
142 <xsl:template match="appendix" mode="is.autonumber">
143 <xsl:value-of select="$appendix.autolabel"/>
146 <xsl:template match="chapter" mode="is.autonumber">
147 <xsl:value-of select="$chapter.autolabel"/>
150 <xsl:template match="part" mode="is.autonumber">
151 <xsl:value-of select="$part.autolabel"/>
154 <xsl:template match="preface" mode="is.autonumber">
155 <xsl:value-of select="$preface.autolabel"/>
158 <xsl:template match="question|answer" mode="is.autonumber">
160 <xsl:when test="$qanda.defaultlabel = 'number'
162 <xsl:value-of select="'1'"/>
165 <xsl:value-of select="'0'"/>
170 <xsl:template match="qandadiv" mode="is.autonumber">
171 <xsl:value-of select="$qandadiv.autolabel"/>
174 <xsl:template match="bridgehead" mode="is.autonumber">
175 <xsl:value-of select="$section.autolabel"/>
178 <xsl:template match="*" mode="object.xref.template">
179 <xsl:param name="purpose"/>
180 <xsl:param name="xrefstyle"/>
181 <xsl:param name="referrer"/>
183 <!-- Is autonumbering on? -->
184 <xsl:variable name="autonumber">
185 <xsl:apply-templates select="." mode="is.autonumber"/>
188 <xsl:variable name="number-and-title-template">
189 <xsl:call-template name="gentext.template.exists">
190 <xsl:with-param name="context" select="'xref-number-and-title'"/>
191 <xsl:with-param name="name">
192 <xsl:call-template name="xpath.location"/>
197 <xsl:variable name="number-template">
198 <xsl:call-template name="gentext.template.exists">
199 <xsl:with-param name="context" select="'xref-number'"/>
200 <xsl:with-param name="name">
201 <xsl:call-template name="xpath.location"/>
206 <xsl:variable name="context">
208 <xsl:when test="$autonumber != 0
209 and $number-and-title-template != 0
210 and $xref.with.number.and.title != 0">
211 <xsl:value-of select="'xref-number-and-title'"/>
213 <xsl:when test="$autonumber != 0
214 and $number-template != 0">
215 <xsl:value-of select="'xref-number'"/>
218 <xsl:value-of select="'xref'"/>
223 <xsl:call-template name="gentext.template">
224 <xsl:with-param name="context" select="$context"/>
225 <xsl:with-param name="name">
226 <xsl:call-template name="xpath.location"/>
228 <xsl:with-param name="purpose" select="$purpose"/>
229 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
230 <xsl:with-param name="referrer" select="$referrer"/>
236 <!-- ============================================================ -->
238 <xsl:template match="*" mode="object.title.markup">
239 <xsl:param name="allow-anchors" select="0"/>
240 <xsl:variable name="template">
241 <xsl:apply-templates select="." mode="object.title.template"/>
246 <xsl:text>object.title.markup: </xsl:text>
247 <xsl:value-of select="local-name(.)"/>
248 <xsl:text>: </xsl:text>
249 <xsl:value-of select="$template"/>
253 <xsl:call-template name="substitute-markup">
254 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
255 <xsl:with-param name="template" select="$template"/>
259 <xsl:template match="*" mode="object.title.markup.textonly">
260 <xsl:variable name="title">
261 <xsl:apply-templates select="." mode="object.title.markup"/>
263 <xsl:value-of select="$title"/>
266 <!-- ============================================================ -->
268 <xsl:template match="*" mode="object.titleabbrev.markup">
269 <xsl:param name="allow-anchors" select="0"/>
271 <!-- Just for consistency in template naming -->
273 <xsl:apply-templates select="." mode="titleabbrev.markup">
274 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
275 </xsl:apply-templates>
278 <!-- ============================================================ -->
280 <xsl:template match="*" mode="object.subtitle.markup">
281 <xsl:variable name="template">
282 <xsl:apply-templates select="." mode="object.subtitle.template"/>
285 <xsl:call-template name="substitute-markup">
286 <xsl:with-param name="template" select="$template"/>
290 <!-- ============================================================ -->
292 <xsl:template match="*" mode="object.xref.markup">
293 <xsl:param name="purpose"/>
294 <xsl:param name="xrefstyle"/>
295 <xsl:param name="referrer"/>
297 <xsl:variable name="template">
299 <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')">
300 <xsl:call-template name="make.gentext.template">
301 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
302 <xsl:with-param name="purpose" select="$purpose"/>
303 <xsl:with-param name="referrer" select="$referrer"/>
306 <xsl:when test="starts-with(normalize-space($xrefstyle), 'template:')">
307 <xsl:value-of select="substring-after(normalize-space($xrefstyle), 'template:')"/>
310 <xsl:apply-templates select="." mode="object.xref.template">
311 <xsl:with-param name="purpose" select="$purpose"/>
312 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
313 <xsl:with-param name="referrer" select="$referrer"/>
314 </xsl:apply-templates>
321 <xsl:text>object.xref.markup: </xsl:text>
322 <xsl:value-of select="local-name(.)"/>
323 <xsl:text>(</xsl:text>
324 <xsl:value-of select="$xrefstyle"/>
325 <xsl:text>, </xsl:text>
326 <xsl:value-of select="$purpose"/>
327 <xsl:text>)</xsl:text>
328 <xsl:text>: [</xsl:text>
329 <xsl:value-of select="$template"/>
330 <xsl:text>]</xsl:text>
334 <xsl:if test="$template = ''">
336 <xsl:text>object.xref.markup: empty xref template</xsl:text>
337 <xsl:text> for linkend="</xsl:text>
338 <xsl:value-of select="@id"/>
339 <xsl:text>" and @xrefstyle="</xsl:text>
340 <xsl:value-of select="$xrefstyle"/>
341 <xsl:text>"</xsl:text>
345 <xsl:call-template name="substitute-markup">
346 <xsl:with-param name="purpose" select="$purpose"/>
347 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
348 <xsl:with-param name="referrer" select="$referrer"/>
349 <xsl:with-param name="template" select="$template"/>
353 <xsl:template match="listitem" mode="object.xref.markup">
355 <xsl:when test="parent::orderedlist">
356 <xsl:variable name="template">
357 <xsl:apply-templates select="." mode="object.xref.template"/>
359 <xsl:call-template name="substitute-markup">
360 <xsl:with-param name="template" select="$template"/>
365 <xsl:text>Xref is only supported to listitems in an</xsl:text>
366 <xsl:text> orderedlist: </xsl:text>
367 <xsl:value-of select="@id"/>
369 <xsl:text>???</xsl:text>
374 <xsl:template match="question" mode="object.xref.markup">
375 <xsl:param name="purpose"/>
376 <xsl:param name="xrefstyle"/>
377 <xsl:param name="referrer"/>
379 <xsl:variable name="deflabel">
381 <xsl:when test="ancestor-or-self::*[@defaultlabel]">
382 <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
386 <xsl:value-of select="$qanda.defaultlabel"/>
391 <xsl:variable name="template">
393 <!-- This avoids double Q: Q: in xref when defaultlabel=qanda -->
394 <xsl:when test="$deflabel = 'qanda' and not(label)">%n</xsl:when>
396 <xsl:apply-templates select="." mode="object.xref.template">
397 <xsl:with-param name="purpose" select="$purpose"/>
398 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
399 <xsl:with-param name="referrer" select="$referrer"/>
400 </xsl:apply-templates>
405 <xsl:call-template name="substitute-markup">
406 <xsl:with-param name="purpose" select="$purpose"/>
407 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
408 <xsl:with-param name="referrer" select="$referrer"/>
409 <xsl:with-param name="template" select="$template"/>
413 <!-- ============================================================ -->
415 <xsl:template name="substitute-markup">
416 <xsl:param name="template" select="''"/>
417 <xsl:param name="allow-anchors" select="'0'"/>
418 <xsl:param name="title" select="''"/>
419 <xsl:param name="subtitle" select="''"/>
420 <xsl:param name="label" select="''"/>
421 <xsl:param name="pagenumber" select="''"/>
422 <xsl:param name="purpose"/>
423 <xsl:param name="xrefstyle"/>
424 <xsl:param name="referrer"/>
427 <xsl:when test="contains($template, '%')">
428 <xsl:value-of select="substring-before($template, '%')"/>
429 <xsl:variable name="candidate"
430 select="substring(substring-after($template, '%'), 1, 1)"/>
432 <xsl:when test="$candidate = 't'">
433 <xsl:apply-templates select="." mode="insert.title.markup">
434 <xsl:with-param name="purpose" select="$purpose"/>
435 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
436 <xsl:with-param name="title">
438 <xsl:when test="$title != ''">
439 <xsl:copy-of select="$title"/>
442 <xsl:apply-templates select="." mode="title.markup">
443 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
444 </xsl:apply-templates>
448 </xsl:apply-templates>
450 <xsl:when test="$candidate = 's'">
451 <xsl:apply-templates select="." mode="insert.subtitle.markup">
452 <xsl:with-param name="purpose" select="$purpose"/>
453 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
454 <xsl:with-param name="subtitle">
456 <xsl:when test="$subtitle != ''">
457 <xsl:copy-of select="$subtitle"/>
460 <xsl:apply-templates select="." mode="subtitle.markup">
461 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
462 </xsl:apply-templates>
466 </xsl:apply-templates>
468 <xsl:when test="$candidate = 'n'">
469 <xsl:apply-templates select="." mode="insert.label.markup">
470 <xsl:with-param name="purpose" select="$purpose"/>
471 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
472 <xsl:with-param name="label">
474 <xsl:when test="$label != ''">
475 <xsl:copy-of select="$label"/>
478 <xsl:apply-templates select="." mode="label.markup"/>
482 </xsl:apply-templates>
484 <xsl:when test="$candidate = 'p'">
485 <xsl:apply-templates select="." mode="insert.pagenumber.markup">
486 <xsl:with-param name="purpose" select="$purpose"/>
487 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
488 <xsl:with-param name="pagenumber">
490 <xsl:when test="$pagenumber != ''">
491 <xsl:copy-of select="$pagenumber"/>
494 <xsl:apply-templates select="." mode="pagenumber.markup"/>
498 </xsl:apply-templates>
500 <xsl:when test="$candidate = 'd'">
501 <xsl:apply-templates select="." mode="insert.direction.markup">
502 <xsl:with-param name="purpose" select="$purpose"/>
503 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
504 <xsl:with-param name="direction">
506 <xsl:when test="$referrer">
507 <xsl:variable name="referent-is-below">
508 <xsl:for-each select="preceding::xref">
509 <xsl:if test="generate-id(.) = generate-id($referrer)">1</xsl:if>
513 <xsl:when test="$referent-is-below = ''">
514 <xsl:call-template name="gentext">
515 <xsl:with-param name="key" select="'above'"/>
519 <xsl:call-template name="gentext">
520 <xsl:with-param name="key" select="'below'"/>
526 <xsl:message>Attempt to use %d in gentext with no referrer!</xsl:message>
530 </xsl:apply-templates>
532 <xsl:when test="$candidate = '%' ">
533 <xsl:text>%</xsl:text>
536 <xsl:text>%</xsl:text><xsl:value-of select="$candidate"/>
539 <!-- recurse with the rest of the template string -->
540 <xsl:variable name="rest"
541 select="substring($template,
542 string-length(substring-before($template, '%'))+3)"/>
543 <xsl:call-template name="substitute-markup">
544 <xsl:with-param name="template" select="$rest"/>
545 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
546 <xsl:with-param name="title" select="$title"/>
547 <xsl:with-param name="subtitle" select="$subtitle"/>
548 <xsl:with-param name="label" select="$label"/>
549 <xsl:with-param name="pagenumber" select="$pagenumber"/>
550 <xsl:with-param name="purpose" select="$purpose"/>
551 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
552 <xsl:with-param name="referrer" select="$referrer"/>
556 <xsl:value-of select="$template"/>
561 <!-- ============================================================ -->
563 <xsl:template name="make.gentext.template">
564 <xsl:param name="xrefstyle" select="''"/>
565 <xsl:param name="purpose"/>
566 <xsl:param name="referrer"/>
567 <xsl:param name="lang">
568 <xsl:call-template name="l10n.language"/>
571 <!-- parse xrefstyle to get parts -->
572 <xsl:variable name="parts"
573 select="substring-after(normalize-space($xrefstyle), 'select:')"/>
575 <xsl:variable name="labeltype">
577 <xsl:when test="contains($parts, 'labelnumber')">
578 <xsl:text>labelnumber</xsl:text>
580 <xsl:when test="contains($parts, 'labelname')">
581 <xsl:text>labelname</xsl:text>
583 <xsl:when test="contains($parts, 'label')">
584 <xsl:text>label</xsl:text>
589 <xsl:variable name="titletype">
591 <xsl:when test="contains($parts, 'quotedtitle')">
592 <xsl:text>quotedtitle</xsl:text>
594 <xsl:when test="contains($parts, 'title')">
595 <xsl:text>title</xsl:text>
600 <xsl:variable name="pagetype">
602 <xsl:when test="$insert.xref.page.number = 'no'">
603 <!-- suppress page numbers -->
605 <xsl:when test="contains($parts, 'nopage')">
606 <xsl:text>nopage</xsl:text>
608 <xsl:when test="contains($parts, 'pagenumber')">
609 <xsl:text>pagenumber</xsl:text>
611 <xsl:when test="contains($parts, 'pageabbrev')">
612 <xsl:text>pageabbrev</xsl:text>
614 <xsl:when test="contains($parts, 'Page')">
615 <xsl:text>Page</xsl:text>
617 <xsl:when test="contains($parts, 'page')">
618 <xsl:text>page</xsl:text>
623 <xsl:if test="$labeltype != ''">
625 <xsl:when test="$labeltype = 'labelname'">
626 <xsl:call-template name="gentext"/>
628 <xsl:when test="$labeltype = 'labelnumber'">
629 <xsl:text>%n</xsl:text>
631 <xsl:when test="$labeltype = 'label'">
632 <xsl:call-template name="gentext.template">
633 <xsl:with-param name="context" select="'xref-number'"/>
634 <xsl:with-param name="name">
635 <xsl:call-template name="xpath.location"/>
637 <xsl:with-param name="purpose" select="$purpose"/>
638 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
639 <xsl:with-param name="referrer" select="$referrer"/>
645 <xsl:when test="$titletype != ''">
646 <xsl:value-of select="$xref.label-title.separator"/>
648 <xsl:when test="$pagetype != ''">
649 <xsl:value-of select="$xref.label-page.separator"/>
654 <xsl:if test="$titletype != ''">
656 <xsl:when test="$titletype = 'title'">
657 <xsl:text>%t</xsl:text>
659 <xsl:when test="$titletype = 'quotedtitle'">
660 <xsl:call-template name="gentext.dingbat">
661 <xsl:with-param name="dingbat" select="'startquote'"/>
663 <xsl:text>%t</xsl:text>
664 <xsl:call-template name="gentext.dingbat">
665 <xsl:with-param name="dingbat" select="'endquote'"/>
671 <xsl:when test="$pagetype != '' and $pagetype != 'nopage'">
672 <xsl:value-of select="$xref.title-page.separator"/>
677 <xsl:if test="$pagetype != ''">
679 <!-- special case: use regular xref template -->
680 <xsl:when test="$pagetype = 'nopage'
682 and $titletype = ''">
683 <xsl:apply-templates select="." mode="object.xref.template">
684 <xsl:with-param name="purpose" select="$purpose"/>
685 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
686 <xsl:with-param name="referrer" select="$referrer"/>
687 </xsl:apply-templates>
689 <xsl:when test="$pagetype = 'page'">
690 <xsl:call-template name="gentext.template">
691 <xsl:with-param name="context" select="'xref'"/>
692 <xsl:with-param name="name" select="'page'"/>
695 <xsl:when test="$pagetype = 'Page'">
696 <xsl:call-template name="gentext.template">
697 <xsl:with-param name="context" select="'xref'"/>
698 <xsl:with-param name="name" select="'Page'"/>
701 <xsl:when test="$pagetype = 'pageabbrev'">
702 <xsl:call-template name="gentext.template">
703 <xsl:with-param name="context" select="'xref'"/>
704 <xsl:with-param name="name" select="'pageabbrev'"/>
707 <xsl:when test="$pagetype = 'pagenumber'">
708 <xsl:text>%p</xsl:text>