olink.xsl 45 KB

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