map2htmtocImpl.xsl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. <!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->
  5. <xsl:stylesheet version="2.0"
  6. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  8. xmlns:ditamsg="http://dita-ot.sourceforge.net/ns/200704/ditamsg"
  9. exclude-result-prefixes="dita-ot ditamsg">
  10. <!-- Include error message template -->
  11. <xsl:import href="plugin:org.dita.base:xsl/common/output-message.xsl"/>
  12. <xsl:import href="plugin:org.dita.base:xsl/common/dita-utilities.xsl"/>
  13. <xsl:import href="plugin:org.dita.base:xsl/common/dita-textonly.xsl"/>
  14. <!-- *************************** Command line parameters *********************** -->
  15. <xsl:param name="contenttarget" select="'contentwin'"/>
  16. <xsl:param name="CSS"/>
  17. <xsl:param name="CSSPATH"/>
  18. <xsl:param name="OUTPUTCLASS"/> <!-- class to put on body element. -->
  19. <!-- the path back to the project. Used for c.gif, delta.gif, css to allow user's to have
  20. these files in 1 location. -->
  21. <xsl:param name="PATH2PROJ">
  22. <xsl:apply-templates select="/processing-instruction('path2project-uri')[1]" mode="get-path2project"/>
  23. </xsl:param>
  24. <xsl:param name="genDefMeta" select="'no'"/>
  25. <xsl:param name="YEAR" select="format-date(current-date(), '[Y]')"/>
  26. <!-- Define a newline character -->
  27. <xsl:variable name="newline"><xsl:text>
  28. </xsl:text></xsl:variable>
  29. <!-- *********************************************************************************
  30. Setup the HTML wrapper for the table of contents
  31. ********************************************************************************* -->
  32. <xsl:template match="/">
  33. <xsl:call-template name="generate-toc"/>
  34. </xsl:template>
  35. <!-- -->
  36. <xsl:template name="generate-toc">
  37. <html><xsl:value-of select="$newline"/>
  38. <head><xsl:value-of select="$newline"/>
  39. <xsl:if test="string-length($contenttarget)>0 and
  40. $contenttarget!='NONE'">
  41. <base target="{$contenttarget}"/>
  42. <xsl:value-of select="$newline"/>
  43. </xsl:if>
  44. <!-- initial meta information -->
  45. <xsl:call-template name="generateCharset"/> <!-- Set the character set to UTF-8 -->
  46. <xsl:call-template name="generateDefaultCopyright"/> <!-- Generate a default copyright, if needed -->
  47. <xsl:call-template name="generateDefaultMeta"/> <!-- Standard meta for security, robots, etc -->
  48. <xsl:call-template name="copyright"/> <!-- Generate copyright, if specified manually -->
  49. <xsl:call-template name="generateCssLinks"/> <!-- Generate links to CSS files -->
  50. <xsl:call-template name="generateMapTitle"/> <!-- Generate the <title> element -->
  51. <xsl:call-template name="gen-user-head" /> <!-- include user's XSL HEAD processing here -->
  52. <xsl:call-template name="gen-user-scripts" /> <!-- include user's XSL javascripts here -->
  53. <xsl:call-template name="gen-user-styles" /> <!-- include user's XSL style element and content here -->
  54. </head><xsl:value-of select="$newline"/>
  55. <body>
  56. <xsl:if test="string-length($OUTPUTCLASS) &gt; 0">
  57. <xsl:attribute name="class">
  58. <xsl:value-of select="$OUTPUTCLASS"/>
  59. </xsl:attribute>
  60. </xsl:if>
  61. <xsl:value-of select="$newline"/>
  62. <xsl:apply-templates mode="toc"/>
  63. </body><xsl:value-of select="$newline"/>
  64. </html>
  65. </xsl:template>
  66. <xsl:template name="generateCharset">
  67. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><xsl:value-of select="$newline"/>
  68. </xsl:template>
  69. <!-- If there is no copyright in the document, make the standard one -->
  70. <xsl:template name="generateDefaultCopyright">
  71. <xsl:if test="not(//*[contains(@class,' topic/copyright ')])">
  72. <meta name="copyright">
  73. <xsl:attribute name="content">
  74. <xsl:text>(C) </xsl:text>
  75. <xsl:call-template name="getVariable">
  76. <xsl:with-param name="id" select="'Copyright'"/>
  77. </xsl:call-template>
  78. <xsl:text> </xsl:text><xsl:value-of select="$YEAR"/>
  79. </xsl:attribute>
  80. </meta>
  81. <xsl:value-of select="$newline"/>
  82. <meta name="DC.rights.owner">
  83. <xsl:attribute name="content">
  84. <xsl:text>(C) </xsl:text>
  85. <xsl:call-template name="getVariable">
  86. <xsl:with-param name="id" select="'Copyright'"/>
  87. </xsl:call-template>
  88. <xsl:text> </xsl:text><xsl:value-of select="$YEAR"/>
  89. </xsl:attribute>
  90. </meta>
  91. <xsl:value-of select="$newline"/>
  92. </xsl:if>
  93. </xsl:template>
  94. <xsl:template name="generateDefaultMeta">
  95. <xsl:if test="$genDefMeta = 'yes'">
  96. <meta name="security" content="public" /><xsl:value-of select="$newline"/>
  97. <meta name="Robots" content="index,follow" /><xsl:value-of select="$newline"/>
  98. <xsl:text disable-output-escaping="yes">&lt;meta http-equiv="PICS-Label" content = '(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' /></xsl:text>
  99. <xsl:value-of select="$newline"/>
  100. </xsl:if>
  101. </xsl:template>
  102. <xsl:template name="copyright">
  103. </xsl:template>
  104. <xsl:template name="generateMapTitle">
  105. <!-- Title processing - special handling for short descriptions -->
  106. <xsl:if test="/*[contains(@class,' map/map ')]/*[contains(@class,' topic/title ')] or /*[contains(@class,' map/map ')]/@title">
  107. <title>
  108. <xsl:call-template name="gen-user-panel-title-pfx"/> <!-- hook for a user-XSL title prefix -->
  109. <xsl:choose>
  110. <xsl:when test="/*[contains(@class,' map/map ')]/*[contains(@class,' topic/title ')]">
  111. <xsl:value-of select="normalize-space(/*[contains(@class,' map/map ')]/*[contains(@class,' topic/title ')])"/>
  112. </xsl:when>
  113. <xsl:when test="/*[contains(@class,' map/map ')]/@title">
  114. <xsl:value-of select="/*[contains(@class,' map/map ')]/@title"/>
  115. </xsl:when>
  116. </xsl:choose>
  117. </title><xsl:value-of select="$newline"/>
  118. </xsl:if>
  119. </xsl:template>
  120. <xsl:template name="gen-user-panel-title-pfx">
  121. <xsl:apply-templates select="." mode="gen-user-panel-title-pfx"/>
  122. </xsl:template>
  123. <xsl:template match="/|node()|@*" mode="gen-user-panel-title-pfx">
  124. <!-- to customize: copy this to your override transform, add the content you want. -->
  125. <!-- It will be placed immediately after TITLE tag, in the title -->
  126. </xsl:template>
  127. <!-- Link to user CSS. -->
  128. <!-- Test for URL: returns "url" when the content starts with a URL;
  129. Otherwise, leave blank -->
  130. <xsl:template name="url-string">
  131. <xsl:param name="urltext"/>
  132. <xsl:choose>
  133. <xsl:when test="starts-with($urltext,'http://')">url</xsl:when>
  134. <xsl:when test="starts-with($urltext,'https://')">url</xsl:when>
  135. <xsl:otherwise/>
  136. </xsl:choose>
  137. </xsl:template>
  138. <!-- Can't link to commonltr.css or commonrtl.css because we don't know what language the map is in. -->
  139. <xsl:template name="generateCssLinks">
  140. <xsl:variable name="urltest">
  141. <xsl:call-template name="url-string">
  142. <xsl:with-param name="urltext">
  143. <xsl:value-of select="concat($CSSPATH,$CSS)"/>
  144. </xsl:with-param>
  145. </xsl:call-template>
  146. </xsl:variable>
  147. <xsl:if test="string-length($CSS)>0">
  148. <xsl:choose>
  149. <xsl:when test="$urltest = 'url'">
  150. <link rel="stylesheet" type="text/css" href="{$CSSPATH}{$CSS}" />
  151. </xsl:when>
  152. <xsl:otherwise>
  153. <link rel="stylesheet" type="text/css" href="{$PATH2PROJ}{$CSSPATH}{$CSS}" />
  154. </xsl:otherwise>
  155. </xsl:choose><xsl:value-of select="$newline"/>
  156. </xsl:if>
  157. </xsl:template>
  158. <!-- To be overridden by user shell. -->
  159. <xsl:template name="gen-user-head">
  160. <xsl:apply-templates select="." mode="gen-user-head"/>
  161. </xsl:template>
  162. <xsl:template match="/|node()|@*" mode="gen-user-head">
  163. <!-- to customize: copy this to your override transform, add the content you want. -->
  164. <!-- it will be placed in the HEAD section of the XHTML. -->
  165. </xsl:template>
  166. <xsl:template name="gen-user-header">
  167. <xsl:apply-templates select="." mode="gen-user-header"/>
  168. </xsl:template>
  169. <xsl:template match="/|node()|@*" mode="gen-user-header">
  170. <!-- to customize: copy this to your override transform, add the content you want. -->
  171. <!-- it will be placed in the running heading section of the XHTML. -->
  172. </xsl:template>
  173. <xsl:template name="gen-user-footer">
  174. <xsl:apply-templates select="." mode="gen-user-footer"/>
  175. </xsl:template>
  176. <xsl:template match="/|node()|@*" mode="gen-user-footer">
  177. <!-- to customize: copy this to your override transform, add the content you want. -->
  178. <!-- it will be placed in the running footing section of the XHTML. -->
  179. </xsl:template>
  180. <xsl:template name="gen-user-sidetoc">
  181. <xsl:apply-templates select="." mode="gen-user-sidetoc"/>
  182. </xsl:template>
  183. <xsl:template match="/|node()|@*" mode="gen-user-sidetoc">
  184. <!-- to customize: copy this to your override transform, add the content you want. -->
  185. <!-- Uncomment the line below to have a "freebie" table of contents on the top-right -->
  186. </xsl:template>
  187. <xsl:template name="gen-user-scripts">
  188. <xsl:apply-templates select="." mode="gen-user-scripts"/>
  189. </xsl:template>
  190. <xsl:template match="/|node()|@*" mode="gen-user-scripts">
  191. <!-- to customize: copy this to your override transform, add the content you want. -->
  192. <!-- It will be placed before the ending HEAD tag -->
  193. <!-- see (or enable) the named template "script-sample" for an example -->
  194. </xsl:template>
  195. <xsl:template name="gen-user-styles">
  196. <xsl:apply-templates select="." mode="gen-user-styles"/>
  197. </xsl:template>
  198. <xsl:template match="/|node()|@*" mode="gen-user-styles">
  199. <!-- to customize: copy this to your override transform, add the content you want. -->
  200. <!-- It will be placed before the ending HEAD tag -->
  201. </xsl:template>
  202. <xsl:template name="gen-user-external-link">
  203. <xsl:apply-templates select="." mode="gen-user-external-link"/>
  204. </xsl:template>
  205. <xsl:template match="/|node()|@*" mode="gen-user-external-link">
  206. <!-- to customize: copy this to your override transform, add the content you want. -->
  207. <!-- It will be placed after an external LINK or XREF -->
  208. </xsl:template>
  209. <!-- Template to get the relative path to a map -->
  210. <xsl:template name="getRelativePath">
  211. <xsl:param name="remainingPath" select="@file"/>
  212. <xsl:choose>
  213. <xsl:when test="contains($remainingPath,'/')">
  214. <xsl:value-of select="substring-before($remainingPath,'/')"/><xsl:text>/</xsl:text>
  215. <xsl:call-template name="getRelativePath">
  216. <xsl:with-param name="remainingPath" select="substring-after($remainingPath,'/')"/>
  217. </xsl:call-template>
  218. </xsl:when>
  219. <xsl:when test="contains($remainingPath,'\')">
  220. <xsl:value-of select="substring-before($remainingPath,'\')"/><xsl:text>/</xsl:text>
  221. <xsl:call-template name="getRelativePath">
  222. <xsl:with-param name="remainingPath" select="substring-after($remainingPath,'\')"/>
  223. </xsl:call-template>
  224. </xsl:when>
  225. </xsl:choose>
  226. </xsl:template>
  227. </xsl:stylesheet>