lfs-xref.xsl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <?xml version='1.0' encoding='ISO-8859-1'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xlink="http://www.w3.org/1999/xlink"
  4. xmlns="http://www.w3.org/1999/xhtml"
  5. exclude-result-prefixes="xlink"
  6. version="1.0">
  7. <!-- This stylesheet fixes English punctuation in xref links
  8. (as was requested by the publisher) via adding @role propagation
  9. in xref tags.
  10. This hack may not work with xref flavours not used in the book.
  11. For other languages, just remove the xref @role attributes
  12. in the book XML sources and/or comment-out the inclusion of
  13. this file in lfs-chunked2.xsl -->
  14. <!-- xref:
  15. Added role variable and use it when calling mode xref-to.-->
  16. <!-- The original template is in {docbook-xsl}/xhtml/xref.xsl -->
  17. <xsl:template match="xref" name="xref">
  18. <xsl:param name="xhref" select="@xlink:href"/>
  19. <!-- is the @xlink:href a local idref link? -->
  20. <xsl:param name="xlink.idref">
  21. <xsl:if test="starts-with($xhref,'#') and (not(contains($xhref,'('))
  22. or starts-with($xhref, '#xpointer(id('))">
  23. <xsl:call-template name="xpointer.idref">
  24. <xsl:with-param name="xpointer" select="$xhref"/>
  25. </xsl:call-template>
  26. </xsl:if>
  27. </xsl:param>
  28. <xsl:param name="xlink.targets" select="key('id',$xlink.idref)"/>
  29. <xsl:param name="linkend.targets" select="key('id',@linkend)"/>
  30. <xsl:param name="target" select="($xlink.targets | $linkend.targets)[1]"/>
  31. <!-- Added role variable -->
  32. <xsl:variable name="role" select="@role"/>
  33. <xsl:variable name="xrefstyle">
  34. <xsl:choose>
  35. <xsl:when test="@role and not(@xrefstyle) and $use.role.as.xrefstyle != 0">
  36. <xsl:value-of select="@role"/>
  37. </xsl:when>
  38. <xsl:otherwise>
  39. <xsl:value-of select="@xrefstyle"/>
  40. </xsl:otherwise>
  41. </xsl:choose>
  42. </xsl:variable>
  43. <xsl:call-template name="anchor"/>
  44. <xsl:variable name="content">
  45. <xsl:choose>
  46. <xsl:when test="@endterm">
  47. <xsl:variable name="etargets" select="key('id',@endterm)"/>
  48. <xsl:variable name="etarget" select="$etargets[1]"/>
  49. <xsl:choose>
  50. <xsl:when test="count($etarget) = 0">
  51. <xsl:message>
  52. <xsl:value-of select="count($etargets)"/>
  53. <xsl:text>Endterm points to nonexistent ID: </xsl:text>
  54. <xsl:value-of select="@endterm"/>
  55. </xsl:message>
  56. <xsl:text>???</xsl:text>
  57. </xsl:when>
  58. <xsl:otherwise>
  59. <xsl:apply-templates select="$etarget" mode="endterm"/>
  60. </xsl:otherwise>
  61. </xsl:choose>
  62. </xsl:when>
  63. <xsl:when test="$target/@xreflabel">
  64. <xsl:call-template name="xref.xreflabel">
  65. <xsl:with-param name="target" select="$target"/>
  66. </xsl:call-template>
  67. </xsl:when>
  68. <xsl:when test="$target">
  69. <xsl:if test="not(parent::citation)">
  70. <xsl:apply-templates select="$target" mode="xref-to-prefix"/>
  71. </xsl:if>
  72. <xsl:apply-templates select="$target" mode="xref-to">
  73. <xsl:with-param name="referrer" select="."/>
  74. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  75. <!-- Propagate role -->
  76. <xsl:with-param name="role" select="$role"/>
  77. </xsl:apply-templates>
  78. <xsl:if test="not(parent::citation)">
  79. <xsl:apply-templates select="$target" mode="xref-to-suffix"/>
  80. </xsl:if>
  81. </xsl:when>
  82. <xsl:otherwise>
  83. <xsl:message>
  84. <xsl:text>ERROR: xref linking to </xsl:text>
  85. <xsl:value-of select="@linkend|@xlink:href"/>
  86. <xsl:text> has no generated link text.</xsl:text>
  87. </xsl:message>
  88. <xsl:text>???</xsl:text>
  89. </xsl:otherwise>
  90. </xsl:choose>
  91. </xsl:variable>
  92. <xsl:call-template name="simple.xlink">
  93. <xsl:with-param name="content" select="$content"/>
  94. </xsl:call-template>
  95. </xsl:template>
  96. <!-- sect* mode xref-to:
  97. Propagate role to mode object.xref.markup -->
  98. <!-- The original template is in {docbook-xsl}/xhtml/xref.xsl -->
  99. <xsl:template match="section|simplesect|sect1|sect2|sect3|sect4|sect5|refsect1
  100. |refsect2|refsect3|refsection" mode="xref-to">
  101. <xsl:param name="referrer"/>
  102. <xsl:param name="xrefstyle"/>
  103. <xsl:param name="verbose" select="1"/>
  104. <xsl:param name="role"/>
  105. <xsl:apply-templates select="." mode="object.xref.markup">
  106. <xsl:with-param name="purpose" select="'xref'"/>
  107. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  108. <xsl:with-param name="referrer" select="$referrer"/>
  109. <xsl:with-param name="verbose" select="$verbose"/>
  110. <xsl:with-param name="role" select="$role"/>
  111. </xsl:apply-templates>
  112. </xsl:template>
  113. <!-- mode object.xref.markup:
  114. Propagate role to named template substitute-markup -->
  115. <!-- The original template is in {docbook-xsl}/common/gentext.xsl -->
  116. <xsl:template match="*" mode="object.xref.markup">
  117. <xsl:param name="purpose"/>
  118. <xsl:param name="xrefstyle"/>
  119. <xsl:param name="referrer"/>
  120. <xsl:param name="verbose" select="1"/>
  121. <xsl:param name="role"/>
  122. <xsl:variable name="template">
  123. <xsl:choose>
  124. <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')">
  125. <xsl:call-template name="make.gentext.template">
  126. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  127. <xsl:with-param name="purpose" select="$purpose"/>
  128. <xsl:with-param name="referrer" select="$referrer"/>
  129. </xsl:call-template>
  130. </xsl:when>
  131. <xsl:when test="starts-with(normalize-space($xrefstyle), 'template:')">
  132. <xsl:value-of select="substring-after(normalize-space($xrefstyle), 'template:')"/>
  133. </xsl:when>
  134. <xsl:otherwise>
  135. <xsl:apply-templates select="." mode="object.xref.template">
  136. <xsl:with-param name="purpose" select="$purpose"/>
  137. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  138. <xsl:with-param name="referrer" select="$referrer"/>
  139. </xsl:apply-templates>
  140. </xsl:otherwise>
  141. </xsl:choose>
  142. </xsl:variable>
  143. <xsl:if test="$template = '' and $verbose != 0">
  144. <xsl:message>
  145. <xsl:text>object.xref.markup: empty xref template</xsl:text>
  146. <xsl:text> for linkend="</xsl:text>
  147. <xsl:value-of select="@id|@xml:id"/>
  148. <xsl:text>" and @xrefstyle="</xsl:text>
  149. <xsl:value-of select="$xrefstyle"/>
  150. <xsl:text>"</xsl:text>
  151. </xsl:message>
  152. </xsl:if>
  153. <xsl:call-template name="substitute-markup">
  154. <xsl:with-param name="purpose" select="$purpose"/>
  155. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  156. <xsl:with-param name="referrer" select="$referrer"/>
  157. <xsl:with-param name="template" select="$template"/>
  158. <xsl:with-param name="verbose" select="$verbose"/>
  159. <xsl:with-param name="role" select="$role"/>
  160. </xsl:call-template>
  161. </xsl:template>
  162. <!-- substitute-markup:
  163. Propagate role to mode insert.title.markup -->
  164. <!-- The original template is in {docbook-xsl}/common/gentext.xsl -->
  165. <xsl:template name="substitute-markup">
  166. <xsl:param name="template" select="''"/>
  167. <xsl:param name="allow-anchors" select="'0'"/>
  168. <xsl:param name="title" select="''"/>
  169. <xsl:param name="subtitle" select="''"/>
  170. <xsl:param name="docname" select="''"/>
  171. <xsl:param name="label" select="''"/>
  172. <xsl:param name="pagenumber" select="''"/>
  173. <xsl:param name="purpose"/>
  174. <xsl:param name="xrefstyle"/>
  175. <xsl:param name="referrer"/>
  176. <xsl:param name="verbose"/>
  177. <xsl:param name="role"/>
  178. <xsl:choose>
  179. <xsl:when test="contains($template, '%')">
  180. <xsl:value-of select="substring-before($template, '%')"/>
  181. <xsl:variable name="candidate"
  182. select="substring(substring-after($template, '%'), 1, 1)"/>
  183. <xsl:choose>
  184. <xsl:when test="$candidate = 't'">
  185. <xsl:apply-templates select="." mode="insert.title.markup">
  186. <xsl:with-param name="purpose" select="$purpose"/>
  187. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  188. <xsl:with-param name="role" select="$role"/>
  189. <xsl:with-param name="title">
  190. <xsl:choose>
  191. <xsl:when test="$title != ''">
  192. <xsl:copy-of select="$title"/>
  193. </xsl:when>
  194. <xsl:otherwise>
  195. <xsl:apply-templates select="." mode="title.markup">
  196. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  197. <xsl:with-param name="verbose" select="$verbose"/>
  198. </xsl:apply-templates>
  199. </xsl:otherwise>
  200. </xsl:choose>
  201. </xsl:with-param>
  202. </xsl:apply-templates>
  203. </xsl:when>
  204. <xsl:when test="$candidate = 's'">
  205. <xsl:apply-templates select="." mode="insert.subtitle.markup">
  206. <xsl:with-param name="purpose" select="$purpose"/>
  207. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  208. <xsl:with-param name="subtitle">
  209. <xsl:choose>
  210. <xsl:when test="$subtitle != ''">
  211. <xsl:copy-of select="$subtitle"/>
  212. </xsl:when>
  213. <xsl:otherwise>
  214. <xsl:apply-templates select="." mode="subtitle.markup">
  215. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  216. </xsl:apply-templates>
  217. </xsl:otherwise>
  218. </xsl:choose>
  219. </xsl:with-param>
  220. </xsl:apply-templates>
  221. </xsl:when>
  222. <xsl:when test="$candidate = 'n'">
  223. <xsl:apply-templates select="." mode="insert.label.markup">
  224. <xsl:with-param name="purpose" select="$purpose"/>
  225. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  226. <xsl:with-param name="label">
  227. <xsl:choose>
  228. <xsl:when test="$label != ''">
  229. <xsl:copy-of select="$label"/>
  230. </xsl:when>
  231. <xsl:otherwise>
  232. <xsl:apply-templates select="." mode="label.markup"/>
  233. </xsl:otherwise>
  234. </xsl:choose>
  235. </xsl:with-param>
  236. </xsl:apply-templates>
  237. </xsl:when>
  238. <xsl:when test="$candidate = 'p'">
  239. <xsl:apply-templates select="." mode="insert.pagenumber.markup">
  240. <xsl:with-param name="purpose" select="$purpose"/>
  241. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  242. <xsl:with-param name="pagenumber">
  243. <xsl:choose>
  244. <xsl:when test="$pagenumber != ''">
  245. <xsl:copy-of select="$pagenumber"/>
  246. </xsl:when>
  247. <xsl:otherwise>
  248. <xsl:apply-templates select="." mode="pagenumber.markup"/>
  249. </xsl:otherwise>
  250. </xsl:choose>
  251. </xsl:with-param>
  252. </xsl:apply-templates>
  253. </xsl:when>
  254. <xsl:when test="$candidate = 'o'">
  255. <!-- olink target document title -->
  256. <xsl:apply-templates select="." mode="insert.olink.docname.markup">
  257. <xsl:with-param name="purpose" select="$purpose"/>
  258. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  259. <xsl:with-param name="docname">
  260. <xsl:choose>
  261. <xsl:when test="$docname != ''">
  262. <xsl:copy-of select="$docname"/>
  263. </xsl:when>
  264. <xsl:otherwise>
  265. <xsl:apply-templates select="." mode="olink.docname.markup"/>
  266. </xsl:otherwise>
  267. </xsl:choose>
  268. </xsl:with-param>
  269. </xsl:apply-templates>
  270. </xsl:when>
  271. <xsl:when test="$candidate = 'd'">
  272. <xsl:apply-templates select="." mode="insert.direction.markup">
  273. <xsl:with-param name="purpose" select="$purpose"/>
  274. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  275. <xsl:with-param name="direction">
  276. <xsl:choose>
  277. <xsl:when test="$referrer">
  278. <xsl:variable name="referent-is-below">
  279. <xsl:for-each select="preceding::xref">
  280. <xsl:if test="generate-id(.) = generate-id($referrer)">1</xsl:if>
  281. </xsl:for-each>
  282. </xsl:variable>
  283. <xsl:choose>
  284. <xsl:when test="$referent-is-below = ''">
  285. <xsl:call-template name="gentext">
  286. <xsl:with-param name="key" select="'above'"/>
  287. </xsl:call-template>
  288. </xsl:when>
  289. <xsl:otherwise>
  290. <xsl:call-template name="gentext">
  291. <xsl:with-param name="key" select="'below'"/>
  292. </xsl:call-template>
  293. </xsl:otherwise>
  294. </xsl:choose>
  295. </xsl:when>
  296. <xsl:otherwise>
  297. <xsl:message>Attempt to use %d in gentext with no referrer!</xsl:message>
  298. </xsl:otherwise>
  299. </xsl:choose>
  300. </xsl:with-param>
  301. </xsl:apply-templates>
  302. </xsl:when>
  303. <xsl:when test="$candidate = '%' ">
  304. <xsl:text>%</xsl:text>
  305. </xsl:when>
  306. <xsl:otherwise>
  307. <xsl:text>%</xsl:text><xsl:value-of select="$candidate"/>
  308. </xsl:otherwise>
  309. </xsl:choose>
  310. <!-- recurse with the rest of the template string -->
  311. <xsl:variable name="rest"
  312. select="substring($template,
  313. string-length(substring-before($template, '%'))+3)"/>
  314. <xsl:call-template name="substitute-markup">
  315. <xsl:with-param name="template" select="$rest"/>
  316. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  317. <xsl:with-param name="title" select="$title"/>
  318. <xsl:with-param name="subtitle" select="$subtitle"/>
  319. <xsl:with-param name="docname" select="$docname"/>
  320. <xsl:with-param name="label" select="$label"/>
  321. <xsl:with-param name="pagenumber" select="$pagenumber"/>
  322. <xsl:with-param name="purpose" select="$purpose"/>
  323. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  324. <xsl:with-param name="referrer" select="$referrer"/>
  325. <xsl:with-param name="verbose" select="$verbose"/>
  326. <xsl:with-param name="role" select="$role"/>
  327. </xsl:call-template>
  328. </xsl:when>
  329. <xsl:otherwise>
  330. <xsl:value-of select="$template"/>
  331. </xsl:otherwise>
  332. </xsl:choose>
  333. </xsl:template>
  334. <!-- insert.title.markup:
  335. Apply the role value. -->
  336. <!-- The original template is in {docbook-xsl}/xhtml/xref.xsl -->
  337. <xsl:template match="*" mode="insert.title.markup">
  338. <xsl:param name="purpose"/>
  339. <xsl:param name="xrefstyle"/>
  340. <xsl:param name="title"/>
  341. <xsl:param name="role"/>
  342. <xsl:choose>
  343. <xsl:when test="$purpose = 'xref' and titleabbrev">
  344. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  345. </xsl:when>
  346. <xsl:otherwise>
  347. <xsl:copy-of select="$title"/>
  348. <xsl:value-of select="$role"/>
  349. </xsl:otherwise>
  350. </xsl:choose>
  351. </xsl:template>
  352. </xsl:stylesheet>