rel-links.xsl 37 KB

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