callout.xsl 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:sverb="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Verbatim"
  4. xmlns:xverb="xalan://com.nwalsh.xalan.Verbatim"
  5. xmlns:lxslt="http://xml.apache.org/xslt"
  6. exclude-result-prefixes="sverb xverb lxslt"
  7. version='1.0'>
  8. <!-- ********************************************************************
  9. $Id: callout.xsl 9305 2012-04-27 21:50:53Z bobstayton $
  10. ********************************************************************
  11. This file is part of the XSL DocBook Stylesheet distribution.
  12. See ../README or http://docbook.sf.net/release/xsl/current/ for
  13. copyright and other information.
  14. ******************************************************************** -->
  15. <lxslt:component prefix="xverb"
  16. functions="insertCallouts"/>
  17. <xsl:template match="programlistingco|screenco">
  18. <xsl:variable name="verbatim" select="programlisting|screen"/>
  19. <xsl:choose>
  20. <xsl:when test="$use.extensions != '0'
  21. and $callouts.extension != '0'">
  22. <xsl:variable name="rtf">
  23. <xsl:apply-templates select="$verbatim">
  24. <xsl:with-param name="suppress-numbers" select="'1'"/>
  25. </xsl:apply-templates>
  26. </xsl:variable>
  27. <xsl:variable name="rtf-with-callouts">
  28. <xsl:choose>
  29. <xsl:when test="function-available('sverb:insertCallouts')">
  30. <xsl:copy-of select="sverb:insertCallouts(areaspec,$rtf)"/>
  31. </xsl:when>
  32. <xsl:when test="function-available('xverb:insertCallouts')">
  33. <xsl:copy-of select="xverb:insertCallouts(areaspec,$rtf)"/>
  34. </xsl:when>
  35. <xsl:otherwise>
  36. <xsl:message terminate="yes">
  37. <xsl:text>No insertCallouts function is available.</xsl:text>
  38. </xsl:message>
  39. </xsl:otherwise>
  40. </xsl:choose>
  41. </xsl:variable>
  42. <xsl:choose>
  43. <xsl:when test="$verbatim/@linenumbering = 'numbered'
  44. and $linenumbering.extension != '0'">
  45. <div>
  46. <xsl:call-template name="common.html.attributes"/>
  47. <xsl:call-template name="id.attribute"/>
  48. <xsl:call-template name="number.rtf.lines">
  49. <xsl:with-param name="rtf" select="$rtf-with-callouts"/>
  50. <xsl:with-param name="pi.context"
  51. select="programlisting|screen"/>
  52. </xsl:call-template>
  53. <xsl:apply-templates select="calloutlist"/>
  54. </div>
  55. </xsl:when>
  56. <xsl:otherwise>
  57. <div>
  58. <xsl:call-template name="common.html.attributes"/>
  59. <xsl:call-template name="id.attribute"/>
  60. <xsl:copy-of select="$rtf-with-callouts"/>
  61. <xsl:apply-templates select="calloutlist"/>
  62. </div>
  63. </xsl:otherwise>
  64. </xsl:choose>
  65. </xsl:when>
  66. <xsl:otherwise>
  67. <div>
  68. <xsl:apply-templates select="." mode="common.html.attributes"/>
  69. <xsl:call-template name="id.attribute"/>
  70. <xsl:apply-templates/>
  71. </div>
  72. </xsl:otherwise>
  73. </xsl:choose>
  74. </xsl:template>
  75. <xsl:template match="areaspec|areaset|area">
  76. </xsl:template>
  77. <xsl:template match="areaset" mode="conumber">
  78. <xsl:number count="area|areaset" format="1"/>
  79. </xsl:template>
  80. <xsl:template match="area" mode="conumber">
  81. <xsl:number count="area|areaset" format="1"/>
  82. </xsl:template>
  83. <xsl:template match="co" name="co">
  84. <!-- Support a single linkend in HTML -->
  85. <xsl:variable name="targets" select="key('id', @linkends)"/>
  86. <xsl:variable name="target" select="$targets[1]"/>
  87. <xsl:choose>
  88. <xsl:when test="$target">
  89. <a>
  90. <xsl:apply-templates select="." mode="common.html.attributes"/>
  91. <xsl:choose>
  92. <xsl:when test="$generate.id.attributes = 0">
  93. <!-- force an id attribute here -->
  94. <xsl:if test="@id or @xml:id">
  95. <xsl:attribute name="name">
  96. <xsl:value-of select="(@id|@xml:id)[1]"/>
  97. </xsl:attribute>
  98. </xsl:if>
  99. </xsl:when>
  100. <xsl:otherwise>
  101. <xsl:call-template name="id.attribute"/>
  102. </xsl:otherwise>
  103. </xsl:choose>
  104. <xsl:attribute name="href">
  105. <xsl:call-template name="href.target">
  106. <xsl:with-param name="object" select="$target"/>
  107. </xsl:call-template>
  108. </xsl:attribute>
  109. <xsl:apply-templates select="." mode="callout-bug"/>
  110. </a>
  111. </xsl:when>
  112. <xsl:otherwise>
  113. <xsl:if test="$generate.id.attributes != 0">
  114. <xsl:if test="@id or @xml:id">
  115. <span>
  116. <xsl:attribute name="id">
  117. <xsl:value-of select="(@id|@xml:id)[1]"/>
  118. </xsl:attribute>
  119. </span>
  120. </xsl:if>
  121. </xsl:if>
  122. <xsl:call-template name="anchor"/>
  123. <xsl:apply-templates select="." mode="callout-bug"/>
  124. </xsl:otherwise>
  125. </xsl:choose>
  126. </xsl:template>
  127. <xsl:template match="coref">
  128. <!-- tricky; this relies on the fact that we can process the "co" that's -->
  129. <!-- "over there" as if it were "right here" -->
  130. <xsl:variable name="co" select="key('id', @linkend)"/>
  131. <xsl:choose>
  132. <xsl:when test="not($co)">
  133. <xsl:message>
  134. <xsl:text>Error: coref link is broken: </xsl:text>
  135. <xsl:value-of select="@linkend"/>
  136. </xsl:message>
  137. </xsl:when>
  138. <xsl:when test="local-name($co) != 'co'">
  139. <xsl:message>
  140. <xsl:text>Error: coref doesn't point to a co: </xsl:text>
  141. <xsl:value-of select="@linkend"/>
  142. </xsl:message>
  143. </xsl:when>
  144. <xsl:otherwise>
  145. <xsl:apply-templates select="$co"/>
  146. </xsl:otherwise>
  147. </xsl:choose>
  148. </xsl:template>
  149. <xsl:template match="co" mode="callout-bug">
  150. <xsl:call-template name="callout-bug">
  151. <xsl:with-param name="conum">
  152. <xsl:number count="co"
  153. level="any"
  154. from="programlisting|screen|literallayout|synopsis"
  155. format="1"/>
  156. </xsl:with-param>
  157. </xsl:call-template>
  158. </xsl:template>
  159. <xsl:template name="callout-bug">
  160. <xsl:param name="conum" select='1'/>
  161. <xsl:choose>
  162. <xsl:when test="$callout.graphics != 0
  163. and $conum &lt;= $callout.graphics.number.limit">
  164. <!-- Added span to make valid in XHTML 1 -->
  165. <span><img src="{$callout.graphics.path}{$conum}{$callout.graphics.extension}"
  166. alt="{$conum}" border="0"/></span>
  167. </xsl:when>
  168. <xsl:when test="$callout.unicode != 0
  169. and $conum &lt;= $callout.unicode.number.limit">
  170. <xsl:choose>
  171. <xsl:when test="$callout.unicode.start.character = 10102">
  172. <xsl:choose>
  173. <xsl:when test="$conum = 1">&#10102;</xsl:when>
  174. <xsl:when test="$conum = 2">&#10103;</xsl:when>
  175. <xsl:when test="$conum = 3">&#10104;</xsl:when>
  176. <xsl:when test="$conum = 4">&#10105;</xsl:when>
  177. <xsl:when test="$conum = 5">&#10106;</xsl:when>
  178. <xsl:when test="$conum = 6">&#10107;</xsl:when>
  179. <xsl:when test="$conum = 7">&#10108;</xsl:when>
  180. <xsl:when test="$conum = 8">&#10109;</xsl:when>
  181. <xsl:when test="$conum = 9">&#10110;</xsl:when>
  182. <xsl:when test="$conum = 10">&#10111;</xsl:when>
  183. </xsl:choose>
  184. </xsl:when>
  185. <xsl:otherwise>
  186. <xsl:message>
  187. <xsl:text>Don't know how to generate Unicode callouts </xsl:text>
  188. <xsl:text>when $callout.unicode.start.character is </xsl:text>
  189. <xsl:value-of select="$callout.unicode.start.character"/>
  190. </xsl:message>
  191. <xsl:text>(</xsl:text>
  192. <xsl:value-of select="$conum"/>
  193. <xsl:text>)</xsl:text>
  194. </xsl:otherwise>
  195. </xsl:choose>
  196. </xsl:when>
  197. <xsl:otherwise>
  198. <xsl:text>(</xsl:text>
  199. <xsl:value-of select="$conum"/>
  200. <xsl:text>)</xsl:text>
  201. </xsl:otherwise>
  202. </xsl:choose>
  203. </xsl:template>
  204. </xsl:stylesheet>