xref.xsl 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  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="area|areaset" mode="xref-to">
  625. <xsl:param name="referrer"/>
  626. <xsl:param name="xrefstyle"/>
  627. <xsl:call-template name="callout-bug">
  628. <xsl:with-param name="conum">
  629. <xsl:apply-templates select="." mode="conumber"/>
  630. </xsl:with-param>
  631. </xsl:call-template>
  632. </xsl:template>
  633. <xsl:template match="book" mode="xref-to">
  634. <xsl:param name="referrer"/>
  635. <xsl:param name="xrefstyle"/>
  636. <xsl:param name="verbose" select="1"/>
  637. <xsl:apply-templates select="." mode="object.xref.markup">
  638. <xsl:with-param name="purpose" select="'xref'"/>
  639. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  640. <xsl:with-param name="referrer" select="$referrer"/>
  641. <xsl:with-param name="verbose" select="$verbose"/>
  642. </xsl:apply-templates>
  643. </xsl:template>
  644. <xsl:template match="para" mode="xref-to">
  645. <xsl:param name="referrer"/>
  646. <xsl:param name="xrefstyle"/>
  647. <xsl:param name="verbose"/>
  648. <xsl:variable name="context" select="(ancestor::simplesect
  649. |ancestor::section
  650. |ancestor::sect1
  651. |ancestor::sect2
  652. |ancestor::sect3
  653. |ancestor::sect4
  654. |ancestor::sect5
  655. |ancestor::refsection
  656. |ancestor::refsect1
  657. |ancestor::refsect2
  658. |ancestor::refsect3
  659. |ancestor::chapter
  660. |ancestor::appendix
  661. |ancestor::preface
  662. |ancestor::partintro
  663. |ancestor::dedication
  664. |ancestor::colophon
  665. |ancestor::bibliography
  666. |ancestor::index
  667. |ancestor::glossary
  668. |ancestor::glossentry
  669. |ancestor::listitem
  670. |ancestor::varlistentry)[last()]"/>
  671. <xsl:apply-templates select="$context" mode="xref-to">
  672. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  673. <xsl:with-param name="referrer" select="$referrer"/>
  674. <xsl:with-param name="verbose" select="$verbose"/>
  675. </xsl:apply-templates>
  676. </xsl:template>
  677. <!-- ==================================================================== -->
  678. <xsl:template match="link" name="link">
  679. <xsl:param name="linkend" select="@linkend"/>
  680. <xsl:param name="targets" select="key('id',$linkend)"/>
  681. <xsl:param name="target" select="$targets[1]"/>
  682. <xsl:variable name="xrefstyle">
  683. <xsl:choose>
  684. <xsl:when test="@role and not(@xrefstyle)
  685. and $use.role.as.xrefstyle != 0">
  686. <xsl:value-of select="@role"/>
  687. </xsl:when>
  688. <xsl:otherwise>
  689. <xsl:value-of select="@xrefstyle"/>
  690. </xsl:otherwise>
  691. </xsl:choose>
  692. </xsl:variable>
  693. <xsl:variable name="content">
  694. <fo:inline xsl:use-attribute-sets="xref.properties">
  695. <xsl:choose>
  696. <xsl:when test="count(child::node()) &gt; 0">
  697. <!-- If it has content, use it -->
  698. <xsl:apply-templates/>
  699. </xsl:when>
  700. <!-- look for an endterm -->
  701. <xsl:when test="@endterm">
  702. <xsl:variable name="etargets" select="key('id',@endterm)"/>
  703. <xsl:variable name="etarget" select="$etargets[1]"/>
  704. <xsl:choose>
  705. <xsl:when test="count($etarget) = 0">
  706. <xsl:message>
  707. <xsl:value-of select="count($etargets)"/>
  708. <xsl:text>Endterm points to nonexistent ID: </xsl:text>
  709. <xsl:value-of select="@endterm"/>
  710. </xsl:message>
  711. <xsl:text>???</xsl:text>
  712. </xsl:when>
  713. <xsl:otherwise>
  714. <xsl:apply-templates select="$etarget" mode="endterm"/>
  715. </xsl:otherwise>
  716. </xsl:choose>
  717. </xsl:when>
  718. <!-- Use the xlink:href if no other text -->
  719. <xsl:when test="@xlink:href">
  720. <xsl:value-of select="@xlink:href"/>
  721. </xsl:when>
  722. <xsl:otherwise>
  723. <xsl:message>
  724. <xsl:text>Link element has no content and no Endterm. </xsl:text>
  725. <xsl:text>Nothing to show in the link to </xsl:text>
  726. <xsl:value-of select="$target"/>
  727. </xsl:message>
  728. <xsl:text>???</xsl:text>
  729. </xsl:otherwise>
  730. </xsl:choose>
  731. </fo:inline>
  732. </xsl:variable>
  733. <xsl:call-template name="simple.xlink">
  734. <xsl:with-param name="node" select="."/>
  735. <xsl:with-param name="linkend" select="$linkend"/>
  736. <xsl:with-param name="content" select="$content"/>
  737. </xsl:call-template>
  738. <!-- Add standard page reference? -->
  739. <xsl:choose>
  740. <!-- page numbering on link only enabled for @linkend -->
  741. <!-- There is no link element in DB5 with xlink:href -->
  742. <xsl:when test="not($linkend)">
  743. </xsl:when>
  744. <!-- negative xrefstyle in instance turns it off -->
  745. <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')
  746. and contains($xrefstyle, 'nopage')">
  747. </xsl:when>
  748. <xsl:when test="(starts-with(normalize-space($xrefstyle), 'select:')
  749. and $insert.link.page.number = 'maybe'
  750. and (contains($xrefstyle, 'page')
  751. or contains($xrefstyle, 'Page')))
  752. or ( $insert.link.page.number = 'yes'
  753. or $insert.link.page.number = '1')
  754. or local-name($target) = 'para'">
  755. <xsl:apply-templates select="$target" mode="page.citation">
  756. <xsl:with-param name="id" select="$linkend"/>
  757. </xsl:apply-templates>
  758. </xsl:when>
  759. </xsl:choose>
  760. </xsl:template>
  761. <xsl:template match="ulink" name="ulink">
  762. <xsl:param name="url" select="@url"/>
  763. <xsl:variable name ="ulink.url">
  764. <xsl:call-template name="fo-external-image">
  765. <xsl:with-param name="filename" select="$url"/>
  766. </xsl:call-template>
  767. </xsl:variable>
  768. <fo:basic-link xsl:use-attribute-sets="xref.properties"
  769. external-destination="{$ulink.url}">
  770. <xsl:choose>
  771. <xsl:when test="count(child::node())=0">
  772. <xsl:call-template name="hyphenate-url">
  773. <xsl:with-param name="url" select="$url"/>
  774. </xsl:call-template>
  775. </xsl:when>
  776. <xsl:otherwise>
  777. <xsl:apply-templates/>
  778. </xsl:otherwise>
  779. </xsl:choose>
  780. </fo:basic-link>
  781. <xsl:if test="count(child::node()) != 0
  782. and string(.) != $url
  783. and $ulink.show != 0">
  784. <!-- yes, show the URI -->
  785. <xsl:choose>
  786. <xsl:when test="$ulink.footnotes != 0 and not(ancestor::footnote)">
  787. <fo:footnote>
  788. <xsl:call-template name="ulink.footnote.number"/>
  789. <fo:footnote-body xsl:use-attribute-sets="footnote.properties">
  790. <fo:block>
  791. <xsl:call-template name="ulink.footnote.number"/>
  792. <xsl:text> </xsl:text>
  793. <fo:basic-link external-destination="{$ulink.url}">
  794. <xsl:value-of select="$url"/>
  795. </fo:basic-link>
  796. </fo:block>
  797. </fo:footnote-body>
  798. </fo:footnote>
  799. </xsl:when>
  800. <xsl:otherwise>
  801. <fo:inline hyphenate="false">
  802. <xsl:text> [</xsl:text>
  803. <fo:basic-link external-destination="{$ulink.url}">
  804. <xsl:call-template name="hyphenate-url">
  805. <xsl:with-param name="url" select="$url"/>
  806. </xsl:call-template>
  807. </fo:basic-link>
  808. <xsl:text>]</xsl:text>
  809. </fo:inline>
  810. </xsl:otherwise>
  811. </xsl:choose>
  812. </xsl:if>
  813. </xsl:template>
  814. <xsl:template name="ulink.footnote.number">
  815. <fo:inline xsl:use-attribute-sets="footnote.mark.properties">
  816. <xsl:choose>
  817. <xsl:when test="$fop.extensions != 0">
  818. <xsl:attribute name="vertical-align">super</xsl:attribute>
  819. </xsl:when>
  820. <xsl:otherwise>
  821. <xsl:attribute name="baseline-shift">super</xsl:attribute>
  822. </xsl:otherwise>
  823. </xsl:choose>
  824. <xsl:variable name="fnum">
  825. <!-- FIXME: list in @from is probably not complete -->
  826. <xsl:number level="any"
  827. from="chapter|appendix|preface|article|refentry|bibliography[not(parent::article)]"
  828. count="footnote[not(@label)][not(ancestor::tgroup)]|ulink[node()][@url != .][not(ancestor::footnote)]"
  829. format="1"/>
  830. </xsl:variable>
  831. <xsl:choose>
  832. <xsl:when test="string-length($footnote.number.symbols) &gt;= $fnum">
  833. <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
  834. </xsl:when>
  835. <xsl:otherwise>
  836. <xsl:number value="$fnum" format="{$footnote.number.format}"/>
  837. </xsl:otherwise>
  838. </xsl:choose>
  839. </fo:inline>
  840. </xsl:template>
  841. <xsl:template name="hyphenate-url">
  842. <xsl:param name="url" select="''"/>
  843. <xsl:choose>
  844. <xsl:when test="$ulink.hyphenate = ''">
  845. <xsl:value-of select="$url"/>
  846. </xsl:when>
  847. <xsl:when test="string-length($url) &gt; 1">
  848. <xsl:variable name="char" select="substring($url, 1, 1)"/>
  849. <xsl:value-of select="$char"/>
  850. <xsl:if test="contains($ulink.hyphenate.chars, $char)">
  851. <!-- Do not hyphen in-between // -->
  852. <xsl:if test="not($char = '/' and substring($url,2,1) = '/')">
  853. <xsl:copy-of select="$ulink.hyphenate"/>
  854. </xsl:if>
  855. </xsl:if>
  856. <!-- recurse to the next character -->
  857. <xsl:call-template name="hyphenate-url">
  858. <xsl:with-param name="url" select="substring($url, 2)"/>
  859. </xsl:call-template>
  860. </xsl:when>
  861. <xsl:otherwise>
  862. <xsl:value-of select="$url"/>
  863. </xsl:otherwise>
  864. </xsl:choose>
  865. </xsl:template>
  866. <xsl:template match="olink" name="olink">
  867. <!-- olink content may be passed in from xlink olink -->
  868. <xsl:param name="content" select="NOTANELEMENT"/>
  869. <xsl:call-template name="anchor"/>
  870. <xsl:variable name="localinfo" select="@localinfo"/>
  871. <xsl:choose>
  872. <!-- olinks resolved by stylesheet and target database -->
  873. <xsl:when test="@targetdoc or @targetptr or
  874. (@xlink:role=$xolink.role and
  875. contains(@xlink:href, '#') )" >
  876. <xsl:variable name="targetdoc.att">
  877. <xsl:choose>
  878. <xsl:when test="@targetdoc != ''">
  879. <xsl:value-of select="@targetdoc"/>
  880. </xsl:when>
  881. <xsl:when test="@xlink:role=$xolink.role and
  882. contains(@xlink:href, '#')" >
  883. <xsl:value-of select="substring-before(@xlink:href, '#')"/>
  884. </xsl:when>
  885. </xsl:choose>
  886. </xsl:variable>
  887. <xsl:variable name="targetptr.att">
  888. <xsl:choose>
  889. <xsl:when test="@targetptr != ''">
  890. <xsl:value-of select="@targetptr"/>
  891. </xsl:when>
  892. <xsl:when test="@xlink:role=$xolink.role and
  893. contains(@xlink:href, '#')" >
  894. <xsl:value-of select="substring-after(@xlink:href, '#')"/>
  895. </xsl:when>
  896. </xsl:choose>
  897. </xsl:variable>
  898. <xsl:variable name="olink.lang">
  899. <xsl:call-template name="l10n.language">
  900. <xsl:with-param name="xref-context" select="true()"/>
  901. </xsl:call-template>
  902. </xsl:variable>
  903. <xsl:variable name="target.database.filename">
  904. <xsl:call-template name="select.target.database">
  905. <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
  906. <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
  907. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  908. </xsl:call-template>
  909. </xsl:variable>
  910. <xsl:variable name="target.database"
  911. select="document($target.database.filename, /)"/>
  912. <xsl:if test="$olink.debug != 0">
  913. <xsl:message>
  914. <xsl:text>Olink debug: root element of target.database is '</xsl:text>
  915. <xsl:value-of select="local-name($target.database/*[1])"/>
  916. <xsl:text>'.</xsl:text>
  917. </xsl:message>
  918. </xsl:if>
  919. <xsl:variable name="olink.key">
  920. <xsl:call-template name="select.olink.key">
  921. <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
  922. <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
  923. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  924. <xsl:with-param name="target.database" select="$target.database"/>
  925. </xsl:call-template>
  926. </xsl:variable>
  927. <xsl:if test="string-length($olink.key) = 0">
  928. <xsl:message>
  929. <xsl:text>Error: unresolved olink: </xsl:text>
  930. <xsl:text>targetdoc/targetptr = '</xsl:text>
  931. <xsl:value-of select="$targetdoc.att"/>
  932. <xsl:text>/</xsl:text>
  933. <xsl:value-of select="$targetptr.att"/>
  934. <xsl:text>'.</xsl:text>
  935. </xsl:message>
  936. </xsl:if>
  937. <xsl:variable name="href">
  938. <xsl:call-template name="make.olink.href">
  939. <xsl:with-param name="olink.key" select="$olink.key"/>
  940. <xsl:with-param name="target.database" select="$target.database"/>
  941. </xsl:call-template>
  942. </xsl:variable>
  943. <!-- Olink that points to internal id can be a link -->
  944. <xsl:variable name="linkend">
  945. <xsl:call-template name="olink.as.linkend">
  946. <xsl:with-param name="olink.key" select="$olink.key"/>
  947. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  948. <xsl:with-param name="target.database" select="$target.database"/>
  949. </xsl:call-template>
  950. </xsl:variable>
  951. <xsl:variable name="hottext">
  952. <xsl:choose>
  953. <xsl:when test="$content">
  954. <xsl:copy-of select="$content"/>
  955. </xsl:when>
  956. <xsl:otherwise>
  957. <xsl:call-template name="olink.hottext">
  958. <xsl:with-param name="olink.key" select="$olink.key"/>
  959. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  960. <xsl:with-param name="target.database" select="$target.database"/>
  961. </xsl:call-template>
  962. </xsl:otherwise>
  963. </xsl:choose>
  964. </xsl:variable>
  965. <xsl:variable name="olink.docname.citation">
  966. <xsl:call-template name="olink.document.citation">
  967. <xsl:with-param name="olink.key" select="$olink.key"/>
  968. <xsl:with-param name="target.database" select="$target.database"/>
  969. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  970. </xsl:call-template>
  971. </xsl:variable>
  972. <xsl:variable name="olink.page.citation">
  973. <xsl:call-template name="olink.page.citation">
  974. <xsl:with-param name="olink.key" select="$olink.key"/>
  975. <xsl:with-param name="target.database" select="$target.database"/>
  976. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  977. <xsl:with-param name="linkend" select="$linkend"/>
  978. </xsl:call-template>
  979. </xsl:variable>
  980. <xsl:choose>
  981. <xsl:when test="$linkend != ''">
  982. <fo:basic-link internal-destination="{$linkend}"
  983. xsl:use-attribute-sets="xref.properties">
  984. <xsl:copy-of select="$hottext"/>
  985. <xsl:copy-of select="$olink.page.citation"/>
  986. </fo:basic-link>
  987. </xsl:when>
  988. <xsl:when test="$href != ''">
  989. <xsl:choose>
  990. <xsl:when test="$xep.extensions != 0">
  991. <fo:basic-link external-destination="url({$href})"
  992. xsl:use-attribute-sets="olink.properties">
  993. <xsl:copy-of select="$hottext"/>
  994. </fo:basic-link>
  995. <xsl:copy-of select="$olink.page.citation"/>
  996. <xsl:copy-of select="$olink.docname.citation"/>
  997. </xsl:when>
  998. <xsl:when test="$axf.extensions != 0">
  999. <fo:basic-link external-destination="{$href}"
  1000. xsl:use-attribute-sets="olink.properties">
  1001. <xsl:copy-of select="$hottext"/>
  1002. </fo:basic-link>
  1003. <xsl:copy-of select="$olink.page.citation"/>
  1004. <xsl:copy-of select="$olink.docname.citation"/>
  1005. </xsl:when>
  1006. <xsl:otherwise>
  1007. <fo:basic-link external-destination="{$href}"
  1008. xsl:use-attribute-sets="olink.properties">
  1009. <xsl:copy-of select="$hottext"/>
  1010. </fo:basic-link>
  1011. <xsl:copy-of select="$olink.page.citation"/>
  1012. <xsl:copy-of select="$olink.docname.citation"/>
  1013. </xsl:otherwise>
  1014. </xsl:choose>
  1015. </xsl:when>
  1016. <xsl:otherwise>
  1017. <xsl:copy-of select="$hottext"/>
  1018. <xsl:copy-of select="$olink.page.citation"/>
  1019. <xsl:copy-of select="$olink.docname.citation"/>
  1020. </xsl:otherwise>
  1021. </xsl:choose>
  1022. </xsl:when>
  1023. <!-- olink never implemented in FO for old olink entity syntax -->
  1024. <xsl:otherwise>
  1025. <xsl:apply-templates/>
  1026. </xsl:otherwise>
  1027. </xsl:choose>
  1028. </xsl:template>
  1029. <xsl:template match="*" mode="insert.olink.docname.markup">
  1030. <xsl:param name="docname" select="''"/>
  1031. <fo:inline font-style="italic">
  1032. <xsl:value-of select="$docname"/>
  1033. </fo:inline>
  1034. </xsl:template>
  1035. <!-- This prevents error message when processing olinks with xrefstyle -->
  1036. <xsl:template match="olink" mode="object.xref.template"/>
  1037. <xsl:template name="olink.as.linkend">
  1038. <xsl:param name="olink.key" select="''"/>
  1039. <xsl:param name="olink.lang" select="''"/>
  1040. <xsl:param name="target.database" select="NotANode"/>
  1041. <xsl:variable name="targetdoc">
  1042. <xsl:value-of select="substring-before($olink.key, '/')"/>
  1043. </xsl:variable>
  1044. <xsl:variable name="targetptr">
  1045. <xsl:value-of
  1046. select="substring-before(substring-after($olink.key, '/'), '/')"/>
  1047. </xsl:variable>
  1048. <xsl:variable name="target.lang">
  1049. <xsl:variable name="candidate">
  1050. <xsl:for-each select="$target.database" >
  1051. <xsl:value-of
  1052. select="key('targetptr-key', $olink.key)/@lang" />
  1053. </xsl:for-each>
  1054. </xsl:variable>
  1055. <xsl:choose>
  1056. <xsl:when test="$candidate != ''">
  1057. <xsl:value-of select="$candidate"/>
  1058. </xsl:when>
  1059. <xsl:otherwise>
  1060. <xsl:value-of select="$olink.lang"/>
  1061. </xsl:otherwise>
  1062. </xsl:choose>
  1063. </xsl:variable>
  1064. <xsl:if test="$current.docid = $targetdoc and
  1065. $olink.lang = $target.lang">
  1066. <xsl:variable name="targets" select="key('id',$targetptr)"/>
  1067. <xsl:variable name="target" select="$targets[1]"/>
  1068. <xsl:if test="$target">
  1069. <xsl:value-of select="$targetptr"/>
  1070. </xsl:if>
  1071. </xsl:if>
  1072. </xsl:template>
  1073. <xsl:template name="olink.outline">
  1074. <xsl:param name="outline.base.uri"/>
  1075. <xsl:param name="localinfo"/>
  1076. <xsl:param name="return" select="href"/>
  1077. <xsl:message terminate="yes">Fatal error: olink.outline template: what is this supposed to do?</xsl:message>
  1078. </xsl:template>
  1079. <!-- ==================================================================== -->
  1080. <xsl:template name="title.xref">
  1081. <xsl:param name="target" select="."/>
  1082. <xsl:choose>
  1083. <xsl:when test="local-name($target) = 'figure'
  1084. or local-name($target) = 'example'
  1085. or local-name($target) = 'equation'
  1086. or local-name($target) = 'table'
  1087. or local-name($target) = 'dedication'
  1088. or local-name($target) = 'preface'
  1089. or local-name($target) = 'bibliography'
  1090. or local-name($target) = 'glossary'
  1091. or local-name($target) = 'index'
  1092. or local-name($target) = 'setindex'
  1093. or local-name($target) = 'colophon'">
  1094. <xsl:call-template name="gentext.startquote"/>
  1095. <xsl:apply-templates select="$target" mode="title.markup"/>
  1096. <xsl:call-template name="gentext.endquote"/>
  1097. </xsl:when>
  1098. <xsl:otherwise>
  1099. <fo:inline font-style="italic">
  1100. <xsl:apply-templates select="$target" mode="title.markup"/>
  1101. </fo:inline>
  1102. </xsl:otherwise>
  1103. </xsl:choose>
  1104. </xsl:template>
  1105. <xsl:template name="number.xref">
  1106. <xsl:param name="target" select="."/>
  1107. <xsl:apply-templates select="$target" mode="label.markup"/>
  1108. </xsl:template>
  1109. <!-- ==================================================================== -->
  1110. <xsl:template name="xref.xreflabel">
  1111. <!-- called to process an xreflabel...you might use this to make -->
  1112. <!-- xreflabels come out in the right font for different targets, -->
  1113. <!-- for example. -->
  1114. <xsl:param name="target" select="."/>
  1115. <xsl:value-of select="$target/@xreflabel"/>
  1116. </xsl:template>
  1117. <!-- ==================================================================== -->
  1118. <xsl:template match="title" mode="xref">
  1119. <xsl:apply-templates/>
  1120. </xsl:template>
  1121. <xsl:template match="command" mode="xref">
  1122. <xsl:call-template name="inline.boldseq"/>
  1123. </xsl:template>
  1124. <xsl:template match="function" mode="xref">
  1125. <xsl:call-template name="inline.monoseq"/>
  1126. </xsl:template>
  1127. <xsl:template match="*" mode="page.citation">
  1128. <xsl:param name="id" select="'???'"/>
  1129. <fo:basic-link internal-destination="{$id}"
  1130. xsl:use-attribute-sets="xref.properties">
  1131. <fo:inline keep-together.within-line="always">
  1132. <xsl:call-template name="substitute-markup">
  1133. <xsl:with-param name="template">
  1134. <xsl:call-template name="gentext.template">
  1135. <xsl:with-param name="name" select="'page.citation'"/>
  1136. <xsl:with-param name="context" select="'xref'"/>
  1137. </xsl:call-template>
  1138. </xsl:with-param>
  1139. </xsl:call-template>
  1140. </fo:inline>
  1141. </fo:basic-link>
  1142. </xsl:template>
  1143. <xsl:template match="*" mode="pagenumber.markup">
  1144. <xsl:variable name="id">
  1145. <xsl:call-template name="object.id"/>
  1146. </xsl:variable>
  1147. <fo:page-number-citation ref-id="{$id}"/>
  1148. </xsl:template>
  1149. <!-- ==================================================================== -->
  1150. <xsl:template match="*" mode="insert.title.markup">
  1151. <xsl:param name="purpose"/>
  1152. <xsl:param name="xrefstyle"/>
  1153. <xsl:param name="title"/>
  1154. <xsl:choose>
  1155. <!-- FIXME: what about the case where titleabbrev is inside the info? -->
  1156. <xsl:when test="$purpose = 'xref' and titleabbrev">
  1157. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  1158. </xsl:when>
  1159. <xsl:otherwise>
  1160. <xsl:copy-of select="$title"/>
  1161. </xsl:otherwise>
  1162. </xsl:choose>
  1163. </xsl:template>
  1164. <xsl:template match="chapter|appendix" mode="insert.title.markup">
  1165. <xsl:param name="purpose"/>
  1166. <xsl:param name="xrefstyle"/>
  1167. <xsl:param name="title"/>
  1168. <xsl:choose>
  1169. <xsl:when test="$purpose = 'xref'">
  1170. <fo:inline font-style="italic">
  1171. <xsl:copy-of select="$title"/>
  1172. </fo:inline>
  1173. </xsl:when>
  1174. <xsl:otherwise>
  1175. <xsl:copy-of select="$title"/>
  1176. </xsl:otherwise>
  1177. </xsl:choose>
  1178. </xsl:template>
  1179. <xsl:template match="*" mode="insert.subtitle.markup">
  1180. <xsl:param name="purpose"/>
  1181. <xsl:param name="xrefstyle"/>
  1182. <xsl:param name="subtitle"/>
  1183. <xsl:copy-of select="$subtitle"/>
  1184. </xsl:template>
  1185. <xsl:template match="*" mode="insert.label.markup">
  1186. <xsl:param name="purpose"/>
  1187. <xsl:param name="xrefstyle"/>
  1188. <xsl:param name="label"/>
  1189. <xsl:copy-of select="$label"/>
  1190. </xsl:template>
  1191. <xsl:template match="*" mode="insert.pagenumber.markup">
  1192. <xsl:param name="purpose"/>
  1193. <xsl:param name="xrefstyle"/>
  1194. <xsl:param name="pagenumber"/>
  1195. <xsl:copy-of select="$pagenumber"/>
  1196. </xsl:template>
  1197. <xsl:template match="*" mode="insert.direction.markup">
  1198. <xsl:param name="purpose"/>
  1199. <xsl:param name="xrefstyle"/>
  1200. <xsl:param name="direction"/>
  1201. <xsl:copy-of select="$direction"/>
  1202. </xsl:template>
  1203. <xsl:template match="olink" mode="pagenumber.markup">
  1204. <!-- Local olinks can use page-citation -->
  1205. <xsl:variable name="targetdoc.att" select="@targetdoc"/>
  1206. <xsl:variable name="targetptr.att" select="@targetptr"/>
  1207. <xsl:variable name="olink.lang">
  1208. <xsl:call-template name="l10n.language">
  1209. <xsl:with-param name="xref-context" select="true()"/>
  1210. </xsl:call-template>
  1211. </xsl:variable>
  1212. <xsl:variable name="target.database.filename">
  1213. <xsl:call-template name="select.target.database">
  1214. <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
  1215. <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
  1216. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  1217. </xsl:call-template>
  1218. </xsl:variable>
  1219. <xsl:variable name="target.database"
  1220. select="document($target.database.filename, /)"/>
  1221. <xsl:if test="$olink.debug != 0">
  1222. <xsl:message>
  1223. <xsl:text>Olink debug: root element of target.database is '</xsl:text>
  1224. <xsl:value-of select="local-name($target.database/*[1])"/>
  1225. <xsl:text>'.</xsl:text>
  1226. </xsl:message>
  1227. </xsl:if>
  1228. <xsl:variable name="olink.key">
  1229. <xsl:call-template name="select.olink.key">
  1230. <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
  1231. <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
  1232. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  1233. <xsl:with-param name="target.database" select="$target.database"/>
  1234. </xsl:call-template>
  1235. </xsl:variable>
  1236. <!-- Olink that points to internal id can be a link -->
  1237. <xsl:variable name="linkend">
  1238. <xsl:call-template name="olink.as.linkend">
  1239. <xsl:with-param name="olink.key" select="$olink.key"/>
  1240. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  1241. <xsl:with-param name="target.database" select="$target.database"/>
  1242. </xsl:call-template>
  1243. </xsl:variable>
  1244. <xsl:choose>
  1245. <xsl:when test="$linkend != ''">
  1246. <fo:page-number-citation ref-id="{$linkend}"/>
  1247. </xsl:when>
  1248. <xsl:otherwise>
  1249. <xsl:message>
  1250. <xsl:text>Olink error: no page number linkend for local olink '</xsl:text>
  1251. <xsl:value-of select="$olink.key"/>
  1252. <xsl:text>'</xsl:text>
  1253. </xsl:message>
  1254. </xsl:otherwise>
  1255. </xsl:choose>
  1256. </xsl:template>
  1257. </xsl:stylesheet>