annotations.xsl 5.5 KB

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