1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                version='1.0'>
4
5<xsl:template name="add.annotation.links">
6  <xsl:param name="scripts" select="normalize-space($annotation.js)"/>
7  <xsl:choose>
8    <xsl:when test="contains($scripts, ' ')">
9      <script type="text/javascript" src="{substring-before($scripts, ' ')}"/>
10      <xsl:call-template name="add.annotation.links">
11	<xsl:with-param name="scripts" select="substring-after($scripts, ' ')"/>
12      </xsl:call-template>
13    </xsl:when>
14    <xsl:otherwise>
15      <script type="text/javascript" src="{$scripts}"/>
16    </xsl:otherwise>
17  </xsl:choose>
18</xsl:template>
19
20<xsl:template match="annotation"/>
21
22<xsl:template name="apply-annotations">
23  <xsl:if test="$annotation.support != 0">
24  <!-- do any annotations apply to the context node? -->
25  <xsl:variable name="id" select="(@id|@xml:id)[1]"/>
26
27  <xsl:variable name="aids">
28    <xsl:for-each select="//annotation">
29      <xsl:if test="@annotates=$id
30	            or starts-with(@annotates, concat($id, ' '))
31		    or contains(@annotates, concat(' ', $id, ' '))
32		    or substring(@annotates, string-length(@annotates)-3)
33		       = concat(' ', $id)">
34	<xsl:value-of select="generate-id()"/>
35	<xsl:text> </xsl:text>
36      </xsl:if>
37    </xsl:for-each>
38    <xsl:if test="normalize-space(@annotations) != ''">
39      <xsl:call-template name="annotations-pointed-to">
40	<xsl:with-param name="annotations"
41			select="normalize-space(@annotations)"/>
42      </xsl:call-template>
43    </xsl:if>
44  </xsl:variable>
45
46  <xsl:if test="$aids != ''">
47    <xsl:call-template name="apply-annotations-by-gid">
48      <xsl:with-param name="gids" select="normalize-space($aids)"/>
49    </xsl:call-template>
50  </xsl:if>
51  </xsl:if>
52</xsl:template>
53
54<xsl:template name="annotations-pointed-to">
55  <xsl:param name="annotations"/>
56  <xsl:choose>
57    <xsl:when test="contains($annotations, ' ')">
58      <xsl:variable name='a'
59		    select="key('id', substring-before($annotations, ' '))"/>
60      <xsl:if test="$a">
61	<xsl:value-of select="generate-id($a)"/>
62	<xsl:text> </xsl:text>
63      </xsl:if>
64      <xsl:call-template name="annotations-pointed-to">
65	<xsl:with-param name="annotations"
66			select="substring-after($annotations, ' ')"/>
67      </xsl:call-template>
68    </xsl:when>
69    <xsl:otherwise>
70      <xsl:variable name='a'
71		    select="key('id', $annotations)"/>
72      <xsl:if test="$a">
73	<xsl:value-of select="generate-id($a)"/>
74	<xsl:text> </xsl:text>
75      </xsl:if>
76    </xsl:otherwise>
77  </xsl:choose>
78</xsl:template>
79
80<xsl:template name="apply-annotations-by-gid">
81  <xsl:param name="gids"/>
82
83  <xsl:choose>
84    <xsl:when test="contains($gids, ' ')">
85      <xsl:variable name="gid" select="substring-before($gids, ' ')"/>
86      <xsl:apply-templates select="key('gid', $gid)"
87			   mode="annotation-inline"/>
88      <xsl:call-template name="apply-annotations-by-gid">
89	<xsl:with-param name="gids"
90			select="substring-after($gids, ' ')"/>
91      </xsl:call-template>
92    </xsl:when>
93    <xsl:otherwise>
94      <xsl:apply-templates select="key('gid', $gids)"
95			   mode="annotation-inline"/>
96    </xsl:otherwise>
97  </xsl:choose>
98</xsl:template>
99
100<xsl:template match="annotation" mode="annotation-inline">
101  <xsl:variable name="title">
102    <xsl:choose>
103      <xsl:when test="title">
104	<xsl:value-of select="title"/>
105      </xsl:when>
106      <xsl:otherwise>
107	<xsl:text>[Annotation #</xsl:text>
108	<xsl:number count="annotation" level="any" format="1"/>
109	<xsl:text>]</xsl:text>
110      </xsl:otherwise>
111    </xsl:choose>
112  </xsl:variable>
113
114  <a href="#annot-{generate-id(.)}" title="{$title}"
115     name="anch-{generate-id(.)}" id="anch-{generate-id(.)}">
116    <xsl:attribute name="onClick">
117      <xsl:text>popup_</xsl:text>
118      <xsl:value-of select="generate-id(.)"/>
119      <xsl:text>.showPopup('anch-</xsl:text>
120      <xsl:value-of select="generate-id(.)"/>
121      <xsl:text>'); return false;</xsl:text>
122    </xsl:attribute>
123    <img src="{$annotation.graphic.open}" border="0" alt="{$title}"/>
124  </a>
125</xsl:template>
126
127<xsl:template match="annotation" mode="annotation-popup">
128  <div class="annotation-nocss">
129    <p>
130      <a name="annot-{generate-id(.)}"/>
131      <xsl:text>Annotation #</xsl:text>
132      <xsl:number count="annotation" level="any" format="1"/>
133      <xsl:text>:</xsl:text>
134    </p>
135  </div>
136
137  <div id="popup-{generate-id(.)}" class="annotation-popup">
138    <xsl:if test="string-length(.) &gt; 300">
139      <xsl:attribute name="style">width:400px</xsl:attribute>
140    </xsl:if>
141
142    <xsl:call-template name="annotation-title"/>
143    <div class="annotation-body">
144      <xsl:apply-templates select="*[local-name(.) != 'title']"/>
145    </div>
146    <div class="annotation-close">
147      <a href="#" onclick="popup_{generate-id(.)}.hidePopup();return false;">
148	<img src="{$annotation.graphic.close}" alt="X" border="0"/>
149      </a>
150    </div>
151  </div>
152</xsl:template>
153
154<xsl:template name="annotation-title">
155  <div class="annotation-title">
156    <xsl:choose>
157      <xsl:when test="title">
158	<xsl:apply-templates select="title/node()"/>
159      </xsl:when>
160      <xsl:otherwise>
161	<xsl:text>Annotation</xsl:text>
162      </xsl:otherwise>
163    </xsl:choose>
164  </div>
165</xsl:template>
166
167</xsl:stylesheet>
168