chunker.xsl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2. xmlns:saxon="http://icl.com/saxon"
  3. xmlns:lxslt="http://xml.apache.org/xslt"
  4. xmlns:redirect="http://xml.apache.org/xalan/redirect"
  5. xmlns:exsl="http://exslt.org/common"
  6. xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
  7. version="1.0"
  8. exclude-result-prefixes="doc"
  9. extension-element-prefixes="saxon redirect lxslt exsl">
  10. <!-- ********************************************************************
  11. $Id$
  12. ********************************************************************
  13. This file is part of the XSL DocBook Stylesheet distribution.
  14. See ../README or http://docbook.sf.net/release/xsl/current/ for
  15. copyright and other information.
  16. ******************************************************************** -->
  17. <!-- ==================================================================== -->
  18. <!-- This stylesheet works with XSLT implementations that support -->
  19. <!-- exsl:document, saxon:output, or Xalan's redirect:write -->
  20. <!-- Note: Only Saxon 6.4.2 or later is supported. -->
  21. <xsl:param name="chunker.output.method" select="'html'"/>
  22. <xsl:param name="chunker.output.encoding" select="'ISO-8859-1'"/>
  23. <xsl:param name="chunker.output.indent" select="'no'"/>
  24. <xsl:param name="chunker.output.omit-xml-declaration" select="'no'"/>
  25. <xsl:param name="chunker.output.standalone" select="'no'"/>
  26. <xsl:param name="chunker.output.doctype-public" select="''"/>
  27. <xsl:param name="chunker.output.doctype-system" select="''"/>
  28. <xsl:param name="chunker.output.media-type" select="''"/>
  29. <xsl:param name="chunker.output.cdata-section-elements" select="''"/>
  30. <xsl:param name="chunker.output.quiet" select="0"/>
  31. <xsl:param name="saxon.character.representation" select="'entity;decimal'"/>
  32. <!-- ==================================================================== -->
  33. <xsl:template name="make-relative-filename">
  34. <xsl:param name="base.dir" select="'./'"/>
  35. <xsl:param name="base.name" select="''"/>
  36. <xsl:choose>
  37. <!-- put Saxon first to work around a bug in libxslt -->
  38. <xsl:when test="element-available('saxon:output')">
  39. <!-- Saxon doesn't make the chunks relative -->
  40. <xsl:value-of select="concat($base.dir,$base.name)"/>
  41. </xsl:when>
  42. <xsl:when test="element-available('exsl:document')">
  43. <!-- EXSL document does make the chunks relative, I think -->
  44. <xsl:choose>
  45. <xsl:when test="count(parent::*) = 0">
  46. <xsl:value-of select="concat($base.dir,$base.name)"/>
  47. </xsl:when>
  48. <xsl:otherwise>
  49. <xsl:value-of select="$base.name"/>
  50. </xsl:otherwise>
  51. </xsl:choose>
  52. </xsl:when>
  53. <xsl:when test="element-available('redirect:write')">
  54. <!-- Xalan doesn't make the chunks relative -->
  55. <xsl:value-of select="concat($base.dir,$base.name)"/>
  56. </xsl:when>
  57. <xsl:otherwise>
  58. <xsl:message terminate="yes">
  59. <xsl:text>Don't know how to chunk with </xsl:text>
  60. <xsl:value-of select="system-property('xsl:vendor')"/>
  61. </xsl:message>
  62. </xsl:otherwise>
  63. </xsl:choose>
  64. </xsl:template>
  65. <xsl:template name="write.chunk">
  66. <xsl:param name="filename" select="''"/>
  67. <xsl:param name="quiet" select="$chunker.output.quiet"/>
  68. <xsl:param name="suppress-context-node-name" select="0"/>
  69. <xsl:param name="message-prolog"/>
  70. <xsl:param name="message-epilog"/>
  71. <xsl:param name="method" select="$chunker.output.method"/>
  72. <xsl:param name="encoding" select="$chunker.output.encoding"/>
  73. <xsl:param name="indent" select="$chunker.output.indent"/>
  74. <xsl:param name="omit-xml-declaration"
  75. select="$chunker.output.omit-xml-declaration"/>
  76. <xsl:param name="standalone" select="$chunker.output.standalone"/>
  77. <xsl:param name="doctype-public" select="$chunker.output.doctype-public"/>
  78. <xsl:param name="doctype-system" select="$chunker.output.doctype-system"/>
  79. <xsl:param name="media-type" select="$chunker.output.media-type"/>
  80. <xsl:param name="cdata-section-elements"
  81. select="$chunker.output.cdata-section-elements"/>
  82. <xsl:param name="content"/>
  83. <xsl:if test="$quiet = 0">
  84. <xsl:message>
  85. <xsl:if test="not($message-prolog = '')">
  86. <xsl:value-of select="$message-prolog"/>
  87. </xsl:if>
  88. <xsl:text>Writing </xsl:text>
  89. <xsl:value-of select="$filename"/>
  90. <xsl:if test="name(.) != '' and $suppress-context-node-name = 0">
  91. <xsl:text> for </xsl:text>
  92. <xsl:value-of select="name(.)"/>
  93. <xsl:if test="@id or @xml:id">
  94. <xsl:text>(</xsl:text>
  95. <xsl:value-of select="(@id|@xml:id)[1]"/>
  96. <xsl:text>)</xsl:text>
  97. </xsl:if>
  98. </xsl:if>
  99. <xsl:if test="not($message-epilog = '')">
  100. <xsl:value-of select="$message-epilog"/>
  101. </xsl:if>
  102. </xsl:message>
  103. </xsl:if>
  104. <xsl:choose>
  105. <xsl:when test="element-available('exsl:document')">
  106. <xsl:choose>
  107. <!-- Handle the permutations ... -->
  108. <xsl:when test="$media-type != ''">
  109. <xsl:choose>
  110. <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  111. <exsl:document href="{$filename}"
  112. method="{$method}"
  113. encoding="{$encoding}"
  114. indent="{$indent}"
  115. omit-xml-declaration="{$omit-xml-declaration}"
  116. cdata-section-elements="{$cdata-section-elements}"
  117. media-type="{$media-type}"
  118. doctype-public="{$doctype-public}"
  119. doctype-system="{$doctype-system}"
  120. standalone="{$standalone}">
  121. <xsl:copy-of select="$content"/>
  122. </exsl:document>
  123. </xsl:when>
  124. <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  125. <exsl:document href="{$filename}"
  126. method="{$method}"
  127. encoding="{$encoding}"
  128. indent="{$indent}"
  129. omit-xml-declaration="{$omit-xml-declaration}"
  130. cdata-section-elements="{$cdata-section-elements}"
  131. media-type="{$media-type}"
  132. doctype-public="{$doctype-public}"
  133. standalone="{$standalone}">
  134. <xsl:copy-of select="$content"/>
  135. </exsl:document>
  136. </xsl:when>
  137. <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  138. <exsl:document href="{$filename}"
  139. method="{$method}"
  140. encoding="{$encoding}"
  141. indent="{$indent}"
  142. omit-xml-declaration="{$omit-xml-declaration}"
  143. cdata-section-elements="{$cdata-section-elements}"
  144. media-type="{$media-type}"
  145. doctype-system="{$doctype-system}"
  146. standalone="{$standalone}">
  147. <xsl:copy-of select="$content"/>
  148. </exsl:document>
  149. </xsl:when>
  150. <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  151. <exsl:document href="{$filename}"
  152. method="{$method}"
  153. encoding="{$encoding}"
  154. indent="{$indent}"
  155. omit-xml-declaration="{$omit-xml-declaration}"
  156. cdata-section-elements="{$cdata-section-elements}"
  157. media-type="{$media-type}"
  158. standalone="{$standalone}">
  159. <xsl:copy-of select="$content"/>
  160. </exsl:document>
  161. </xsl:otherwise>
  162. </xsl:choose>
  163. </xsl:when>
  164. <xsl:otherwise>
  165. <xsl:choose>
  166. <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  167. <exsl:document href="{$filename}"
  168. method="{$method}"
  169. encoding="{$encoding}"
  170. indent="{$indent}"
  171. omit-xml-declaration="{$omit-xml-declaration}"
  172. cdata-section-elements="{$cdata-section-elements}"
  173. doctype-public="{$doctype-public}"
  174. doctype-system="{$doctype-system}"
  175. standalone="{$standalone}">
  176. <xsl:copy-of select="$content"/>
  177. </exsl:document>
  178. </xsl:when>
  179. <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  180. <exsl:document href="{$filename}"
  181. method="{$method}"
  182. encoding="{$encoding}"
  183. indent="{$indent}"
  184. omit-xml-declaration="{$omit-xml-declaration}"
  185. cdata-section-elements="{$cdata-section-elements}"
  186. doctype-public="{$doctype-public}"
  187. standalone="{$standalone}">
  188. <xsl:copy-of select="$content"/>
  189. </exsl:document>
  190. </xsl:when>
  191. <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  192. <exsl:document href="{$filename}"
  193. method="{$method}"
  194. encoding="{$encoding}"
  195. indent="{$indent}"
  196. omit-xml-declaration="{$omit-xml-declaration}"
  197. cdata-section-elements="{$cdata-section-elements}"
  198. doctype-system="{$doctype-system}"
  199. standalone="{$standalone}">
  200. <xsl:copy-of select="$content"/>
  201. </exsl:document>
  202. </xsl:when>
  203. <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  204. <exsl:document href="{$filename}"
  205. method="{$method}"
  206. encoding="{$encoding}"
  207. indent="{$indent}"
  208. omit-xml-declaration="{$omit-xml-declaration}"
  209. cdata-section-elements="{$cdata-section-elements}"
  210. standalone="{$standalone}">
  211. <xsl:copy-of select="$content"/>
  212. </exsl:document>
  213. </xsl:otherwise>
  214. </xsl:choose>
  215. </xsl:otherwise>
  216. </xsl:choose>
  217. </xsl:when>
  218. <xsl:when test="element-available('saxon:output')">
  219. <xsl:choose>
  220. <!-- Handle the permutations ... -->
  221. <xsl:when test="$media-type != ''">
  222. <xsl:choose>
  223. <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  224. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  225. href="{$filename}"
  226. method="{$method}"
  227. encoding="{$encoding}"
  228. indent="{$indent}"
  229. omit-xml-declaration="{$omit-xml-declaration}"
  230. cdata-section-elements="{$cdata-section-elements}"
  231. media-type="{$media-type}"
  232. doctype-public="{$doctype-public}"
  233. doctype-system="{$doctype-system}"
  234. standalone="{$standalone}">
  235. <xsl:copy-of select="$content"/>
  236. </saxon:output>
  237. </xsl:when>
  238. <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  239. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  240. href="{$filename}"
  241. method="{$method}"
  242. encoding="{$encoding}"
  243. indent="{$indent}"
  244. omit-xml-declaration="{$omit-xml-declaration}"
  245. cdata-section-elements="{$cdata-section-elements}"
  246. media-type="{$media-type}"
  247. doctype-public="{$doctype-public}"
  248. standalone="{$standalone}">
  249. <xsl:copy-of select="$content"/>
  250. </saxon:output>
  251. </xsl:when>
  252. <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  253. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  254. href="{$filename}"
  255. method="{$method}"
  256. encoding="{$encoding}"
  257. indent="{$indent}"
  258. omit-xml-declaration="{$omit-xml-declaration}"
  259. cdata-section-elements="{$cdata-section-elements}"
  260. media-type="{$media-type}"
  261. doctype-system="{$doctype-system}"
  262. standalone="{$standalone}">
  263. <xsl:copy-of select="$content"/>
  264. </saxon:output>
  265. </xsl:when>
  266. <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  267. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  268. href="{$filename}"
  269. method="{$method}"
  270. encoding="{$encoding}"
  271. indent="{$indent}"
  272. omit-xml-declaration="{$omit-xml-declaration}"
  273. cdata-section-elements="{$cdata-section-elements}"
  274. media-type="{$media-type}"
  275. standalone="{$standalone}">
  276. <xsl:copy-of select="$content"/>
  277. </saxon:output>
  278. </xsl:otherwise>
  279. </xsl:choose>
  280. </xsl:when>
  281. <xsl:otherwise>
  282. <xsl:choose>
  283. <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  284. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  285. href="{$filename}"
  286. method="{$method}"
  287. encoding="{$encoding}"
  288. indent="{$indent}"
  289. omit-xml-declaration="{$omit-xml-declaration}"
  290. cdata-section-elements="{$cdata-section-elements}"
  291. doctype-public="{$doctype-public}"
  292. doctype-system="{$doctype-system}"
  293. standalone="{$standalone}">
  294. <xsl:copy-of select="$content"/>
  295. </saxon:output>
  296. </xsl:when>
  297. <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  298. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  299. href="{$filename}"
  300. method="{$method}"
  301. encoding="{$encoding}"
  302. indent="{$indent}"
  303. omit-xml-declaration="{$omit-xml-declaration}"
  304. cdata-section-elements="{$cdata-section-elements}"
  305. doctype-public="{$doctype-public}"
  306. standalone="{$standalone}">
  307. <xsl:copy-of select="$content"/>
  308. </saxon:output>
  309. </xsl:when>
  310. <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  311. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  312. href="{$filename}"
  313. method="{$method}"
  314. encoding="{$encoding}"
  315. indent="{$indent}"
  316. omit-xml-declaration="{$omit-xml-declaration}"
  317. cdata-section-elements="{$cdata-section-elements}"
  318. doctype-system="{$doctype-system}"
  319. standalone="{$standalone}">
  320. <xsl:copy-of select="$content"/>
  321. </saxon:output>
  322. </xsl:when>
  323. <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  324. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  325. href="{$filename}"
  326. method="{$method}"
  327. encoding="{$encoding}"
  328. indent="{$indent}"
  329. omit-xml-declaration="{$omit-xml-declaration}"
  330. cdata-section-elements="{$cdata-section-elements}"
  331. standalone="{$standalone}">
  332. <xsl:copy-of select="$content"/>
  333. </saxon:output>
  334. </xsl:otherwise>
  335. </xsl:choose>
  336. </xsl:otherwise>
  337. </xsl:choose>
  338. </xsl:when>
  339. <xsl:when test="element-available('redirect:write')">
  340. <!-- Xalan uses redirect -->
  341. <redirect:write file="{$filename}">
  342. <xsl:copy-of select="$content"/>
  343. </redirect:write>
  344. </xsl:when>
  345. <xsl:otherwise>
  346. <!-- it doesn't matter since we won't be making chunks... -->
  347. <xsl:message terminate="yes">
  348. <xsl:text>Can't make chunks with </xsl:text>
  349. <xsl:value-of select="system-property('xsl:vendor')"/>
  350. <xsl:text>'s processor.</xsl:text>
  351. </xsl:message>
  352. </xsl:otherwise>
  353. </xsl:choose>
  354. </xsl:template>
  355. <xsl:template name="write.chunk.with.doctype">
  356. <xsl:param name="filename" select="''"/>
  357. <xsl:param name="quiet" select="$chunker.output.quiet"/>
  358. <xsl:param name="method" select="$chunker.output.method"/>
  359. <xsl:param name="encoding" select="$chunker.output.encoding"/>
  360. <xsl:param name="indent" select="$chunker.output.indent"/>
  361. <xsl:param name="omit-xml-declaration"
  362. select="$chunker.output.omit-xml-declaration"/>
  363. <xsl:param name="standalone" select="$chunker.output.standalone"/>
  364. <xsl:param name="doctype-public" select="$chunker.output.doctype-public"/>
  365. <xsl:param name="doctype-system" select="$chunker.output.doctype-system"/>
  366. <xsl:param name="media-type" select="$chunker.output.media-type"/>
  367. <xsl:param name="cdata-section-elements"
  368. select="$chunker.output.cdata-section-elements"/>
  369. <xsl:param name="content"/>
  370. <xsl:call-template name="write.chunk">
  371. <xsl:with-param name="filename" select="$filename"/>
  372. <xsl:with-param name="quiet" select="$quiet"/>
  373. <xsl:with-param name="method" select="$method"/>
  374. <xsl:with-param name="encoding" select="$encoding"/>
  375. <xsl:with-param name="indent" select="$indent"/>
  376. <xsl:with-param name="omit-xml-declaration" select="$omit-xml-declaration"/>
  377. <xsl:with-param name="standalone" select="$standalone"/>
  378. <xsl:with-param name="doctype-public" select="$doctype-public"/>
  379. <xsl:with-param name="doctype-system" select="$doctype-system"/>
  380. <xsl:with-param name="media-type" select="$media-type"/>
  381. <xsl:with-param name="cdata-section-elements" select="$cdata-section-elements"/>
  382. <xsl:with-param name="content" select="$content"/>
  383. </xsl:call-template>
  384. </xsl:template>
  385. <xsl:template name="write.text.chunk">
  386. <xsl:param name="filename" select="''"/>
  387. <xsl:param name="quiet" select="$chunker.output.quiet"/>
  388. <xsl:param name="suppress-context-node-name" select="0"/>
  389. <xsl:param name="message-prolog"/>
  390. <xsl:param name="message-epilog"/>
  391. <xsl:param name="method" select="'text'"/>
  392. <xsl:param name="encoding" select="$chunker.output.encoding"/>
  393. <xsl:param name="media-type" select="$chunker.output.media-type"/>
  394. <xsl:param name="content"/>
  395. <xsl:call-template name="write.chunk">
  396. <xsl:with-param name="filename" select="$filename"/>
  397. <xsl:with-param name="quiet" select="$quiet"/>
  398. <xsl:with-param name="suppress-context-node-name" select="$suppress-context-node-name"/>
  399. <xsl:with-param name="message-prolog" select="$message-prolog"/>
  400. <xsl:with-param name="message-epilog" select="$message-epilog"/>
  401. <xsl:with-param name="method" select="$method"/>
  402. <xsl:with-param name="encoding" select="$encoding"/>
  403. <xsl:with-param name="indent" select="'no'"/>
  404. <xsl:with-param name="omit-xml-declaration" select="'no'"/>
  405. <xsl:with-param name="standalone" select="'no'"/>
  406. <xsl:with-param name="doctype-public"/>
  407. <xsl:with-param name="doctype-system"/>
  408. <xsl:with-param name="media-type" select="$media-type"/>
  409. <xsl:with-param name="cdata-section-elements"/>
  410. <xsl:with-param name="content" select="$content"/>
  411. </xsl:call-template>
  412. </xsl:template>
  413. </xsl:stylesheet>