topicref.xsl 8.3 KB

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