topicref.xsl 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <!--
  2. This file is part of the DITA Open Toolkit project.
  3. Copyright 2007 Shawn McKenzie
  4. See the accompanying LICENSE file for applicable license.
  5. -->
  6. <!--
  7. UPDATES:
  8. 20110817 RDA Include several fixes:
  9. * Make several element tests specialization aware
  10. * Topichead with navtitle element and navtitle attribute
  11. duplicates the branch underneath
  12. * Topicref with no href or title drops the branch
  13. * Toc=no drops any nested toc=yes branches (unlike XHTML / others)
  14. *-->
  15. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  16. <xsl:variable name="quote">"</xsl:variable>
  17. <xsl:variable name="quotestring">\"</xsl:variable>
  18. <xsl:variable name="lessthan">&lt;</xsl:variable>
  19. <xsl:variable name="lessthanstring">&amp;lt;</xsl:variable>
  20. <xsl:template match="*[contains(@class, ' map/topicref ')]">
  21. <xsl:param name="parent"/>
  22. <xsl:param name="contentwin"/>
  23. <!-- <xsl:message>
  24. ####### In map/topicref for <xsl:value-of select="@href"/>, $contentwin is set to: <xsl:value-of select="$contentwin"/>
  25. </xsl:message>-->
  26. <xsl:variable name="apos">'</xsl:variable>
  27. <xsl:variable name="jsapos">\'</xsl:variable>
  28. <xsl:variable name="comma">,</xsl:variable>
  29. <xsl:variable name="empty_string" select="''"/>
  30. <xsl:variable name="self" select="generate-id()"/>
  31. <xsl:choose>
  32. <xsl:when test="ancestor-or-self::*[@toc][1]/@toc = 'no' or
  33. ancestor-or-self::*[@processing-role][1]/@processing-role = 'resource-only'">
  34. <!-- Continue to children; if they turn @toc back on, connect to the last @toc=yes parent -->
  35. <xsl:apply-templates>
  36. <xsl:with-param name="parent" select="$parent"/>
  37. <xsl:with-param name="contentwin" select="$contentwin"/>
  38. </xsl:apply-templates>
  39. </xsl:when>
  40. <xsl:when test="@href">
  41. <xsl:text>var </xsl:text>
  42. <xsl:value-of select="concat('obj', $self)"/>
  43. <xsl:text> = { label: "</xsl:text>
  44. <xsl:choose>
  45. <xsl:when test="*[contains(@class, ' map/topicmeta ')]/*[contains(@class, ' topic/navtitle ')]">
  46. <!--<xsl:message> - testing navtitle - <xsl:value-of select="topicmeta/navtitle"/></xsl:message>-->
  47. <xsl:call-template name="fix-title">
  48. <xsl:with-param name="text">
  49. <xsl:value-of select="*[contains(@class, ' map/topicmeta ')]/*[contains(@class, ' topic/navtitle ')]"/>
  50. </xsl:with-param>
  51. </xsl:call-template>
  52. </xsl:when>
  53. <xsl:when test="@navtitle">
  54. <!--<xsl:message> - testing2 navtitle - <xsl:value-of select="@navtitle"/></xsl:message>-->
  55. <xsl:call-template name="fix-title">
  56. <xsl:with-param name="text">
  57. <xsl:value-of select="@navtitle"/>
  58. </xsl:with-param>
  59. </xsl:call-template>
  60. </xsl:when>
  61. <xsl:otherwise>
  62. <!--<xsl:message> - testing3 navtitle - <xsl:value-of select="@navtitle"/></xsl:message>-->
  63. <xsl:call-template name="fix-title">
  64. <xsl:with-param name="text">
  65. <xsl:value-of select="@navtitle"/>
  66. </xsl:with-param>
  67. </xsl:call-template>
  68. </xsl:otherwise>
  69. </xsl:choose>
  70. <xsl:text>", href:"</xsl:text>
  71. <xsl:call-template name="gethref">
  72. <xsl:with-param name="ditahref" select="@href"/>
  73. </xsl:call-template>
  74. <xsl:text>", target:"</xsl:text><xsl:value-of select="$contentwin"/><xsl:text>" };
  75. </xsl:text>
  76. <xsl:text>var </xsl:text>
  77. <xsl:value-of select="$self"/>
  78. <xsl:text> = new YAHOO.widget.TextNode(</xsl:text>
  79. <xsl:value-of select="concat('obj', $self)"/>
  80. <xsl:text>, </xsl:text>
  81. <xsl:value-of select="$parent"/>
  82. <xsl:text>, false);</xsl:text>
  83. <xsl:apply-templates>
  84. <xsl:with-param name="parent" select="$self"/>
  85. <xsl:with-param name="contentwin" select="$contentwin"/>
  86. </xsl:apply-templates>
  87. </xsl:when>
  88. <xsl:when test="*[contains(@class, ' map/topicmeta ')]/*[contains(@class, ' topic/navtitle ')]">
  89. <!-- No href, has a navtitle element. Used in DITA-OT 1.5 and later. -->
  90. <xsl:text>var </xsl:text>
  91. <xsl:value-of select="$self"/>
  92. <xsl:text> = new YAHOO.widget.TextNode("</xsl:text>
  93. <xsl:value-of select="*[contains(@class, ' map/topicmeta ')]/*[contains(@class, ' topic/navtitle ')]"/>
  94. <xsl:text>", </xsl:text>
  95. <xsl:value-of select="$parent"/>
  96. <xsl:text>, false);</xsl:text>
  97. <xsl:apply-templates>
  98. <xsl:with-param name="parent" select="$self"/>
  99. <xsl:with-param name="contentwin" select="$contentwin"/>
  100. </xsl:apply-templates>
  101. </xsl:when>
  102. <xsl:when test="@navtitle">
  103. <!-- No href, has navtitle attribute. -->
  104. <xsl:text>var </xsl:text>
  105. <xsl:value-of select="$self"/>
  106. <xsl:text> = new YAHOO.widget.TextNode("</xsl:text>
  107. <xsl:value-of select="@navtitle"/>
  108. <xsl:text>", </xsl:text>
  109. <xsl:value-of select="$parent"/>
  110. <xsl:text>, false);</xsl:text>
  111. <xsl:apply-templates>
  112. <xsl:with-param name="parent" select="$self"/>
  113. <xsl:with-param name="contentwin" select="$contentwin"/>
  114. </xsl:apply-templates>
  115. </xsl:when>
  116. <xsl:otherwise>
  117. <!-- Topicgroup or similar (no href, no title): continue to children -->
  118. <xsl:apply-templates>
  119. <xsl:with-param name="parent" select="$parent"/>
  120. <xsl:with-param name="contentwin" select="$contentwin"/>
  121. </xsl:apply-templates>
  122. </xsl:otherwise>
  123. </xsl:choose>
  124. </xsl:template>
  125. <!-- Remove known problem characters " and < from TOC -->
  126. <xsl:template name="fix-title">
  127. <xsl:param name="text"/>
  128. <xsl:choose>
  129. <xsl:when test="contains($text,$quote) and contains($text,$lessthan)">
  130. <xsl:variable name="chopquote">
  131. <xsl:call-template name="replace-string">
  132. <xsl:with-param name="text" select="$text"/>
  133. <xsl:with-param name="from" select="$quote"/>
  134. <xsl:with-param name="to" select="$quotestring"/>
  135. </xsl:call-template>
  136. </xsl:variable>
  137. <xsl:call-template name="replace-string">
  138. <xsl:with-param name="text" select="$chopquote"/>
  139. <xsl:with-param name="from" select="$lessthan"/>
  140. <xsl:with-param name="to" select="$lessthanstring"/>
  141. </xsl:call-template>
  142. </xsl:when>
  143. <xsl:when test="contains($text,$quote)">
  144. <xsl:call-template name="replace-string">
  145. <xsl:with-param name="text" select="$text"/>
  146. <xsl:with-param name="from" select="$quote"/>
  147. <xsl:with-param name="to" select="$quotestring"/>
  148. </xsl:call-template>
  149. </xsl:when>
  150. <xsl:when test="contains($text,$lessthan)">
  151. <xsl:call-template name="replace-string">
  152. <xsl:with-param name="text" select="$text"/>
  153. <xsl:with-param name="from" select="$lessthan"/>
  154. <xsl:with-param name="to" select="$lessthanstring"/>
  155. </xsl:call-template>
  156. </xsl:when>
  157. <xsl:otherwise>
  158. <xsl:value-of select="$text"/>
  159. </xsl:otherwise>
  160. </xsl:choose>
  161. </xsl:template>
  162. <xsl:template name="replace-string">
  163. <xsl:param name="text"/>
  164. <xsl:param name="from"/>
  165. <xsl:param name="to"/>
  166. <xsl:choose>
  167. <xsl:when test="contains($text, $from)">
  168. <xsl:variable name="before" select="substring-before($text, $from)"/>
  169. <xsl:variable name="after" select="substring-after($text, $from)"/>
  170. <xsl:variable name="prefix" select="concat($before, $to)"/>
  171. <xsl:value-of select="$before"/>
  172. <xsl:value-of select="$to"/>
  173. <xsl:call-template name="replace-string">
  174. <xsl:with-param name="text" select="$after"/>
  175. <xsl:with-param name="from" select="$from"/>
  176. <xsl:with-param name="to" select="$to"/>
  177. </xsl:call-template>
  178. </xsl:when>
  179. <xsl:otherwise>
  180. <xsl:value-of select="$text"/>
  181. </xsl:otherwise>
  182. </xsl:choose>
  183. </xsl:template>
  184. </xsl:stylesheet>