map2htmlImpl.xsl 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!-- This file is part of the DITA Open Toolkit project.
  3. See the accompanying license.txt file for applicable licenses.-->
  4. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  5. xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  6. xmlns:ditamsg="http://dita-ot.sourceforge.net/ns/200704/ditamsg" version="2.0"
  7. exclude-result-prefixes="dita-ot ditamsg">
  8. <xsl:import href="plugin:org.dita.base:xsl/common/output-message.xsl"/>
  9. <xsl:import href="plugin:org.dita.base:xsl/common/dita-utilities.xsl"/>
  10. <xsl:import href="plugin:org.dita.base:xsl/common/dita-textonly.xsl"/>
  11. <!-- Deprecated since 2.3 -->
  12. <xsl:variable name="msgprefix">DOTX</xsl:variable>
  13. <xsl:param name="OUTEXT" select="'.html'"/>
  14. <xsl:param name="WORKDIR">
  15. <xsl:apply-templates select="/processing-instruction('workdir-uri')[1]" mode="get-work-dir"/>
  16. </xsl:param>
  17. <xsl:template match="*[contains(@class, ' map/map ')]" mode="toc">
  18. <xsl:param name="pathFromMaplist"/>
  19. <xsl:if test="descendant::*[contains(@class, ' map/topicref ')]
  20. [not(@toc = 'no')]
  21. [not(@processing-role = 'resource-only')]">
  22. <nav>
  23. <ul>
  24. <xsl:call-template name="commonattributes"/>
  25. <xsl:apply-templates select="*[contains(@class, ' map/topicref ')]" mode="toc">
  26. <xsl:with-param name="pathFromMaplist" select="$pathFromMaplist"/>
  27. </xsl:apply-templates>
  28. </ul>
  29. </nav>
  30. </xsl:if>
  31. </xsl:template>
  32. <xsl:template match="*[contains(@class, ' map/topicref ')]
  33. [not(@toc = 'no')]
  34. [not(@processing-role = 'resource-only')]"
  35. mode="toc">
  36. <xsl:param name="pathFromMaplist"/>
  37. <xsl:variable name="title">
  38. <xsl:apply-templates select="." mode="get-navtitle"/>
  39. </xsl:variable>
  40. <xsl:choose>
  41. <xsl:when test="normalize-space($title)">
  42. <li>
  43. <xsl:call-template name="commonattributes"/>
  44. <xsl:choose>
  45. <!-- If there is a reference to a DITA or HTML file, and it is not external: -->
  46. <xsl:when test="normalize-space(@href)">
  47. <a>
  48. <xsl:attribute name="href">
  49. <xsl:choose>
  50. <xsl:when test="@copy-to and not(contains(@chunk, 'to-content')) and
  51. (not(@format) or @format = 'dita' or @format = 'ditamap') ">
  52. <xsl:if test="not(@scope = 'external')">
  53. <xsl:value-of select="$pathFromMaplist"/>
  54. </xsl:if>
  55. <xsl:call-template name="replace-extension">
  56. <xsl:with-param name="filename" select="@copy-to"/>
  57. <xsl:with-param name="extension" select="$OUTEXT"/>
  58. </xsl:call-template>
  59. <xsl:if test="not(contains(@copy-to, '#')) and contains(@href, '#')">
  60. <xsl:value-of select="concat('#', substring-after(@href, '#'))"/>
  61. </xsl:if>
  62. </xsl:when>
  63. <xsl:when test="not(@scope = 'external') and (not(@format) or @format = 'dita' or @format = 'ditamap')">
  64. <xsl:if test="not(@scope = 'external')">
  65. <xsl:value-of select="$pathFromMaplist"/>
  66. </xsl:if>
  67. <xsl:call-template name="replace-extension">
  68. <xsl:with-param name="filename" select="@href"/>
  69. <xsl:with-param name="extension" select="$OUTEXT"/>
  70. </xsl:call-template>
  71. </xsl:when>
  72. <xsl:otherwise><!-- If non-DITA, keep the href as-is -->
  73. <xsl:if test="not(@scope = 'external')">
  74. <xsl:value-of select="$pathFromMaplist"/>
  75. </xsl:if>
  76. <xsl:value-of select="@href"/>
  77. </xsl:otherwise>
  78. </xsl:choose>
  79. </xsl:attribute>
  80. <xsl:if test="@scope = 'external' or not(not(@format) or @format = 'dita' or @format = 'ditamap')">
  81. <xsl:attribute name="target">_blank</xsl:attribute>
  82. </xsl:if>
  83. <xsl:value-of select="$title"/>
  84. </a>
  85. </xsl:when>
  86. <xsl:otherwise>
  87. <xsl:value-of select="$title"/>
  88. </xsl:otherwise>
  89. </xsl:choose>
  90. <!-- If there are any children that should be in the TOC, process them -->
  91. <xsl:if test="descendant::*[contains(@class, ' map/topicref ')]
  92. [not(@toc = 'no')]
  93. [not(@processing-role = 'resource-only')]">
  94. <ul>
  95. <xsl:apply-templates select="*[contains(@class, ' map/topicref ')]" mode="toc">
  96. <xsl:with-param name="pathFromMaplist" select="$pathFromMaplist"/>
  97. </xsl:apply-templates>
  98. </ul>
  99. </xsl:if>
  100. </li>
  101. </xsl:when>
  102. <xsl:otherwise><!-- if it is an empty topicref -->
  103. <xsl:apply-templates select="*[contains(@class, ' map/topicref ')]" mode="toc">
  104. <xsl:with-param name="pathFromMaplist" select="$pathFromMaplist"/>
  105. </xsl:apply-templates>
  106. </xsl:otherwise>
  107. </xsl:choose>
  108. </xsl:template>
  109. <!-- If toc=no, but a child has toc=yes, that child should bubble up to the top -->
  110. <xsl:template match="*[contains(@class, ' map/topicref ')]
  111. [@toc = 'no']
  112. [not(@processing-role = 'resource-only')]"
  113. mode="toc">
  114. <xsl:param name="pathFromMaplist"/>
  115. <xsl:apply-templates select="*[contains(@class, ' map/topicref ')]" mode="toc">
  116. <xsl:with-param name="pathFromMaplist" select="$pathFromMaplist"/>
  117. </xsl:apply-templates>
  118. </xsl:template>
  119. <xsl:template match="*" mode="toc" priority="-1"/>
  120. <xsl:template match="*" mode="get-navtitle">
  121. <xsl:choose>
  122. <!-- If navtitle is specified -->
  123. <xsl:when test="*[contains(@class, ' map/topicmeta ')]/*[contains(@class, ' topic/navtitle ')]">
  124. <xsl:apply-templates select="*[contains(@class, ' map/topicmeta ')]/*[contains(@class, ' topic/navtitle ')]"
  125. mode="dita-ot:text-only"/>
  126. </xsl:when>
  127. <xsl:when test="@navtitle">
  128. <xsl:value-of select="@navtitle"/>
  129. </xsl:when>
  130. <!-- If there is no title and none can be retrieved, check for <linktext> -->
  131. <xsl:when test="*[contains(@class, ' map/topicmeta ')]/*[contains(@class, ' map/linktext ')]">
  132. <xsl:apply-templates select="*[contains(@class, ' map/topicmeta ')]/*[contains(@class, ' map/linktext ')]"
  133. mode="dita-ot:text-only"/>
  134. </xsl:when>
  135. <!-- No local title, and not targeting a DITA file. Could be just a container setting
  136. metadata, or a file reference with no title. Issue message for the second case. -->
  137. <xsl:otherwise>
  138. <xsl:if test="normalize-space(@href)">
  139. <xsl:apply-templates select="." mode="ditamsg:could-not-retrieve-navtitle-using-fallback">
  140. <xsl:with-param name="target" select="@href"/>
  141. <xsl:with-param name="fallback" select="@href"/>
  142. </xsl:apply-templates>
  143. <xsl:value-of select="@href"/>
  144. </xsl:if>
  145. </xsl:otherwise>
  146. </xsl:choose>
  147. </xsl:template>
  148. <xsl:template match="*" mode="ditamsg:missing-target-file-no-navtitle">
  149. <xsl:call-template name="output-message">
  150. <xsl:with-param name="id" select="'DOTX008W'"/>
  151. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/></xsl:with-param>
  152. </xsl:call-template>
  153. </xsl:template>
  154. <xsl:template match="*" mode="ditamsg:could-not-retrieve-navtitle-using-fallback">
  155. <xsl:param name="target"/>
  156. <xsl:param name="fallback"/>
  157. <xsl:call-template name="output-message">
  158. <xsl:with-param name="id" select="'DOTX009W'"/>
  159. <xsl:with-param name="msgparams">%1=<xsl:value-of select="$target"/>;%2=<xsl:value-of select="$fallback"/></xsl:with-param>
  160. </xsl:call-template>
  161. </xsl:template>
  162. <!-- Normalize map -->
  163. <xsl:template match="/ | @* | node()" mode="normalize-map">
  164. <xsl:copy>
  165. <xsl:apply-templates select="@* | node()" mode="normalize-map"/>
  166. </xsl:copy>
  167. </xsl:template>
  168. <xsl:template match="*[contains(@class, ' mapgroup-d/topicgroup ')]" mode="normalize-map">
  169. <xsl:apply-templates select="* except *[contains(@class, ' map/topicmeta ')]" mode="normalize-map"/>
  170. </xsl:template>
  171. </xsl:stylesheet>