xref.xsl 56 KB

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