1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                xmlns:fo="http://www.w3.org/1999/XSL/Format"
4                xmlns:sverb="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Verbatim"
5                xmlns:xverb="com.nwalsh.xalan.Verbatim"
6                xmlns:lxslt="http://xml.apache.org/xslt"
7                exclude-result-prefixes="sverb xverb lxslt"
8                version='1.0'>
9
10<!-- ********************************************************************
11     $Id: callout.xsl,v 1.12 2003/08/28 20:51:58 bobstayton Exp $
12     ********************************************************************
13
14     This file is part of the XSL DocBook Stylesheet distribution.
15     See /README or http://nwalsh.com/docbook/xsl/ for copyright
16     and other information.
17
18     ******************************************************************** -->
19
20<lxslt:component prefix="xverb"
21                 functions="insertCallouts"/>
22
23<xsl:template match="programlistingco|screenco">
24  <xsl:variable name="verbatim" select="programlisting|screen"/>
25  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
26
27  <xsl:choose>
28    <xsl:when test="$use.extensions != '0'
29                    and $callouts.extension != '0'">
30      <xsl:variable name="rtf">
31        <xsl:apply-templates select="$verbatim">
32          <xsl:with-param name="suppress-numbers" select="'1'"/>
33        </xsl:apply-templates>
34      </xsl:variable>
35
36      <xsl:variable name="rtf-with-callouts">
37        <xsl:choose>
38          <xsl:when test="contains($vendor, 'SAXON ')">
39            <xsl:copy-of select="sverb:insertCallouts(areaspec,$rtf)"/>
40          </xsl:when>
41          <xsl:when test="contains($vendor, 'Apache Software Foundation')">
42            <xsl:copy-of select="xverb:insertCallouts(areaspec,$rtf)"/>
43          </xsl:when>
44          <xsl:otherwise>
45            <xsl:message terminate="yes">
46              <xsl:text>Don't know how to do callouts with </xsl:text>
47              <xsl:value-of select="$vendor"/>
48            </xsl:message>
49          </xsl:otherwise>
50        </xsl:choose>
51      </xsl:variable>
52
53      <xsl:choose>
54        <xsl:when test="$verbatim/@linenumbering = 'numbered'
55                        and $linenumbering.extension != '0'">
56          <xsl:call-template name="number.rtf.lines">
57            <xsl:with-param name="rtf" select="$rtf-with-callouts"/>
58            <xsl:with-param name="pi.context"
59                            select="programlisting|screen"/>
60          </xsl:call-template>
61          <xsl:apply-templates select="calloutlist"/>
62        </xsl:when>
63        <xsl:otherwise>
64          <xsl:copy-of select="$rtf-with-callouts"/>
65          <xsl:apply-templates select="calloutlist"/>
66        </xsl:otherwise>
67      </xsl:choose>
68    </xsl:when>
69    <xsl:otherwise>
70      <xsl:apply-templates/>
71    </xsl:otherwise>
72  </xsl:choose>
73</xsl:template>
74
75<xsl:template match="areaspec|areaset|area">
76</xsl:template>
77
78<xsl:template match="areaset" mode="conumber">
79  <xsl:number count="area|areaset" format="1"/>
80</xsl:template>
81
82<xsl:template match="area" mode="conumber">
83  <xsl:number count="area|areaset" format="1"/>
84</xsl:template>
85
86<xsl:template match="co">
87  <fo:inline id="{@id}">
88    <xsl:apply-templates select="." mode="callout-bug"/>
89  </fo:inline>
90</xsl:template>
91
92<xsl:template match="coref">
93  <!-- tricky; this relies on the fact that we can process the "co" that's -->
94  <!-- "over there" as if it were "right here" -->
95
96  <xsl:variable name="co" select="key('id', @linkend)"/>
97  <xsl:variable name="id" select="@id"/>
98  <xsl:choose>
99    <xsl:when test="not($co)">
100      <xsl:message>
101        <xsl:text>Error: coref link is broken: </xsl:text>
102        <xsl:value-of select="@linkend"/>
103      </xsl:message>
104    </xsl:when>
105    <xsl:when test="local-name($co) != 'co'">
106      <xsl:message>
107        <xsl:text>Error: coref doesn't point to a co: </xsl:text>
108        <xsl:value-of select="@linkend"/>
109      </xsl:message>
110    </xsl:when>
111    <xsl:otherwise>
112      <fo:inline>
113        <xsl:if test="$id != ''">
114	  <xsl:attribute name="id">
115	    <xsl:value-of select="$id"/>
116	  </xsl:attribute>
117	</xsl:if>
118        <xsl:apply-templates select="$co" mode="callout-bug"/>
119      </fo:inline>
120    </xsl:otherwise>
121  </xsl:choose>
122</xsl:template>
123
124<xsl:template match="co" mode="callout-bug">
125  <xsl:call-template name="callout-bug">
126    <xsl:with-param name="conum">
127      <xsl:number count="co"
128                  level="any"
129                  from="programlisting|screen|literallayout|synopsis"
130                  format="1"/>
131    </xsl:with-param>
132  </xsl:call-template>
133</xsl:template>
134
135<xsl:template name="callout-bug">
136  <xsl:param name="conum" select='1'/>
137
138  <xsl:choose>
139    <!-- Draw callouts as images -->
140    <xsl:when test="$callout.graphics != '0'
141                    and $conum &lt;= $callout.graphics.number.limit">
142      <xsl:variable name="filename"
143                    select="concat($callout.graphics.path,$conum,$callout.graphics.extension)"/>
144
145      <fo:external-graphic>
146        <xsl:attribute name="src">
147          <xsl:choose>
148            <xsl:when test="$passivetex.extensions != 0
149                            or $fop.extensions != 0
150                            or $arbortext.extensions != 0">
151              <xsl:value-of select="$filename"/>
152            </xsl:when>
153            <xsl:otherwise>
154              <xsl:text>url(</xsl:text>
155              <xsl:value-of select="$filename"/>
156              <xsl:text>)</xsl:text>
157            </xsl:otherwise>
158          </xsl:choose>
159        </xsl:attribute>
160      </fo:external-graphic>
161    </xsl:when>
162
163    <xsl:when test="$callout.unicode != 0
164                    and $conum &lt;= $callout.unicode.number.limit">
165      <xsl:variable name="comarkup">
166        <xsl:choose>
167          <xsl:when test="$callout.unicode.start.character = 10102">
168            <xsl:choose>
169              <xsl:when test="$conum = 1">&#10102;</xsl:when>
170              <xsl:when test="$conum = 2">&#10103;</xsl:when>
171              <xsl:when test="$conum = 3">&#10104;</xsl:when>
172              <xsl:when test="$conum = 4">&#10105;</xsl:when>
173              <xsl:when test="$conum = 5">&#10106;</xsl:when>
174              <xsl:when test="$conum = 6">&#10107;</xsl:when>
175              <xsl:when test="$conum = 7">&#10108;</xsl:when>
176              <xsl:when test="$conum = 8">&#10109;</xsl:when>
177              <xsl:when test="$conum = 9">&#10110;</xsl:when>
178              <xsl:when test="$conum = 10">&#10111;</xsl:when>
179            </xsl:choose>
180          </xsl:when>
181          <xsl:otherwise>
182            <xsl:message>
183              <xsl:text>Don't know how to generate Unicode callouts </xsl:text>
184              <xsl:text>when $callout.unicode.start.character is </xsl:text>
185              <xsl:value-of select="$callout.unicode.start.character"/>
186            </xsl:message>
187            <fo:inline background-color="#404040"
188                       color="white"
189                       padding-top="0.1em"
190                       padding-bottom="0.1em"
191                       padding-start="0.2em"
192                       padding-end="0.2em"
193                       baseline-shift="0.1em"
194                       font-family="{$body.fontset}"
195                       font-weight="bold"
196                       font-size="75%">
197              <xsl:value-of select="$conum"/>
198            </fo:inline>
199          </xsl:otherwise>
200        </xsl:choose>
201      </xsl:variable>
202
203      <xsl:choose>
204        <xsl:when test="$callout.unicode.font != ''">
205          <fo:inline font-family="{$callout.unicode.font}">
206            <xsl:copy-of select="$comarkup"/>
207          </fo:inline>
208        </xsl:when>
209        <xsl:otherwise>
210          <xsl:copy-of select="$comarkup"/>
211        </xsl:otherwise>
212      </xsl:choose>
213    </xsl:when>
214
215    <!-- Most safe: draw a dark gray square with a white number inside -->
216    <xsl:otherwise>
217      <fo:inline background-color="#404040"
218                 color="white"
219                 padding-top="0.1em"
220                 padding-bottom="0.1em"
221                 padding-start="0.2em"
222                 padding-end="0.2em"
223                 baseline-shift="0.1em"
224                 font-family="{$body.fontset}"
225                 font-weight="bold"
226                 font-size="75%">
227        <xsl:value-of select="$conum"/>
228      </fo:inline>
229    </xsl:otherwise>
230  </xsl:choose>
231</xsl:template>
232
233</xsl:stylesheet>
234