rel-links.xsl 37 KB

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