lfs-xref.xsl 13 KB

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