lfs-xref.xsl 16 KB

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