map2htmtocImpl.xsl 11 KB

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