rel-links.xsl 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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. <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:for-each>
  126. </xsl:template>
  127. <!--create prerequisite links with all dups eliminated. -->
  128. <xsl:template match="*[contains(@class, ' topic/related-links ')]" mode="prereqs">
  129. <!--if there are any prereqs create a list with dups-->
  130. <!--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-->
  131. <xsl:variable name="prereqs"
  132. select="descendant::*[generate-id(.) = generate-id(key('link', related-links:link(.))[1])]
  133. [@href]
  134. [@importance = 'required' and (empty(@role) or @role = ('sibling', 'friend', 'previous', 'cousin'))]
  135. [not(ancestor::*[contains(@class, ' topic/linklist ')])]"/>
  136. <xsl:if test="exists($prereqs)">
  137. <dl class="prereqlinks">
  138. <dt class="prereq">
  139. <xsl:call-template name="getVariable">
  140. <xsl:with-param name="id" select="'Prerequisites'"/>
  141. </xsl:call-template>
  142. </dt>
  143. <xsl:apply-templates select="$prereqs" mode="prereqs"/>
  144. </dl>
  145. </xsl:if>
  146. </xsl:template>
  147. <xsl:attribute-set name="navigation">
  148. <xsl:attribute name="role">navigation</xsl:attribute>
  149. </xsl:attribute-set>
  150. <!--main template for setting up all links after the body - applied to the related-links container-->
  151. <xsl:template match="*[contains(@class, ' topic/related-links ')]" name="topic.related-links">
  152. <nav xsl:use-attribute-sets="navigation">
  153. <xsl:call-template name="commonattributes"/>
  154. <xsl:if test="$include.roles = ('child', 'descendant')">
  155. <xsl:call-template name="ul-child-links"/>
  156. <!--handle child/descendants outside of linklists in collection-type=unordered or choice-->
  157. <xsl:call-template name="ol-child-links"/>
  158. <!--handle child/descendants outside of linklists in collection-type=ordered/sequence-->
  159. </xsl:if>
  160. <xsl:if test="$include.roles = ('next', 'previous', 'parent')">
  161. <xsl:call-template name="next-prev-parent-links"/>
  162. <!--handle next and previous links-->
  163. </xsl:if>
  164. <!-- Group all unordered links (which have not already been handled by prior sections). Skip duplicate links. -->
  165. <!-- NOTE: The actual grouping code for related-links:group-unordered-links is common between
  166. transform types, and is located in ../common/related-links.xsl. Actual code for
  167. creating group titles and formatting links is located in XSL files specific to each type. -->
  168. <xsl:variable name="unordered-links" as="element()*">
  169. <xsl:apply-templates select="." mode="related-links:group-unordered-links">
  170. <xsl:with-param name="nodes"
  171. select="descendant::*[contains(@class, ' topic/link ')]
  172. [not(related-links:omit-from-unordered-links(.))]
  173. [generate-id(.) = generate-id(key('hideduplicates', related-links:hideduplicates(.))[1])]"/>
  174. </xsl:apply-templates>
  175. </xsl:variable>
  176. <xsl:apply-templates select="$unordered-links">
  177. <xsl:with-param name="root" select="root()" as="document-node()" tunnel="yes"/>
  178. </xsl:apply-templates>
  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. <ul class="ullinks">
  193. <!--once you've tested that at least one child/descendant exists, apply templates to only the unique ones-->
  194. <xsl:apply-templates select="$children[generate-id(.) = generate-id(key('link', related-links:link(.))[1])]"/>
  195. </ul>
  196. </xsl:if>
  197. </xsl:template>
  198. <!--children links - handle all child or descendant links in ordered collection-types.
  199. Children are displayed in a numbered list, with the target title as the cmd and the shortdesc as info, like a task.
  200. -->
  201. <xsl:template name="ol-child-links">
  202. <xsl:variable name="children"
  203. select="descendant::*[contains(@class, ' topic/link ')]
  204. [@role = ('child', 'descendant')]
  205. [parent::*/@collection-type = 'sequence']
  206. [not(ancestor::*[contains(@class, ' topic/linklist ')])]"/>
  207. <xsl:if test="$children">
  208. <ol class="olchildlinks">
  209. <!--once you've tested that at least one child/descendant exists, apply templates to only the unique ones-->
  210. <xsl:apply-templates select="$children[generate-id(.) = generate-id(key('link', related-links:link(.))[1])]"/>
  211. </ol>
  212. </xsl:if>
  213. </xsl:template>
  214. <!--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-->
  215. <xsl:template name="next-prev-parent-links">
  216. <xsl:for-each select="descendant::*[contains(@class, ' topic/link ')]
  217. [@role = ('parent', 'next', 'previous') and
  218. generate-id(.) = generate-id(key('link', related-links:link(.))[1])]/parent::*">
  219. <div class="familylinks">
  220. <xsl:if test="$NOPARENTLINK = 'no' and $include.roles = 'parent'">
  221. <xsl:choose>
  222. <xsl:when test="*[@href][@role = 'parent']">
  223. <xsl:for-each select="*[@href][@role = 'parent']">
  224. <div class="parentlink">
  225. <xsl:apply-templates select="."/>
  226. </div>
  227. </xsl:for-each>
  228. </xsl:when>
  229. <xsl:otherwise>
  230. <xsl:for-each select="*[@href][@role = 'ancestor'][last()]">
  231. <div class="parentlink">
  232. <xsl:call-template name="parentlink"/>
  233. </div>
  234. </xsl:for-each>
  235. </xsl:otherwise>
  236. </xsl:choose>
  237. </xsl:if>
  238. <xsl:if test="$include.roles = 'previous'">
  239. <xsl:for-each select="*[@href][@role = 'previous']">
  240. <div class="previouslink">
  241. <xsl:apply-templates select="."/>
  242. </div>
  243. </xsl:for-each>
  244. </xsl:if>
  245. <xsl:if test="$include.roles = 'next'">
  246. <xsl:for-each select="*[@href][@role = 'next']">
  247. <div class="nextlink">
  248. <xsl:apply-templates select="."/>
  249. </div>
  250. </xsl:for-each>
  251. </xsl:if>
  252. </div>
  253. </xsl:for-each>
  254. </xsl:template>
  255. <!-- Override no-name group wrapper template for HTML: output "Related Information" in a <linklist>. -->
  256. <xsl:template match="*[contains(@class, ' topic/link ')]" mode="related-links:result-group" name="related-links:group-result."
  257. as="element()">
  258. <xsl:param name="links" as="node()*"/>
  259. <xsl:if test="exists($links)">
  260. <linklist class="- topic/linklist " outputclass="relinfo">
  261. <xsl:copy-of select="ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
  262. <title class="- topic/title ">
  263. <xsl:call-template name="getVariable">
  264. <xsl:with-param name="id" select="'Related information'"/>
  265. </xsl:call-template>
  266. </title>
  267. <xsl:copy-of select="$links"/>
  268. </linklist>
  269. </xsl:if>
  270. </xsl:template>
  271. <!-- Links with @type="topic" belong in no-name group. -->
  272. <xsl:template match="*[contains(@class, ' topic/link ')][@type = 'topic']" mode="related-links:get-group-priority"
  273. name="related-links:group-priority.topic" priority="2"
  274. as="xs:integer">
  275. <xsl:call-template name="related-links:group-priority."/>
  276. </xsl:template>
  277. <xsl:template match="*[contains(@class, ' topic/link ')][@type = 'topic']" mode="related-links:get-group"
  278. name="related-links:group.topic" priority="2"
  279. as="xs:string">
  280. <xsl:call-template name="related-links:group."/>
  281. </xsl:template>
  282. <xsl:template match="*[contains(@class, ' topic/link ')][@type = 'topic']" mode="related-links:result-group"
  283. name="related-links:group-result.topic" priority="2">
  284. <xsl:param name="links" as="node()*"/>
  285. <xsl:call-template name="related-links:group-result.">
  286. <xsl:with-param name="links" select="$links"/>
  287. </xsl:call-template>
  288. </xsl:template>
  289. <!--calculate href-->
  290. <xsl:template name="href">
  291. <xsl:apply-templates select="." mode="determine-final-href"/>
  292. </xsl:template>
  293. <xsl:template match="*" mode="determine-final-href">
  294. <xsl:choose>
  295. <xsl:when test="not(normalize-space(@href)) or empty(@href)"/>
  296. <!-- For non-DITA formats - use the href as is -->
  297. <xsl:when test="(empty(@format) and @scope = 'external') or (@format and not(@format = 'dita'))">
  298. <xsl:value-of select="@href"/>
  299. </xsl:when>
  300. <!-- For DITA - process the internal href -->
  301. <xsl:when test="starts-with(@href, '#')">
  302. <xsl:text>#</xsl:text>
  303. <xsl:value-of select="dita-ot:generate-id(dita-ot:get-topic-id(@href), dita-ot:get-element-id(@href))"/>
  304. </xsl:when>
  305. <!-- It's to a DITA file - process the file name (adding the html extension)
  306. and process the rest of the href -->
  307. <xsl:when test="(empty(@scope) or @scope = ('local', 'peer')) and (empty(@format) or @format = 'dita')">
  308. <xsl:call-template name="replace-extension">
  309. <xsl:with-param name="filename" select="@href"/>
  310. <xsl:with-param name="extension" select="$OUTEXT"/>
  311. <xsl:with-param name="ignore-fragment" select="true()"/>
  312. </xsl:call-template>
  313. <xsl:if test="contains(@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:if>
  317. </xsl:when>
  318. <xsl:otherwise>
  319. <xsl:apply-templates select="." mode="ditamsg:unknown-extension"/>
  320. <xsl:value-of select="@href"/>
  321. </xsl:otherwise>
  322. </xsl:choose>
  323. </xsl:template>
  324. <!--breadcrumb template: next, prev-->
  325. <xsl:template match="*[contains(@class, ' topic/link ')][@role = ('next', 'previous')]" mode="breadcrumb">
  326. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  327. <a>
  328. <xsl:call-template name="commonattributes"/>
  329. <xsl:apply-templates select="." mode="add-linking-attributes"/>
  330. <xsl:apply-templates select="." mode="add-title-as-hoverhelp"/>
  331. <!-- Allow for unknown metadata (future-proofing) -->
  332. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  333. <!--use string as output link text for now, use image eventually-->
  334. <xsl:choose>
  335. <xsl:when test="@role = 'next'">
  336. <xsl:call-template name="getVariable">
  337. <xsl:with-param name="id" select="'Next topic'"/>
  338. </xsl:call-template>
  339. </xsl:when>
  340. <xsl:when test="@role = 'previous'">
  341. <xsl:call-template name="getVariable">
  342. <xsl:with-param name="id" select="'Previous topic'"/>
  343. </xsl:call-template>
  344. </xsl:when>
  345. <xsl:otherwise><!--both role values tested - no otherwise--></xsl:otherwise>
  346. </xsl:choose>
  347. </a>
  348. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  349. </xsl:template>
  350. <!--prereq template-->
  351. <xsl:template mode="prereqs" match="*[contains(@class, ' topic/link ')]" priority="2">
  352. <dd>
  353. <!-- Allow for unknown metadata (future-proofing) -->
  354. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  355. <xsl:call-template name="makelink"/>
  356. </dd>
  357. </xsl:template>
  358. <!--plain templates: next, prev, ancestor/parent, children, everything else-->
  359. <xsl:template name="nextlink" match="*[contains(@class, ' topic/link ')][@role = 'next']" priority="2">
  360. <strong>
  361. <!-- Allow for unknown metadata (future-proofing) -->
  362. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  363. <xsl:call-template name="getVariable">
  364. <xsl:with-param name="id" select="'Next topic'"/>
  365. </xsl:call-template>
  366. <xsl:call-template name="getVariable">
  367. <xsl:with-param name="id" select="'ColonSymbol'"/>
  368. </xsl:call-template>
  369. </strong>
  370. <xsl:text> </xsl:text>
  371. <xsl:call-template name="makelink"/>
  372. </xsl:template>
  373. <xsl:template name="prevlink" match="*[contains(@class, ' topic/link ')][@role = 'previous']" priority="2">
  374. <strong>
  375. <!-- Allow for unknown metadata (future-proofing) -->
  376. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  377. <xsl:call-template name="getVariable">
  378. <xsl:with-param name="id" select="'Previous topic'"/>
  379. </xsl:call-template>
  380. <xsl:call-template name="getVariable">
  381. <xsl:with-param name="id" select="'ColonSymbol'"/>
  382. </xsl:call-template>
  383. </strong>
  384. <xsl:text> </xsl:text>
  385. <xsl:call-template name="makelink"/>
  386. </xsl:template>
  387. <xsl:template name="parentlink" match="*[contains(@class, ' topic/link ')][@role = 'parent']" priority="2">
  388. <strong>
  389. <!-- Allow for unknown metadata (future-proofing) -->
  390. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  391. <xsl:call-template name="getVariable">
  392. <xsl:with-param name="id" select="'Parent topic'"/>
  393. </xsl:call-template>
  394. <xsl:call-template name="getVariable">
  395. <xsl:with-param name="id" select="'ColonSymbol'"/>
  396. </xsl:call-template>
  397. </strong>
  398. <xsl:text> </xsl:text>
  399. <xsl:call-template name="makelink"/>
  400. </xsl:template>
  401. <!--basic child processing-->
  402. <xsl:template match="*[contains(@class, ' topic/link ')][@role = ('child', 'descendant')]" priority="2" name="topic.link_child">
  403. <li class="ulchildlink">
  404. <xsl:call-template name="commonattributes">
  405. <xsl:with-param name="default-output-class" select="'ulchildlink'"/>
  406. </xsl:call-template>
  407. <!-- Allow for unknown metadata (future-proofing) -->
  408. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  409. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  410. <strong>
  411. <xsl:apply-templates select="." mode="related-links:unordered.child.prefix"/>
  412. <xsl:apply-templates select="." mode="add-link-highlight-at-start"/>
  413. <a>
  414. <xsl:apply-templates select="." mode="add-linking-attributes"/>
  415. <xsl:apply-templates select="." mode="add-hoverhelp-to-child-links"/>
  416. <!--use linktext as linktext if it exists, otherwise use href as linktext-->
  417. <xsl:choose>
  418. <xsl:when test="*[contains(@class, ' topic/linktext ')]">
  419. <xsl:apply-templates select="*[contains(@class, ' topic/linktext ')]"/>
  420. </xsl:when>
  421. <xsl:otherwise>
  422. <!--use href-->
  423. <xsl:call-template name="href"/>
  424. </xsl:otherwise>
  425. </xsl:choose>
  426. </a>
  427. <xsl:apply-templates select="." mode="add-link-highlight-at-end"/>
  428. </strong>
  429. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  430. <br/>
  431. <!--add the description on the next line, like a summary-->
  432. <xsl:apply-templates select="*[contains(@class, ' topic/desc ')]"/>
  433. </li>
  434. </xsl:template>
  435. <!--ordered child processing-->
  436. <xsl:template match="*[@collection-type = 'sequence']/*[contains(@class, ' topic/link ')][@role = ('child', 'descendant')]" priority="3" name="topic.link_orderedchild">
  437. <li class="olchildlink">
  438. <xsl:call-template name="commonattributes">
  439. <xsl:with-param name="default-output-class" select="'olchildlink'"/>
  440. </xsl:call-template>
  441. <!-- Allow for unknown metadata (future-proofing) -->
  442. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  443. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  444. <xsl:apply-templates select="." mode="related-links:ordered.child.prefix"/>
  445. <xsl:apply-templates select="." mode="add-link-highlight-at-start"/>
  446. <a>
  447. <xsl:apply-templates select="." mode="add-linking-attributes"/>
  448. <xsl:apply-templates select="." mode="add-hoverhelp-to-child-links"/>
  449. <!--use linktext as linktext if it exists, otherwise use href as linktext-->
  450. <xsl:choose>
  451. <xsl:when test="*[contains(@class, ' topic/linktext ')]">
  452. <xsl:apply-templates select="*[contains(@class, ' topic/linktext ')]"/>
  453. </xsl:when>
  454. <xsl:otherwise>
  455. <!--use href-->
  456. <xsl:call-template name="href"/>
  457. </xsl:otherwise>
  458. </xsl:choose>
  459. </a>
  460. <xsl:apply-templates select="." mode="add-link-highlight-at-end"/>
  461. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  462. <br/>
  463. <!--add the description on a new line, unlike an info, to avoid issues with punctuation (adding a period)-->
  464. <xsl:apply-templates select="*[contains(@class, ' topic/desc ')]"/>
  465. </li>
  466. </xsl:template>
  467. <xsl:template match="*[contains(@class, ' topic/link ')]" name="topic.link">
  468. <xsl:if test="(@role and $include.roles = @role) or
  469. (empty(@role) and $include.roles = '#default')">
  470. <xsl:choose>
  471. <!-- Linklist links put out <br/> in "processlinklist" -->
  472. <xsl:when test="ancestor::*[contains(@class, ' topic/linklist ')]">
  473. <li class="linklist"><xsl:call-template name="makelink"/></li>
  474. </xsl:when>
  475. <!-- Ancestor links go in the breadcrumb trail, and should not get a <br/> -->
  476. <xsl:when test="@role = 'ancestor'">
  477. <xsl:call-template name="makelink"/>
  478. </xsl:when>
  479. <!-- Items with these roles should always go to output, and are not included in the hideduplicates key. -->
  480. <xsl:when test="@role and not(@role = ('cousin', 'external', 'friend', 'other', 'sample', 'sibling'))">
  481. <div>
  482. <xsl:call-template name="makelink"/>
  483. </div>
  484. </xsl:when>
  485. <!-- If roles do not match, but nearly everything else does, skip the link. -->
  486. <xsl:when test="key('hideduplicates', related-links:hideduplicates(.))[2]">
  487. <xsl:choose>
  488. <xsl:when test="generate-id(.) = generate-id(key('hideduplicates', related-links:hideduplicates(.))[1])">
  489. <div>
  490. <xsl:call-template name="makelink"/>
  491. </div>
  492. </xsl:when>
  493. <!-- If this is filtered out, we may need the duplicate link message anyway. -->
  494. <xsl:otherwise>
  495. <xsl:call-template name="linkdupinfo"/>
  496. </xsl:otherwise>
  497. </xsl:choose>
  498. </xsl:when>
  499. <xsl:otherwise>
  500. <div>
  501. <xsl:call-template name="makelink"/>
  502. </div>
  503. </xsl:otherwise>
  504. </xsl:choose>
  505. </xsl:if>
  506. </xsl:template>
  507. <!--creating the actual link-->
  508. <xsl:template name="makelink">
  509. <xsl:call-template name="linkdupinfo"/>
  510. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  511. <xsl:apply-templates select="." mode="add-link-highlight-at-start"/>
  512. <a>
  513. <xsl:call-template name="commonattributes"/>
  514. <xsl:apply-templates select="." mode="add-linking-attributes"/>
  515. <xsl:apply-templates select="." mode="add-desc-as-hoverhelp"/>
  516. <!-- Allow for unknown metadata (future-proofing) -->
  517. <xsl:apply-templates select="*[contains(@class, ' topic/data ') or contains(@class, ' topic/foreign ')]"/>
  518. <!--use linktext as linktext if it exists, otherwise use href as linktext-->
  519. <xsl:choose>
  520. <xsl:when test="*[contains(@class, ' topic/linktext ')]">
  521. <xsl:apply-templates select="*[contains(@class, ' topic/linktext ')]"/>
  522. </xsl:when>
  523. <xsl:otherwise>
  524. <!--use href-->
  525. <xsl:call-template name="href"/>
  526. </xsl:otherwise>
  527. </xsl:choose>
  528. </a>
  529. <xsl:apply-templates select="." mode="add-link-highlight-at-end"/>
  530. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  531. </xsl:template>
  532. <!--process linktext elements by explicitly ignoring them and applying templates to their content; otherwise flagged as unprocessed content by the dit2htm transform-->
  533. <xsl:template match="*[contains(@class, ' topic/linktext ')]" name="topic.linktext">
  534. <xsl:apply-templates select="* | text()"/>
  535. </xsl:template>
  536. <!--process link desc by explicitly ignoring them and applying templates to their content; otherwise flagged as unprocessed content by the dit2htm transform-->
  537. <xsl:template match="*[contains(@class, ' topic/link ')]/*[contains(@class, ' topic/desc ')]" name="topic.link_desc">
  538. <xsl:apply-templates select="* | text()"/>
  539. </xsl:template>
  540. <!--linklists-->
  541. <xsl:template match="*[contains(@class, ' topic/linklist ')]/@xml:lang" priority="100">
  542. <xsl:variable name="ancestorLang" select="parent::*/ancestor::*[@xml:lang][1]/@xml:lang" as="attribute()?"/>
  543. <xsl:if test="(empty($ancestorLang) and .!=$DEFAULTLANG) or
  544. .!=$ancestorLang">
  545. <xsl:next-match/>
  546. </xsl:if>
  547. </xsl:template>
  548. <xsl:template match="*[contains(@class, ' topic/linklist ')]" name="topic.linklist">
  549. <xsl:choose>
  550. <!-- if this is a first-level linklist with no child links in it, put it in a div (flush left)-->
  551. <xsl:when test="(empty(parent::*) or parent::*[contains(@class, ' topic/related-links ')])
  552. and not(child::*[contains(@class, ' topic/link ')][@role = ('child', 'descendant')])">
  553. <div class="linklist">
  554. <xsl:apply-templates select="." mode="processlinklist"/>
  555. </div>
  556. </xsl:when>
  557. <!-- When it contains children, indent with child class -->
  558. <xsl:when test="child::*[contains(@class, ' topic/link ')][@role = ('child', 'descendant')]">
  559. <div class="linklistwithchild">
  560. <xsl:apply-templates select="." mode="processlinklist">
  561. <xsl:with-param name="default-list-type" select="'linklistwithchild'"/>
  562. </xsl:apply-templates>
  563. </div>
  564. </xsl:when>
  565. <!-- It is a nested linklist, indent with other class -->
  566. <xsl:otherwise>
  567. <div class="sublinklist">
  568. <xsl:apply-templates select="." mode="processlinklist">
  569. <xsl:with-param name="default-list-type" select="'sublinklist'"/>
  570. </xsl:apply-templates>
  571. </div>
  572. </xsl:otherwise>
  573. </xsl:choose>
  574. </xsl:template>
  575. <xsl:template match="*" mode="processlinklist">
  576. <xsl:param name="default-list-type" select="'linklist'" as="xs:string"/>
  577. <xsl:call-template name="commonattributes">
  578. <xsl:with-param name="default-output-class" select="$default-list-type"/>
  579. </xsl:call-template>
  580. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  581. <xsl:apply-templates select="*[contains(@class, ' topic/title ')]"/>
  582. <xsl:apply-templates select="*[contains(@class, ' topic/desc ')]"/>
  583. <xsl:if test="exists(*[contains(@class, ' topic/linklist ')] | *[contains(@class, ' topic/link ')])">
  584. <ul class="linklist">
  585. <xsl:for-each select="*[contains(@class, ' topic/linklist ')] | *[contains(@class, ' topic/link ')]">
  586. <xsl:choose>
  587. <!-- for children, li wrapper is created in main template -->
  588. <xsl:when test="contains(@class, ' topic/link ') and (@role = ('child', 'descendant'))">
  589. <xsl:apply-templates select="."/>
  590. </xsl:when>
  591. <xsl:when test="contains(@class, ' topic/link ')">
  592. <xsl:apply-templates select="."/>
  593. </xsl:when>
  594. <xsl:otherwise><!-- nested linklist -->
  595. <li class="sublinklist"><xsl:apply-templates select="."/></li>
  596. </xsl:otherwise>
  597. </xsl:choose>
  598. </xsl:for-each>
  599. </ul>
  600. </xsl:if>
  601. <xsl:apply-templates select="*[contains(@class, ' topic/linkinfo ')]"/>
  602. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  603. </xsl:template>
  604. <xsl:template match="*[contains(@class, ' topic/linkinfo ')]" name="topic.linkinfo">
  605. <xsl:apply-templates/>
  606. <br/>
  607. </xsl:template>
  608. <xsl:template match="*[contains(@class, ' topic/linklist ')]/*[contains(@class, ' topic/title ')]" name="topic.linklist_title">
  609. <strong>
  610. <xsl:apply-templates/>
  611. </strong>
  612. <br/>
  613. </xsl:template>
  614. <xsl:template match="*[contains(@class, ' topic/linklist ')]/*[contains(@class, ' topic/desc ')]" name="topic.linklist_desc">
  615. <xsl:apply-templates/>
  616. <br/>
  617. </xsl:template>
  618. <xsl:template name="linkdupinfo">
  619. <!-- Skip duplicate test for generated links -->
  620. <xsl:if test="ancestor::*[contains(@class, ' topic/related-links ')]">
  621. <xsl:variable name="linkdup" select="key('linkdup', concat(ancestor::*[contains(@class, ' topic/related-links ')]/parent::*[contains(@class, ' topic/topic ')]/@id, ' ', @href))"/>
  622. <!-- has duplicate links and this is the first occurrance -->
  623. <xsl:if test="$linkdup[2] and generate-id(.) = generate-id($linkdup[1])">
  624. <!-- If the link is exactly the same, do not output message. The duplicate will automatically be removed. -->
  625. <xsl:if test="not(key('link', related-links:link(.))[2])">
  626. <xsl:apply-templates select="." mode="ditamsg:link-may-be-duplicate"/>
  627. </xsl:if>
  628. </xsl:if>
  629. </xsl:if>
  630. </xsl:template>
  631. <!-- Match an xref or link and add hover help.
  632. Normal treatment: if desc is present and not empty, create hovertext.
  633. Using title (for next/previous links, etc): always create, use title or target. -->
  634. <xsl:template match="*" mode="add-desc-as-hoverhelp">
  635. <xsl:param name="hovertext"/>
  636. <xsl:variable name="h">
  637. <xsl:choose>
  638. <xsl:when test="normalize-space($hovertext)">
  639. <xsl:value-of select="$hovertext"/>
  640. </xsl:when>
  641. <xsl:otherwise>
  642. <xsl:apply-templates select="*[contains(@class, ' topic/desc ')][1]" mode="text-only"/>
  643. </xsl:otherwise>
  644. </xsl:choose>
  645. </xsl:variable>
  646. <xsl:if test="normalize-space($h)">
  647. <xsl:attribute name="title" select="normalize-space($h)"/>
  648. </xsl:if>
  649. </xsl:template>
  650. <xsl:template match="*" mode="add-title-as-hoverhelp">
  651. <!--use link element's linktext as hoverhelp-->
  652. <xsl:attribute name="title">
  653. <xsl:choose>
  654. <xsl:when test="*[contains(@class, ' topic/linktext ')]">
  655. <xsl:value-of select="normalize-space(*[contains(@class, ' topic/linktext ')])"/>
  656. </xsl:when>
  657. <xsl:otherwise>
  658. <xsl:call-template name="href"/>
  659. </xsl:otherwise>
  660. </xsl:choose>
  661. </xsl:attribute>
  662. </xsl:template>
  663. <xsl:template match="*" mode="add-hoverhelp-to-child-links">
  664. <!-- By default, desc comes out inline, so no hover help is added.
  665. Can override this template to add hover help to child links. -->
  666. </xsl:template>
  667. <!-- When converting to mode template, move commonattributes out;
  668. this template is dedicated to linking based attributes, and
  669. allows the common linking set to be used when commonattributes
  670. already exists for an ancestor. -->
  671. <xsl:template match="*" mode="add-linking-attributes">
  672. <xsl:apply-templates select="." mode="add-href-attribute"/>
  673. <xsl:apply-templates select="." mode="add-link-target-attribute"/>
  674. <xsl:apply-templates select="." mode="add-custom-link-attributes"/>
  675. </xsl:template>
  676. <xsl:template match="*" mode="add-href-attribute">
  677. <xsl:if test="@href and normalize-space(@href)">
  678. <xsl:attribute name="href">
  679. <xsl:apply-templates select="." mode="determine-final-href"/>
  680. </xsl:attribute>
  681. </xsl:if>
  682. </xsl:template>
  683. <xsl:template match="*" mode="add-link-target-attribute">
  684. <xsl:if test="@scope = 'external' or @type = 'external' or ((lower-case(@format) = 'pdf') and not(@scope = 'local'))">
  685. <xsl:attribute name="target">_blank</xsl:attribute>
  686. </xsl:if>
  687. </xsl:template>
  688. <xsl:template match="*" mode="ditamsg:link-may-be-duplicate">
  689. <xsl:param name="href" select="@href" as="xs:string"/>
  690. <xsl:param name="outfile" as="xs:string">
  691. <xsl:call-template name="replace-extension">
  692. <xsl:with-param name="filename" select="$FILENAME"/>
  693. <xsl:with-param name="extension" select="$OUTEXT"/>
  694. <xsl:with-param name="ignore-fragment" select="true()"/>
  695. </xsl:call-template>
  696. </xsl:param>
  697. <xsl:call-template name="output-message">
  698. <xsl:with-param name="id" select="'DOTX043I'"/>
  699. <xsl:with-param name="msgparams">%1=<xsl:value-of select="$href"/>;%2=<xsl:value-of select="$outfile"/></xsl:with-param>
  700. </xsl:call-template>
  701. </xsl:template>
  702. </xsl:stylesheet>