olink.xsl 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. version="1.0">
  4. <!-- ********************************************************************
  5. $Id: olink.xsl 9650 2012-10-26 18:24:02Z bobstayton $
  6. ********************************************************************
  7. This file is part of the DocBook XSL Stylesheet distribution.
  8. See ../README or http://docbook.sf.net/ for copyright
  9. copyright and other information.
  10. ******************************************************************** -->
  11. <!-- Create keys for quickly looking up olink targets -->
  12. <xsl:key name="targetdoc-key" match="document" use="@targetdoc" />
  13. <xsl:key name="targetptr-key" match="div|obj"
  14. use="concat(ancestor::document/@targetdoc, '/',
  15. @targetptr, '/', ancestor::document/@lang)" />
  16. <!-- Return filename of database -->
  17. <xsl:template name="select.target.database">
  18. <xsl:param name="targetdoc.att" select="''"/>
  19. <xsl:param name="targetptr.att" select="''"/>
  20. <xsl:param name="olink.lang" select="''"/>
  21. <!-- use root's xml:base if exists -->
  22. <xsl:variable name="xml.base" select="/*/@xml:base"/>
  23. <!-- This selection can be customized if needed -->
  24. <xsl:variable name="target.database.filename">
  25. <xsl:choose>
  26. <xsl:when test="$xml.base != '' and
  27. not(starts-with($target.database.document, 'file:/')) and
  28. not(starts-with($target.database.document, '/'))">
  29. <xsl:call-template name="systemIdToBaseURI">
  30. <xsl:with-param name="systemId" select="$xml.base"/>
  31. </xsl:call-template>
  32. <xsl:value-of select="$target.database.document"/>
  33. </xsl:when>
  34. <xsl:otherwise>
  35. <xsl:value-of select="$target.database.document"/>
  36. </xsl:otherwise>
  37. </xsl:choose>
  38. </xsl:variable>
  39. <xsl:variable name="target.database"
  40. select="document($target.database.filename,/)"/>
  41. <xsl:choose>
  42. <!-- Was the database document parameter not set? -->
  43. <xsl:when test="$target.database.document = ''">
  44. <xsl:message>
  45. <xsl:text>Olinks not processed: must specify a </xsl:text>
  46. <xsl:text>$target.database.document parameter&#10;</xsl:text>
  47. <xsl:text>when using olinks with targetdoc </xsl:text>
  48. <xsl:text>and targetptr attributes.</xsl:text>
  49. </xsl:message>
  50. </xsl:when>
  51. <xsl:when test="namespace-uri($target.database/*) != ''">
  52. <xsl:message>
  53. <xsl:text>Olink error: the targetset element and children in '</xsl:text>
  54. <xsl:value-of select="$target.database.document"/>
  55. <xsl:text>' should not be in any namespace.</xsl:text>
  56. </xsl:message>
  57. </xsl:when>
  58. <!-- Did it not open? Should be a targetset element -->
  59. <xsl:when test="not($target.database/*)">
  60. <xsl:message>
  61. <xsl:text>Olink error: could not open target database '</xsl:text>
  62. <xsl:value-of select="$target.database.filename"/>
  63. <xsl:text>'.</xsl:text>
  64. </xsl:message>
  65. </xsl:when>
  66. <xsl:otherwise>
  67. <xsl:value-of select="$target.database.filename"/>
  68. </xsl:otherwise>
  69. </xsl:choose>
  70. </xsl:template>
  71. <xsl:template name="select.olink.key">
  72. <xsl:param name="targetdoc.att" select="''"/>
  73. <xsl:param name="targetptr.att" select="''"/>
  74. <xsl:param name="olink.lang" select="''"/>
  75. <xsl:param name="target.database"/>
  76. <xsl:if test="$target.database/*">
  77. <xsl:variable name="olink.fallback.sequence">
  78. <xsl:call-template name="select.olink.lang.fallback">
  79. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  80. </xsl:call-template>
  81. </xsl:variable>
  82. <!-- Recurse through the languages until you find a match -->
  83. <xsl:call-template name="select.olink.key.in.lang">
  84. <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
  85. <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
  86. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  87. <xsl:with-param name="target.database" select="$target.database"/>
  88. <xsl:with-param name="fallback.index" select="1"/>
  89. <xsl:with-param name="olink.fallback.sequence"
  90. select="$olink.fallback.sequence"/>
  91. </xsl:call-template>
  92. </xsl:if>
  93. </xsl:template>
  94. <!-- Locate olink key in a particular language -->
  95. <xsl:template name="select.olink.key.in.lang">
  96. <xsl:param name="targetdoc.att" select="''"/>
  97. <xsl:param name="targetptr.att" select="''"/>
  98. <xsl:param name="olink.lang" select="''"/>
  99. <xsl:param name="target.database"/>
  100. <xsl:param name="fallback.index" select="1"/>
  101. <xsl:param name="olink.fallback.sequence" select="''"/>
  102. <xsl:variable name="target.lang">
  103. <xsl:call-template name="select.target.lang">
  104. <xsl:with-param name="fallback.index" select="$fallback.index"/>
  105. <xsl:with-param name="olink.fallback.sequence"
  106. select="$olink.fallback.sequence"/>
  107. </xsl:call-template>
  108. </xsl:variable>
  109. <xsl:if test="$olink.debug != 0">
  110. <xsl:message><xsl:text>Olink debug: cases for targetdoc='</xsl:text>
  111. <xsl:value-of select="$targetdoc.att"/>
  112. <xsl:text>' and targetptr='</xsl:text>
  113. <xsl:value-of select="$targetptr.att"/>
  114. <xsl:text>' in language '</xsl:text>
  115. <xsl:value-of select="$target.lang"/>
  116. <xsl:text>'.</xsl:text>
  117. </xsl:message>
  118. </xsl:if>
  119. <!-- Customize these cases if you want different selection logic -->
  120. <xsl:variable name="CaseA">
  121. <!-- targetdoc.att = not blank
  122. targetptr.att = not blank
  123. -->
  124. <xsl:if test="$targetdoc.att != '' and
  125. $targetptr.att != ''">
  126. <xsl:for-each select="$target.database">
  127. <xsl:variable name="key"
  128. select="concat($targetdoc.att, '/',
  129. $targetptr.att, '/',
  130. $target.lang)"/>
  131. <xsl:choose>
  132. <xsl:when test="key('targetptr-key', $key)[1]/@href != ''">
  133. <xsl:value-of select="$key"/>
  134. <xsl:if test="$olink.debug != 0">
  135. <xsl:message>Olink debug: CaseA matched.</xsl:message>
  136. </xsl:if>
  137. </xsl:when>
  138. <xsl:when test="$olink.debug != 0">
  139. <xsl:message>Olink debug: CaseA NOT matched</xsl:message>
  140. </xsl:when>
  141. </xsl:choose>
  142. </xsl:for-each>
  143. </xsl:if>
  144. </xsl:variable>
  145. <xsl:variable name="CaseB">
  146. <!-- targetdoc.att = not blank
  147. targetptr.att = not blank
  148. prefer.internal.olink = not zero
  149. current.docid = not blank
  150. -->
  151. <xsl:if test="$targetdoc.att != '' and
  152. $targetptr.att != '' and
  153. $current.docid != '' and
  154. $prefer.internal.olink != 0">
  155. <xsl:for-each select="$target.database">
  156. <xsl:variable name="key"
  157. select="concat($current.docid, '/',
  158. $targetptr.att, '/',
  159. $target.lang)"/>
  160. <xsl:choose>
  161. <xsl:when test="key('targetptr-key', $key)[1]/@href != ''">
  162. <xsl:value-of select="$key"/>
  163. <xsl:if test="$olink.debug != 0">
  164. <xsl:message>Olink debug: CaseB matched.</xsl:message>
  165. </xsl:if>
  166. </xsl:when>
  167. <xsl:when test="$olink.debug != 0">
  168. <xsl:message>Olink debug: CaseB NOT matched</xsl:message>
  169. </xsl:when>
  170. </xsl:choose>
  171. </xsl:for-each>
  172. </xsl:if>
  173. </xsl:variable>
  174. <xsl:variable name="CaseC">
  175. <!-- targetdoc.att = blank
  176. targetptr.att = not blank
  177. current.docid = not blank
  178. -->
  179. <xsl:if test="string-length($targetdoc.att) = 0 and
  180. $targetptr.att != '' and
  181. $current.docid != ''">
  182. <!-- Must use a for-each to change context for keys to work -->
  183. <xsl:for-each select="$target.database">
  184. <xsl:variable name="key"
  185. select="concat($current.docid, '/',
  186. $targetptr.att, '/',
  187. $target.lang)"/>
  188. <xsl:choose>
  189. <xsl:when test="key('targetptr-key', $key)[1]/@href != ''">
  190. <xsl:value-of select="$key"/>
  191. <xsl:if test="$olink.debug != 0">
  192. <xsl:message>Olink debug: CaseC matched.</xsl:message>
  193. </xsl:if>
  194. </xsl:when>
  195. <xsl:when test="$olink.debug != 0">
  196. <xsl:message>Olink debug: CaseC NOT matched.</xsl:message>
  197. </xsl:when>
  198. </xsl:choose>
  199. </xsl:for-each>
  200. </xsl:if>
  201. </xsl:variable>
  202. <xsl:variable name="CaseD">
  203. <!-- targetdoc.att = blank
  204. targetptr.att = not blank
  205. current.docid = blank
  206. -->
  207. <!-- This is possible if only one document in the database -->
  208. <xsl:if test="string-length($targetdoc.att) = 0 and
  209. $targetptr.att != '' and
  210. string-length($current.docid) = 0 and
  211. count($target.database//document) = 1">
  212. <xsl:for-each select="$target.database">
  213. <xsl:variable name="key"
  214. select="concat(.//document/@targetdoc, '/',
  215. $targetptr.att, '/',
  216. $target.lang)"/>
  217. <xsl:choose>
  218. <xsl:when test="key('targetptr-key', $key)[1]/@href != ''">
  219. <xsl:value-of select="$key"/>
  220. <xsl:if test="$olink.debug != 0">
  221. <xsl:message>Olink debug: CaseD matched.</xsl:message>
  222. </xsl:if>
  223. </xsl:when>
  224. <xsl:when test="$olink.debug != 0">
  225. <xsl:message>Olink debug: CaseD NOT matched</xsl:message>
  226. </xsl:when>
  227. </xsl:choose>
  228. </xsl:for-each>
  229. </xsl:if>
  230. </xsl:variable>
  231. <xsl:variable name="CaseE">
  232. <!-- targetdoc.att = not blank
  233. targetptr.att = blank
  234. -->
  235. <xsl:if test="$targetdoc.att != '' and
  236. string-length($targetptr.att) = 0">
  237. <!-- Try the document's root element id -->
  238. <xsl:variable name="rootid">
  239. <xsl:choose>
  240. <xsl:when test="$target.lang != ''">
  241. <xsl:value-of select="$target.database//document[@targetdoc = $targetdoc.att and @lang = $target.lang]/*[1]/@targetptr"/>
  242. </xsl:when>
  243. <xsl:otherwise>
  244. <xsl:value-of select="$target.database//document[@targetdoc = $targetdoc.att and not(@lang)]/*[1]/@targetptr"/>
  245. </xsl:otherwise>
  246. </xsl:choose>
  247. </xsl:variable>
  248. <xsl:for-each select="$target.database">
  249. <xsl:variable name="key"
  250. select="concat($targetdoc.att, '/',
  251. $rootid, '/',
  252. $target.lang)"/>
  253. <xsl:choose>
  254. <xsl:when test="key('targetptr-key', $key)[1]/@href != ''">
  255. <xsl:value-of select="$key"/>
  256. <xsl:if test="$olink.debug != 0">
  257. <xsl:message>Olink debug: CaseE matched.</xsl:message>
  258. </xsl:if>
  259. </xsl:when>
  260. <xsl:when test="$olink.debug != 0">
  261. <xsl:message>Olink debug: CaseE NOT matched.</xsl:message>
  262. </xsl:when>
  263. </xsl:choose>
  264. </xsl:for-each>
  265. </xsl:if>
  266. </xsl:variable>
  267. <xsl:variable name="CaseF">
  268. <!-- targetdoc.att = not blank
  269. targetptr.att = blank
  270. prefer.internal.olink = not zero
  271. current.docid = not blank
  272. -->
  273. <xsl:if test="$targetdoc.att != '' and
  274. string-length($targetptr.att) = 0 and
  275. $current.docid != '' and
  276. $prefer.internal.olink != 0">
  277. <!-- Try the document's root element id -->
  278. <xsl:variable name="rootid">
  279. <xsl:choose>
  280. <xsl:when test="$target.lang != ''">
  281. <xsl:value-of select="$target.database//document[@targetdoc = $current.docid and @lang = $target.lang]/*[1]/@targetptr"/>
  282. </xsl:when>
  283. <xsl:otherwise>
  284. <xsl:value-of select="$target.database//document[@targetdoc = $current.docid and not(@lang)]/*[1]/@targetptr"/>
  285. </xsl:otherwise>
  286. </xsl:choose>
  287. </xsl:variable>
  288. <xsl:for-each select="$target.database">
  289. <xsl:variable name="key"
  290. select="concat($current.docid, '/',
  291. $rootid, '/',
  292. $target.lang)"/>
  293. <xsl:choose>
  294. <xsl:when test="key('targetptr-key', $key)[1]/@href != ''">
  295. <xsl:value-of select="$key"/>
  296. <xsl:if test="$olink.debug != 0">
  297. <xsl:message>Olink debug: CaseF matched.</xsl:message>
  298. </xsl:if>
  299. </xsl:when>
  300. <xsl:when test="$olink.debug != 0">
  301. <xsl:message>Olink debug: CaseF NOT matched.</xsl:message>
  302. </xsl:when>
  303. </xsl:choose>
  304. </xsl:for-each>
  305. </xsl:if>
  306. </xsl:variable>
  307. <!-- Now select the best match. Customize the order if needed -->
  308. <xsl:variable name="selected.key">
  309. <xsl:choose>
  310. <xsl:when test="$CaseB != ''">
  311. <xsl:value-of select="$CaseB"/>
  312. <xsl:if test="$olink.debug != 0">
  313. <xsl:message>
  314. <xsl:text>Olink debug: CaseB key is the final selection: </xsl:text>
  315. <xsl:value-of select="$CaseB"/>
  316. </xsl:message>
  317. </xsl:if>
  318. </xsl:when>
  319. <xsl:when test="$CaseA != ''">
  320. <xsl:value-of select="$CaseA"/>
  321. <xsl:if test="$olink.debug != 0">
  322. <xsl:message>
  323. <xsl:text>Olink debug: CaseA key is the final selection: </xsl:text>
  324. <xsl:value-of select="$CaseA"/>
  325. </xsl:message>
  326. </xsl:if>
  327. </xsl:when>
  328. <xsl:when test="$CaseC != ''">
  329. <xsl:value-of select="$CaseC"/>
  330. <xsl:if test="$olink.debug != 0">
  331. <xsl:message>
  332. <xsl:text>Olink debug: CaseC key is the final selection: </xsl:text>
  333. <xsl:value-of select="$CaseC"/>
  334. </xsl:message>
  335. </xsl:if>
  336. </xsl:when>
  337. <xsl:when test="$CaseD != ''">
  338. <xsl:value-of select="$CaseD"/>
  339. <xsl:if test="$olink.debug != 0">
  340. <xsl:message>
  341. <xsl:text>Olink debug: CaseD key is the final selection: </xsl:text>
  342. <xsl:value-of select="$CaseD"/>
  343. </xsl:message>
  344. </xsl:if>
  345. </xsl:when>
  346. <xsl:when test="$CaseF != ''">
  347. <xsl:value-of select="$CaseF"/>
  348. <xsl:if test="$olink.debug != 0">
  349. <xsl:message>
  350. <xsl:text>Olink debug: CaseF key is the final selection: </xsl:text>
  351. <xsl:value-of select="$CaseF"/>
  352. </xsl:message>
  353. </xsl:if>
  354. </xsl:when>
  355. <xsl:when test="$CaseE != ''">
  356. <xsl:value-of select="$CaseE"/>
  357. <xsl:if test="$olink.debug != 0">
  358. <xsl:message>
  359. <xsl:text>Olink debug: CaseE key is the final selection: </xsl:text>
  360. <xsl:value-of select="$CaseE"/>
  361. </xsl:message>
  362. </xsl:if>
  363. </xsl:when>
  364. <xsl:otherwise>
  365. <xsl:if test="$olink.debug != 0">
  366. <xsl:message>
  367. <xsl:text>Olink debug: No case matched for lang '</xsl:text>
  368. <xsl:value-of select="$target.lang"/>
  369. <xsl:text>'.</xsl:text>
  370. </xsl:message>
  371. </xsl:if>
  372. </xsl:otherwise>
  373. </xsl:choose>
  374. </xsl:variable>
  375. <xsl:choose>
  376. <xsl:when test="$selected.key != ''">
  377. <xsl:value-of select="$selected.key"/>
  378. </xsl:when>
  379. <xsl:when test="string-length($selected.key) = 0 and
  380. string-length($target.lang) = 0">
  381. <!-- No match on last try, and we are done -->
  382. </xsl:when>
  383. <xsl:otherwise>
  384. <!-- Recurse through next language -->
  385. <xsl:call-template name="select.olink.key.in.lang">
  386. <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
  387. <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
  388. <xsl:with-param name="olink.lang" select="$olink.lang"/>
  389. <xsl:with-param name="target.database" select="$target.database"/>
  390. <xsl:with-param name="fallback.index" select="$fallback.index + 1"/>
  391. <xsl:with-param name="olink.fallback.sequence"
  392. select="$olink.fallback.sequence"/>
  393. </xsl:call-template>
  394. </xsl:otherwise>
  395. </xsl:choose>
  396. </xsl:template>
  397. <xsl:template name="select.target.lang">
  398. <xsl:param name="fallback.index" select="1"/>
  399. <xsl:param name="olink.fallback.sequence" select="''"/>
  400. <!-- recurse backwards to find the lang matching the index -->
  401. <xsl:variable name="firstlang"
  402. select="substring-before($olink.fallback.sequence, ' ')"/>
  403. <xsl:variable name="rest"
  404. select="substring-after($olink.fallback.sequence, ' ')"/>
  405. <xsl:choose>
  406. <xsl:when test="$fallback.index = 1">
  407. <xsl:value-of select="$firstlang"/>
  408. </xsl:when>
  409. <xsl:when test="$fallback.index &gt; 1">
  410. <xsl:call-template name="select.target.lang">
  411. <xsl:with-param name="fallback.index" select="$fallback.index - 1"/>
  412. <xsl:with-param name="olink.fallback.sequence"
  413. select="$rest"/>
  414. </xsl:call-template>
  415. </xsl:when>
  416. <xsl:otherwise>
  417. </xsl:otherwise>
  418. </xsl:choose>
  419. </xsl:template>
  420. <xsl:template name="select.olink.lang.fallback">
  421. <xsl:param name="olink.lang" select="''"/>
  422. <!-- Prefer language of the olink element -->
  423. <xsl:value-of select="concat(normalize-space(concat($olink.lang, ' ',
  424. $olink.lang.fallback.sequence)), ' ')"/>
  425. </xsl:template>
  426. <!-- Returns the complete olink href value if found -->
  427. <xsl:template name="make.olink.href">
  428. <xsl:param name="olink.key" select="''"/>
  429. <xsl:param name="target.database"/>
  430. <xsl:if test="$olink.key != ''">
  431. <xsl:variable name="target.href" >
  432. <xsl:for-each select="$target.database" >
  433. <xsl:value-of select="key('targetptr-key', $olink.key)[1]/@href" />
  434. </xsl:for-each>
  435. </xsl:variable>
  436. <xsl:variable name="targetdoc">
  437. <xsl:value-of select="substring-before($olink.key, '/')"/>
  438. </xsl:variable>
  439. <!-- Does the target database use a sitemap? -->
  440. <xsl:variable name="use.sitemap">
  441. <xsl:choose>
  442. <xsl:when test="$target.database//sitemap">1</xsl:when>
  443. <xsl:otherwise>0</xsl:otherwise>
  444. </xsl:choose>
  445. </xsl:variable>
  446. <!-- Get the baseuri for this targetptr -->
  447. <xsl:variable name="baseuri" >
  448. <xsl:choose>
  449. <!-- Does the database use a sitemap? -->
  450. <xsl:when test="$use.sitemap != 0" >
  451. <xsl:choose>
  452. <!-- Was current.docid parameter set? -->
  453. <xsl:when test="$current.docid != ''">
  454. <!-- Was it found in the database? -->
  455. <xsl:variable name="currentdoc.key" >
  456. <xsl:for-each select="$target.database" >
  457. <xsl:value-of select="key('targetdoc-key',
  458. $current.docid)[1]/@targetdoc" />
  459. </xsl:for-each>
  460. </xsl:variable>
  461. <xsl:choose>
  462. <xsl:when test="$currentdoc.key != ''">
  463. <xsl:for-each select="$target.database" >
  464. <xsl:call-template name="targetpath" >
  465. <xsl:with-param name="dirnode"
  466. select="key('targetdoc-key', $current.docid)[1]/parent::dir"/>
  467. <xsl:with-param name="targetdoc" select="$targetdoc"/>
  468. </xsl:call-template>
  469. </xsl:for-each >
  470. </xsl:when>
  471. <xsl:otherwise>
  472. <xsl:message>
  473. <xsl:text>Olink error: cannot compute relative </xsl:text>
  474. <xsl:text>sitemap path because $current.docid '</xsl:text>
  475. <xsl:value-of select="$current.docid"/>
  476. <xsl:text>' not found in target database.</xsl:text>
  477. </xsl:message>
  478. </xsl:otherwise>
  479. </xsl:choose>
  480. </xsl:when>
  481. <xsl:otherwise>
  482. <xsl:message>
  483. <xsl:text>Olink warning: cannot compute relative </xsl:text>
  484. <xsl:text>sitemap path without $current.docid parameter</xsl:text>
  485. </xsl:message>
  486. </xsl:otherwise>
  487. </xsl:choose>
  488. <!-- In either case, add baseuri from its document entry-->
  489. <xsl:variable name="docbaseuri">
  490. <xsl:for-each select="$target.database" >
  491. <xsl:value-of select="key('targetdoc-key', $targetdoc)[1]/@baseuri" />
  492. </xsl:for-each>
  493. </xsl:variable>
  494. <xsl:if test="$docbaseuri != ''" >
  495. <xsl:value-of select="$docbaseuri"/>
  496. </xsl:if>
  497. </xsl:when>
  498. <!-- No database sitemap in use -->
  499. <xsl:otherwise>
  500. <!-- Just use any baseuri from its document entry -->
  501. <xsl:variable name="docbaseuri">
  502. <xsl:for-each select="$target.database" >
  503. <xsl:value-of select="key('targetdoc-key', $targetdoc)[1]/@baseuri" />
  504. </xsl:for-each>
  505. </xsl:variable>
  506. <xsl:if test="$docbaseuri != ''" >
  507. <xsl:value-of select="$docbaseuri"/>
  508. </xsl:if>
  509. </xsl:otherwise>
  510. </xsl:choose>
  511. </xsl:variable>
  512. <!-- Is this olink to be active? -->
  513. <xsl:variable name="active.olink">
  514. <xsl:choose>
  515. <xsl:when test="$activate.external.olinks = 0">
  516. <xsl:choose>
  517. <xsl:when test="$current.docid = ''">1</xsl:when>
  518. <xsl:when test="$targetdoc = ''">1</xsl:when>
  519. <xsl:when test="$targetdoc = $current.docid">1</xsl:when>
  520. <xsl:otherwise>0</xsl:otherwise>
  521. </xsl:choose>
  522. </xsl:when>
  523. <xsl:otherwise>1</xsl:otherwise>
  524. </xsl:choose>
  525. </xsl:variable>
  526. <!-- Form the href information -->
  527. <xsl:if test="$active.olink != 0">
  528. <xsl:if test="$baseuri != ''">
  529. <xsl:value-of select="$baseuri"/>
  530. <xsl:if test="substring($target.href,1,1) != '#'">
  531. <!--xsl:text>/</xsl:text-->
  532. </xsl:if>
  533. </xsl:if>
  534. <!-- optionally turn off frag for PDF references -->
  535. <xsl:if test="not($insert.olink.pdf.frag = 0 and
  536. translate(substring($baseuri, string-length($baseuri) - 3),
  537. 'PDF', 'pdf') = '.pdf'
  538. and starts-with($target.href, '#') )">
  539. <xsl:value-of select="$target.href"/>
  540. </xsl:if>
  541. </xsl:if>
  542. </xsl:if>
  543. </xsl:template>
  544. <!-- Computes the href of the object containing the olink element -->
  545. <xsl:template name="olink.from.uri">
  546. <xsl:param name="target.database"/>
  547. <xsl:param name="object" select="NotAnElement"/>
  548. <xsl:param name="object.targetdoc" select="$current.docid"/>
  549. <xsl:param name="object.lang"
  550. select="concat($object/ancestor::*[last()]/@lang,
  551. $object/ancestor::*[last()]/@xml:lang)"/>
  552. <xsl:variable name="parent.id">
  553. <xsl:call-template name="object.id">
  554. <xsl:with-param name="object" select="$object"/>
  555. </xsl:call-template>
  556. </xsl:variable>
  557. <!-- Get the olink key for the parent of olink element -->
  558. <xsl:variable name="from.key">
  559. <xsl:call-template name="select.olink.key">
  560. <xsl:with-param name="targetdoc.att" select="$object.targetdoc"/>
  561. <xsl:with-param name="targetptr.att" select="$parent.id"/>
  562. <xsl:with-param name="olink.lang" select="$object.lang"/>
  563. <xsl:with-param name="target.database" select="$target.database"/>
  564. </xsl:call-template>
  565. </xsl:variable>
  566. <xsl:variable name="from.olink.href">
  567. <xsl:for-each select="$target.database" >
  568. <xsl:value-of select="key('targetptr-key', $from.key)[1]/@href" />
  569. </xsl:for-each>
  570. </xsl:variable>
  571. <xsl:choose>
  572. <!-- we found the olink object -->
  573. <xsl:when test="$from.olink.href != ''">
  574. <xsl:value-of select="$from.olink.href"/>
  575. </xsl:when>
  576. <xsl:when test="not($object/parent::*)">
  577. <xsl:value-of select="$from.olink.href"/>
  578. </xsl:when>
  579. <xsl:otherwise>
  580. <!-- recurse upward in current document -->
  581. <xsl:call-template name="olink.from.uri">
  582. <xsl:with-param name="target.database" select="$target.database"/>
  583. <xsl:with-param name="object" select="$object/parent::*"/>
  584. <xsl:with-param name="object.targetdoc" select="$object.targetdoc"/>
  585. <xsl:with-param name="object.lang" select="$object.lang"/>
  586. </xsl:call-template>
  587. </xsl:otherwise>
  588. </xsl:choose>
  589. </xsl:template>
  590. <xsl:template name="olink.hottext">
  591. <xsl:param name="target.database"/>
  592. <xsl:param name="olink.lang" select="''"/>
  593. <xsl:param name="olink.key" select="''"/>
  594. <xsl:param name="referrer" select="."/>
  595. <xsl:param name="xrefstyle">
  596. <xsl:choose>
  597. <xsl:when test="@role and not(@xrefstyle)
  598. and $use.role.as.xrefstyle != 0">
  599. <xsl:value-of select="@role"/>
  600. </xsl:when>
  601. <xsl:otherwise>
  602. <xsl:value-of select="@xrefstyle"/>
  603. </xsl:otherwise>
  604. </xsl:choose>
  605. </xsl:param>
  606. <xsl:choose>
  607. <!-- If it has elements or text (not just PI or comment) -->
  608. <xsl:when test="child::text() or child::*">
  609. <xsl:apply-templates/>
  610. </xsl:when>
  611. <xsl:when test="$olink.key != ''">
  612. <!-- Get the xref text for this record -->
  613. <xsl:variable name="xref.text" >
  614. <xsl:for-each select="$target.database" >
  615. <xsl:call-template name="insert.targetdb.data">
  616. <xsl:with-param name="data"
  617. select="key('targetptr-key', $olink.key)[1]/xreftext/node()" />
  618. </xsl:call-template>
  619. </xsl:for-each>
  620. </xsl:variable>
  621. <xsl:variable name="xref.number" >
  622. <xsl:for-each select="$target.database" >
  623. <xsl:value-of select="key('targetptr-key', $olink.key)[1]/@number" />
  624. </xsl:for-each>
  625. </xsl:variable>
  626. <xsl:variable name="target.elem" >
  627. <xsl:for-each select="$target.database" >
  628. <xsl:value-of select="key('targetptr-key', $olink.key)[1]/@element" />
  629. </xsl:for-each>
  630. </xsl:variable>
  631. <xsl:variable name="lang">
  632. <xsl:variable name="candidate">
  633. <xsl:for-each select="$target.database" >
  634. <xsl:value-of
  635. select="key('targetptr-key', $olink.key)[1]/@lang" />
  636. </xsl:for-each>
  637. </xsl:variable>
  638. <xsl:choose>
  639. <xsl:when test="$candidate != ''">
  640. <xsl:value-of select="$candidate"/>
  641. </xsl:when>
  642. <xsl:otherwise>
  643. <xsl:value-of select="$olink.lang"/>
  644. </xsl:otherwise>
  645. </xsl:choose>
  646. </xsl:variable>
  647. <xsl:variable name="targetdoc">
  648. <xsl:value-of select="substring-before($olink.key, '/')"/>
  649. </xsl:variable>
  650. <xsl:choose>
  651. <xsl:when test="$xrefstyle != '' and
  652. starts-with(normalize-space($xrefstyle), 'select:') and
  653. (contains($xrefstyle, 'nodocname') or
  654. contains($xrefstyle, 'nopage')) and
  655. not(contains($xrefstyle, 'title')) and
  656. not(contains($xrefstyle, 'label'))">
  657. <xsl:copy-of select="$xref.text"/>
  658. </xsl:when>
  659. <xsl:when test="$xrefstyle != ''">
  660. <xsl:if test="$olink.debug != 0">
  661. <xsl:message>
  662. <xsl:text>xrefstyle is '</xsl:text>
  663. <xsl:value-of select="$xrefstyle"/>
  664. <xsl:text>'.</xsl:text>
  665. </xsl:message>
  666. </xsl:if>
  667. <xsl:variable name="template">
  668. <xsl:choose>
  669. <xsl:when test="starts-with(normalize-space($xrefstyle),
  670. 'select:')">
  671. <xsl:call-template name="make.gentext.template">
  672. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  673. <xsl:with-param name="purpose" select="'olink'"/>
  674. <xsl:with-param name="referrer" select="."/>
  675. <xsl:with-param name="target.elem" select="$target.elem"/>
  676. </xsl:call-template>
  677. </xsl:when>
  678. <xsl:when test="starts-with(normalize-space($xrefstyle),
  679. 'template:')">
  680. <xsl:value-of select="substring-after(
  681. normalize-space($xrefstyle), 'template:')"/>
  682. </xsl:when>
  683. <xsl:otherwise>
  684. <!-- Look for Gentext template with @style attribute -->
  685. <!-- Must compare to no style value because gentext.template
  686. falls back to no style -->
  687. <xsl:variable name="xref-context">
  688. <xsl:call-template name="gentext.template">
  689. <xsl:with-param name="context" select="'xref'"/>
  690. <xsl:with-param name="name" select="$target.elem"/>
  691. <xsl:with-param name="lang" select="$lang"/>
  692. </xsl:call-template>
  693. </xsl:variable>
  694. <xsl:variable name="styled-xref-context">
  695. <xsl:call-template name="gentext.template">
  696. <xsl:with-param name="context" select="'xref'"/>
  697. <xsl:with-param name="name" select="$target.elem"/>
  698. <xsl:with-param name="lang" select="$lang"/>
  699. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  700. </xsl:call-template>
  701. </xsl:variable>
  702. <xsl:variable name="xref-number-context">
  703. <xsl:call-template name="gentext.template">
  704. <xsl:with-param name="context" select="'xref-number'"/>
  705. <xsl:with-param name="name" select="$target.elem"/>
  706. <xsl:with-param name="lang" select="$lang"/>
  707. </xsl:call-template>
  708. </xsl:variable>
  709. <xsl:variable name="styled-xref-number-context">
  710. <xsl:call-template name="gentext.template">
  711. <xsl:with-param name="context" select="'xref-number'"/>
  712. <xsl:with-param name="name" select="$target.elem"/>
  713. <xsl:with-param name="lang" select="$lang"/>
  714. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  715. </xsl:call-template>
  716. </xsl:variable>
  717. <xsl:variable name="xref-number-and-title-context">
  718. <xsl:call-template name="gentext.template">
  719. <xsl:with-param name="context"
  720. select="'xref-number-and-title'"/>
  721. <xsl:with-param name="name" select="$target.elem"/>
  722. <xsl:with-param name="lang" select="$lang"/>
  723. </xsl:call-template>
  724. </xsl:variable>
  725. <xsl:variable name="styled-xref-number-and-title-context">
  726. <xsl:call-template name="gentext.template">
  727. <xsl:with-param name="context"
  728. select="'xref-number-and-title'"/>
  729. <xsl:with-param name="name" select="$target.elem"/>
  730. <xsl:with-param name="lang" select="$lang"/>
  731. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  732. </xsl:call-template>
  733. </xsl:variable>
  734. <xsl:choose>
  735. <xsl:when test="$xref-number-and-title-context !=
  736. $styled-xref-number-and-title-context and
  737. $xref.number != '' and
  738. $xref.with.number.and.title != 0">
  739. <xsl:value-of
  740. select="$styled-xref-number-and-title-context"/>
  741. </xsl:when>
  742. <xsl:when test="$xref-number-context !=
  743. $styled-xref-number-context and
  744. $xref.number != ''">
  745. <xsl:value-of select="$styled-xref-number-context"/>
  746. </xsl:when>
  747. <xsl:when test="$xref-context != $styled-xref-context">
  748. <xsl:value-of select="$styled-xref-context"/>
  749. </xsl:when>
  750. <xsl:when test="$xref-number-and-title-context != '' and
  751. $xref.number != '' and
  752. $xref.with.number.and.title != 0">
  753. <xsl:value-of
  754. select="$xref-number-and-title-context"/>
  755. <xsl:if test="$olink.debug">
  756. <xsl:message>
  757. <xsl:text>Olink error: no gentext template</xsl:text>
  758. <xsl:text> exists for xrefstyle '</xsl:text>
  759. <xsl:value-of select="$xrefstyle"/>
  760. <xsl:text>' for element '</xsl:text>
  761. <xsl:value-of select="$target.elem"/>
  762. <xsl:text>' in language '</xsl:text>
  763. <xsl:value-of select="$lang"/>
  764. <xsl:text>' in context 'xref-number-and-title</xsl:text>
  765. <xsl:text>'. Using template without @style.</xsl:text>
  766. </xsl:message>
  767. </xsl:if>
  768. </xsl:when>
  769. <xsl:when test="$xref-number-context != '' and
  770. $xref.number != ''">
  771. <xsl:value-of select="$xref-number-context"/>
  772. <xsl:if test="$olink.debug">
  773. <xsl:message>
  774. <xsl:text>Olink error: no gentext template</xsl:text>
  775. <xsl:text> exists for xrefstyle '</xsl:text>
  776. <xsl:value-of select="$xrefstyle"/>
  777. <xsl:text>' for element '</xsl:text>
  778. <xsl:value-of select="$target.elem"/>
  779. <xsl:text>' in language '</xsl:text>
  780. <xsl:value-of select="$lang"/>
  781. <xsl:text>' in context 'xref-number</xsl:text>
  782. <xsl:text>'. Using template without @style.</xsl:text>
  783. </xsl:message>
  784. </xsl:if>
  785. </xsl:when>
  786. <xsl:when test="$xref-context != ''">
  787. <xsl:value-of select="$xref-context"/>
  788. <xsl:if test="$olink.debug">
  789. <xsl:message>
  790. <xsl:text>Olink error: no gentext template</xsl:text>
  791. <xsl:text> exists for xrefstyle '</xsl:text>
  792. <xsl:value-of select="$xrefstyle"/>
  793. <xsl:text>' for element '</xsl:text>
  794. <xsl:value-of select="$target.elem"/>
  795. <xsl:text>' in language '</xsl:text>
  796. <xsl:value-of select="$lang"/>
  797. <xsl:text>' in context 'xref</xsl:text>
  798. <xsl:text>'. Using template without @style.</xsl:text>
  799. </xsl:message>
  800. </xsl:if>
  801. </xsl:when>
  802. <xsl:otherwise>
  803. <xsl:message>
  804. <xsl:text>Olink error: no gentext template</xsl:text>
  805. <xsl:text> exists for xrefstyle '</xsl:text>
  806. <xsl:value-of select="$xrefstyle"/>
  807. <xsl:text>' for element '</xsl:text>
  808. <xsl:value-of select="$target.elem"/>
  809. <xsl:text>' in language '</xsl:text>
  810. <xsl:value-of select="$lang"/>
  811. <xsl:text>'. Trying '%t'.</xsl:text>
  812. </xsl:message>
  813. <xsl:value-of select="'%t'"/>
  814. </xsl:otherwise>
  815. </xsl:choose>
  816. </xsl:otherwise>
  817. </xsl:choose>
  818. </xsl:variable>
  819. <xsl:if test="$olink.debug != 0">
  820. <xsl:message>
  821. <xsl:text>Olink debug: xrefstyle template is '</xsl:text>
  822. <xsl:value-of select="$template"/>
  823. <xsl:text>'.</xsl:text>
  824. </xsl:message>
  825. </xsl:if>
  826. <xsl:call-template name="substitute-markup">
  827. <xsl:with-param name="template" select="$template"/>
  828. <xsl:with-param name="title">
  829. <xsl:for-each select="$target.database" >
  830. <xsl:call-template name="insert.targetdb.data">
  831. <xsl:with-param name="data"
  832. select="key('targetptr-key', $olink.key)/ttl/node()"/>
  833. </xsl:call-template>
  834. </xsl:for-each>
  835. </xsl:with-param>
  836. <xsl:with-param name="label">
  837. <xsl:for-each select="$target.database" >
  838. <xsl:value-of
  839. select="key('targetptr-key', $olink.key)[1]/@number" />
  840. </xsl:for-each>
  841. </xsl:with-param>
  842. <xsl:with-param name="pagenumber">
  843. <xsl:for-each select="$target.database" >
  844. <xsl:value-of
  845. select="key('targetptr-key', $olink.key)[1]/@page" />
  846. </xsl:for-each>
  847. </xsl:with-param>
  848. <xsl:with-param name="docname">
  849. <xsl:for-each select="$target.database" >
  850. <xsl:call-template name="insert.targetdb.data">
  851. <xsl:with-param name="data"
  852. select="key('targetdoc-key', $targetdoc)[1]/div[1]/ttl/node()" />
  853. </xsl:call-template>
  854. </xsl:for-each>
  855. </xsl:with-param>
  856. </xsl:call-template>
  857. </xsl:when>
  858. <xsl:when test="$use.local.olink.style != 0">
  859. <!-- Is autonumbering on? -->
  860. <xsl:variable name="target.number">
  861. <xsl:for-each select="$target.database" >
  862. <xsl:value-of
  863. select="key('targetptr-key', $olink.key)[1]/@number" />
  864. </xsl:for-each>
  865. </xsl:variable>
  866. <xsl:variable name="autonumber">
  867. <xsl:choose>
  868. <xsl:when test="$target.number != ''">1</xsl:when>
  869. <xsl:otherwise>0</xsl:otherwise>
  870. </xsl:choose>
  871. </xsl:variable>
  872. <xsl:variable name="number-and-title-template">
  873. <xsl:call-template name="gentext.template.exists">
  874. <xsl:with-param name="context" select="'xref-number-and-title'"/>
  875. <xsl:with-param name="name" select="$target.elem"/>
  876. </xsl:call-template>
  877. </xsl:variable>
  878. <xsl:variable name="number-template">
  879. <xsl:call-template name="gentext.template.exists">
  880. <xsl:with-param name="context" select="'xref-number'"/>
  881. <xsl:with-param name="name" select="$target.elem"/>
  882. </xsl:call-template>
  883. </xsl:variable>
  884. <xsl:variable name="context">
  885. <xsl:choose>
  886. <xsl:when test="string($autonumber) != 0
  887. and $number-and-title-template != 0
  888. and $xref.with.number.and.title != 0">
  889. <xsl:value-of select="'xref-number-and-title'"/>
  890. </xsl:when>
  891. <xsl:when test="string($autonumber) != 0
  892. and $number-template != 0">
  893. <xsl:value-of select="'xref-number'"/>
  894. </xsl:when>
  895. <xsl:otherwise>
  896. <xsl:value-of select="'xref'"/>
  897. </xsl:otherwise>
  898. </xsl:choose>
  899. </xsl:variable>
  900. <xsl:variable name="template">
  901. <xsl:call-template name="gentext.template">
  902. <xsl:with-param name="context" select="$context"/>
  903. <xsl:with-param name="name" select="$target.elem"/>
  904. <xsl:with-param name="lang" select="$lang"/>
  905. </xsl:call-template>
  906. </xsl:variable>
  907. <xsl:call-template name="substitute-markup">
  908. <xsl:with-param name="template" select="$template"/>
  909. <xsl:with-param name="title">
  910. <xsl:for-each select="$target.database" >
  911. <xsl:call-template name="insert.targetdb.data">
  912. <xsl:with-param name="data"
  913. select="key('targetptr-key', $olink.key)[1]/ttl/node()" />
  914. </xsl:call-template>
  915. </xsl:for-each>
  916. </xsl:with-param>
  917. <xsl:with-param name="label">
  918. <xsl:for-each select="$target.database" >
  919. <xsl:call-template name="insert.targetdb.data">
  920. <xsl:with-param name="data"
  921. select="key('targetptr-key', $olink.key)[1]/@number" />
  922. </xsl:call-template>
  923. </xsl:for-each>
  924. </xsl:with-param>
  925. </xsl:call-template>
  926. </xsl:when>
  927. <xsl:when test="$xref.text !=''">
  928. <xsl:copy-of select="$xref.text"/>
  929. </xsl:when>
  930. <xsl:otherwise>
  931. <xsl:message>
  932. <xsl:text>Olink error: no generated text for </xsl:text>
  933. <xsl:text>targetdoc/targetptr/lang = '</xsl:text>
  934. <xsl:value-of select="$olink.key"/>
  935. <xsl:text>'.</xsl:text>
  936. </xsl:message>
  937. <xsl:text>????</xsl:text>
  938. </xsl:otherwise>
  939. </xsl:choose>
  940. </xsl:when>
  941. <xsl:otherwise>
  942. <xsl:if test="$olink.key != ''">
  943. <xsl:message>
  944. <xsl:text>Olink error: no generated text for </xsl:text>
  945. <xsl:text>targetdoc/targetptr/lang = '</xsl:text>
  946. <xsl:value-of select="$olink.key"/>
  947. <xsl:text>'.</xsl:text>
  948. </xsl:message>
  949. </xsl:if>
  950. <xsl:text>????</xsl:text>
  951. </xsl:otherwise>
  952. </xsl:choose>
  953. </xsl:template>
  954. <xsl:template name="insert.targetdb.data">
  955. <xsl:param name="data"/>
  956. <!-- Customize this to massage data further -->
  957. <xsl:copy-of select="$data"/>
  958. </xsl:template>
  959. <xsl:template match="*" mode="olink.docname.markup">
  960. <!-- No-op for now -->
  961. </xsl:template>
  962. <xsl:template name="targetpath">
  963. <xsl:param name="dirnode" />
  964. <xsl:param name="targetdoc" select="''"/>
  965. <!--
  966. <xsl:message>dirnode is <xsl:value-of select="$dirnode/@name"/></xsl:message>
  967. <xsl:message>targetdoc is <xsl:value-of select="$targetdoc"/></xsl:message>
  968. -->
  969. <!-- recursive template generates path to olink target directory -->
  970. <xsl:choose>
  971. <!-- Have we arrived at the final path step? -->
  972. <xsl:when test="$dirnode/child::document[@targetdoc = $targetdoc]">
  973. <!-- We are done -->
  974. </xsl:when>
  975. <!-- Have we reached the top without a match? -->
  976. <xsl:when test="local-name($dirnode) != 'dir'" >
  977. <xsl:message>Olink error: cannot locate targetdoc <xsl:value-of select="$targetdoc"/> in sitemap</xsl:message>
  978. </xsl:when>
  979. <!-- Is the target in a descendant? -->
  980. <xsl:when test="$dirnode/descendant::document/@targetdoc = $targetdoc">
  981. <xsl:variable name="step" select="$dirnode/child::dir[descendant::document/@targetdoc = $targetdoc]"/>
  982. <xsl:if test = "$step">
  983. <xsl:value-of select="$step/@name"/>
  984. <xsl:text>/</xsl:text>
  985. </xsl:if>
  986. <!-- Now recurse with the child -->
  987. <xsl:call-template name="targetpath" >
  988. <xsl:with-param name="dirnode" select="$step"/>
  989. <xsl:with-param name="targetdoc" select="$targetdoc"/>
  990. </xsl:call-template>
  991. </xsl:when>
  992. <!-- Otherwise we need to move up a step -->
  993. <xsl:otherwise>
  994. <xsl:if test="$dirnode/parent::dir">
  995. <xsl:text>../</xsl:text>
  996. </xsl:if>
  997. <xsl:call-template name="targetpath" >
  998. <xsl:with-param name="dirnode" select="$dirnode/parent::*"/>
  999. <xsl:with-param name="targetdoc" select="$targetdoc"/>
  1000. </xsl:call-template>
  1001. </xsl:otherwise>
  1002. </xsl:choose>
  1003. </xsl:template>
  1004. <xsl:template name="olink.page.citation">
  1005. <xsl:param name="olink.key" select="''"/>
  1006. <xsl:param name="olink.lang" select="'en'"/>
  1007. <xsl:param name="target.database"/>
  1008. <xsl:param name="linkend" select="''"/>
  1009. <xsl:param name="xrefstyle">
  1010. <xsl:choose>
  1011. <xsl:when test="@role and not(@xrefstyle)
  1012. and $use.role.as.xrefstyle != 0">
  1013. <xsl:value-of select="@role"/>
  1014. </xsl:when>
  1015. <xsl:otherwise>
  1016. <xsl:value-of select="@xrefstyle"/>
  1017. </xsl:otherwise>
  1018. </xsl:choose>
  1019. </xsl:param>
  1020. <xsl:variable name="targetdoc">
  1021. <xsl:value-of select="substring-before($olink.key, '/')"/>
  1022. </xsl:variable>
  1023. <xsl:choose>
  1024. <xsl:when test="$linkend != ''">
  1025. <xsl:call-template name="xref.page.citation">
  1026. <xsl:with-param name="linkend" select="$linkend"/>
  1027. <xsl:with-param name="target" select="key('id', $linkend)"/>
  1028. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  1029. </xsl:call-template>
  1030. </xsl:when>
  1031. <xsl:when test="not(starts-with(normalize-space($xrefstyle),
  1032. 'select:')
  1033. and (contains($xrefstyle, 'page')
  1034. or contains($xrefstyle, 'Page')))
  1035. and $current.docid != ''
  1036. and $current.docid != $targetdoc
  1037. and $insert.olink.page.number = 'yes' ">
  1038. <xsl:variable name="page-number">
  1039. <xsl:for-each select="$target.database" >
  1040. <xsl:value-of
  1041. select="key('targetptr-key', $olink.key)[1]/@page" />
  1042. </xsl:for-each>
  1043. </xsl:variable>
  1044. <xsl:if test="$page-number != ''">
  1045. <xsl:call-template name="substitute-markup">
  1046. <xsl:with-param name="template">
  1047. <xsl:call-template name="gentext.template">
  1048. <xsl:with-param name="name" select="'olink.page.citation'"/>
  1049. <xsl:with-param name="context" select="'xref'"/>
  1050. <xsl:with-param name="lang" select="$olink.lang"/>
  1051. </xsl:call-template>
  1052. </xsl:with-param>
  1053. <xsl:with-param name="pagenumber" select="$page-number"/>
  1054. </xsl:call-template>
  1055. </xsl:if>
  1056. </xsl:when>
  1057. </xsl:choose>
  1058. </xsl:template>
  1059. <xsl:template name="olink.document.citation">
  1060. <xsl:param name="olink.key" select="''"/>
  1061. <xsl:param name="olink.lang" select="'en'"/>
  1062. <xsl:param name="target.database"/>
  1063. <xsl:param name="xrefstyle">
  1064. <xsl:choose>
  1065. <xsl:when test="@role and not(@xrefstyle)
  1066. and $use.role.as.xrefstyle != 0">
  1067. <xsl:value-of select="@role"/>
  1068. </xsl:when>
  1069. <xsl:otherwise>
  1070. <xsl:value-of select="@xrefstyle"/>
  1071. </xsl:otherwise>
  1072. </xsl:choose>
  1073. </xsl:param>
  1074. <xsl:variable name="page">
  1075. <xsl:for-each select="$target.database" >
  1076. <xsl:value-of
  1077. select="key('targetptr-key', $olink.key)[1]/@page" />
  1078. </xsl:for-each>
  1079. </xsl:variable>
  1080. <xsl:variable name="targetdoc">
  1081. <xsl:value-of select="substring-before($olink.key, '/')"/>
  1082. </xsl:variable>
  1083. <xsl:variable name="targetptr">
  1084. <xsl:value-of
  1085. select="substring-before(substring-after($olink.key, '/'), '/')"/>
  1086. </xsl:variable>
  1087. <!-- Don't add docname if pointing to root element -->
  1088. <xsl:variable name="rootptr">
  1089. <xsl:for-each select="$target.database" >
  1090. <xsl:value-of
  1091. select="key('targetdoc-key', $targetdoc)[1]/div[1]/@targetptr" />
  1092. </xsl:for-each>
  1093. </xsl:variable>
  1094. <xsl:variable name="docname">
  1095. <xsl:for-each select="$target.database" >
  1096. <xsl:call-template name="insert.targetdb.data">
  1097. <xsl:with-param name="data"
  1098. select="key('targetdoc-key', $targetdoc)[1]/div[1]/ttl/node()" />
  1099. </xsl:call-template>
  1100. </xsl:for-each>
  1101. </xsl:variable>
  1102. <xsl:if test="not(starts-with(normalize-space($xrefstyle), 'select:')
  1103. and (contains($xrefstyle, 'docname')))
  1104. and ($olink.doctitle = 'yes' or $olink.doctitle = '1')
  1105. and $current.docid != ''
  1106. and $rootptr != $targetptr
  1107. and $current.docid != $targetdoc
  1108. and $docname != ''">
  1109. <xsl:call-template name="substitute-markup">
  1110. <xsl:with-param name="template">
  1111. <xsl:call-template name="gentext.template">
  1112. <xsl:with-param name="name" select="'olink.document.citation'"/>
  1113. <xsl:with-param name="context" select="'xref'"/>
  1114. <xsl:with-param name="lang" select="$olink.lang"/>
  1115. </xsl:call-template>
  1116. </xsl:with-param>
  1117. <xsl:with-param name="docname" select="$docname"/>
  1118. <xsl:with-param name="pagenumber" select="$page"/>
  1119. </xsl:call-template>
  1120. </xsl:if>
  1121. </xsl:template>
  1122. <xsl:template name="xref.page.citation">
  1123. <!-- Determine if this xref should have a page citation.
  1124. Context node is the xref or local olink element -->
  1125. <xsl:param name="linkend" select="@linkend"/>
  1126. <xsl:param name="target" select="key('id', $linkend)"/>
  1127. <xsl:param name="xrefstyle">
  1128. <xsl:choose>
  1129. <xsl:when test="@role and not(@xrefstyle)
  1130. and $use.role.as.xrefstyle != 0">
  1131. <xsl:value-of select="@role"/>
  1132. </xsl:when>
  1133. <xsl:otherwise>
  1134. <xsl:value-of select="@xrefstyle"/>
  1135. </xsl:otherwise>
  1136. </xsl:choose>
  1137. </xsl:param>
  1138. <xsl:if test="not(starts-with(normalize-space($xrefstyle),'select:')
  1139. and (contains($xrefstyle, 'page')
  1140. or contains($xrefstyle, 'Page')))
  1141. and ( $insert.xref.page.number = 'yes'
  1142. or $insert.xref.page.number = '1')
  1143. or local-name($target) = 'para'">
  1144. <xsl:apply-templates select="$target" mode="page.citation">
  1145. <xsl:with-param name="id" select="$linkend"/>
  1146. </xsl:apply-templates>
  1147. </xsl:if>
  1148. </xsl:template>
  1149. </xsl:stylesheet>