summaryrefslogtreecommitdiff
path: root/docs/xslt/db2latex-xsl/xsl/callout.mod.xsl
blob: c671d30b7dd8b56d9a11441f9fbe1f14ee17dd70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
<?xml version='1.0'?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY % xsldoc.ent SYSTEM "./xsldoc.ent"> %xsldoc.ent; ]>
<!--############################################################################# 
|	$Id: callout.mod.xsl,v 1.10 2004/01/14 14:54:32 j-devenish Exp $
|- #############################################################################
|	$Author: j-devenish $
+ ############################################################################## -->

<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
	exclude-result-prefixes="doc" version='1.0'>

	<doc:reference id="callout" xmlns="">
		<referenceinfo>
			<releaseinfo role="meta">
				$Id: callout.mod.xsl,v 1.10 2004/01/14 14:54:32 j-devenish Exp $
			</releaseinfo>
			<authorgroup>
				&ramon;
				&james;
			</authorgroup>
			<copyright>
				<year>2000</year><year>2001</year><year>2002</year><year>2003</year><year>2004</year>
				<holder>Ramon Casellas</holder>
			</copyright>
			<revhistory>
				<doc:revision rcasver="1.5">&rev_2003_05;</doc:revision>
				<doc:revision rcasver="1.6">
					<date>January 2004</date>
					<revremark>Added callout support.</revremark>
				</doc:revision>
			</revhistory>
		</referenceinfo>
		<title>Callouts <filename>callout.mod.xsl</filename></title>
		<partintro>
			<para>
			
			These template use the concept of an <quote>areamark</quote>, an
			<quote>arearef</quote> and an <quote>areasymbol</quote>. An areamark
			is a way of illustrating a callout area as part of an image or
			listing. An arearef is a way of illustrating a callout area as part of
			a callout list. By default, the areamark and the arearef are both
			represented by the areasymbol. (Aside: that the areamark is drawn
			first.) This system allows opens the possibility for an areamark to
			draw a box around an area in addition to displaying the areasymbol.
			
			</para>
		</partintro>
	</doc:reference>

	<doc:template xmlns="">
		<refpurpose> Essential preamble for <filename>callout.mod.xsl</filename> support </refpurpose>
		<doc:description>
			<para>

				Loads the <productname>overpic</productname> packages and
				defines <function condition="latex">calsscale</function>
				and <function condition="latex">calspair</function> (which
				are used to convert <quote>calspair</quote> coordinates into
				<productname>overpic</productname> percent-style coordinates.

			</para>
		</doc:description>
		<doc:variables>
			<variablelist>
				<varlistentry>
					<term><xref linkend="param.latex.use.overpic"/></term>
					<listitem><simpara>
						Whether to enable this preamble or not.
						If 0, callouts will cause &LaTeX; errors.
					</simpara></listitem>
				</varlistentry>
			</variablelist>
		</doc:variables>
		<doc:seealso>
			<itemizedlist>
				<listitem><simpara>&preamble;</simpara></listitem>
			</itemizedlist>
		</doc:seealso>
	</doc:template>
	<xsl:template name="latex.preamble.essential.callout">
		<xsl:if test="$latex.use.overpic=1 and //callout">
			<xsl:text>
				<![CDATA[
\usepackage[percent]{overpic}
\newdimen\dblatex@ascale \newdimen\dblatex@bscale
\newdimen\dblatex@adimen \newdimen\dblatex@bdimen
\newdimen\dblatex@cdimen \newdimen\dblatex@ddimen
\newcommand{\calsscale}{%
   \ifnum\@tempcnta>\@tempcntb%
      \dblatex@ascale=1pt%
      \dblatex@bscale=\@tempcntb pt%
      \divide\dblatex@bscale by \@tempcnta%
   \else%
      \dblatex@bscale=1 pt%
      \dblatex@ascale=\@tempcnta pt%
      \divide\dblatex@ascale by \@tempcntb%
   \fi%
}
\newcommand{\calspair}[3]{
   \sbox{\z@}{#3}
   \settowidth{\dblatex@cdimen}{\usebox{\z@}}
   \settoheight{\dblatex@ddimen}{\usebox{\z@}}
   \divide\dblatex@cdimen by 2
   \divide\dblatex@ddimen by 2
   \dblatex@adimen=#1 pt \dblatex@adimen=\strip@pt\dblatex@ascale\dblatex@adimen
   \dblatex@bdimen=#2 pt \dblatex@bdimen=\strip@pt\dblatex@bscale\dblatex@bdimen
   \put(\strip@pt\dblatex@adimen,\strip@pt\dblatex@bdimen){\hspace{-\dblatex@cdimen}\raisebox{-\dblatex@ddimen}{\usebox{\z@}}}
}
]]>
			</xsl:text>
		</xsl:if>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>programlistingco</doc:db> and <doc:db>screenco</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Applies templates.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	<xsl:template match="programlistingco|screenco">
		<xsl:apply-templates select="programlisting|screen|calloutlist"/>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>areaset</doc:db>-related elements</refpurpose>
		<doc:description>
			<para>
				Suppressed (<doc:db>area</doc:db> templates are applied by
				<xref linkend="template.imagedata"/>).
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	 <xsl:template match="areaspec|areaset"/>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>co</doc:db>-related elements</refpurpose>
		<doc:description>
			<para>
				Print a callout number as a parenthesis.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>This template is probably never applied, because
			we can't yet handled <doc:db basename="co">cos</doc:db>
			in verbatim environments.</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="co">
		<xsl:variable name="conum">
			<xsl:number count="co" format="1"/>
		</xsl:variable>
		<xsl:text>(</xsl:text>
		<xsl:value-of select="$conum"/>
		<xsl:text>)</xsl:text>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>calloutlist</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Applies templates.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	<xsl:template match="calloutlist">
		<xsl:apply-templates select="./title"/>
		<xsl:text>&#10;\begin{description}&#10;</xsl:text>
		<xsl:apply-templates select="callout"/>
		<xsl:text>\end{description}&#10;</xsl:text>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process titles for <doc:db>calloutlist</doc:db> elements</refpurpose>
		<doc:description>
			<para>
			
			Formats a title.
			
			</para>
		</doc:description>
		<doc:variables>
			<variablelist>
				<varlistentry>
					<term><xref linkend="param.latex.list.title.style"/></term>
					<listitem><simpara>
						The &LaTeX; command for formatting titles.
					</simpara></listitem>
				</varlistentry>
			</variablelist>
		</doc:variables>
		<doc:params>
			<variablelist>
				<varlistentry>
					<term>style</term>
					<listitem><simpara>The &LaTeX; command to use. Defaults to
					<xref linkend="param.latex.list.title.style"/>.</simpara></listitem>
				</varlistentry>
			</variablelist>
		</doc:params>
		<doc:notes>
			<para>
				Applies templates as a paragraph, formatted with the specified style.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="calloutlist/title">
		<xsl:param name="style" select="$latex.list.title.style"/>
		<xsl:text>&#10;{</xsl:text>
		<xsl:value-of select="$style"/>
		<xsl:text>{</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>}}&#10;</xsl:text>
	</xsl:template>

	<doc:template basename="callout" xmlns="">
		<refpurpose>Process <doc:db>callout</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Formats arearefs as an <function condition="latex">item</function>,
				then applies templates. Since there may be multiple IDs specified
				in the <sgmltag class="attribute">arearefs</sgmltag> attribute,
				the <xref linkend="template.generate.callout.arearefs"/> template is
				called recursively to generate the arearefs.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	<xsl:template match="callout">
		<xsl:text>\item[{</xsl:text>
		<xsl:call-template name="generate.callout.arearefs"/>
		<xsl:text>}]\null{}&#10;</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>&#10;</xsl:text>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Determine a <doc:db>callout</doc:db>'s arearefs</refpurpose>
		<doc:description>
			<para>
				Splits the arearef attribute on whitespace, then
				constructs a list of references by applying templates
				in <quote>generate.callout.arearef</quote> mode.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				The current node must be a <doc:db>callout</doc:db>.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template name="generate.callout.arearefs">
		<xsl:param name="arearefs" select="normalize-space(@arearefs)"/>
		<xsl:param name="count" select="1"/>
		<xsl:if test="$arearefs!=''">
			<xsl:choose>
				<xsl:when test="substring-before($arearefs,' ')=''">
					<xsl:apply-templates select="." mode="generate.callout.arearef">
						<xsl:with-param name="arearef" select="$arearefs"/>
						<xsl:with-param name="count" select="$count"/>
						<xsl:with-param name="last" select="true()"/>
					</xsl:apply-templates>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates select="." mode="generate.callout.arearef">
						<xsl:with-param name="arearef" select="substring-before($arearefs,' ')"/>
						<xsl:with-param name="count" select="$count"/>
						<xsl:with-param name="last" select="false()"/>
					</xsl:apply-templates>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:call-template name="generate.callout.arearefs">
				<xsl:with-param name="arearefs" select="substring-after($arearefs,' ')"/>
				<xsl:with-param name="count" select="$count + 1"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Format a <doc:db>callout</doc:db>'s arearefs</refpurpose>
		<doc:description>
			<para>
				Applies templates in <quote>generate.callout.arearef</quote> mode.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:params>
			<variablelist>
				<varlistentry>
					<term>arearef</term>
					<listitem><simpara>
						The ID of the <doc:db>area</doc:db> to which a <doc:db>callout</doc:db>
						refers.
					</simpara></listitem>
				</varlistentry>
				<varlistentry>
					<term>area</term>
					<listitem><simpara>
						The <doc:db>area</doc:db> object to which a <doc:db>callout</doc:db>
						refers. By default, this searches for a area whose <sgmltag
						class="attribute">id</sgmltag> attribute equals the
						<literal>arearef</literal> parameter.
					</simpara></listitem>
				</varlistentry>
				<varlistentry>
					<term>count</term>
					<listitem><simpara>
						The position of this reference in the list of references
						used by a given <doc:db>callout</doc:db>. Influences
						delimiters for list items.
					</simpara></listitem>
				</varlistentry>
				<varlistentry>
					<term>last</term>
					<listitem><simpara>
						Whether this area reference is the last one for a given
						<doc:db>callout</doc:db>. Influences delimiters for list
						items.
					</simpara></listitem>
				</varlistentry>
			</variablelist>
		</doc:params>
		<doc:notes>
			<para>
				Formats a reference for a single arearef. This is performed by
				applying templates for the <doc:db>area</doc:db> in
				<quote>generate.area.arearef</quote> mode.
			</para>
			<para>
				The current node must be a <doc:db>callout</doc:db>.
			</para>
			<para>
				Uses the <quote>naturalinlinelist</quote> localisation context.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="callout" mode="generate.callout.arearef">
		<xsl:param name="arearef" select="@arearefs"/>
		<xsl:param name="area" select="key('id', $arearef)"/>
		<xsl:param name="last" select="false()"/>
		<xsl:param name="count" select="1"/>
		<xsl:variable name="first" select="$count=1"/>
		<xsl:choose>
			<xsl:when test="$first">
				<xsl:call-template name="gentext.template">
					<xsl:with-param name="context" select="'naturalinlinelist'"/>
					<xsl:with-param name="name" select="'start'"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="$last">
				<xsl:call-template name="gentext.template">
					<xsl:with-param name="context" select="'naturalinlinelist'"/>
					<xsl:with-param name="name">
						<xsl:choose>
							<xsl:when test="$count &gt; 2">
								<xsl:text>lastofmany</xsl:text>
							</xsl:when>
							<xsl:otherwise>
								<xsl:text>lastoftwo</xsl:text>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="gentext.template">
					<xsl:with-param name="context" select="'naturalinlinelist'"/>
					<xsl:with-param name="name" select="'middle'"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="$area">
				<xsl:apply-templates select="$area" mode="generate.area.arearef"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>?</xsl:text>
				<xsl:message>
					<xsl:text>Error: no ID for constraint arearefs: </xsl:text>
					<xsl:value-of select="$arearef"/>
					<xsl:text>.</xsl:text>
				</xsl:message>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:if test="$last">
			<xsl:call-template name="gentext.template">
				<xsl:with-param name="context" select="'naturalinlinelist'"/>
				<xsl:with-param name="name" select="'end'"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<doc:template basename="area" xmlns="">
		<refpurpose>Illustrate a reference to a callout's area</refpurpose>
		<doc:description>
			<para>
				Formats an <doc:db>area</doc:db> as part of a
				callout list.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				The current node must be an <doc:db>area</doc:db>.
			</para>
			<para>
				Applies templates in the <quote>generate.arearef.calspair</quote>,
				<quote>generate.arearef.linerange</quote> and
				<quote>generate.arearef</quote> modes.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="area" mode="generate.area.arearef">
		<xsl:variable name="units">
			<xsl:choose>
				<xsl:when test="@units!=''">
					<xsl:value-of select="@units"/>
				</xsl:when>
				<xsl:when test="../@units!=''">
					<xsl:value-of select="../@units"/>
				</xsl:when>
				<xsl:when test="../../@units!=''">
					<xsl:value-of select="../../@units"/>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$units='calspair'">
				<xsl:apply-templates select="." mode="generate.arearef.calspair"/>
			</xsl:when>
			<xsl:when test="$units='linerange'">
				<xsl:apply-templates select="." mode="generate.arearef.linerange"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="generate.arearef">
					<xsl:with-param name="units" select="$units"/>
				</xsl:apply-templates>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<doc:template basename="area" xmlns="">
		<refpurpose>Illustrate a reference to a callout's area</refpurpose>
		<doc:description>
			<para>
				Formats an <doc:db>area</doc:db> as part of a
				callout list.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				This is a fallback template for unknown units.
				It does not format an arearef but instead prints
				an error message.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="area" mode="generate.arearef">
		<xsl:param name="units"/>
		<xsl:message>Error: unsupported arearef units <xsl:value-of select="$units"/>.</xsl:message>
	</xsl:template>

	<doc:template basename="area" xmlns="">
		<refpurpose>Illustrate a reference to a callout's area</refpurpose>
		<doc:description>
			<para>
				Formats calspair units for a callout list.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				Calls <xref linkend="template.area-generate.area.areasymbol"/>.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="area" mode="generate.arearef.calspair">
		<xsl:apply-templates select="." mode="generate.area.areasymbol"/>
	</xsl:template>

	<doc:template basename="area" xmlns="">
		<refpurpose>Illustrate a reference to a callout's area</refpurpose>
		<doc:description>
			<para>
				Formats linerange units for a callout list.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				Formats a line range numerically, condensing the line range
				down to a single line reference if the starting line is the
				same as the finishing line.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="area" mode="generate.arearef.linerange">
		<xsl:choose>
			<xsl:when test="not(contains(@coords, ' '))">
				<xsl:value-of select="@coords"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="start" select="substring-before(@coords, ' ')"/>
				<xsl:variable name="finish" select="substring-after(@coords, ' ')"/>
				<xsl:choose>
					<xsl:when test="$start=$finish">
						<xsl:value-of select="$start"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="string-replace">
							<xsl:with-param name="from" select="' '"/>
							<xsl:with-param name="to" select="'--'"/>
							<xsl:with-param name="string" select="@coords"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<doc:template basename="area" xmlns="">
		<refpurpose>Illustrate a callout's area as part of an image or listing</refpurpose>
		<doc:description>
			<para>
				Formats an <doc:db>area</doc:db> as part of a
				displayed image or listing.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				Applies templates in the <quote>generate.area.areamark</quote> mode.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="area">
		<xsl:apply-templates select="." mode="generate.area.areamark"/>
	</xsl:template>

	<doc:template basename="area" xmlns="">
		<refpurpose>Illustrate a callout's area as part of an image or listing</refpurpose>
		<doc:description>
			<para>
				Formats an <doc:db>area</doc:db> as part of a
				displayed image or listing.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				Applies templates in the <quote>generate.areamark.calspair</quote> or
				<quote>generate.areamark</quote> modes.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="area" mode="generate.area.areamark">
		<xsl:variable name="units">
			<xsl:choose>
				<xsl:when test="@units!=''">
					<xsl:value-of select="@units"/>
				</xsl:when>
				<xsl:when test="../@units!=''">
					<xsl:value-of select="../@units"/>
				</xsl:when>
				<xsl:when test="../../@units!=''">
					<xsl:value-of select="../../@units"/>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$units='calspair'">
				<xsl:apply-templates select="." mode="generate.areamark.calspair"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="generate.areamark">
					<xsl:with-param name="units" select="$units"/>
				</xsl:apply-templates>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<doc:template basename="area" xmlns="">
		<refpurpose>Illustrate a callout's area as part of an image or listing</refpurpose>
		<doc:description>
			<para>
				Formats an <doc:db>area</doc:db> as part of a
				displayed image or listing.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				This is a fallback template for unknown units.
				It does not format an areamark but instead prints
				an error message.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="area" mode="generate.areamark">
		<xsl:param name="units"/>
		<xsl:message>Error: unsupported areamark units <xsl:value-of select="$units"/>.</xsl:message>
	</xsl:template>

	<doc:template basename="area" xmlns="">
		<refpurpose>Illustrate a callout's area as part of an image or listing</refpurpose>
		<doc:description>
			<para>
				Formats calspair units for a displayed image or listing.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				Converts calspair coordinates relative to the width and height of the
				displayed image area. Will understand "x1,y1 x2,y2" and also "x1 y1".
				In the former case, the drawing location is moved to the centre of
				the implied rectangle. Templates are then applied in the
				<quote>generate.area.areasymbol</quote> mode.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="area" mode="generate.areamark.calspair">
		<xsl:choose>
			<xsl:when test="not(contains(@coords, ' '))">
				<xsl:message>Error: invalid calspair '<xsl:value-of select="@coords"/>'.</xsl:message>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="x1y1">
					<xsl:value-of select="substring-before(@coords, ' ')"/>
				</xsl:variable>
				<xsl:variable name="x1">
					<xsl:choose>
						<xsl:when test="contains($x1y1, ',')">
							<xsl:value-of select="substring-before($x1y1, ',')"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$x1y1"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:variable name="y1">
					<xsl:choose>
						<xsl:when test="contains($x1y1, ',')">
							<xsl:value-of select="substring-after($x1y1, ',')"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="''"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:variable name="x2y2">
					<xsl:value-of select="substring-after(@coords, ' ')"/>
				</xsl:variable>
				<xsl:variable name="y2">
					<xsl:choose>
						<xsl:when test="contains($x2y2, ',')">
							<xsl:value-of select="substring-after($x2y2, ',')"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$x2y2"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:variable name="x2">
					<xsl:choose>
						<xsl:when test="contains($x2y2, ',')">
							<xsl:value-of select="substring-before($x2y2, ',')"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="''"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:text>\calspair{</xsl:text>
				<!-- choose horizontal coordinate -->
				<xsl:choose>
					<xsl:when test="$x1 != '' and $x2 != ''">
						<xsl:value-of select="(number($x1)+number($x2)) div 200"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="number(concat($x1, $x2)) div 100"/>
					</xsl:otherwise>
				</xsl:choose>
				<xsl:text>}{</xsl:text>
				<!-- choose vertical coordinate -->
				<xsl:choose>
					<xsl:when test="$y1 != '' and $y2 != ''">
						<xsl:value-of select="(number($y1)+number($y2)) div 200"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="number(concat($y1, $y2)) div 100"/>
					</xsl:otherwise>
				</xsl:choose>
				<xsl:text>}{</xsl:text>
				<xsl:apply-templates select="." mode="generate.area.areasymbol"/>
				<xsl:text>}&#10;</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<doc:template basename="area" xmlns="">
		<refpurpose>Illustrate a callout's area as part of an image or listing</refpurpose>
		<doc:description>
			<para>
				Formats an <doc:db>area</doc:db> as an overlay
				on an image or listing.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				If the area has a <sgmltag class="attribute">label</sgmltag>
				attribute, it is used as raw &LaTeX; code.
			</para>
			<para>
				If the area has a linkends attribute, templates are
				applied for the first linkend using
				<quote>generate.callout.areasymbol</quote> mode.
				It is implicit in this scenario that an arearef
				and an areamark will both consist of an identical
				icon for an area.
			</para>
			<para>
				If none of the above were performed, an asterisk is printed.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="area" mode="generate.area.areasymbol">
		<xsl:param name="linkends" select="normalize-space(@linkends)"/>
		<xsl:choose>
			<xsl:when test="@label">
				<xsl:value-of select="@label"/>
			</xsl:when>
			<xsl:when test="$linkends!=''">
				<xsl:variable name="linkend">
					<xsl:choose>
						<xsl:when test="contains($linkends, ' ')">
							<xsl:value-of select="substring-before($linkends, ' ')"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$linkends"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:variable name="target" select="key('id', $linkend)"/>
				<xsl:choose>
					<xsl:when test="count($target)&gt;0">
						<xsl:for-each select="$target">
							<xsl:apply-templates select="." mode="generate.callout.areasymbol">
								<xsl:with-param name="arearef" select="generate-id(current())"/>
								<xsl:with-param name="area" select="current()"/>
							</xsl:apply-templates>
						</xsl:for-each>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>?</xsl:text>
						<xsl:message>
							<xsl:text>Error: no ID for constraint linkends: </xsl:text>
							<xsl:value-of select="$linkends"/>
							<xsl:text>.</xsl:text>
						</xsl:message>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>*</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<doc:template basename="callout" xmlns="">
		<refpurpose>Illustrate a callout's area as part of an image or listing</refpurpose>
		<doc:description>
			<para>
				Illustrates an <doc:db>area</doc:db> as part of a
				displayed image or listing.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
		<doc:notes>
			<para>
				Prints the numeric position of the <doc:db>callout</doc:db> within its <doc:db>calloutlist</doc:db>.
			</para>
		</doc:notes>
	</doc:template>
	<xsl:template match="callout" mode="generate.callout.areasymbol">
		<xsl:number count="callout" format="1"/>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>mediaobjectco</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Applies templates.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	<xsl:template match="mediaobjectco">
		<xsl:text>&#10;</xsl:text>
		<xsl:apply-templates select="imageobjectco"/>
		<xsl:text>&#10;</xsl:text>
	</xsl:template>

	<doc:template xmlns="">
		<refpurpose>Process <doc:db>imageobjectco</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Applies templates.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	<xsl:template match="imageobjectco">
		<xsl:apply-templates select="imageobject"/>
		<xsl:text>&#10;</xsl:text>
		<xsl:apply-templates select="calloutlist"/>
	</xsl:template>

	<doc:template basename="imageobject" xmlns="">
		<refpurpose>Process a <doc:db>imageobjectco</doc:db>'s <doc:db>imageobject</doc:db> elements</refpurpose>
		<doc:description>
			<para>
				Applies templates for <doc:db>imagedata</doc:db>.
			</para>
		</doc:description>
		<doc:variables>
			&no_var;
		</doc:variables>
	</doc:template>
	<xsl:template match="imageobjectco/imageobject">
		<xsl:apply-templates select="imagedata">
			<xsl:with-param name="is.imageobjectco" select="true()"/>
		</xsl:apply-templates>
	</xsl:template>

</xsl:stylesheet>