chunker.xsl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <?xml version="1.0" encoding="ASCII"?><!--This file was created automatically by html2xhtml--><!--from the HTML stylesheets.--><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://icl.com/saxon" xmlns:lxslt="http://xml.apache.org/xslt" xmlns:redirect="http://xml.apache.org/xalan/redirect" xmlns:exsl="http://exslt.org/common" xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" xmlns="http://www.w3.org/1999/xhtml" version="1.0" exclude-result-prefixes="saxon lxslt redirect exsl doc" extension-element-prefixes="saxon redirect lxslt exsl">
  2. <!-- ********************************************************************
  3. $Id: chunker.xsl 9656 2012-10-29 18:09:53Z bobstayton $
  4. ********************************************************************
  5. This file is part of the XSL DocBook Stylesheet distribution.
  6. See ../README or http://docbook.sf.net/release/xsl/current/ for
  7. copyright and other information.
  8. ******************************************************************** -->
  9. <!-- ==================================================================== -->
  10. <!-- This stylesheet works with XSLT implementations that support -->
  11. <!-- exsl:document, saxon:output, or Xalan's redirect:write -->
  12. <!-- Note: Only Saxon 6.4.2 or later is supported. -->
  13. <xsl:param name="chunker.output.method" select="'xml'"/>
  14. <xsl:param name="chunker.output.encoding" select="'UTF-8'"/>
  15. <xsl:param name="chunker.output.indent" select="'no'"/>
  16. <xsl:param name="chunker.output.omit-xml-declaration" select="'no'"/>
  17. <xsl:param name="chunker.output.standalone" select="'no'"/>
  18. <xsl:param name="chunker.output.doctype-public" select="'-//W3C//DTD XHTML 1.1//EN'"/>
  19. <xsl:param name="chunker.output.doctype-system" select="'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'"/>
  20. <xsl:param name="chunker.output.media-type" select="''"/>
  21. <xsl:param name="chunker.output.cdata-section-elements" select="''"/>
  22. <!-- Make sure base.dir has a trailing slash now -->
  23. <xsl:param name="chunk.base.dir">
  24. <xsl:choose>
  25. <xsl:when test="string-length($base.dir) = 0"/>
  26. <!-- make sure to add trailing slash if omitted by user -->
  27. <xsl:when test="substring($base.dir, string-length($base.dir), 1) = '/'">
  28. <xsl:value-of select="$base.dir"/>
  29. </xsl:when>
  30. <xsl:otherwise>
  31. <xsl:value-of select="concat($base.dir, '/')"/>
  32. </xsl:otherwise>
  33. </xsl:choose>
  34. </xsl:param>
  35. <xsl:param name="saxon.character.representation" select="'entity;decimal'"/>
  36. <!-- ==================================================================== -->
  37. <xsl:template name="make-relative-filename">
  38. <xsl:param name="base.dir" select="'./'"/>
  39. <xsl:param name="base.name" select="''"/>
  40. <xsl:choose>
  41. <!-- put Saxon first to work around a bug in libxslt -->
  42. <xsl:when test="element-available('saxon:output')">
  43. <!-- Saxon doesn't make the chunks relative -->
  44. <xsl:value-of select="concat($base.dir,$base.name)"/>
  45. </xsl:when>
  46. <xsl:when test="element-available('exsl:document')">
  47. <!-- EXSL document does make the chunks relative, I think -->
  48. <xsl:choose>
  49. <xsl:when test="count(parent::*) = 0">
  50. <xsl:value-of select="concat($base.dir,$base.name)"/>
  51. </xsl:when>
  52. <xsl:otherwise>
  53. <xsl:value-of select="$base.name"/>
  54. </xsl:otherwise>
  55. </xsl:choose>
  56. </xsl:when>
  57. <xsl:when test="element-available('redirect:write')">
  58. <!-- Xalan doesn't make the chunks relative -->
  59. <xsl:value-of select="concat($base.dir,$base.name)"/>
  60. </xsl:when>
  61. <xsl:otherwise>
  62. <xsl:message terminate="yes">
  63. <xsl:text>Don't know how to chunk with </xsl:text>
  64. <xsl:value-of select="system-property('xsl:vendor')"/>
  65. </xsl:message>
  66. </xsl:otherwise>
  67. </xsl:choose>
  68. </xsl:template>
  69. <xsl:template name="write.chunk">
  70. <xsl:param name="filename" select="''"/>
  71. <xsl:param name="quiet" select="$chunk.quietly"/>
  72. <xsl:param name="suppress-context-node-name" select="0"/>
  73. <xsl:param name="message-prolog"/>
  74. <xsl:param name="message-epilog"/>
  75. <xsl:param name="method" select="$chunker.output.method"/>
  76. <xsl:param name="encoding" select="$chunker.output.encoding"/>
  77. <xsl:param name="indent" select="$chunker.output.indent"/>
  78. <xsl:param name="omit-xml-declaration" select="$chunker.output.omit-xml-declaration"/>
  79. <xsl:param name="standalone" select="$chunker.output.standalone"/>
  80. <xsl:param name="doctype-public" select="$chunker.output.doctype-public"/>
  81. <xsl:param name="doctype-system" select="$chunker.output.doctype-system"/>
  82. <xsl:param name="media-type" select="$chunker.output.media-type"/>
  83. <xsl:param name="cdata-section-elements" select="$chunker.output.cdata-section-elements"/>
  84. <xsl:param name="content"/>
  85. <xsl:if test="$quiet = 0">
  86. <xsl:message>
  87. <xsl:if test="not($message-prolog = '')">
  88. <xsl:value-of select="$message-prolog"/>
  89. </xsl:if>
  90. <xsl:text>Writing </xsl:text>
  91. <xsl:value-of select="$filename"/>
  92. <xsl:if test="name(.) != '' and $suppress-context-node-name = 0">
  93. <xsl:text> for </xsl:text>
  94. <xsl:value-of select="name(.)"/>
  95. <xsl:if test="@id or @xml:id">
  96. <xsl:text>(</xsl:text>
  97. <xsl:value-of select="(@id|@xml:id)[1]"/>
  98. <xsl:text>)</xsl:text>
  99. </xsl:if>
  100. </xsl:if>
  101. <xsl:if test="not($message-epilog = '')">
  102. <xsl:value-of select="$message-epilog"/>
  103. </xsl:if>
  104. </xsl:message>
  105. </xsl:if>
  106. <xsl:choose>
  107. <xsl:when test="element-available('exsl:document')">
  108. <xsl:choose>
  109. <!-- Handle the permutations ... -->
  110. <xsl:when test="$media-type != ''">
  111. <xsl:choose>
  112. <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  113. <exsl:document href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" media-type="{$media-type}" doctype-public="{$doctype-public}" doctype-system="{$doctype-system}" standalone="{$standalone}">
  114. <xsl:copy-of select="$content"/>
  115. </exsl:document>
  116. </xsl:when>
  117. <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  118. <exsl:document href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" media-type="{$media-type}" doctype-public="{$doctype-public}" standalone="{$standalone}">
  119. <xsl:copy-of select="$content"/>
  120. </exsl:document>
  121. </xsl:when>
  122. <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  123. <exsl:document href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" media-type="{$media-type}" doctype-system="{$doctype-system}" standalone="{$standalone}">
  124. <xsl:copy-of select="$content"/>
  125. </exsl:document>
  126. </xsl:when>
  127. <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  128. <exsl:document href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" media-type="{$media-type}" standalone="{$standalone}">
  129. <xsl:copy-of select="$content"/>
  130. </exsl:document>
  131. </xsl:otherwise>
  132. </xsl:choose>
  133. </xsl:when>
  134. <xsl:otherwise>
  135. <xsl:choose>
  136. <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  137. <exsl:document href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" doctype-public="{$doctype-public}" doctype-system="{$doctype-system}" standalone="{$standalone}">
  138. <xsl:copy-of select="$content"/>
  139. </exsl:document>
  140. </xsl:when>
  141. <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  142. <exsl:document href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" doctype-public="{$doctype-public}" standalone="{$standalone}">
  143. <xsl:copy-of select="$content"/>
  144. </exsl:document>
  145. </xsl:when>
  146. <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  147. <exsl:document href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" doctype-system="{$doctype-system}" standalone="{$standalone}">
  148. <xsl:copy-of select="$content"/>
  149. </exsl:document>
  150. </xsl:when>
  151. <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  152. <exsl:document href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" standalone="{$standalone}">
  153. <xsl:copy-of select="$content"/>
  154. </exsl:document>
  155. </xsl:otherwise>
  156. </xsl:choose>
  157. </xsl:otherwise>
  158. </xsl:choose>
  159. </xsl:when>
  160. <xsl:when test="element-available('saxon:output')">
  161. <xsl:choose>
  162. <!-- Handle the permutations ... -->
  163. <xsl:when test="$media-type != ''">
  164. <xsl:choose>
  165. <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  166. <saxon:output saxon:character-representation="{$saxon.character.representation}" href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" media-type="{$media-type}" doctype-public="{$doctype-public}" doctype-system="{$doctype-system}" standalone="{$standalone}">
  167. <xsl:copy-of select="$content"/>
  168. </saxon:output>
  169. </xsl:when>
  170. <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  171. <saxon:output saxon:character-representation="{$saxon.character.representation}" href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" media-type="{$media-type}" doctype-public="{$doctype-public}" standalone="{$standalone}">
  172. <xsl:copy-of select="$content"/>
  173. </saxon:output>
  174. </xsl:when>
  175. <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  176. <saxon:output saxon:character-representation="{$saxon.character.representation}" href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" media-type="{$media-type}" doctype-system="{$doctype-system}" standalone="{$standalone}">
  177. <xsl:copy-of select="$content"/>
  178. </saxon:output>
  179. </xsl:when>
  180. <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  181. <saxon:output saxon:character-representation="{$saxon.character.representation}" href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" media-type="{$media-type}" standalone="{$standalone}">
  182. <xsl:copy-of select="$content"/>
  183. </saxon:output>
  184. </xsl:otherwise>
  185. </xsl:choose>
  186. </xsl:when>
  187. <xsl:otherwise>
  188. <xsl:choose>
  189. <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  190. <saxon:output saxon:character-representation="{$saxon.character.representation}" href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" doctype-public="{$doctype-public}" doctype-system="{$doctype-system}" standalone="{$standalone}">
  191. <xsl:copy-of select="$content"/>
  192. </saxon:output>
  193. </xsl:when>
  194. <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  195. <saxon:output saxon:character-representation="{$saxon.character.representation}" href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" doctype-public="{$doctype-public}" standalone="{$standalone}">
  196. <xsl:copy-of select="$content"/>
  197. </saxon:output>
  198. </xsl:when>
  199. <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  200. <saxon:output saxon:character-representation="{$saxon.character.representation}" href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" doctype-system="{$doctype-system}" standalone="{$standalone}">
  201. <xsl:copy-of select="$content"/>
  202. </saxon:output>
  203. </xsl:when>
  204. <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  205. <saxon:output saxon:character-representation="{$saxon.character.representation}" href="{$filename}" method="{$method}" encoding="{$encoding}" indent="{$indent}" omit-xml-declaration="{$omit-xml-declaration}" cdata-section-elements="{$cdata-section-elements}" standalone="{$standalone}">
  206. <xsl:copy-of select="$content"/>
  207. </saxon:output>
  208. </xsl:otherwise>
  209. </xsl:choose>
  210. </xsl:otherwise>
  211. </xsl:choose>
  212. </xsl:when>
  213. <xsl:when test="element-available('redirect:write')">
  214. <!-- Xalan uses redirect -->
  215. <redirect:write file="{$filename}">
  216. <xsl:copy-of select="$content"/>
  217. </redirect:write>
  218. </xsl:when>
  219. <xsl:otherwise>
  220. <!-- it doesn't matter since we won't be making chunks... -->
  221. <xsl:message terminate="yes">
  222. <xsl:text>Can't make chunks with </xsl:text>
  223. <xsl:value-of select="system-property('xsl:vendor')"/>
  224. <xsl:text>'s processor.</xsl:text>
  225. </xsl:message>
  226. </xsl:otherwise>
  227. </xsl:choose>
  228. </xsl:template>
  229. <xsl:template name="write.chunk.with.doctype">
  230. <xsl:param name="filename" select="''"/>
  231. <xsl:param name="quiet" select="$chunk.quietly"/>
  232. <xsl:param name="method" select="$chunker.output.method"/>
  233. <xsl:param name="encoding" select="$chunker.output.encoding"/>
  234. <xsl:param name="indent" select="$chunker.output.indent"/>
  235. <xsl:param name="omit-xml-declaration" select="$chunker.output.omit-xml-declaration"/>
  236. <xsl:param name="standalone" select="$chunker.output.standalone"/>
  237. <xsl:param name="doctype-public" select="$chunker.output.doctype-public"/>
  238. <xsl:param name="doctype-system" select="$chunker.output.doctype-system"/>
  239. <xsl:param name="media-type" select="$chunker.output.media-type"/>
  240. <xsl:param name="cdata-section-elements" select="$chunker.output.cdata-section-elements"/>
  241. <xsl:param name="content"/>
  242. <xsl:call-template name="write.chunk">
  243. <xsl:with-param name="filename" select="$filename"/>
  244. <xsl:with-param name="quiet" select="$quiet"/>
  245. <xsl:with-param name="method" select="$method"/>
  246. <xsl:with-param name="encoding" select="$encoding"/>
  247. <xsl:with-param name="indent" select="$indent"/>
  248. <xsl:with-param name="omit-xml-declaration" select="$omit-xml-declaration"/>
  249. <xsl:with-param name="standalone" select="$standalone"/>
  250. <xsl:with-param name="doctype-public" select="$doctype-public"/>
  251. <xsl:with-param name="doctype-system" select="$doctype-system"/>
  252. <xsl:with-param name="media-type" select="$media-type"/>
  253. <xsl:with-param name="cdata-section-elements" select="$cdata-section-elements"/>
  254. <xsl:with-param name="content" select="$content"/>
  255. </xsl:call-template>
  256. </xsl:template>
  257. <xsl:template name="write.text.chunk">
  258. <xsl:param name="filename" select="''"/>
  259. <xsl:param name="quiet" select="$chunk.quietly"/>
  260. <xsl:param name="suppress-context-node-name" select="0"/>
  261. <xsl:param name="message-prolog"/>
  262. <xsl:param name="message-epilog"/>
  263. <xsl:param name="method" select="'text'"/>
  264. <xsl:param name="encoding" select="$chunker.output.encoding"/>
  265. <xsl:param name="media-type" select="$chunker.output.media-type"/>
  266. <xsl:param name="content"/>
  267. <xsl:call-template name="write.chunk">
  268. <xsl:with-param name="filename" select="$filename"/>
  269. <xsl:with-param name="quiet" select="$quiet"/>
  270. <xsl:with-param name="suppress-context-node-name" select="$suppress-context-node-name"/>
  271. <xsl:with-param name="message-prolog" select="$message-prolog"/>
  272. <xsl:with-param name="message-epilog" select="$message-epilog"/>
  273. <xsl:with-param name="method" select="$method"/>
  274. <xsl:with-param name="encoding" select="$encoding"/>
  275. <xsl:with-param name="indent" select="'no'"/>
  276. <xsl:with-param name="omit-xml-declaration" select="'yes'"/>
  277. <xsl:with-param name="standalone" select="'no'"/>
  278. <xsl:with-param name="doctype-public"/>
  279. <xsl:with-param name="doctype-system"/>
  280. <xsl:with-param name="media-type" select="$media-type"/>
  281. <xsl:with-param name="cdata-section-elements"/>
  282. <xsl:with-param name="content" select="$content"/>
  283. </xsl:call-template>
  284. </xsl:template>
  285. </xsl:stylesheet>