rel-links.xsl 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!-- This file is part of the DITA Open Toolkit project hosted on
  3. Sourceforge.net. See the accompanying license.txt file for
  4. applicable licenses.-->
  5. <!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->
  6. <xsl:stylesheet version="2.0"
  7. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  8. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  9. xmlns:ditamsg="http://dita-ot.sourceforge.net/ns/200704/ditamsg"
  10. xmlns:related-links="http://dita-ot.sourceforge.net/ns/200709/related-links"
  11. xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  12. exclude-result-prefixes="xs related-links ditamsg dita-ot">
  13. <xsl:key name="linkdup"
  14. match="*[contains(@class, ' topic/link ')][not(ancestor::*[contains(@class, ' topic/linklist ')])]
  15. [not(@role = ('child', 'parent', 'previous', 'next', 'ancestor', 'descendant'))]"
  16. use="concat(ancestor::*[contains(@class, ' topic/related-links ')]/parent::*[contains(@class, ' topic/topic ')]/@id,
  17. ' ',
  18. @href)"/>
  19. <xsl:param name="NOPARENTLINK" select="'no'" as="xs:string"/><!-- "no" and "yes" are valid values; non-'no' is ignored -->
  20. <xsl:param name="include.rellinks" select="'#default parent child sibling friend next previous cousin ancestor descendant sample external other'" as="xs:string"/>
  21. <xsl:variable name="include.roles" select="tokenize(normalize-space($include.rellinks), '\s+')" as="xs:string*"/>
  22. <!-- ========== Hooks for common user customizations ============== -->
  23. <!-- The following two templates are available for anybody who needs
  24. to put out an token at the start or end of a link, such as an
  25. icon to indicate links to PDF files or external web addresses. -->
  26. <xsl:template match="*" mode="add-link-highlight-at-start"/>
  27. <xsl:template match="*" mode="add-link-highlight-at-end"/>
  28. <xsl:template match="*" mode="add-xref-highlight-at-start"/>
  29. <xsl:template match="*" mode="add-xref-highlight-at-end"/>
  30. <!-- Override this template to add any standard link attributes.
  31. Called for all links. -->
  32. <xsl:template match="*" mode="add-custom-link-attributes"/>
  33. <!-- Override these templates to place some a prefix before generated
  34. child links, such as "Optional" for optional child links. Called
  35. for all child links. -->
  36. <xsl:template match="*" mode="related-links:ordered.child.prefix"/>
  37. <xsl:template match="*" mode="related-links:unordered.child.prefix"/>
  38. <!-- ========== End hooks for common user customizations ========== -->
  39. <!--template for xref-->
  40. <xsl:template match="*[contains(@class, ' topic/xref ')]" name="topic.xref">
  41. <xsl:choose>
  42. <xsl:when test="@href and normalize-space(@href)">
  43. <xsl:apply-templates select="." mode="add-xref-highlight-at-start"/>
  44. <a>
  45. <xsl:call-template name="commonattributes"/>
  46. <xsl:apply-templates select="." mode="add-linking-attributes"/>
  47. <xsl:apply-templates select="." mode="add-desc-as-hoverhelp"/>
  48. <!-- if there is text or sub element other than desc, apply templates to them
  49. otherwise, use the href as the value of link text. -->
  50. <xsl:choose>
  51. <xsl:when test="@type = 'fn'">
  52. <sup>
  53. <xsl:choose>
  54. <xsl:when test="*[not(contains(@class, ' topic/desc '))] | text()">
  55. <xsl:apply-templates select="*[not(contains(@class, ' topic/desc '))] | text()"/>
  56. <!--use xref content-->
  57. </xsl:when>
  58. <xsl:otherwise>
  59. <xsl:call-template name="href"/><!--use href text-->
  60. </xsl:otherwise>
  61. </xsl:choose>
  62. </sup>
  63. </xsl:when>
  64. <xsl:otherwise>
  65. <xsl:choose>
  66. <xsl:when test="*[not(contains(@class, ' topic/desc '))] | text()">
  67. <xsl:apply-templates select="*[not(contains(@class, ' topic/desc '))] | text()"/>
  68. <!--use xref content-->
  69. </xsl:when>
  70. <xsl:otherwise>
  71. <xsl:call-template name="href"/><!--use href text-->
  72. </xsl:otherwise>
  73. </xsl:choose>
  74. </xsl:otherwise>
  75. </xsl:choose>
  76. </a>
  77. <xsl:apply-templates select="." mode="add-xref-highlight-at-end"/>
  78. </xsl:when>
  79. <xsl:otherwise>
  80. <span>
  81. <xsl:call-template name="commonattributes"/>
  82. <xsl:apply-templates select="." mode="add-desc-as-hoverhelp"/>
  83. <xsl:apply-templates select="*[not(contains(@class, ' topic/desc '))] | text() | comment() | processing-instruction()"/>
  84. </span>
  85. </xsl:otherwise>
  86. </xsl:choose>
  87. </xsl:template>
  88. <!--create breadcrumbs for each grouping of ancestor links; include previous, next, and ancestor links, sorted by linkpool/related-links parent. If there is more than one linkpool that contains ancestors, multiple breadcrumb trails will be generated-->
  89. <xsl:template match="*[contains(@class, ' topic/related-links ')]" mode="breadcrumb">
  90. <xsl:for-each select="descendant-or-self::*[contains(@class, ' topic/related-links ') or contains(@class, ' topic/linkpool ')][*[@role = 'ancestor']]">
  91. <xsl:value-of select="$newline"/>
  92. <div class="breadcrumb">
  93. <xsl:if test="$include.roles = 'previous'">
  94. <!--output previous link first, if it exists-->
  95. <xsl:if test="*[@href][@role = 'previous']">
  96. <xsl:apply-templates select="*[@href][@role = 'previous'][1]" mode="breadcrumb"/>
  97. </xsl:if>
  98. </xsl:if>
  99. <!--if both previous and next links exist, output a separator bar-->
  100. <xsl:if test="$include.roles = 'previous' and $include.roles = 'next'">
  101. <xsl:if test="*[@href][@role = 'next'] and *[@href][@role = 'previous']">
  102. <xsl:text> | </xsl:text>
  103. </xsl:if>
  104. </xsl:if>
  105. <xsl:if test="$include.roles = 'next'">
  106. <!--output next link, if it exists-->
  107. <xsl:if test="*[@href][@role = 'next']">
  108. <xsl:apply-templates select="*[@href][@role = 'next'][1]" mode="breadcrumb"/>
  109. </xsl:if>
  110. </xsl:if>
  111. <xsl:if test="$include.roles = 'previous' and $include.roles = 'next' and $include.roles = 'ancestor'">
  112. <!--if we have either next or previous, plus ancestors, separate the next/prev from the ancestors with a vertical bar-->
  113. <xsl:if test="(*[@href][@role = 'next'] or *[@href][@role = 'previous']) and *[@href][@role = 'ancestor']">
  114. <xsl:text> | </xsl:text>
  115. </xsl:if>
  116. </xsl:if>
  117. <xsl:if test="$include.roles = 'ancestor'">
  118. <!--if ancestors exist, output them, and include a greater-than symbol after each one, including a trailing one-->
  119. <xsl:for-each select="*[@href][@role = 'ancestor']">
  120. <xsl:apply-templates select="."/>
  121. <xsl:text> &gt; </xsl:text>
  122. </xsl:for-each>
  123. </xsl:if>
  124. </div>
  125. <xsl:value-of select="$newline"/>
  126. </xsl:for-each>
  127. </xsl:template>
  128. <!--create prerequisite links with all dups eliminated. -->
  129. <xsl:template match="*[contains(@class, ' topic/related-links ')]" mode="prereqs">
  130. <!--if there are any prereqs create a list with dups-->
  131. <!--only create link if there is an href, its importance is required, and the role is compatible (don't want a prereq showing up for a "next" or "parent" link, for example) - remove dups-->
  132. <xsl:variable name="prereqs"
  133. select="descendant::*[generate-id(.) = generate-id(key('link', related-links:link(.))[1])]
  134. [@href]
  135. [@importance = 'required' and (empty(@role) or @role = ('sibling', 'friend', 'previous', 'cousin'))]
  136. [not(ancestor::*[contains(@class, ' topic/linklist ')])]"/>
  137. <xsl:if test="exists($prereqs)">
  138. <xsl:value-of select="$newline"/>
  139. <dl class="prereqlinks">
  140. <xsl:value-of select="$newline"/>
  141. <dt class="prereq">
  142. <xsl:call-template name="getVariable">
  143. <xsl:with-param name="id" select="'Prerequisites'"/>
  144. </xsl:call-template>
  145. </dt>
  146. <xsl:value-of select="$newline"/>
  147. <xsl:apply-templates select="$prereqs" mode="prereqs"/>
  148. </dl>
  149. <xsl:value-of select="$newline"/>
  150. </xsl:if>
  151. </xsl:template>
  152. <!--main template for setting up all links after the body - applied to the related-links container-->
  153. <xsl:template match="*[contains(@class, ' topic/related-links ')]" name="topic.related-links">
  154. <nav role="navigation">
  155. <xsl:call-template name="commonattributes"/>
  156. <xsl:if test="$include.roles = ('child', 'descendant')">
  157. <xsl:call-template name="ul-child-links"/>
  158. <!--handle child/descendants outside of linklists in collection-type=unordered or choice-->
  159. <xsl:call-template name="ol-child-links"/>
  160. <!--handle child/descendants outside of linklists in collection-type=ordered/sequence-->
  161. </xsl:if>
  162. <xsl:if test="$include.roles = ('next', 'previous', 'parent')">
  163. <xsl:call-template name="next-prev-parent-links"/>
  164. <!--handle next and previous links-->
  165. </xsl:if>
  166. <!-- Group all unordered links (which have not already been handled by prior sections). Skip duplicate links. -->
  167. <!-- NOTE: The actual grouping code for related-links:group-unordered-links is common between
  168. transform types, and is located in ../common/related-links.xsl. Actual code for
  169. creating group titles and formatting links is located in XSL files specific to each type. -->
  170. <xsl:variable name="unordered-links" as="element()*">
  171. <xsl:apply-templates select="." mode="related-links:group-unordered-links">
  172. <xsl:with-param name="nodes"
  173. select="descendant::*[contains(@class, ' topic/link ')]
  174. [not(related-links:omit-from-unordered-links(.))]
  175. [generate-id(.) = generate-id(key('hideduplicates', related-links:hideduplicates(.))[1])]"/>
  176. </xsl:apply-templates>
  177. </xsl:variable>
  178. <xsl:apply-templates select="$unordered-links"/>
  179. <!--linklists - last but not least, create all the linklists and their links, with no sorting or re-ordering-->
  180. <xsl:apply-templates select="*[contains(@class, ' topic/linklist ')]"/>
  181. </nav>
  182. </xsl:template>
  183. <!--children links - handle all child or descendant links except those in linklists or ordered collection-types.
  184. Each child is indented, the linktext is bold, and the shortdesc appears in normal text directly below the link, to create a summary-like appearance.-->
  185. <xsl:template name="ul-child-links">
  186. <xsl:variable name="children"
  187. select="descendant::*[contains(@class, ' topic/link ')]
  188. [@role = ('child', 'descendant')]
  189. [not(parent::*/@collection-type = 'sequence')]
  190. [not(ancestor::*[contains(@class, ' topic/linklist ')])]"/>
  191. <xsl:if test="$children">
  192. <xsl:value-of select="$newline"/>
  193. <ul class="ullinks">
  194. <xsl:value-of select="$newline"/>
  195. <!--once you've tested that at least one child/descendant exists, apply templates to only the unique ones-->
  196. <xsl:apply-templates select="$children[generate-id(.) = generate-id(key('link', related-links:link(.))[1])]"/>
  197. </ul>
  198. <xsl:value-of select="$newline"/>
  199. </xsl:if>
  200. </xsl:template>
  201. <!--children links - handle all child or descendant links in ordered collection-types.
  202. Children are displayed in a numbered list, with the target title as the cmd and the shortdesc as info, like a task.
  203. -->
  204. <xsl:template name="ol-child-links">
  205. <xsl:variable name="children"
  206. select="descendant::*[contains(@class, ' topic/link ')]
  207. [@role = ('child', 'descendant')]
  208. [parent::*/@collection-type = 'sequence']
  209. [not(ancestor::*[contains(@class, ' topic/linklist ')])]"/>
  210. <xsl:if test="$children">
  211. <xsl:value-of select="$newline"/>
  212. <ol class="olchildlinks">
  213. <xsl:value-of select="$newline"/>
  214. <!--once you've tested that at least one child/descendant exists, apply templates to only the unique ones-->
  215. <xsl:apply-templates select="$children[generate-id(.) = generate-id(key('link', related-links:link(.))[1])]"/>
  216. </ol>
  217. <xsl:value-of select="$newline"/>
  218. </xsl:if>
  219. </xsl:template>
  220. <!--create the next and previous links, with accompanying parent link if any; create group for each unique parent, as well as for any next and previous links that aren't in the same group as a parent-->
  221. <xsl:template name="next-prev-parent-links">
  222. <xsl:for-each select="descendant::*[contains(@class, ' topic/link ')]
  223. [@role = ('parent', 'next', 'previous') and
  224. generate-id(.) = generate-id(key('link', related-links:link(.))[1])]/parent::*">
  225. <xsl:value-of select="$newline"/>
  226. <div class="familylinks">
  227. <xsl:value-of select="$newline"/>
  228. <xsl:if test="$NOPARENTLINK = 'no' and $include.roles = 'parent'">
  229. <xsl:choose>
  230. <xsl:when test="*[@href][@role = 'parent']">
  231. <xsl:for-each select="*[@href][@role = 'parent']">
  232. <div class="parentlink">
  233. <xsl:apply-templates select="."/>
  234. </div>
  235. <xsl:value-of select="$newline"/>
  236. </xsl:for-each>
  237. </xsl:when>
  238. <xsl:otherwise>
  239. <xsl:for-each select="*[@href][@role = 'ancestor'][last()]">
  240. <div class="parentlink">
  241. <xsl:call-template name="parentlink"/>
  242. </div>
  243. <xsl:value-of select="$newline"/>
  244. </xsl:for-each>
  245. </xsl:otherwise>
  246. </xsl:choose>
  247. </xsl:if>
  248. <xsl:if test="$include.roles = 'previous'">
  249. <xsl:for-each select="*[@href][@role = 'previous']">
  250. <div class="previouslink">
  251. <xsl:apply-templates select="."/>
  252. </div>
  253. <xsl:value-of select="$newline"/>
  254. </xsl:for-each>
  255. </xsl:if>
  256. <xsl:if test="$include.roles = 'next'">
  257. <xsl:for-each select="*[@href][@role = 'next']">
  258. <div class="nextlink">
  259. <xsl:apply-templates select="."/>
  260. </div>
  261. <xsl:value-of select="$newline"/>
  262. </xsl:for-each>
  263. </xsl:if>
  264. </div>
  265. <xsl:value-of select="$newline"/>
  266. </xsl:for-each>
  267. </xsl:template>
  268. <!-- Override no-name group wrapper template for HTML: output "Related Information" in a <linklist>. -->
  269. <xsl:template match="*[contains(@class, ' topic/link ')]" mode="related-links:result-group" name="related-links:group-result."
  270. as="element()">
  271. <xsl:param name="links" as="node()*"/>
  272. <xsl:if test="exists($links)">
  273. <linklist class="- topic/linklist " outputclass="relinfo">
  274. <title class="- topic/title ">
  275. <xsl:call-template name="getVariable">
  276. <xsl:with-param name="id" select="'Related information'"/>
  277. </xsl:call-template>
  278. </title>
  279. <xsl:copy-of select="$links"/>
  280. </linklist>
  281. </xsl:if>
  282. </xsl:template>
  283. <!-- Links with @type="topic" belong in no-name group. -->
  284. <xsl:template match="*[contains(@class, ' topic/link ')][@type = 'topic']" mode="related-links:get-group-priority"
  285. name="related-links:group-priority.topic" priority="2"
  286. as="xs:integer">
  287. <xsl:call-template name="related-links:group-priority."/>
  288. </xsl:template>
  289. <xsl:template match="*[contains(@class, ' topic/link ')][@type = 'topic']" mode="related-links:get-group"
  290. name="related-links:group.topic" priority="2"
  291. as="xs:string">
  292. <xsl:call-template name="related-links:group."/>
  293. </xsl:template>
  294. <xsl:template match="*[contains(@class, ' topic/link ')][@type = 'topic']" mode="related-links:result-group"
  295. name="related-links:group-result.topic" priority="2">
  296. <xsl:param name="links" as="node()*"/>
  297. <xsl:call-template name="related-links:group-result.">
  298. <xsl:with-param name="links" select="$links"/>
  299. </xsl:call-template>
  300. </xsl:template>
  301. <!--calculate href-->
  302. <xsl:template name="href">
  303. <xsl:apply-templates select="." mode="determine-final-href"/>
  304. </xsl:template>
  305. <xsl:template match="*" mode="determine-final-href">
  306. <xsl:choose>
  307. <xsl:when test="not(normalize-space(@href)) or empty(@href)"/>
  308. <!-- For non-DITA formats - use the href as is -->
  309. <xsl:when test="(empty(@format) and @scope = 'external') or (@format and not(@format = 'dita'))">
  310. <xsl:value-of select="@href"/>
  311. </xsl:when>
  312. <!-- For DITA - process the internal href -->
  313. <xsl:when test="starts-with(@href, '#')">
  314. <xsl:text>#</xsl:text>
  315. <xsl:value-of select="dita-ot:generate-id(dita-ot:get-topic-id(@href), dita-ot:get-element-id(@href))"/>
  316. </xsl:when>
  317. <!-- It's to a DITA file - process the file name (adding the html extension)
  318. and process the rest of the href -->
  319. <xsl:when test="(empty(@scope) or @scope = ('local', 'peer')) and (empty(@format) or @format = 'dita')">
  320. <xsl:call-template name="replace-extension">
  321. <xsl:with-param name="filename" select="@href"/>
  322. <xsl:with-param name="extension" select="$OUTEXT"/>
  323. <xsl:with-param name="ignore-fragment" select="true()"/>
  324. </xsl:call-template>
  325. <xsl:if test="contains(@href, '#')">
  326. <xsl:text>#</xsl:text>
  327. <xsl:value-of select="dita-ot:generate-id(dita-ot:get-topic-id(@href), dita-ot:get-element-id(@href))"/>
  328. </xsl:if>
  329. </xsl:when>
  330. <xsl:otherwise>
  331. <xsl:apply-templates select="." mode="ditamsg:unknown-extension"/>
  332. <xsl:value-of select="@href"/>
  333. </xsl:otherwise>
  334. </xsl:choose>
  335. </xsl:template>
  336. <!--breadcrumb template: next, prev-->
  337. <xsl:template match="*[contains(@class, ' topic/link ')][@role = ('next', 'previous')]" mode="breadcrumb">
  338. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  339. <a>
  340. <xsl:call-template name="commonattributes"/>
  341. <xsl:apply-templates select="." mode="add-linking-attributes"/>
  342. <xsl:apply-templates select="." mode="add-title-as-hoverhelp"/>
  343. <!-- Allow for unknown metadata (future-proofing) -->
  344. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  345. <!--use string as output link text for now, use image eventually-->
  346. <xsl:choose>
  347. <xsl:when test="@role = 'next'">
  348. <xsl:call-template name="getVariable">
  349. <xsl:with-param name="id" select="'Next topic'"/>
  350. </xsl:call-template>
  351. </xsl:when>
  352. <xsl:when test="@role = 'previous'">
  353. <xsl:call-template name="getVariable">
  354. <xsl:with-param name="id" select="'Previous topic'"/>
  355. </xsl:call-template>
  356. </xsl:when>
  357. <xsl:otherwise><!--both role values tested - no otherwise--></xsl:otherwise>
  358. </xsl:choose>
  359. </a>
  360. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  361. </xsl:template>
  362. <!--prereq template-->
  363. <xsl:template mode="prereqs" match="*[contains(@class, ' topic/link ')]" priority="2">
  364. <dd>
  365. <!-- Allow for unknown metadata (future-proofing) -->
  366. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  367. <xsl:call-template name="makelink"/>
  368. </dd>
  369. <xsl:value-of select="$newline"/>
  370. </xsl:template>
  371. <!--plain templates: next, prev, ancestor/parent, children, everything else-->
  372. <xsl:template name="nextlink" match="*[contains(@class, ' topic/link ')][@role = 'next']" priority="2">
  373. <strong>
  374. <!-- Allow for unknown metadata (future-proofing) -->
  375. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  376. <xsl:call-template name="getVariable">
  377. <xsl:with-param name="id" select="'Next topic'"/>
  378. </xsl:call-template>
  379. <xsl:call-template name="getVariable">
  380. <xsl:with-param name="id" select="'ColonSymbol'"/>
  381. </xsl:call-template>
  382. </strong>
  383. <xsl:text> </xsl:text>
  384. <xsl:call-template name="makelink"/>
  385. </xsl:template>
  386. <xsl:template name="prevlink" match="*[contains(@class, ' topic/link ')][@role = 'previous']" priority="2">
  387. <strong>
  388. <!-- Allow for unknown metadata (future-proofing) -->
  389. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  390. <xsl:call-template name="getVariable">
  391. <xsl:with-param name="id" select="'Previous topic'"/>
  392. </xsl:call-template>
  393. <xsl:call-template name="getVariable">
  394. <xsl:with-param name="id" select="'ColonSymbol'"/>
  395. </xsl:call-template>
  396. </strong>
  397. <xsl:text> </xsl:text>
  398. <xsl:call-template name="makelink"/>
  399. </xsl:template>
  400. <xsl:template name="parentlink" match="*[contains(@class, ' topic/link ')][@role = 'parent']" priority="2">
  401. <strong>
  402. <!-- Allow for unknown metadata (future-proofing) -->
  403. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  404. <xsl:call-template name="getVariable">
  405. <xsl:with-param name="id" select="'Parent topic'"/>
  406. </xsl:call-template>
  407. <xsl:call-template name="getVariable">
  408. <xsl:with-param name="id" select="'ColonSymbol'"/>
  409. </xsl:call-template>
  410. </strong>
  411. <xsl:text> </xsl:text>
  412. <xsl:call-template name="makelink"/>
  413. </xsl:template>
  414. <!--basic child processing-->
  415. <xsl:template match="*[contains(@class, ' topic/link ')][@role = ('child', 'descendant')]" priority="2" name="topic.link_child">
  416. <xsl:variable name="el-name">
  417. <xsl:choose>
  418. <xsl:when test="contains(../@class, ' topic/linklist ')">div</xsl:when>
  419. <xsl:otherwise>li</xsl:otherwise>
  420. </xsl:choose>
  421. </xsl:variable>
  422. <xsl:element name="{$el-name}">
  423. <xsl:attribute name="class">ulchildlink</xsl:attribute>
  424. <xsl:call-template name="commonattributes">
  425. <xsl:with-param name="default-output-class" select="'ulchildlink'"/>
  426. </xsl:call-template>
  427. <!-- Allow for unknown metadata (future-proofing) -->
  428. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  429. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  430. <strong>
  431. <xsl:apply-templates select="." mode="related-links:unordered.child.prefix"/>
  432. <xsl:apply-templates select="." mode="add-link-highlight-at-start"/>
  433. <a>
  434. <xsl:apply-templates select="." mode="add-linking-attributes"/>
  435. <xsl:apply-templates select="." mode="add-hoverhelp-to-child-links"/>
  436. <!--use linktext as linktext if it exists, otherwise use href as linktext-->
  437. <xsl:choose>
  438. <xsl:when test="*[contains(@class, ' topic/linktext ')]">
  439. <xsl:apply-templates select="*[contains(@class, ' topic/linktext ')]"/>
  440. </xsl:when>
  441. <xsl:otherwise>
  442. <!--use href-->
  443. <xsl:call-template name="href"/>
  444. </xsl:otherwise>
  445. </xsl:choose>
  446. </a>
  447. <xsl:apply-templates select="." mode="add-link-highlight-at-end"/>
  448. </strong>
  449. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  450. <br/>
  451. <xsl:value-of select="$newline"/>
  452. <!--add the description on the next line, like a summary-->
  453. <xsl:apply-templates select="*[contains(@class, ' topic/desc ')]"/>
  454. </xsl:element>
  455. <xsl:value-of select="$newline"/>
  456. </xsl:template>
  457. <!--ordered child processing-->
  458. <xsl:template match="*[@collection-type = 'sequence']/*[contains(@class, ' topic/link ')][@role = ('child', 'descendant')]" priority="3" name="topic.link_orderedchild">
  459. <xsl:variable name="el-name" as="xs:string">
  460. <xsl:choose>
  461. <xsl:when test="contains(../@class, ' topic/linklist ')">div</xsl:when>
  462. <xsl:otherwise>li</xsl:otherwise>
  463. </xsl:choose>
  464. </xsl:variable>
  465. <xsl:element name="{$el-name}">
  466. <xsl:attribute name="class">olchildlink</xsl:attribute>
  467. <xsl:call-template name="commonattributes">
  468. <xsl:with-param name="default-output-class" select="'olchildlink'"/>
  469. </xsl:call-template>
  470. <!-- Allow for unknown metadata (future-proofing) -->
  471. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  472. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  473. <xsl:apply-templates select="." mode="related-links:ordered.child.prefix"/>
  474. <xsl:apply-templates select="." mode="add-link-highlight-at-start"/>
  475. <a>
  476. <xsl:apply-templates select="." mode="add-linking-attributes"/>
  477. <xsl:apply-templates select="." mode="add-hoverhelp-to-child-links"/>
  478. <!--use linktext as linktext if it exists, otherwise use href as linktext-->
  479. <xsl:choose>
  480. <xsl:when test="*[contains(@class, ' topic/linktext ')]">
  481. <xsl:apply-templates select="*[contains(@class, ' topic/linktext ')]"/>
  482. </xsl:when>
  483. <xsl:otherwise>
  484. <!--use href-->
  485. <xsl:call-template name="href"/>
  486. </xsl:otherwise>
  487. </xsl:choose>
  488. </a>
  489. <xsl:apply-templates select="." mode="add-link-highlight-at-end"/>
  490. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  491. <br/>
  492. <xsl:value-of select="$newline"/>
  493. <!--add the description on a new line, unlike an info, to avoid issues with punctuation (adding a period)-->
  494. <xsl:apply-templates select="*[contains(@class, ' topic/desc ')]"/>
  495. </xsl:element>
  496. <xsl:value-of select="$newline"/>
  497. </xsl:template>
  498. <xsl:template match="*[contains(@class, ' topic/link ')]" name="topic.link">
  499. <xsl:if test="(@role and $include.roles = @role) or
  500. (empty(@role) and $include.roles = '#default')">
  501. <xsl:choose>
  502. <!-- Linklist links put out <br/> in "processlinklist" -->
  503. <xsl:when test="ancestor::*[contains(@class, ' topic/linklist ')]">
  504. <xsl:call-template name="makelink"/>
  505. </xsl:when>
  506. <!-- Ancestor links go in the breadcrumb trail, and should not get a <br/> -->
  507. <xsl:when test="@role = 'ancestor'">
  508. <xsl:call-template name="makelink"/>
  509. </xsl:when>
  510. <!-- Items with these roles should always go to output, and are not included in the hideduplicates key. -->
  511. <xsl:when test="@role and not(@role = ('cousin', 'external', 'friend', 'other', 'sample', 'sibling'))">
  512. <div>
  513. <xsl:call-template name="makelink"/>
  514. </div>
  515. <xsl:value-of select="$newline"/>
  516. </xsl:when>
  517. <!-- If roles do not match, but nearly everything else does, skip the link. -->
  518. <xsl:when test="key('hideduplicates', related-links:hideduplicates(.))[2]">
  519. <xsl:choose>
  520. <xsl:when test="generate-id(.) = generate-id(key('hideduplicates', related-links:hideduplicates(.))[1])">
  521. <div>
  522. <xsl:call-template name="makelink"/>
  523. </div>
  524. <xsl:value-of select="$newline"/>
  525. </xsl:when>
  526. <!-- If this is filtered out, we may need the duplicate link message anyway. -->
  527. <xsl:otherwise>
  528. <xsl:call-template name="linkdupinfo"/>
  529. </xsl:otherwise>
  530. </xsl:choose>
  531. </xsl:when>
  532. <xsl:otherwise>
  533. <div>
  534. <xsl:call-template name="makelink"/>
  535. </div>
  536. <xsl:value-of select="$newline"/>
  537. </xsl:otherwise>
  538. </xsl:choose>
  539. </xsl:if>
  540. </xsl:template>
  541. <!--creating the actual link-->
  542. <xsl:template name="makelink">
  543. <xsl:call-template name="linkdupinfo"/>
  544. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  545. <xsl:apply-templates select="." mode="add-link-highlight-at-start"/>
  546. <a>
  547. <xsl:call-template name="commonattributes"/>
  548. <xsl:apply-templates select="." mode="add-linking-attributes"/>
  549. <xsl:apply-templates select="." mode="add-desc-as-hoverhelp"/>
  550. <!-- Allow for unknown metadata (future-proofing) -->
  551. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  552. <!--use linktext as linktext if it exists, otherwise use href as linktext-->
  553. <xsl:choose>
  554. <xsl:when test="*[contains(@class, ' topic/linktext ')]">
  555. <xsl:apply-templates select="*[contains(@class, ' topic/linktext ')]"/>
  556. </xsl:when>
  557. <xsl:otherwise>
  558. <!--use href-->
  559. <xsl:call-template name="href"/>
  560. </xsl:otherwise>
  561. </xsl:choose>
  562. </a>
  563. <xsl:apply-templates select="." mode="add-link-highlight-at-end"/>
  564. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  565. </xsl:template>
  566. <!--process linktext elements by explicitly ignoring them and applying templates to their content; otherwise flagged as unprocessed content by the dit2htm transform-->
  567. <xsl:template match="*[contains(@class, ' topic/linktext ')]" name="topic.linktext">
  568. <xsl:apply-templates select="* | text()"/>
  569. </xsl:template>
  570. <!--process link desc by explicitly ignoring them and applying templates to their content; otherwise flagged as unprocessed content by the dit2htm transform-->
  571. <xsl:template match="*[contains(@class, ' topic/link ')]/*[contains(@class, ' topic/desc ')]" name="topic.link_desc">
  572. <xsl:apply-templates select="* | text()"/>
  573. </xsl:template>
  574. <!--linklists-->
  575. <xsl:template match="*[contains(@class, ' topic/linklist ')]" name="topic.linklist">
  576. <xsl:value-of select="$newline"/>
  577. <xsl:choose>
  578. <!-- if this is a first-level linklist with no child links in it, put it in a div (flush left)-->
  579. <xsl:when test="(empty(parent::*) or parent::*[contains(@class, ' topic/related-links ')])
  580. and not(child::*[contains(@class, ' topic/link ')][@role = ('child', 'descendant')])">
  581. <div class="linklist">
  582. <xsl:apply-templates select="." mode="processlinklist"/>
  583. </div>
  584. </xsl:when>
  585. <!-- When it contains children, indent with child class -->
  586. <xsl:when test="child::*[contains(@class, ' topic/link ')][@role = ('child', 'descendant')]">
  587. <div class="linklistwithchild">
  588. <xsl:apply-templates select="." mode="processlinklist">
  589. <xsl:with-param name="default-list-type" select="'linklistwithchild'"/>
  590. </xsl:apply-templates>
  591. </div>
  592. </xsl:when>
  593. <!-- It is a nested linklist, indent with other class -->
  594. <xsl:otherwise>
  595. <div class="sublinklist">
  596. <xsl:apply-templates select="." mode="processlinklist">
  597. <xsl:with-param name="default-list-type" select="'sublinklist'"/>
  598. </xsl:apply-templates>
  599. </div>
  600. </xsl:otherwise>
  601. </xsl:choose>
  602. <xsl:value-of select="$newline"/>
  603. </xsl:template>
  604. <xsl:template match="*" mode="processlinklist">
  605. <xsl:param name="default-list-type" select="'linklist'" as="xs:string"/>
  606. <xsl:call-template name="commonattributes">
  607. <xsl:with-param name="default-output-class" select="$default-list-type"/>
  608. </xsl:call-template>
  609. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  610. <xsl:apply-templates select="*[contains(@class, ' topic/title ')]"/>
  611. <xsl:apply-templates select="*[contains(@class, ' topic/desc ')]"/>
  612. <xsl:for-each select="*[contains(@class, ' topic/linklist ')] | *[contains(@class, ' topic/link ')]">
  613. <xsl:choose>
  614. <!-- for children, div wrapper is created in main template -->
  615. <xsl:when test="contains(@class, ' topic/link ') and (@role = ('child', 'descendant'))">
  616. <xsl:value-of select="$newline"/>
  617. <xsl:apply-templates select="."/>
  618. </xsl:when>
  619. <xsl:when test="contains(@class, ' topic/link ')">
  620. <xsl:value-of select="$newline"/>
  621. <div>
  622. <xsl:apply-templates select="."/>
  623. </div>
  624. </xsl:when>
  625. <xsl:otherwise><!-- nested linklist -->
  626. <xsl:apply-templates select="."/>
  627. </xsl:otherwise>
  628. </xsl:choose>
  629. </xsl:for-each>
  630. <xsl:apply-templates select="*[contains(@class, ' topic/linkinfo ')]"/>
  631. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  632. </xsl:template>
  633. <xsl:template match="*[contains(@class, ' topic/linkinfo ')]" name="topic.linkinfo">
  634. <xsl:apply-templates/>
  635. <br/>
  636. <xsl:value-of select="$newline"/>
  637. </xsl:template>
  638. <xsl:template match="*[contains(@class, ' topic/linklist ')]/*[contains(@class, ' topic/title ')]" name="topic.linklist_title">
  639. <strong>
  640. <xsl:apply-templates/>
  641. </strong>
  642. <br/>
  643. <xsl:value-of select="$newline"/>
  644. </xsl:template>
  645. <xsl:template match="*[contains(@class, ' topic/linklist ')]/*[contains(@class, ' topic/desc ')]" name="topic.linklist_desc">
  646. <xsl:apply-templates/>
  647. <br/>
  648. <xsl:value-of select="$newline"/>
  649. </xsl:template>
  650. <xsl:template name="linkdupinfo">
  651. <!-- Skip duplicate test for generated links -->
  652. <xsl:if test="ancestor::*[contains(@class, ' topic/related-links ')]">
  653. <xsl:variable name="linkdup" select="key('linkdup', concat(ancestor::*[contains(@class, ' topic/related-links ')]/parent::*[contains(@class, ' topic/topic ')]/@id, ' ', @href))"/>
  654. <!-- has duplicate links and this is the first occurrance -->
  655. <xsl:if test="$linkdup[2] and generate-id(.) = generate-id($linkdup[1])">
  656. <!-- If the link is exactly the same, do not output message. The duplicate will automatically be removed. -->
  657. <xsl:if test="not(key('link', related-links:link(.))[2])">
  658. <xsl:apply-templates select="." mode="ditamsg:link-may-be-duplicate"/>
  659. </xsl:if>
  660. </xsl:if>
  661. </xsl:if>
  662. </xsl:template>
  663. <!-- Match an xref or link and add hover help.
  664. Normal treatment: if desc is present and not empty, create hovertext.
  665. Using title (for next/previous links, etc): always create, use title or target. -->
  666. <xsl:template match="*" mode="add-desc-as-hoverhelp">
  667. <xsl:param name="hovertext"/>
  668. <xsl:variable name="h">
  669. <xsl:choose>
  670. <xsl:when test="normalize-space($hovertext)">
  671. <xsl:value-of select="$hovertext"/>
  672. </xsl:when>
  673. <xsl:otherwise>
  674. <xsl:apply-templates select="*[contains(@class, ' topic/desc ')][1]" mode="text-only"/>
  675. </xsl:otherwise>
  676. </xsl:choose>
  677. </xsl:variable>
  678. <xsl:if test="normalize-space($h)">
  679. <xsl:attribute name="title" select="normalize-space($h)"/>
  680. </xsl:if>
  681. </xsl:template>
  682. <xsl:template match="*" mode="add-title-as-hoverhelp">
  683. <!--use link element's linktext as hoverhelp-->
  684. <xsl:attribute name="title">
  685. <xsl:choose>
  686. <xsl:when test="*[contains(@class, ' topic/linktext ')]">
  687. <xsl:value-of select="normalize-space(*[contains(@class, ' topic/linktext ')])"/>
  688. </xsl:when>
  689. <xsl:otherwise>
  690. <xsl:call-template name="href"/>
  691. </xsl:otherwise>
  692. </xsl:choose>
  693. </xsl:attribute>
  694. </xsl:template>
  695. <xsl:template match="*" mode="add-hoverhelp-to-child-links">
  696. <!-- By default, desc comes out inline, so no hover help is added.
  697. Can override this template to add hover help to child links. -->
  698. </xsl:template>
  699. <!-- When converting to mode template, move commonattributes out;
  700. this template is dedicated to linking based attributes, and
  701. allows the common linking set to be used when commonattributes
  702. already exists for an ancestor. -->
  703. <xsl:template match="*" mode="add-linking-attributes">
  704. <xsl:apply-templates select="." mode="add-href-attribute"/>
  705. <xsl:apply-templates select="." mode="add-link-target-attribute"/>
  706. <xsl:apply-templates select="." mode="add-custom-link-attributes"/>
  707. </xsl:template>
  708. <xsl:template match="*" mode="add-href-attribute">
  709. <xsl:if test="@href and normalize-space(@href)">
  710. <xsl:attribute name="href">
  711. <xsl:apply-templates select="." mode="determine-final-href"/>
  712. </xsl:attribute>
  713. </xsl:if>
  714. </xsl:template>
  715. <xsl:template match="*" mode="add-link-target-attribute">
  716. <xsl:if test="@scope = 'external' or @type = 'external' or ((lower-case(@format) = 'pdf') and not(@scope = 'local'))">
  717. <xsl:attribute name="target">_blank</xsl:attribute>
  718. </xsl:if>
  719. </xsl:template>
  720. <xsl:template match="*" mode="ditamsg:link-may-be-duplicate">
  721. <xsl:param name="href" select="@href" as="xs:string"/>
  722. <xsl:param name="outfile" as="xs:string">
  723. <xsl:call-template name="replace-extension">
  724. <xsl:with-param name="filename" select="$FILENAME"/>
  725. <xsl:with-param name="extension" select="$OUTEXT"/>
  726. <xsl:with-param name="ignore-fragment" select="true()"/>
  727. </xsl:call-template>
  728. </xsl:param>
  729. <xsl:call-template name="output-message">
  730. <xsl:with-param name="id" select="'DOTX043I'"/>
  731. <xsl:with-param name="msgparams">%1=<xsl:value-of select="$href"/>;%2=<xsl:value-of select="$outfile"/></xsl:with-param>
  732. </xsl:call-template>
  733. </xsl:template>
  734. </xsl:stylesheet>