xref.xsl 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429
  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:exsl="http://exslt.org/common"
  5. xmlns:xlink='http://www.w3.org/1999/xlink'
  6. exclude-result-prefixes="exsl"
  7. version='1.0'>
  8. <!-- ********************************************************************
  9. $Id$
  10. ********************************************************************
  11. This file is part of the XSL DocBook Stylesheet distribution.
  12. See ../README or http://docbook.sf.net/release/xsl/current/ for
  13. copyright and other information.
  14. ******************************************************************** -->
  15. <!-- Use internal variable for olink xlink role for consistency -->
  16. <xsl:variable
  17. name="xolink.role">http://docbook.org/xlink/role/olink</xsl:variable>
  18. <!-- ==================================================================== -->
  19. <xsl:template match="anchor">
  20. <xsl:variable name="id">
  21. <xsl:call-template name="object.id"/>
  22. </xsl:variable>
  23. <fo:inline id="{$id}"/>
  24. </xsl:template>
  25. <!-- ==================================================================== -->
  26. <xsl:template match="xref" name="xref">
  27. <xsl:param name="xhref" select="@xlink:href"/>
  28. <!-- is the @xlink:href a local idref link? -->
  29. <xsl:param name="xlink.idref">
  30. <xsl:if test="starts-with($xhref,'#')
  31. and (not(contains($xhref,'&#40;'))
  32. or starts-with($xhref, '#xpointer&#40;id&#40;'))">
  33. <xsl:call-template name="xpointer.idref">
  34. <xsl:with-param name="xpointer" select="$xhref"/>
  35. </xsl:call-template>
  36. </xsl:if>
  37. </xsl:param>
  38. <xsl:param name="xlink.targets" select="key('id',$xlink.idref)"/>
  39. <xsl:param name="linkend.targets" select="key('id',@linkend)"/>
  40. <xsl:param name="target" select="($xlink.targets | $linkend.targets)[1]"/>
  41. <xsl:param name="refelem" select="local-name($target)"/>
  42. <xsl:variable name="xrefstyle">
  43. <xsl:choose>
  44. <xsl:when test="@role and not(@xrefstyle)
  45. and $use.role.as.xrefstyle != 0">
  46. <xsl:value-of select="@role"/>
  47. </xsl:when>
  48. <xsl:otherwise>
  49. <xsl:value-of select="@xrefstyle"/>
  50. </xsl:otherwise>
  51. </xsl:choose>
  52. </xsl:variable>
  53. <xsl:variable name="content">
  54. <fo:inline xsl:use-attribute-sets="xref.properties">
  55. <xsl:choose>
  56. <xsl:when test="@endterm">
  57. <xsl:variable name="etargets" select="key('id',@endterm)"/>
  58. <xsl:variable name="etarget" select="$etargets[1]"/>
  59. <xsl:choose>
  60. <xsl:when test="count($etarget) = 0">
  61. <xsl:message>
  62. <xsl:value-of select="count($etargets)"/>
  63. <xsl:text>Endterm points to nonexistent ID: </xsl:text>
  64. <xsl:value-of select="@endterm"/>
  65. </xsl:message>
  66. <xsl:text>???</xsl:text>
  67. </xsl:when>
  68. <xsl:otherwise>
  69. <xsl:apply-templates select="$etarget" mode="endterm"/>
  70. </xsl:otherwise>
  71. </xsl:choose>
  72. </xsl:when>
  73. <xsl:when test="$target/@xreflabel">
  74. <xsl:call-template name="xref.xreflabel">
  75. <xsl:with-param name="target" select="$target"/>
  76. </xsl:call-template>
  77. </xsl:when>
  78. <xsl:when test="$target">
  79. <xsl:if test="not(parent::citation)">
  80. <xsl:apply-templates select="$target" mode="xref-to-prefix"/>
  81. </xsl:if>
  82. <xsl:apply-templates select="$target" mode="xref-to">
  83. <xsl:with-param name="referrer" select="."/>
  84. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  85. </xsl:apply-templates>
  86. <xsl:if test="not(parent::citation)">
  87. <xsl:apply-templates select="$target" mode="xref-to-suffix"/>
  88. </xsl:if>
  89. </xsl:when>
  90. <xsl:otherwise>
  91. <xsl:message>
  92. <xsl:text>ERROR: xref linking to </xsl:text>
  93. <xsl:value-of select="@linkend|@xlink:href"/>
  94. <xsl:text> has no generated link text.</xsl:text>
  95. </xsl:message>
  96. <xsl:text>???</xsl:text>
  97. </xsl:otherwise>
  98. </xsl:choose>
  99. </fo:inline>
  100. </xsl:variable>
  101. <!-- Convert it into an active link -->
  102. <xsl:call-template name="simple.xlink">
  103. <xsl:with-param name="content" select="$content"/>
  104. </xsl:call-template>
  105. <!-- Add standard page reference? -->
  106. <xsl:choose>
  107. <xsl:when test="not($target)">
  108. <!-- page numbers only for local targets -->
  109. </xsl:when>
  110. <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')
  111. and contains($xrefstyle, 'nopage')">
  112. <!-- negative xrefstyle in instance turns it off -->
  113. </xsl:when>
  114. <!-- positive xrefstyle already handles it -->
  115. <xsl:when test="not(starts-with(normalize-space($xrefstyle), 'select:')
  116. and (contains($xrefstyle, 'page')
  117. or contains($xrefstyle, 'Page')))
  118. and ( $insert.xref.page.number = 'yes'
  119. or $insert.xref.page.number = '1')
  120. or local-name($target) = 'para'">
  121. <xsl:apply-templates select="$target" mode="page.citation">
  122. <xsl:with-param name="id" select="$target/@id|$target/@xml:id"/>
  123. </xsl:apply-templates>
  124. </xsl:when>
  125. </xsl:choose>
  126. </xsl:template>
  127. <!-- ==================================================================== -->
  128. <!-- Handled largely like an xref -->
  129. <!-- To be done: add support for begin, end, and units attributes -->
  130. <xsl:template match="biblioref" name="biblioref">
  131. <xsl:variable name="targets" select="key('id',@linkend)"/>
  132. <xsl:variable name="target" select="$targets[1]"/>
  133. <xsl:variable name="refelem" select="local-name($target)"/>
  134. <xsl:call-template name="check.id.unique">
  135. <xsl:with-param name="linkend" select="@linkend"/>
  136. </xsl:call-template>
  137. <xsl:choose>
  138. <xsl:when test="$refelem=''">
  139. <xsl:message>
  140. <xsl:text>XRef to nonexistent id: </xsl:text>
  141. <xsl:value-of select="@linkend"/>
  142. </xsl:message>
  143. <xsl:text>???</xsl:text>
  144. </xsl:when>
  145. <xsl:when test="@endterm">
  146. <fo:basic-link internal-destination="{@linkend}"
  147. xsl:use-attribute-sets="xref.properties">
  148. <xsl:variable name="etargets" select="key('id',@endterm)"/>
  149. <xsl:variable name="etarget" select="$etargets[1]"/>
  150. <xsl:choose>
  151. <xsl:when test="count($etarget) = 0">
  152. <xsl:message>
  153. <xsl:value-of select="count($etargets)"/>
  154. <xsl:text>Endterm points to nonexistent ID: </xsl:text>
  155. <xsl:value-of select="@endterm"/>
  156. </xsl:message>
  157. <xsl:text>???</xsl:text>
  158. </xsl:when>
  159. <xsl:otherwise>
  160. <xsl:apply-templates select="$etarget" mode="endterm"/>
  161. </xsl:otherwise>
  162. </xsl:choose>
  163. </fo:basic-link>
  164. </xsl:when>
  165. <xsl:when test="$target/@xreflabel">
  166. <fo:basic-link internal-destination="{@linkend}"
  167. xsl:use-attribute-sets="xref.properties">
  168. <xsl:call-template name="xref.xreflabel">
  169. <xsl:with-param name="target" select="$target"/>
  170. </xsl:call-template>
  171. </fo:basic-link>
  172. </xsl:when>
  173. <xsl:otherwise>
  174. <xsl:if test="not(parent::citation)">
  175. <xsl:apply-templates select="$target" mode="xref-to-prefix"/>
  176. </xsl:if>
  177. <fo:basic-link internal-destination="{@linkend}"
  178. xsl:use-attribute-sets="xref.properties">
  179. <xsl:apply-templates select="$target" mode="xref-to">
  180. <xsl:with-param name="referrer" select="."/>
  181. <xsl:with-param name="xrefstyle">
  182. <xsl:choose>
  183. <xsl:when test="@role and not(@xrefstyle) and $use.role.as.xrefstyle != 0">
  184. <xsl:value-of select="@role"/>
  185. </xsl:when>
  186. <xsl:otherwise>
  187. <xsl:value-of select="@xrefstyle"/>
  188. </xsl:otherwise>
  189. </xsl:choose>
  190. </xsl:with-param>
  191. </xsl:apply-templates>
  192. </fo:basic-link>
  193. <xsl:if test="not(parent::citation)">
  194. <xsl:apply-templates select="$target" mode="xref-to-suffix"/>
  195. </xsl:if>
  196. </xsl:otherwise>
  197. </xsl:choose>
  198. </xsl:template>
  199. <!-- ==================================================================== -->
  200. <xsl:template match="*" mode="endterm">
  201. <!-- Process the children of the endterm element -->
  202. <xsl:variable name="endterm">
  203. <xsl:apply-templates select="child::node()"/>
  204. </xsl:variable>
  205. <xsl:choose>
  206. <xsl:when test="function-available('exsl:node-set')">
  207. <xsl:apply-templates select="exsl:node-set($endterm)" mode="remove-ids"/>
  208. </xsl:when>
  209. <xsl:otherwise>
  210. <xsl:copy-of select="$endterm"/>
  211. </xsl:otherwise>
  212. </xsl:choose>
  213. </xsl:template>
  214. <xsl:template match="*" mode="remove-ids">
  215. <xsl:copy>
  216. <xsl:for-each select="@*">
  217. <xsl:choose>
  218. <xsl:when test="name(.) != 'id'">
  219. <xsl:copy/>
  220. </xsl:when>
  221. <xsl:otherwise>
  222. <xsl:message>removing <xsl:value-of select="name(.)"/></xsl:message>
  223. </xsl:otherwise>
  224. </xsl:choose>
  225. </xsl:for-each>
  226. <xsl:apply-templates mode="remove-ids"/>
  227. </xsl:copy>
  228. </xsl:template>
  229. <!--- ==================================================================== -->
  230. <xsl:template match="*" mode="xref-to-prefix"/>
  231. <xsl:template match="*" mode="xref-to-suffix"/>
  232. <xsl:template match="*" mode="xref-to">
  233. <xsl:param name="referrer"/>
  234. <xsl:param name="xrefstyle"/>
  235. <xsl:param name="verbose" select="1"/>
  236. <xsl:if test="$verbose != 0">
  237. <xsl:message>
  238. <xsl:text>Don't know what gentext to create for xref to: "</xsl:text>
  239. <xsl:value-of select="name(.)"/>
  240. <xsl:text>"</xsl:text>
  241. </xsl:message>
  242. <xsl:text>???</xsl:text>
  243. </xsl:if>
  244. </xsl:template>
  245. <xsl:template match="title" mode="xref-to">
  246. <xsl:param name="referrer"/>
  247. <xsl:param name="xrefstyle"/>
  248. <xsl:param name="verbose" select="1"/>
  249. <!-- if you xref to a title, xref to the parent... -->
  250. <xsl:choose>
  251. <!-- FIXME: how reliable is this? -->
  252. <xsl:when test="contains(local-name(parent::*), 'info')">
  253. <xsl:apply-templates select="parent::*[2]" mode="xref-to">
  254. <xsl:with-param name="referrer" select="$referrer"/>
  255. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  256. <xsl:with-param name="verbose" select="$verbose"/>
  257. </xsl:apply-templates>
  258. </xsl:when>
  259. <xsl:otherwise>
  260. <xsl:apply-templates select="parent::*" mode="xref-to">
  261. <xsl:with-param name="referrer" select="$referrer"/>
  262. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  263. <xsl:with-param name="verbose" select="$verbose"/>
  264. </xsl:apply-templates>
  265. </xsl:otherwise>
  266. </xsl:choose>
  267. </xsl:template>
  268. <xsl:template match="abstract|article|authorblurb|bibliodiv|bibliomset
  269. |biblioset|blockquote|calloutlist|caution|colophon
  270. |constraintdef|formalpara|glossdiv|important|indexdiv
  271. |itemizedlist|legalnotice|lot|msg|msgexplan|msgmain
  272. |msgrel|msgset|msgsub|note|orderedlist|partintro
  273. |productionset|qandadiv|refsynopsisdiv|segmentedlist
  274. |set|setindex|sidebar|tip|toc|variablelist|warning"
  275. mode="xref-to">
  276. <xsl:param name="referrer"/>
  277. <xsl:param name="xrefstyle"/>
  278. <xsl:param name="verbose" select="1"/>
  279. <!-- catch-all for things with (possibly optional) titles -->
  280. <xsl:apply-templates select="." mode="object.xref.markup">
  281. <xsl:with-param name="purpose" select="'xref'"/>
  282. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  283. <xsl:with-param name="referrer" select="$referrer"/>
  284. <xsl:with-param name="verbose" select="$verbose"/>
  285. </xsl:apply-templates>
  286. </xsl:template>
  287. <xsl:template match="author|editor|othercredit|personname" mode="xref-to">
  288. <xsl:param name="referrer"/>
  289. <xsl:param name="xrefstyle"/>
  290. <xsl:param name="verbose" select="1"/>
  291. <xsl:call-template name="person.name"/>
  292. </xsl:template>
  293. <xsl:template match="authorgroup" mode="xref-to">
  294. <xsl:param name="referrer"/>
  295. <xsl:param name="xrefstyle"/>
  296. <xsl:param name="verbose" select="1"/>
  297. <xsl:call-template name="person.name.list"/>
  298. </xsl:template>
  299. <xsl:template match="figure|example|table|equation" mode="xref-to">
  300. <xsl:param name="referrer"/>
  301. <xsl:param name="xrefstyle"/>
  302. <xsl:param name="verbose" select="1"/>
  303. <xsl:apply-templates select="." mode="object.xref.markup">
  304. <xsl:with-param name="purpose" select="'xref'"/>
  305. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  306. <xsl:with-param name="referrer" select="$referrer"/>
  307. <xsl:with-param name="verbose" select="$verbose"/>
  308. </xsl:apply-templates>
  309. </xsl:template>
  310. <xsl:template match="procedure" mode="xref-to">
  311. <xsl:param name="referrer"/>
  312. <xsl:param name="xrefstyle"/>
  313. <xsl:param name="verbose"/>
  314. <xsl:apply-templates select="." mode="object.xref.markup">
  315. <xsl:with-param name="purpose" select="'xref'"/>
  316. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  317. <xsl:with-param name="referrer" select="$referrer"/>
  318. <xsl:with-param name="verbose" select="$verbose"/>
  319. </xsl:apply-templates>
  320. </xsl:template>
  321. <xsl:template match="task" mode="xref-to">
  322. <xsl:param name="referrer"/>
  323. <xsl:param name="xrefstyle"/>
  324. <xsl:param name="verbose"/>
  325. <xsl:apply-templates select="." mode="object.xref.markup">
  326. <xsl:with-param name="purpose" select="'xref'"/>
  327. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  328. <xsl:with-param name="referrer" select="$referrer"/>
  329. <xsl:with-param name="verbose" select="$verbose"/>
  330. </xsl:apply-templates>
  331. </xsl:template>
  332. <xsl:template match="cmdsynopsis" mode="xref-to">
  333. <xsl:param name="referrer"/>
  334. <xsl:param name="xrefstyle"/>
  335. <xsl:param name="verbose" select="1"/>
  336. <xsl:apply-templates select="(.//command)[1]" mode="xref"/>
  337. </xsl:template>
  338. <xsl:template match="funcsynopsis" mode="xref-to">
  339. <xsl:param name="referrer"/>
  340. <xsl:param name="xrefstyle"/>
  341. <xsl:param name="verbose" select="1"/>
  342. <xsl:apply-templates select="(.//function)[1]" mode="xref"/>
  343. </xsl:template>
  344. <xsl:template match="dedication|preface|chapter|appendix" mode="xref-to">
  345. <xsl:param name="referrer"/>
  346. <xsl:param name="xrefstyle"/>
  347. <xsl:param name="verbose" select="1"/>
  348. <xsl:apply-templates select="." mode="object.xref.markup">
  349. <xsl:with-param name="purpose" select="'xref'"/>
  350. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  351. <xsl:with-param name="referrer" select="$referrer"/>
  352. <xsl:with-param name="verbose" select="$verbose"/>
  353. </xsl:apply-templates>
  354. </xsl:template>
  355. <xsl:template match="bibliography" mode="xref-to">
  356. <xsl:param name="referrer"/>
  357. <xsl:param name="xrefstyle"/>
  358. <xsl:param name="verbose" select="1"/>
  359. <xsl:apply-templates select="." mode="object.xref.markup">
  360. <xsl:with-param name="purpose" select="'xref'"/>
  361. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  362. <xsl:with-param name="referrer" select="$referrer"/>
  363. <xsl:with-param name="verbose" select="$verbose"/>
  364. </xsl:apply-templates>
  365. </xsl:template>
  366. <xsl:template match="biblioentry|bibliomixed" mode="xref-to-prefix">
  367. <xsl:text>[</xsl:text>
  368. </xsl:template>
  369. <xsl:template match="biblioentry|bibliomixed" mode="xref-to-suffix">
  370. <xsl:text>]</xsl:text>
  371. </xsl:template>
  372. <xsl:template match="biblioentry|bibliomixed" mode="xref-to">
  373. <xsl:param name="referrer"/>
  374. <xsl:param name="xrefstyle"/>
  375. <xsl:param name="verbose" select="1"/>
  376. <!-- handles both biblioentry and bibliomixed -->
  377. <xsl:choose>
  378. <xsl:when test="string(.) = ''">
  379. <xsl:variable name="bib" select="document($bibliography.collection,.)"/>
  380. <xsl:variable name="id" select="(@id|@xml:id)[1]"/>
  381. <xsl:variable name="entry" select="$bib/bibliography/
  382. *[@id=$id or @xml:id=$id][1]"/>
  383. <xsl:choose>
  384. <xsl:when test="$entry">
  385. <xsl:choose>
  386. <xsl:when test="$bibliography.numbered != 0">
  387. <xsl:number from="bibliography" count="biblioentry|bibliomixed"
  388. level="any" format="1"/>
  389. </xsl:when>
  390. <xsl:when test="local-name($entry/*[1]) = 'abbrev'">
  391. <xsl:apply-templates select="$entry/*[1]"/>
  392. </xsl:when>
  393. <xsl:otherwise>
  394. <xsl:value-of select="(@id|@xml:id)[1]"/>
  395. </xsl:otherwise>
  396. </xsl:choose>
  397. </xsl:when>
  398. <xsl:otherwise>
  399. <xsl:message>
  400. <xsl:text>No bibliography entry: </xsl:text>
  401. <xsl:value-of select="$id"/>
  402. <xsl:text> found in </xsl:text>
  403. <xsl:value-of select="$bibliography.collection"/>
  404. </xsl:message>
  405. <xsl:value-of select="(@id|@xml:id)[1]"/>
  406. </xsl:otherwise>
  407. </xsl:choose>
  408. </xsl:when>
  409. <xsl:otherwise>
  410. <xsl:choose>
  411. <xsl:when test="$bibliography.numbered != 0">
  412. <xsl:number from="bibliography" count="biblioentry|bibliomixed"
  413. level="any" format="1"/>
  414. </xsl:when>
  415. <xsl:when test="local-name(*[1]) = 'abbrev'">
  416. <xsl:apply-templates select="*[1]"/>
  417. </xsl:when>
  418. <xsl:otherwise>
  419. <xsl:value-of select="(@id|@xml:id)[1]"/>
  420. </xsl:otherwise>
  421. </xsl:choose>
  422. </xsl:otherwise>
  423. </xsl:choose>
  424. </xsl:template>
  425. <xsl:template match="glossary" mode="xref-to">
  426. <xsl:param name="referrer"/>
  427. <xsl:param name="xrefstyle"/>
  428. <xsl:param name="verbose" select="1"/>
  429. <xsl:apply-templates select="." mode="object.xref.markup">
  430. <xsl:with-param name="purpose" select="'xref'"/>
  431. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  432. <xsl:with-param name="referrer" select="$referrer"/>
  433. <xsl:with-param name="verbose" select="$verbose"/>
  434. </xsl:apply-templates>
  435. </xsl:template>
  436. <xsl:template match="glossentry" mode="xref-to">
  437. <xsl:choose>
  438. <xsl:when test="$glossentry.show.acronym = 'primary'">
  439. <xsl:choose>
  440. <xsl:when test="acronym|abbrev">
  441. <xsl:apply-templates select="(acronym|abbrev)[1]"/>
  442. </xsl:when>
  443. <xsl:otherwise>
  444. <xsl:apply-templates select="glossterm[1]" mode="xref-to"/>
  445. </xsl:otherwise>
  446. </xsl:choose>
  447. </xsl:when>
  448. <xsl:otherwise>
  449. <xsl:apply-templates select="glossterm[1]" mode="xref-to"/>
  450. </xsl:otherwise>
  451. </xsl:choose>
  452. </xsl:template>
  453. <xsl:template match="glossterm" mode="xref-to">
  454. <xsl:apply-templates/>
  455. </xsl:template>
  456. <xsl:template match="index" mode="xref-to">
  457. <xsl:param name="referrer"/>
  458. <xsl:param name="xrefstyle"/>
  459. <xsl:param name="verbose" select="1"/>
  460. <xsl:apply-templates select="." mode="object.xref.markup">
  461. <xsl:with-param name="purpose" select="'xref'"/>
  462. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  463. <xsl:with-param name="referrer" select="$referrer"/>
  464. <xsl:with-param name="verbose" select="$verbose"/>
  465. </xsl:apply-templates>
  466. </xsl:template>
  467. <xsl:template match="listitem" mode="xref-to">
  468. <xsl:param name="referrer"/>
  469. <xsl:param name="xrefstyle"/>
  470. <xsl:param name="verbose" select="1"/>
  471. <xsl:apply-templates select="." mode="object.xref.markup">
  472. <xsl:with-param name="purpose" select="'xref'"/>
  473. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  474. <xsl:with-param name="referrer" select="$referrer"/>
  475. <xsl:with-param name="verbose" select="$verbose"/>
  476. </xsl:apply-templates>
  477. </xsl:template>
  478. <xsl:template match="section|simplesect
  479. |sect1|sect2|sect3|sect4|sect5
  480. |refsect1|refsect2|refsect3|refsection" mode="xref-to">
  481. <xsl:param name="referrer"/>
  482. <xsl:param name="xrefstyle"/>
  483. <xsl:param name="verbose" select="1"/>
  484. <xsl:apply-templates select="." mode="object.xref.markup">
  485. <xsl:with-param name="purpose" select="'xref'"/>
  486. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  487. <xsl:with-param name="referrer" select="$referrer"/>
  488. <xsl:with-param name="verbose" select="$verbose"/>
  489. </xsl:apply-templates>
  490. <!-- What about "in Chapter X"? -->
  491. </xsl:template>
  492. <xsl:template match="bridgehead" mode="xref-to">
  493. <xsl:param name="referrer"/>
  494. <xsl:param name="xrefstyle"/>
  495. <xsl:param name="verbose" select="1"/>
  496. <xsl:apply-templates select="." mode="object.xref.markup">
  497. <xsl:with-param name="purpose" select="'xref'"/>
  498. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  499. <xsl:with-param name="referrer" select="$referrer"/>
  500. <xsl:with-param name="verbose" select="$verbose"/>
  501. </xsl:apply-templates>
  502. <!-- What about "in Chapter X"? -->
  503. </xsl:template>
  504. <xsl:template match="qandaset" mode="xref-to">
  505. <xsl:param name="referrer"/>
  506. <xsl:param name="xrefstyle"/>
  507. <xsl:param name="verbose" select="1"/>
  508. <xsl:apply-templates select="." mode="object.xref.markup">
  509. <xsl:with-param name="purpose" select="'xref'"/>
  510. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  511. <xsl:with-param name="referrer" select="$referrer"/>
  512. <xsl:with-param name="verbose" select="$verbose"/>
  513. </xsl:apply-templates>
  514. </xsl:template>
  515. <xsl:template match="qandadiv" mode="xref-to">
  516. <xsl:param name="referrer"/>
  517. <xsl:param name="xrefstyle"/>
  518. <xsl:param name="verbose" select="1"/>
  519. <xsl:apply-templates select="." mode="object.xref.markup">
  520. <xsl:with-param name="purpose" select="'xref'"/>
  521. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  522. <xsl:with-param name="referrer" select="$referrer"/>
  523. <xsl:with-param name="verbose" select="$verbose"/>
  524. </xsl:apply-templates>
  525. </xsl:template>
  526. <xsl:template match="qandaentry" mode="xref-to">
  527. <xsl:param name="referrer"/>
  528. <xsl:param name="xrefstyle"/>
  529. <xsl:param name="verbose" select="1"/>
  530. <xsl:apply-templates select="question[1]" mode="object.xref.markup">
  531. <xsl:with-param name="purpose" select="'xref'"/>
  532. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  533. <xsl:with-param name="referrer" select="$referrer"/>
  534. <xsl:with-param name="verbose" select="$verbose"/>
  535. </xsl:apply-templates>
  536. </xsl:template>
  537. <xsl:template match="question|answer" mode="xref-to">
  538. <xsl:param name="referrer"/>
  539. <xsl:param name="xrefstyle"/>
  540. <xsl:param name="verbose" select="1"/>
  541. <xsl:apply-templates select="." mode="object.xref.markup">
  542. <xsl:with-param name="purpose" select="'xref'"/>
  543. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  544. <xsl:with-param name="referrer" select="$referrer"/>
  545. <xsl:with-param name="verbose" select="$verbose"/>
  546. </xsl:apply-templates>
  547. </xsl:template>
  548. <xsl:template match="part|reference" mode="xref-to">
  549. <xsl:param name="referrer"/>
  550. <xsl:param name="xrefstyle"/>
  551. <xsl:param name="verbose" select="1"/>
  552. <xsl:apply-templates select="." mode="object.xref.markup">
  553. <xsl:with-param name="purpose" select="'xref'"/>
  554. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  555. <xsl:with-param name="referrer" select="$referrer"/>
  556. <xsl:with-param name="verbose" select="$verbose"/>
  557. </xsl:apply-templates>
  558. </xsl:template>
  559. <xsl:template match="refentry" mode="xref-to">
  560. <xsl:param name="referrer"/>
  561. <xsl:param name="xrefstyle"/>
  562. <xsl:param name="verbose" select="1"/>
  563. <xsl:choose>
  564. <xsl:when test="refmeta/refentrytitle">
  565. <xsl:apply-templates select="refmeta/refentrytitle"/>
  566. </xsl:when>
  567. <xsl:otherwise>
  568. <xsl:apply-templates select="refnamediv/refname[1]"/>
  569. </xsl:otherwise>
  570. </xsl:choose>
  571. <xsl:apply-templates select="refmeta/manvolnum"/>
  572. </xsl:template>
  573. <xsl:template match="refnamediv" mode="xref-to">
  574. <xsl:param name="referrer"/>
  575. <xsl:param name="xrefstyle"/>
  576. <xsl:param name="verbose" select="1"/>
  577. <xsl:apply-templates select="refname[1]" mode="xref-to">
  578. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  579. <xsl:with-param name="referrer" select="$referrer"/>
  580. <xsl:with-param name="verbose" select="$verbose"/>
  581. </xsl:apply-templates>
  582. </xsl:template>
  583. <xsl:template match="refname" mode="xref-to">
  584. <xsl:param name="referrer"/>
  585. <xsl:param name="xrefstyle"/>
  586. <xsl:param name="verbose" select="1"/>
  587. <xsl:apply-templates mode="xref-to">
  588. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  589. <xsl:with-param name="referrer" select="$referrer"/>
  590. <xsl:with-param name="verbose" select="$verbose"/>
  591. </xsl:apply-templates>
  592. </xsl:template>
  593. <xsl:template match="step" mode="xref-to">
  594. <xsl:param name="referrer"/>
  595. <xsl:param name="xrefstyle"/>
  596. <xsl:param name="verbose" select="1"/>
  597. <xsl:call-template name="gentext">
  598. <xsl:with-param name="key" select="'Step'"/>
  599. </xsl:call-template>
  600. <xsl:text> </xsl:text>
  601. <xsl:apply-templates select="." mode="number"/>
  602. </xsl:template>
  603. <xsl:template match="varlistentry" mode="xref-to">
  604. <xsl:param name="referrer"/>
  605. <xsl:param name="xrefstyle"/>
  606. <xsl:param name="verbose" select="1"/>
  607. <xsl:apply-templates select="term[1]" mode="xref-to">
  608. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  609. <xsl:with-param name="referrer" select="$referrer"/>
  610. <xsl:with-param name="verbose" select="$verbose"/>
  611. </xsl:apply-templates>
  612. </xsl:template>
  613. <xsl:template match="varlistentry/term" mode="xref-to">
  614. <xsl:param name="verbose" select="1"/>
  615. <!-- to avoid the comma that will be generated if there are several terms -->
  616. <xsl:apply-templates/>
  617. </xsl:template>
  618. <xsl:template match="co" mode="xref-to">
  619. <xsl:param name="referrer"/>
  620. <xsl:param name="xrefstyle"/>
  621. <xsl:param name="verbose" select="1"/>
  622. <xsl:apply-templates select="." mode="callout-bug"/>
  623. </xsl:template>
  624. <xsl:template match="book" mode="xref-to">
  625. <xsl:param name="referrer"/>
  626. <xsl:param name="xrefstyle"/>
  627. <xsl:param name="verbose" select="1"/>
  628. <xsl:apply-templates select="." mode="object.xref.markup">
  629. <xsl:with-param name="purpose" select="'xref'"/>
  630. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  631. <xsl:with-param name="referrer" select="$referrer"/>
  632. <xsl:with-param name="verbose" select="$verbose"/>
  633. </xsl:apply-templates>
  634. </xsl:template>
  635. <xsl:template match="para" mode="xref-to">
  636. <xsl:param name="referrer"/>
  637. <xsl:param name="xrefstyle"/>
  638. <xsl:param name="verbose"/>
  639. <xsl:variable name="context" select="(ancestor::simplesect
  640. |ancestor::section
  641. |ancestor::sect1
  642. |ancestor::sect2
  643. |ancestor::sect3
  644. |ancestor::sect4
  645. |ancestor::sect5
  646. |ancestor::refsection
  647. |ancestor::refsect1
  648. |ancestor::refsect2
  649. |ancestor::refsect3
  650. |ancestor::chapter
  651. |ancestor::appendix
  652. |ancestor::preface
  653. |ancestor::partintro
  654. |ancestor::dedication
  655. |ancestor::colophon
  656. |ancestor::bibliography
  657. |ancestor::index
  658. |ancestor::glossary
  659. |ancestor::glossentry
  660. |ancestor::listitem
  661. |ancestor::varlistentry)[last()]"/>
  662. <xsl:apply-templates select="$context" mode="xref-to">
  663. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  664. <xsl:with-param name="referrer" select="$referrer"/>
  665. <xsl:with-param name="verbose" select="$verbose"/>
  666. </xsl:apply-templates>
  667. </xsl:template>
  668. <!-- ==================================================================== -->
  669. <xsl:template match="link" name="link">
  670. <xsl:param name="linkend" select="@linkend"/>
  671. <xsl:param name="targets" select="key('id',$linkend)"/>
  672. <xsl:param name="target" select="$targets[1]"/>
  673. <xsl:variable name="xrefstyle">
  674. <xsl:choose>
  675. <xsl:when test="@role and not(@xrefstyle)
  676. and $use.role.as.xrefstyle != 0">
  677. <xsl:value-of select="@role"/>
  678. </xsl:when>
  679. <xsl:otherwise>
  680. <xsl:value-of select="@xrefstyle"/>
  681. </xsl:otherwise>
  682. </xsl:choose>
  683. </xsl:variable>
  684. <xsl:variable name="content">
  685. <fo:inline xsl:use-attribute-sets="xref.properties">
  686. <xsl:choose>
  687. <xsl:when test="count(child::node()) &gt; 0">
  688. <!-- If it has content, use it -->
  689. <xsl:apply-templates/>
  690. </xsl:when>
  691. <!-- look for an endterm -->
  692. <xsl:when test="@endterm">
  693. <xsl:variable name="etargets" select="key('id',@endterm)"/>
  694. <xsl:variable name="etarget" select="$etargets[1]"/>
  695. <xsl:choose>
  696. <xsl:when test="count($etarget) = 0">
  697. <xsl:message>
  698. <xsl:value-of select="count($etargets)"/>
  699. <xsl:text>Endterm points to nonexistent ID: </xsl:text>
  700. <xsl:value-of select="@endterm"/>
  701. </xsl:message>
  702. <xsl:text>???</xsl:text>
  703. </xsl:when>
  704. <xsl:otherwise>
  705. <xsl:apply-templates select="$etarget" mode="endterm"/>
  706. </xsl:otherwise>
  707. </xsl:choose>
  708. </xsl:when>
  709. <!-- Use the xlink:href if no other text -->
  710. <xsl:when test="@xlink:href">
  711. <xsl:value-of select="@xlink:href"/>
  712. </xsl:when>
  713. <xsl:otherwise>
  714. <xsl:message>
  715. <xsl:text>Link element has no content and no Endterm. </xsl:text>
  716. <xsl:text>Nothing to show in the link to </xsl:text>
  717. <xsl:value-of select="$target"/>
  718. </xsl:message>
  719. <xsl:text>???</xsl:text>
  720. </xsl:otherwise>
  721. </xsl:choose>
  722. </fo:inline>
  723. </xsl:variable>
  724. <xsl:call-template name="simple.xlink">
  725. <xsl:with-param name="node" select="."/>
  726. <xsl:with-param name="linkend" select="$linkend"/>
  727. <xsl:with-param name="content" select="$content"/>
  728. </xsl:call-template>
  729. <!-- Add standard page reference? -->
  730. <xsl:choose>
  731. <!-- page numbering on link only enabled for @linkend -->
  732. <!-- There is no link element in DB5 with xlink:href -->
  733. <xsl:when test="not($linkend)">
  734. </xsl:when>
  735. <!-- negative xrefstyle in instance turns it off -->
  736. <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')
  737. and contains($xrefstyle, 'nopage')">
  738. </xsl:when>
  739. <xsl:when test="(starts-with(normalize-space($xrefstyle), 'select:')
  740. and $insert.link.page.number = 'maybe'
  741. and (contains($xrefstyle, 'page')
  742. or contains($xrefstyle, 'Page')))
  743. or ( $insert.link.page.number = 'yes'
  744. or $insert.link.page.number = '1')
  745. or local-name($target) = 'para'">
  746. <xsl:apply-templates select="$target" mode="page.citation">
  747. <xsl:with-param name="id" select="$linkend"/>
  748. </xsl:apply-templates>
  749. </xsl:when>
  750. </xsl:choose>
  751. </xsl:template>
  752. <xsl:template match="ulink" name="ulink">
  753. <xsl:param name="url" select="@url"/>
  754. <xsl:variable name ="ulink.url">
  755. <xsl:call-template name="fo-external-image">
  756. <xsl:with-param name="filename" select="$url"/>
  757. </xsl:call-template>
  758. </xsl:variable>
  759. <fo:basic-link xsl:use-attribute-sets="xref.properties"
  760. external-destination="{$ulink.url}">
  761. <xsl:choose>
  762. <xsl:when test="count(child::node())=0">
  763. <xsl:call-template name="hyphenate-url">
  764. <xsl:with-param name="url" select="$url"/>
  765. </xsl:call-template>
  766. </xsl:when>
  767. <xsl:otherwise>
  768. <xsl:apply-templates/>
  769. </xsl:otherwise>
  770. </xsl:choose>
  771. </fo:basic-link>
  772. <xsl:if test="count(child::node()) != 0
  773. and string(.) != $url
  774. and $ulink.show != 0">
  775. <!-- yes, show the URI -->
  776. <xsl:choose>
  777. <xsl:when test="$ulink.footnotes != 0 and not(ancestor::footnote)">
  778. <fo:footnote>
  779. <xsl:call-template name="ulink.footnote.number"/>
  780. <fo:footnote-body xsl:use-attribute-sets="footnote.properties">
  781. <fo:block>
  782. <xsl:call-template name="ulink.footnote.number"/>
  783. <xsl:text> </xsl:text>
  784. <fo:basic-link external-destination="{$ulink.url}">
  785. <xsl:value-of select="$url"/>
  786. </fo:basic-link>
  787. </fo:block>
  788. </fo:footnote-body>
  789. </fo:footnote>
  790. </xsl:when>
  791. <xsl:otherwise>
  792. <fo:inline hyphenate="false">
  793. <xsl:text> [</xsl:text>
  794. <fo:basic-link external-destination="{$ulink.url}">
  795. <xsl:call-template name="hyphenate-url">
  796. <xsl:with-param name="url" select="$url"/>
  797. </xsl:call-template>
  798. </fo:basic-link>
  799. <xsl:text>]</xsl:text>
  800. </fo:inline>
  801. </xsl:otherwise>
  802. </xsl:choose>
  803. </xsl:if>
  804. </xsl:template>
  805. <xsl:template name="ulink.footnote.number">
  806. <fo:inline xsl:use-attribute-sets="footnote.mark.properties">
  807. <xsl:choose>
  808. <xsl:when test="$fop.extensions != 0">
  809. <xsl:attribute name="vertical-align">super</xsl:attribute>
  810. </xsl:when>
  811. <xsl:otherwise>
  812. <xsl:attribute name="baseline-shift">super</xsl:attribute>
  813. </xsl:otherwise>
  814. </xsl:choose>
  815. <xsl:variable name="fnum">
  816. <!-- FIXME: list in @from is probably not complete -->
  817. <xsl:number level="any"
  818. from="chapter|appendix|preface|article|refentry|bibliography[not(parent::article)]"
  819. count="footnote[not(@label)][not(ancestor::tgroup)]|ulink[node()][@url != .][not(ancestor::footnote)]"
  820. format="1"/>
  821. </xsl:variable>
  822. <xsl:choose>
  823. <xsl:when test="string-length($footnote.number.symbols) &gt;= $fnum">
  824. <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
  825. </xsl:when>
  826. <xsl:otherwise>
  827. <xsl:number value="$fnum" format="{$footnote.number.format}"/>
  828. </xsl:otherwise>
  829. </xsl:choose>
  830. </fo:inline>
  831. </xsl:template>
  832. <xsl:template name="hyphenate-url">
  833. <xsl:param name="url" select="''"/>
  834. <xsl:choose>
  835. <xsl:when test="$ulink.hyphenate = ''">
  836. <xsl:value-of select="$url"/>
  837. </xsl:when>
  838. <xsl:when test="string-length($url) &gt; 1">
  839. <xsl:variable name="char" select="substring($url, 1, 1)"/>
  840. <xsl:value-of select="$char"/>
  841. <xsl:if test="contains($ulink.hyphenate.chars, $char)">
  842. <!-- Do not hyphen in-between // -->
  843. <xsl:if test="not($char = '/' and substring($url,2,1) = '/')">
  844. <xsl:copy-of select="$ulink.hyphenate"/>
  845. </xsl:if>
  846. </xsl:if>
  847. <!-- recurse to the next character -->
  848. <xsl:call-template name="hyphenate-url">
  849. <xsl:with-param name="url" select="substring($url, 2)"/>
  850. </xsl:call-template>
  851. </xsl:when>
  852. <xsl:otherwise>
  853. <xsl:value-of select="$url"/>
  854. </xsl:otherwise>
  855. </xsl:choose>
  856. </xsl:template>
  857. <xsl:template match="olink" name="olink">
  858. <!-- olink content may be passed in from xlink olink -->
  859. <xsl:param name="content" select="NOTANELEMENT"/>
  860. <xsl:call-template name="anchor"/>
  861. <xsl:variable name="localinfo" select="@localinfo"/>
  862. <xsl:choose>
  863. <!-- olinks resolved by stylesheet and target database -->
  864. <xsl:when test="@targetdoc or @targetptr or
  865. (@xlink:role=$xolink.role and
  866. contains(@xlink:href, '#') )" >
  867. <xsl:variable name="targetdoc.att">
  868. <xsl:choose>
  869. <xsl:when test="@targetdoc != ''">
  870. <xsl:value-of select="@targetdoc"/>
  871. </xsl:when>
  872. <xsl:when test="@xlink:role=$xolink.role and
  873. contains(@xlink:href, '#')" >
  874. <xsl:value-of select="substring-before(@xlink:href, '#')"/>
  875. </xsl:when>
  876. </xsl:choose>
  877. </xsl:variable>
  878. <xsl:variable name="targetptr.att">
  879. <xsl:choose>
  880. <xsl:when test="@targetptr != ''">
  881. <xsl:value-of select="@targetptr"/>
  882. </xsl:when>
  883. <xsl:when test="@xlink:role=$xolink.role and
  884. contains(@xlink:href, '#')" >
  885. <xsl:value-of select="substring-after(@xlink:href, '#')"/>
  886. </xsl:when>
  887. </xsl:choose>
  888. </xsl:variable>
  889. <xsl:variable name="olink.lang">
  890. <xsl:call-template name="l10n.language">
  891. <xsl:with-param name="xref-context" select="true()"/>
  892. </xsl:call-template>
  893. </xsl:variable>
  894. <xsl:variable name="target.database.filename">
  895. <xsl:call-template name="select.target.database">
  896. <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
  897. <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
  898. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  899. </xsl:call-template>
  900. </xsl:variable>
  901. <xsl:variable name="target.database"
  902. select="document($target.database.filename, /)"/>
  903. <xsl:if test="$olink.debug != 0">
  904. <xsl:message>
  905. <xsl:text>Olink debug: root element of target.database is '</xsl:text>
  906. <xsl:value-of select="local-name($target.database/*[1])"/>
  907. <xsl:text>'.</xsl:text>
  908. </xsl:message>
  909. </xsl:if>
  910. <xsl:variable name="olink.key">
  911. <xsl:call-template name="select.olink.key">
  912. <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
  913. <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
  914. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  915. <xsl:with-param name="target.database" select="$target.database"/>
  916. </xsl:call-template>
  917. </xsl:variable>
  918. <xsl:if test="string-length($olink.key) = 0">
  919. <xsl:message>
  920. <xsl:text>Error: unresolved olink: </xsl:text>
  921. <xsl:text>targetdoc/targetptr = '</xsl:text>
  922. <xsl:value-of select="$targetdoc.att"/>
  923. <xsl:text>/</xsl:text>
  924. <xsl:value-of select="$targetptr.att"/>
  925. <xsl:text>'.</xsl:text>
  926. </xsl:message>
  927. </xsl:if>
  928. <xsl:variable name="href">
  929. <xsl:call-template name="make.olink.href">
  930. <xsl:with-param name="olink.key" select="$olink.key"/>
  931. <xsl:with-param name="target.database" select="$target.database"/>
  932. </xsl:call-template>
  933. </xsl:variable>
  934. <!-- Olink that points to internal id can be a link -->
  935. <xsl:variable name="linkend">
  936. <xsl:call-template name="olink.as.linkend">
  937. <xsl:with-param name="olink.key" select="$olink.key"/>
  938. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  939. <xsl:with-param name="target.database" select="$target.database"/>
  940. </xsl:call-template>
  941. </xsl:variable>
  942. <xsl:variable name="hottext">
  943. <xsl:choose>
  944. <xsl:when test="$content">
  945. <xsl:copy-of select="$content"/>
  946. </xsl:when>
  947. <xsl:otherwise>
  948. <xsl:call-template name="olink.hottext">
  949. <xsl:with-param name="olink.key" select="$olink.key"/>
  950. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  951. <xsl:with-param name="target.database" select="$target.database"/>
  952. </xsl:call-template>
  953. </xsl:otherwise>
  954. </xsl:choose>
  955. </xsl:variable>
  956. <xsl:variable name="olink.docname.citation">
  957. <xsl:call-template name="olink.document.citation">
  958. <xsl:with-param name="olink.key" select="$olink.key"/>
  959. <xsl:with-param name="target.database" select="$target.database"/>
  960. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  961. </xsl:call-template>
  962. </xsl:variable>
  963. <xsl:variable name="olink.page.citation">
  964. <xsl:call-template name="olink.page.citation">
  965. <xsl:with-param name="olink.key" select="$olink.key"/>
  966. <xsl:with-param name="target.database" select="$target.database"/>
  967. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  968. <xsl:with-param name="linkend" select="$linkend"/>
  969. </xsl:call-template>
  970. </xsl:variable>
  971. <xsl:choose>
  972. <xsl:when test="$linkend != ''">
  973. <fo:basic-link internal-destination="{$linkend}"
  974. xsl:use-attribute-sets="xref.properties">
  975. <xsl:copy-of select="$hottext"/>
  976. <xsl:copy-of select="$olink.page.citation"/>
  977. </fo:basic-link>
  978. </xsl:when>
  979. <xsl:when test="$href != ''">
  980. <xsl:choose>
  981. <xsl:when test="$xep.extensions != 0">
  982. <fo:basic-link external-destination="url({$href})"
  983. xsl:use-attribute-sets="olink.properties">
  984. <xsl:copy-of select="$hottext"/>
  985. </fo:basic-link>
  986. <xsl:copy-of select="$olink.page.citation"/>
  987. <xsl:copy-of select="$olink.docname.citation"/>
  988. </xsl:when>
  989. <xsl:when test="$axf.extensions != 0">
  990. <fo:basic-link external-destination="{$href}"
  991. xsl:use-attribute-sets="olink.properties">
  992. <xsl:copy-of select="$hottext"/>
  993. </fo:basic-link>
  994. <xsl:copy-of select="$olink.page.citation"/>
  995. <xsl:copy-of select="$olink.docname.citation"/>
  996. </xsl:when>
  997. <xsl:otherwise>
  998. <fo:basic-link external-destination="{$href}"
  999. xsl:use-attribute-sets="olink.properties">
  1000. <xsl:copy-of select="$hottext"/>
  1001. </fo:basic-link>
  1002. <xsl:copy-of select="$olink.page.citation"/>
  1003. <xsl:copy-of select="$olink.docname.citation"/>
  1004. </xsl:otherwise>
  1005. </xsl:choose>
  1006. </xsl:when>
  1007. <xsl:otherwise>
  1008. <xsl:copy-of select="$hottext"/>
  1009. <xsl:copy-of select="$olink.page.citation"/>
  1010. <xsl:copy-of select="$olink.docname.citation"/>
  1011. </xsl:otherwise>
  1012. </xsl:choose>
  1013. </xsl:when>
  1014. <!-- olink never implemented in FO for old olink entity syntax -->
  1015. <xsl:otherwise>
  1016. <xsl:apply-templates/>
  1017. </xsl:otherwise>
  1018. </xsl:choose>
  1019. </xsl:template>
  1020. <xsl:template match="*" mode="insert.olink.docname.markup">
  1021. <xsl:param name="docname" select="''"/>
  1022. <fo:inline font-style="italic">
  1023. <xsl:value-of select="$docname"/>
  1024. </fo:inline>
  1025. </xsl:template>
  1026. <!-- This prevents error message when processing olinks with xrefstyle -->
  1027. <xsl:template match="olink" mode="object.xref.template"/>
  1028. <xsl:template name="olink.as.linkend">
  1029. <xsl:param name="olink.key" select="''"/>
  1030. <xsl:param name="olink.lang" select="''"/>
  1031. <xsl:param name="target.database" select="NotANode"/>
  1032. <xsl:variable name="targetdoc">
  1033. <xsl:value-of select="substring-before($olink.key, '/')"/>
  1034. </xsl:variable>
  1035. <xsl:variable name="targetptr">
  1036. <xsl:value-of
  1037. select="substring-before(substring-after($olink.key, '/'), '/')"/>
  1038. </xsl:variable>
  1039. <xsl:variable name="target.lang">
  1040. <xsl:variable name="candidate">
  1041. <xsl:for-each select="$target.database" >
  1042. <xsl:value-of
  1043. select="key('targetptr-key', $olink.key)/@lang" />
  1044. </xsl:for-each>
  1045. </xsl:variable>
  1046. <xsl:choose>
  1047. <xsl:when test="$candidate != ''">
  1048. <xsl:value-of select="$candidate"/>
  1049. </xsl:when>
  1050. <xsl:otherwise>
  1051. <xsl:value-of select="$olink.lang"/>
  1052. </xsl:otherwise>
  1053. </xsl:choose>
  1054. </xsl:variable>
  1055. <xsl:if test="$current.docid = $targetdoc and
  1056. $olink.lang = $target.lang">
  1057. <xsl:variable name="targets" select="key('id',$targetptr)"/>
  1058. <xsl:variable name="target" select="$targets[1]"/>
  1059. <xsl:if test="$target">
  1060. <xsl:value-of select="$targetptr"/>
  1061. </xsl:if>
  1062. </xsl:if>
  1063. </xsl:template>
  1064. <xsl:template name="olink.outline">
  1065. <xsl:param name="outline.base.uri"/>
  1066. <xsl:param name="localinfo"/>
  1067. <xsl:param name="return" select="href"/>
  1068. <xsl:message terminate="yes">Fatal error: olink.outline template: what is this supposed to do?</xsl:message>
  1069. </xsl:template>
  1070. <!-- ==================================================================== -->
  1071. <xsl:template name="title.xref">
  1072. <xsl:param name="target" select="."/>
  1073. <xsl:choose>
  1074. <xsl:when test="local-name($target) = 'figure'
  1075. or local-name($target) = 'example'
  1076. or local-name($target) = 'equation'
  1077. or local-name($target) = 'table'
  1078. or local-name($target) = 'dedication'
  1079. or local-name($target) = 'preface'
  1080. or local-name($target) = 'bibliography'
  1081. or local-name($target) = 'glossary'
  1082. or local-name($target) = 'index'
  1083. or local-name($target) = 'setindex'
  1084. or local-name($target) = 'colophon'">
  1085. <xsl:call-template name="gentext.startquote"/>
  1086. <xsl:apply-templates select="$target" mode="title.markup"/>
  1087. <xsl:call-template name="gentext.endquote"/>
  1088. </xsl:when>
  1089. <xsl:otherwise>
  1090. <fo:inline font-style="italic">
  1091. <xsl:apply-templates select="$target" mode="title.markup"/>
  1092. </fo:inline>
  1093. </xsl:otherwise>
  1094. </xsl:choose>
  1095. </xsl:template>
  1096. <xsl:template name="number.xref">
  1097. <xsl:param name="target" select="."/>
  1098. <xsl:apply-templates select="$target" mode="label.markup"/>
  1099. </xsl:template>
  1100. <!-- ==================================================================== -->
  1101. <xsl:template name="xref.xreflabel">
  1102. <!-- called to process an xreflabel...you might use this to make -->
  1103. <!-- xreflabels come out in the right font for different targets, -->
  1104. <!-- for example. -->
  1105. <xsl:param name="target" select="."/>
  1106. <xsl:value-of select="$target/@xreflabel"/>
  1107. </xsl:template>
  1108. <!-- ==================================================================== -->
  1109. <xsl:template match="title" mode="xref">
  1110. <xsl:apply-templates/>
  1111. </xsl:template>
  1112. <xsl:template match="command" mode="xref">
  1113. <xsl:call-template name="inline.boldseq"/>
  1114. </xsl:template>
  1115. <xsl:template match="function" mode="xref">
  1116. <xsl:call-template name="inline.monoseq"/>
  1117. </xsl:template>
  1118. <xsl:template match="*" mode="page.citation">
  1119. <xsl:param name="id" select="'???'"/>
  1120. <fo:basic-link internal-destination="{$id}"
  1121. xsl:use-attribute-sets="xref.properties">
  1122. <fo:inline keep-together.within-line="always">
  1123. <xsl:call-template name="substitute-markup">
  1124. <xsl:with-param name="template">
  1125. <xsl:call-template name="gentext.template">
  1126. <xsl:with-param name="name" select="'page.citation'"/>
  1127. <xsl:with-param name="context" select="'xref'"/>
  1128. </xsl:call-template>
  1129. </xsl:with-param>
  1130. </xsl:call-template>
  1131. </fo:inline>
  1132. </fo:basic-link>
  1133. </xsl:template>
  1134. <xsl:template match="*" mode="pagenumber.markup">
  1135. <xsl:variable name="id">
  1136. <xsl:call-template name="object.id"/>
  1137. </xsl:variable>
  1138. <fo:page-number-citation ref-id="{$id}"/>
  1139. </xsl:template>
  1140. <!-- ==================================================================== -->
  1141. <xsl:template match="*" mode="insert.title.markup">
  1142. <xsl:param name="purpose"/>
  1143. <xsl:param name="xrefstyle"/>
  1144. <xsl:param name="title"/>
  1145. <xsl:choose>
  1146. <!-- FIXME: what about the case where titleabbrev is inside the info? -->
  1147. <xsl:when test="$purpose = 'xref' and titleabbrev">
  1148. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  1149. </xsl:when>
  1150. <xsl:otherwise>
  1151. <xsl:copy-of select="$title"/>
  1152. </xsl:otherwise>
  1153. </xsl:choose>
  1154. </xsl:template>
  1155. <xsl:template match="chapter|appendix" mode="insert.title.markup">
  1156. <xsl:param name="purpose"/>
  1157. <xsl:param name="xrefstyle"/>
  1158. <xsl:param name="title"/>
  1159. <xsl:choose>
  1160. <xsl:when test="$purpose = 'xref'">
  1161. <fo:inline font-style="italic">
  1162. <xsl:copy-of select="$title"/>
  1163. </fo:inline>
  1164. </xsl:when>
  1165. <xsl:otherwise>
  1166. <xsl:copy-of select="$title"/>
  1167. </xsl:otherwise>
  1168. </xsl:choose>
  1169. </xsl:template>
  1170. <xsl:template match="*" mode="insert.subtitle.markup">
  1171. <xsl:param name="purpose"/>
  1172. <xsl:param name="xrefstyle"/>
  1173. <xsl:param name="subtitle"/>
  1174. <xsl:copy-of select="$subtitle"/>
  1175. </xsl:template>
  1176. <xsl:template match="*" mode="insert.label.markup">
  1177. <xsl:param name="purpose"/>
  1178. <xsl:param name="xrefstyle"/>
  1179. <xsl:param name="label"/>
  1180. <xsl:copy-of select="$label"/>
  1181. </xsl:template>
  1182. <xsl:template match="*" mode="insert.pagenumber.markup">
  1183. <xsl:param name="purpose"/>
  1184. <xsl:param name="xrefstyle"/>
  1185. <xsl:param name="pagenumber"/>
  1186. <xsl:copy-of select="$pagenumber"/>
  1187. </xsl:template>
  1188. <xsl:template match="*" mode="insert.direction.markup">
  1189. <xsl:param name="purpose"/>
  1190. <xsl:param name="xrefstyle"/>
  1191. <xsl:param name="direction"/>
  1192. <xsl:copy-of select="$direction"/>
  1193. </xsl:template>
  1194. <xsl:template match="olink" mode="pagenumber.markup">
  1195. <!-- Local olinks can use page-citation -->
  1196. <xsl:variable name="targetdoc.att" select="@targetdoc"/>
  1197. <xsl:variable name="targetptr.att" select="@targetptr"/>
  1198. <xsl:variable name="olink.lang">
  1199. <xsl:call-template name="l10n.language">
  1200. <xsl:with-param name="xref-context" select="true()"/>
  1201. </xsl:call-template>
  1202. </xsl:variable>
  1203. <xsl:variable name="target.database.filename">
  1204. <xsl:call-template name="select.target.database">
  1205. <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
  1206. <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
  1207. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  1208. </xsl:call-template>
  1209. </xsl:variable>
  1210. <xsl:variable name="target.database"
  1211. select="document($target.database.filename, /)"/>
  1212. <xsl:if test="$olink.debug != 0">
  1213. <xsl:message>
  1214. <xsl:text>Olink debug: root element of target.database is '</xsl:text>
  1215. <xsl:value-of select="local-name($target.database/*[1])"/>
  1216. <xsl:text>'.</xsl:text>
  1217. </xsl:message>
  1218. </xsl:if>
  1219. <xsl:variable name="olink.key">
  1220. <xsl:call-template name="select.olink.key">
  1221. <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
  1222. <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
  1223. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  1224. <xsl:with-param name="target.database" select="$target.database"/>
  1225. </xsl:call-template>
  1226. </xsl:variable>
  1227. <!-- Olink that points to internal id can be a link -->
  1228. <xsl:variable name="linkend">
  1229. <xsl:call-template name="olink.as.linkend">
  1230. <xsl:with-param name="olink.key" select="$olink.key"/>
  1231. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  1232. <xsl:with-param name="target.database" select="$target.database"/>
  1233. </xsl:call-template>
  1234. </xsl:variable>
  1235. <xsl:choose>
  1236. <xsl:when test="$linkend != ''">
  1237. <fo:page-number-citation ref-id="{$linkend}"/>
  1238. </xsl:when>
  1239. <xsl:otherwise>
  1240. <xsl:message>
  1241. <xsl:text>Olink error: no page number linkend for local olink '</xsl:text>
  1242. <xsl:value-of select="$olink.key"/>
  1243. <xsl:text>'</xsl:text>
  1244. </xsl:message>
  1245. </xsl:otherwise>
  1246. </xsl:choose>
  1247. </xsl:template>
  1248. </xsl:stylesheet>