callout.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. $Id: callout.xsl 9668 2012-11-28 00:47:59Z bobstayton $
  11. ********************************************************************
  12. This file is part of the XSL DocBook Stylesheet distribution.
  13. See ../README or http://docbook.sf.net/release/xsl/current/ for
  14. copyright and other information.
  15. ******************************************************************** -->
  16. <lxslt:component prefix="xverb"
  17. functions="insertCallouts"/>
  18. <xsl:template match="programlistingco|screenco">
  19. <xsl:variable name="verbatim" select="programlisting|screen"/>
  20. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  21. <xsl:choose>
  22. <xsl:when test="$use.extensions != '0'
  23. and $callouts.extension != '0'">
  24. <xsl:variable name="rtf">
  25. <xsl:apply-templates select="$verbatim">
  26. <xsl:with-param name="suppress-numbers" select="'1'"/>
  27. </xsl:apply-templates>
  28. </xsl:variable>
  29. <xsl:variable name="rtf-with-callouts">
  30. <xsl:choose>
  31. <xsl:when test="contains($vendor, 'SAXON ')">
  32. <xsl:copy-of select="sverb:insertCallouts(areaspec,$rtf)"/>
  33. </xsl:when>
  34. <xsl:when test="contains($vendor, 'Apache Software Foundation')">
  35. <xsl:copy-of select="xverb:insertCallouts(areaspec,$rtf)"/>
  36. </xsl:when>
  37. <xsl:otherwise>
  38. <xsl:message terminate="yes">
  39. <xsl:text>Don't know how to do callouts with </xsl:text>
  40. <xsl:value-of select="$vendor"/>
  41. </xsl:message>
  42. </xsl:otherwise>
  43. </xsl:choose>
  44. </xsl:variable>
  45. <xsl:choose>
  46. <xsl:when test="$verbatim/@linenumbering = 'numbered'
  47. and $linenumbering.extension != '0'">
  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. </xsl:when>
  55. <xsl:otherwise>
  56. <xsl:copy-of select="$rtf-with-callouts"/>
  57. <xsl:apply-templates select="calloutlist"/>
  58. </xsl:otherwise>
  59. </xsl:choose>
  60. </xsl:when>
  61. <xsl:otherwise>
  62. <xsl:apply-templates/>
  63. </xsl:otherwise>
  64. </xsl:choose>
  65. </xsl:template>
  66. <xsl:template match="areaspec|areaset|area">
  67. </xsl:template>
  68. <xsl:template match="areaset" mode="conumber">
  69. <xsl:number count="area|areaset" format="1"/>
  70. </xsl:template>
  71. <xsl:template match="area" mode="conumber">
  72. <xsl:number count="area|areaset" format="1"/>
  73. </xsl:template>
  74. <xsl:template match="co">
  75. <xsl:param name="coref"/>
  76. <!-- link to the callout? -->
  77. <xsl:variable name="linkend">
  78. <xsl:choose>
  79. <!-- if more than one target, choose the first -->
  80. <xsl:when test="contains(normalize-space(@linkends), ' ')">
  81. <xsl:value-of select="substring-before(normalize-space(@linkends), ' ')"/>
  82. </xsl:when>
  83. <xsl:when test="string-length(normalize-space(@linkends)) != 0">
  84. <xsl:value-of select="normalize-space(@linkends)"/>
  85. </xsl:when>
  86. <xsl:otherwise>
  87. </xsl:otherwise>
  88. </xsl:choose>
  89. </xsl:variable>
  90. <xsl:choose>
  91. <xsl:when test="string-length($linkend) != 0">
  92. <fo:basic-link internal-destination="{$linkend}">
  93. <xsl:choose>
  94. <xsl:when test="$coref">
  95. <xsl:call-template name="anchor">
  96. <xsl:with-param name="node" select="$coref"/>
  97. <xsl:with-param name="conditional" select="0"/>
  98. </xsl:call-template>
  99. </xsl:when>
  100. <xsl:otherwise>
  101. <xsl:call-template name="anchor">
  102. <xsl:with-param name="conditional" select="0"/>
  103. </xsl:call-template>
  104. </xsl:otherwise>
  105. </xsl:choose>
  106. <xsl:apply-templates select="." mode="callout-bug"/>
  107. </fo:basic-link>
  108. </xsl:when>
  109. <xsl:otherwise>
  110. <fo:inline>
  111. <xsl:choose>
  112. <xsl:when test="$coref">
  113. <xsl:call-template name="anchor">
  114. <xsl:with-param name="node" select="$coref"/>
  115. <xsl:with-param name="conditional" select="0"/>
  116. </xsl:call-template>
  117. </xsl:when>
  118. <xsl:otherwise>
  119. <xsl:call-template name="anchor">
  120. <xsl:with-param name="conditional" select="0"/>
  121. </xsl:call-template>
  122. </xsl:otherwise>
  123. </xsl:choose>
  124. <xsl:apply-templates select="." mode="callout-bug"/>
  125. </fo:inline>
  126. </xsl:otherwise>
  127. </xsl:choose>
  128. </xsl:template>
  129. <xsl:template match="coref">
  130. <!-- this relies on the fact that we can process the "co" that's -->
  131. <!-- "over there" as if it were "right here" -->
  132. <xsl:variable name="co" select="key('id', @linkend)"/>
  133. <xsl:choose>
  134. <xsl:when test="not($co)">
  135. <xsl:message>
  136. <xsl:text>Error: coref link is broken: </xsl:text>
  137. <xsl:value-of select="@linkend"/>
  138. </xsl:message>
  139. </xsl:when>
  140. <xsl:when test="local-name($co) != 'co'">
  141. <xsl:message>
  142. <xsl:text>Error: coref doesn't point to a co: </xsl:text>
  143. <xsl:value-of select="@linkend"/>
  144. </xsl:message>
  145. </xsl:when>
  146. <xsl:otherwise>
  147. <!-- process it as if it were the co itself -->
  148. <xsl:apply-templates select="$co">
  149. <xsl:with-param name="coref" select="."/>
  150. </xsl:apply-templates>
  151. </xsl:otherwise>
  152. </xsl:choose>
  153. </xsl:template>
  154. <xsl:template match="co" mode="callout-bug">
  155. <xsl:call-template name="callout-bug">
  156. <xsl:with-param name="conum">
  157. <xsl:number count="co"
  158. level="any"
  159. from="programlisting|screen|literallayout|synopsis"
  160. format="1"/>
  161. </xsl:with-param>
  162. </xsl:call-template>
  163. </xsl:template>
  164. <xsl:template name="callout-bug">
  165. <xsl:param name="conum" select='1'/>
  166. <xsl:choose>
  167. <!-- Draw callouts as images -->
  168. <xsl:when test="$callout.graphics != '0'
  169. and $conum &lt;= $callout.graphics.number.limit">
  170. <xsl:variable name="filename"
  171. select="concat($callout.graphics.path, $conum,
  172. $callout.graphics.extension)"/>
  173. <fo:external-graphic content-width="{$callout.icon.size}"
  174. width="{$callout.icon.size}">
  175. <xsl:attribute name="src">
  176. <xsl:choose>
  177. <xsl:when test="$fop.extensions != 0
  178. or $arbortext.extensions != 0">
  179. <xsl:value-of select="$filename"/>
  180. </xsl:when>
  181. <xsl:otherwise>
  182. <xsl:text>url(</xsl:text>
  183. <xsl:value-of select="$filename"/>
  184. <xsl:text>)</xsl:text>
  185. </xsl:otherwise>
  186. </xsl:choose>
  187. </xsl:attribute>
  188. </fo:external-graphic>
  189. </xsl:when>
  190. <xsl:when test="$callout.unicode != 0
  191. and $conum &lt;= $callout.unicode.number.limit">
  192. <xsl:variable name="comarkup">
  193. <xsl:choose>
  194. <xsl:when test="$callout.unicode.start.character = 10102">
  195. <xsl:choose>
  196. <xsl:when test="$conum = 1">&#10102;</xsl:when>
  197. <xsl:when test="$conum = 2">&#10103;</xsl:when>
  198. <xsl:when test="$conum = 3">&#10104;</xsl:when>
  199. <xsl:when test="$conum = 4">&#10105;</xsl:when>
  200. <xsl:when test="$conum = 5">&#10106;</xsl:when>
  201. <xsl:when test="$conum = 6">&#10107;</xsl:when>
  202. <xsl:when test="$conum = 7">&#10108;</xsl:when>
  203. <xsl:when test="$conum = 8">&#10109;</xsl:when>
  204. <xsl:when test="$conum = 9">&#10110;</xsl:when>
  205. <xsl:when test="$conum = 10">&#10111;</xsl:when>
  206. <xsl:when test="$conum = 11">&#9451;</xsl:when>
  207. <xsl:when test="$conum = 12">&#9452;</xsl:when>
  208. <xsl:when test="$conum = 13">&#9453;</xsl:when>
  209. <xsl:when test="$conum = 14">&#9454;</xsl:when>
  210. <xsl:when test="$conum = 15">&#9455;</xsl:when>
  211. <xsl:when test="$conum = 16">&#9456;</xsl:when>
  212. <xsl:when test="$conum = 17">&#9457;</xsl:when>
  213. <xsl:when test="$conum = 18">&#9458;</xsl:when>
  214. <xsl:when test="$conum = 19">&#9459;</xsl:when>
  215. <xsl:when test="$conum = 20">&#9460;</xsl:when>
  216. </xsl:choose>
  217. </xsl:when>
  218. <xsl:when test="$callout.unicode.start.character = 9312">
  219. <xsl:choose>
  220. <xsl:when test="$conum = 1">&#9312;</xsl:when>
  221. <xsl:when test="$conum = 2">&#9313;</xsl:when>
  222. <xsl:when test="$conum = 3">&#9314;</xsl:when>
  223. <xsl:when test="$conum = 4">&#9315;</xsl:when>
  224. <xsl:when test="$conum = 5">&#9316;</xsl:when>
  225. <xsl:when test="$conum = 6">&#9317;</xsl:when>
  226. <xsl:when test="$conum = 7">&#9318;</xsl:when>
  227. <xsl:when test="$conum = 8">&#9319;</xsl:when>
  228. <xsl:when test="$conum = 9">&#9320;</xsl:when>
  229. <xsl:when test="$conum = 10">&#9321;</xsl:when>
  230. <xsl:when test="$conum = 11">&#9322;</xsl:when>
  231. <xsl:when test="$conum = 12">&#9323;</xsl:when>
  232. <xsl:when test="$conum = 13">&#9324;</xsl:when>
  233. <xsl:when test="$conum = 14">&#9325;</xsl:when>
  234. <xsl:when test="$conum = 15">&#9326;</xsl:when>
  235. <xsl:when test="$conum = 16">&#9327;</xsl:when>
  236. <xsl:when test="$conum = 17">&#9328;</xsl:when>
  237. <xsl:when test="$conum = 18">&#9329;</xsl:when>
  238. <xsl:when test="$conum = 19">&#9330;</xsl:when>
  239. <xsl:when test="$conum = 20">&#9331;</xsl:when>
  240. </xsl:choose>
  241. </xsl:when>
  242. <xsl:otherwise>
  243. <xsl:message>
  244. <xsl:text>Don't know how to generate Unicode callouts </xsl:text>
  245. <xsl:text>when $callout.unicode.start.character is </xsl:text>
  246. <xsl:value-of select="$callout.unicode.start.character"/>
  247. </xsl:message>
  248. <fo:inline background-color="#404040"
  249. color="white"
  250. padding-top="0.1em"
  251. padding-bottom="0.1em"
  252. padding-start="0.2em"
  253. padding-end="0.2em"
  254. baseline-shift="0.1em"
  255. font-family="{$body.fontset}"
  256. font-weight="bold"
  257. font-size="75%">
  258. <xsl:value-of select="$conum"/>
  259. </fo:inline>
  260. </xsl:otherwise>
  261. </xsl:choose>
  262. </xsl:variable>
  263. <xsl:choose>
  264. <xsl:when test="$callout.unicode.font != ''">
  265. <fo:inline font-family="{$callout.unicode.font}">
  266. <xsl:copy-of select="$comarkup"/>
  267. </fo:inline>
  268. </xsl:when>
  269. <xsl:otherwise>
  270. <xsl:copy-of select="$comarkup"/>
  271. </xsl:otherwise>
  272. </xsl:choose>
  273. </xsl:when>
  274. <!-- Most safe: draw a dark gray square with a white number inside -->
  275. <xsl:otherwise>
  276. <fo:inline background-color="#404040"
  277. color="white"
  278. padding-top="0.1em"
  279. padding-bottom="0.1em"
  280. padding-start="0.2em"
  281. padding-end="0.2em"
  282. baseline-shift="0.1em"
  283. font-family="{$body.fontset}"
  284. font-weight="bold"
  285. font-size="75%">
  286. <xsl:value-of select="$conum"/>
  287. </fo:inline>
  288. </xsl:otherwise>
  289. </xsl:choose>
  290. </xsl:template>
  291. </xsl:stylesheet>