lfs-xref.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?xml version='1.0' encoding='ISO-8859-1'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  4. version="1.0">
  5. <!-- Making a proper punctuation in xref (only for English language).-->
  6. <xsl:template match="xref" name="xref">
  7. <xsl:variable name="targets" select="key('id',@linkend)"/>
  8. <xsl:variable name="target" select="$targets[1]"/>
  9. <xsl:variable name="refelem" select="local-name($target)"/>
  10. <xsl:variable name="role" select="@role"/>
  11. <xsl:call-template name="check.id.unique">
  12. <xsl:with-param name="linkend" select="@linkend"/>
  13. </xsl:call-template>
  14. <xsl:choose>
  15. <xsl:when test="$refelem=''">
  16. <xsl:message>
  17. <xsl:text>XRef to nonexistent id: </xsl:text>
  18. <xsl:value-of select="@linkend"/>
  19. </xsl:message>
  20. <xsl:text>???</xsl:text>
  21. </xsl:when>
  22. <xsl:when test="$target/@xreflabel">
  23. <fo:basic-link internal-destination="{@linkend}"
  24. xsl:use-attribute-sets="xref.properties">
  25. <xsl:call-template name="xref.xreflabel">
  26. <xsl:with-param name="target" select="$target"/>
  27. </xsl:call-template>
  28. </fo:basic-link>
  29. </xsl:when>
  30. <xsl:otherwise>
  31. <fo:basic-link internal-destination="{@linkend}"
  32. xsl:use-attribute-sets="xref.properties">
  33. <xsl:apply-templates select="$target" mode="xref-to">
  34. <xsl:with-param name="referrer" select="."/>
  35. <xsl:with-param name="role" select="$role"/>
  36. <xsl:with-param name="xrefstyle">
  37. <xsl:value-of select="@xrefstyle"/>
  38. </xsl:with-param>
  39. </xsl:apply-templates>
  40. </fo:basic-link>
  41. </xsl:otherwise>
  42. </xsl:choose>
  43. <!-- Add standard page reference? -->
  44. <xsl:if test="not(starts-with(normalize-space(@xrefstyle), 'select:') != ''
  45. and (contains(@xrefstyle, 'page')
  46. or contains(@xrefstyle, 'Page')))
  47. and ( $insert.xref.page.number = 'yes'
  48. or $insert.xref.page.number = '1')
  49. or local-name($target) = 'para'">
  50. <fo:basic-link internal-destination="{@linkend}"
  51. xsl:use-attribute-sets="xref.properties">
  52. <xsl:apply-templates select="$target" mode="page.citation">
  53. <xsl:with-param name="id" select="@linkend"/>
  54. </xsl:apply-templates>
  55. </fo:basic-link>
  56. </xsl:if>
  57. </xsl:template>
  58. <xsl:template match="section|simplesect|sect1|sect2|sect3|sect4|sect5
  59. |refsect1|refsect2|refsect3|refsection" mode="xref-to">
  60. <xsl:param name="referrer"/>
  61. <xsl:param name="xrefstyle"/>
  62. <xsl:param name="role"/>
  63. <xsl:apply-templates select="." mode="object.xref.markup">
  64. <xsl:with-param name="purpose" select="'xref'"/>
  65. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  66. <xsl:with-param name="referrer" select="$referrer"/>
  67. <xsl:with-param name="role" select="$role"/>
  68. </xsl:apply-templates>
  69. </xsl:template>
  70. <xsl:template match="*" mode="object.xref.markup">
  71. <xsl:param name="purpose"/>
  72. <xsl:param name="xrefstyle"/>
  73. <xsl:param name="referrer"/>
  74. <xsl:param name="role"/>
  75. <xsl:variable name="template">
  76. <xsl:choose>
  77. <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')">
  78. <xsl:call-template name="make.gentext.template">
  79. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  80. <xsl:with-param name="purpose" select="$purpose"/>
  81. <xsl:with-param name="referrer" select="$referrer"/>
  82. </xsl:call-template>
  83. </xsl:when>
  84. <xsl:when test="starts-with(normalize-space($xrefstyle), 'template:')">
  85. <xsl:value-of select="substring-after(normalize-space($xrefstyle), 'template:')"/>
  86. </xsl:when>
  87. <xsl:otherwise>
  88. <xsl:apply-templates select="." mode="object.xref.template">
  89. <xsl:with-param name="purpose" select="$purpose"/>
  90. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  91. <xsl:with-param name="referrer" select="$referrer"/>
  92. </xsl:apply-templates>
  93. </xsl:otherwise>
  94. </xsl:choose>
  95. </xsl:variable>
  96. <xsl:if test="$template = ''">
  97. <xsl:message>
  98. <xsl:text>object.xref.markup: empty xref template</xsl:text>
  99. <xsl:text> for linkend="</xsl:text>
  100. <xsl:value-of select="@id"/>
  101. <xsl:text>" and @xrefstyle="</xsl:text>
  102. <xsl:value-of select="$xrefstyle"/>
  103. <xsl:text>"</xsl:text>
  104. </xsl:message>
  105. </xsl:if>
  106. <xsl:call-template name="substitute-markup">
  107. <xsl:with-param name="purpose" select="$purpose"/>
  108. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  109. <xsl:with-param name="referrer" select="$referrer"/>
  110. <xsl:with-param name="template" select="$template"/>
  111. <xsl:with-param name="role" select="$role"/>
  112. </xsl:call-template>
  113. </xsl:template>
  114. <xsl:template name="substitute-markup">
  115. <xsl:param name="template" select="''"/>
  116. <xsl:param name="allow-anchors" select="'0'"/>
  117. <xsl:param name="title" select="''"/>
  118. <xsl:param name="subtitle" select="''"/>
  119. <xsl:param name="label" select="''"/>
  120. <xsl:param name="pagenumber" select="''"/>
  121. <xsl:param name="purpose"/>
  122. <xsl:param name="xrefstyle"/>
  123. <xsl:param name="referrer"/>
  124. <xsl:param name="role"/>
  125. <xsl:choose>
  126. <xsl:when test="contains($template, '%')">
  127. <xsl:value-of select="substring-before($template, '%')"/>
  128. <xsl:variable name="candidate"
  129. select="substring(substring-after($template, '%'), 1, 1)"/>
  130. <xsl:choose>
  131. <xsl:when test="$candidate = 't'">
  132. <xsl:apply-templates select="." mode="insert.title.markup">
  133. <xsl:with-param name="purpose" select="$purpose"/>
  134. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  135. <xsl:with-param name="role" select="$role"/>
  136. <xsl:with-param name="title">
  137. <xsl:choose>
  138. <xsl:when test="$title != ''">
  139. <xsl:copy-of select="$title"/>
  140. </xsl:when>
  141. <xsl:otherwise>
  142. <xsl:apply-templates select="." mode="title.markup">
  143. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  144. </xsl:apply-templates>
  145. </xsl:otherwise>
  146. </xsl:choose>
  147. </xsl:with-param>
  148. </xsl:apply-templates>
  149. </xsl:when>
  150. <xsl:when test="$candidate = 's'">
  151. <xsl:apply-templates select="." mode="insert.subtitle.markup">
  152. <xsl:with-param name="purpose" select="$purpose"/>
  153. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  154. <xsl:with-param name="subtitle">
  155. <xsl:choose>
  156. <xsl:when test="$subtitle != ''">
  157. <xsl:copy-of select="$subtitle"/>
  158. </xsl:when>
  159. <xsl:otherwise>
  160. <xsl:apply-templates select="." mode="subtitle.markup">
  161. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  162. </xsl:apply-templates>
  163. </xsl:otherwise>
  164. </xsl:choose>
  165. </xsl:with-param>
  166. </xsl:apply-templates>
  167. </xsl:when>
  168. <xsl:when test="$candidate = 'n'">
  169. <xsl:apply-templates select="." mode="insert.label.markup">
  170. <xsl:with-param name="purpose" select="$purpose"/>
  171. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  172. <xsl:with-param name="label">
  173. <xsl:choose>
  174. <xsl:when test="$label != ''">
  175. <xsl:copy-of select="$label"/>
  176. </xsl:when>
  177. <xsl:otherwise>
  178. <xsl:apply-templates select="." mode="label.markup"/>
  179. </xsl:otherwise>
  180. </xsl:choose>
  181. </xsl:with-param>
  182. </xsl:apply-templates>
  183. </xsl:when>
  184. <xsl:when test="$candidate = 'p'">
  185. <xsl:apply-templates select="." mode="insert.pagenumber.markup">
  186. <xsl:with-param name="purpose" select="$purpose"/>
  187. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  188. <xsl:with-param name="pagenumber">
  189. <xsl:choose>
  190. <xsl:when test="$pagenumber != ''">
  191. <xsl:copy-of select="$pagenumber"/>
  192. </xsl:when>
  193. <xsl:otherwise>
  194. <xsl:apply-templates select="." mode="pagenumber.markup"/>
  195. </xsl:otherwise>
  196. </xsl:choose>
  197. </xsl:with-param>
  198. </xsl:apply-templates>
  199. </xsl:when>
  200. <xsl:when test="$candidate = 'd'">
  201. <xsl:apply-templates select="." mode="insert.direction.markup">
  202. <xsl:with-param name="purpose" select="$purpose"/>
  203. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  204. <xsl:with-param name="direction">
  205. <xsl:choose>
  206. <xsl:when test="$referrer">
  207. <xsl:variable name="referent-is-below">
  208. <xsl:for-each select="preceding::xref">
  209. <xsl:if test="generate-id(.) = generate-id($referrer)">1</xsl:if>
  210. </xsl:for-each>
  211. </xsl:variable>
  212. <xsl:choose>
  213. <xsl:when test="$referent-is-below = ''">
  214. <xsl:call-template name="gentext">
  215. <xsl:with-param name="key" select="'above'"/>
  216. </xsl:call-template>
  217. </xsl:when>
  218. <xsl:otherwise>
  219. <xsl:call-template name="gentext">
  220. <xsl:with-param name="key" select="'below'"/>
  221. </xsl:call-template>
  222. </xsl:otherwise>
  223. </xsl:choose>
  224. </xsl:when>
  225. <xsl:otherwise>
  226. <xsl:message>Attempt to use %d in gentext with no referrer!</xsl:message>
  227. </xsl:otherwise>
  228. </xsl:choose>
  229. </xsl:with-param>
  230. </xsl:apply-templates>
  231. </xsl:when>
  232. <xsl:when test="$candidate = '%' ">
  233. <xsl:text>%</xsl:text>
  234. </xsl:when>
  235. <xsl:otherwise>
  236. <xsl:text>%</xsl:text><xsl:value-of select="$candidate"/>
  237. </xsl:otherwise>
  238. </xsl:choose>
  239. <!-- recurse with the rest of the template string -->
  240. <xsl:variable name="rest"
  241. select="substring($template,
  242. string-length(substring-before($template, '%'))+3)"/>
  243. <xsl:call-template name="substitute-markup">
  244. <xsl:with-param name="template" select="$rest"/>
  245. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  246. <xsl:with-param name="title" select="$title"/>
  247. <xsl:with-param name="subtitle" select="$subtitle"/>
  248. <xsl:with-param name="label" select="$label"/>
  249. <xsl:with-param name="pagenumber" select="$pagenumber"/>
  250. <xsl:with-param name="purpose" select="$purpose"/>
  251. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  252. <xsl:with-param name="referrer" select="$referrer"/>
  253. <xsl:with-param name="role" select="$role"/>
  254. </xsl:call-template>
  255. </xsl:when>
  256. <xsl:otherwise>
  257. <xsl:value-of select="$template"/>
  258. </xsl:otherwise>
  259. </xsl:choose>
  260. </xsl:template>
  261. <xsl:template match="*" mode="insert.title.markup">
  262. <xsl:param name="purpose"/>
  263. <xsl:param name="xrefstyle"/>
  264. <xsl:param name="title"/>
  265. <xsl:param name="role"/>
  266. <xsl:choose>
  267. <xsl:when test="$purpose = 'xref' and titleabbrev">
  268. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  269. </xsl:when>
  270. <xsl:otherwise>
  271. <xsl:copy-of select="$title"/>
  272. <xsl:value-of select="$role"/>
  273. </xsl:otherwise>
  274. </xsl:choose>
  275. </xsl:template>
  276. </xsl:stylesheet>