chunker.xsl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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="saxon lxslt redirect exsl doc"
  9. extension-element-prefixes="saxon redirect lxslt exsl">
  10. <!-- ********************************************************************
  11. $Id: chunker.xsl 9656 2012-10-29 18:09:53Z bobstayton $
  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. <!-- Make sure base.dir has a trailing slash now -->
  31. <xsl:param name="chunk.base.dir">
  32. <xsl:choose>
  33. <xsl:when test="string-length($base.dir) = 0"></xsl:when>
  34. <!-- make sure to add trailing slash if omitted by user -->
  35. <xsl:when test="substring($base.dir, string-length($base.dir), 1) = '/'">
  36. <xsl:value-of select="$base.dir"/>
  37. </xsl:when>
  38. <xsl:otherwise>
  39. <xsl:value-of select="concat($base.dir, '/')"/>
  40. </xsl:otherwise>
  41. </xsl:choose>
  42. </xsl:param>
  43. <xsl:param name="saxon.character.representation" select="'entity;decimal'"/>
  44. <!-- ==================================================================== -->
  45. <xsl:template name="make-relative-filename">
  46. <xsl:param name="base.dir" select="'./'"/>
  47. <xsl:param name="base.name" select="''"/>
  48. <xsl:choose>
  49. <!-- put Saxon first to work around a bug in libxslt -->
  50. <xsl:when test="element-available('saxon:output')">
  51. <!-- Saxon doesn't make the chunks relative -->
  52. <xsl:value-of select="concat($base.dir,$base.name)"/>
  53. </xsl:when>
  54. <xsl:when test="element-available('exsl:document')">
  55. <!-- EXSL document does make the chunks relative, I think -->
  56. <xsl:choose>
  57. <xsl:when test="count(parent::*) = 0">
  58. <xsl:value-of select="concat($base.dir,$base.name)"/>
  59. </xsl:when>
  60. <xsl:otherwise>
  61. <xsl:value-of select="$base.name"/>
  62. </xsl:otherwise>
  63. </xsl:choose>
  64. </xsl:when>
  65. <xsl:when test="element-available('redirect:write')">
  66. <!-- Xalan doesn't make the chunks relative -->
  67. <xsl:value-of select="concat($base.dir,$base.name)"/>
  68. </xsl:when>
  69. <xsl:otherwise>
  70. <xsl:message terminate="yes">
  71. <xsl:text>Don't know how to chunk with </xsl:text>
  72. <xsl:value-of select="system-property('xsl:vendor')"/>
  73. </xsl:message>
  74. </xsl:otherwise>
  75. </xsl:choose>
  76. </xsl:template>
  77. <xsl:template name="write.chunk">
  78. <xsl:param name="filename" select="''"/>
  79. <xsl:param name="quiet" select="$chunk.quietly"/>
  80. <xsl:param name="suppress-context-node-name" select="0"/>
  81. <xsl:param name="message-prolog"/>
  82. <xsl:param name="message-epilog"/>
  83. <xsl:param name="method" select="$chunker.output.method"/>
  84. <xsl:param name="encoding" select="$chunker.output.encoding"/>
  85. <xsl:param name="indent" select="$chunker.output.indent"/>
  86. <xsl:param name="omit-xml-declaration"
  87. select="$chunker.output.omit-xml-declaration"/>
  88. <xsl:param name="standalone" select="$chunker.output.standalone"/>
  89. <xsl:param name="doctype-public" select="$chunker.output.doctype-public"/>
  90. <xsl:param name="doctype-system" select="$chunker.output.doctype-system"/>
  91. <xsl:param name="media-type" select="$chunker.output.media-type"/>
  92. <xsl:param name="cdata-section-elements"
  93. select="$chunker.output.cdata-section-elements"/>
  94. <xsl:param name="content"/>
  95. <xsl:if test="$quiet = 0">
  96. <xsl:message>
  97. <xsl:if test="not($message-prolog = '')">
  98. <xsl:value-of select="$message-prolog"/>
  99. </xsl:if>
  100. <xsl:text>Writing </xsl:text>
  101. <xsl:value-of select="$filename"/>
  102. <xsl:if test="name(.) != '' and $suppress-context-node-name = 0">
  103. <xsl:text> for </xsl:text>
  104. <xsl:value-of select="name(.)"/>
  105. <xsl:if test="@id or @xml:id">
  106. <xsl:text>(</xsl:text>
  107. <xsl:value-of select="(@id|@xml:id)[1]"/>
  108. <xsl:text>)</xsl:text>
  109. </xsl:if>
  110. </xsl:if>
  111. <xsl:if test="not($message-epilog = '')">
  112. <xsl:value-of select="$message-epilog"/>
  113. </xsl:if>
  114. </xsl:message>
  115. </xsl:if>
  116. <xsl:choose>
  117. <xsl:when test="element-available('exsl:document')">
  118. <xsl:choose>
  119. <!-- Handle the permutations ... -->
  120. <xsl:when test="$media-type != ''">
  121. <xsl:choose>
  122. <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  123. <exsl:document href="{$filename}"
  124. method="{$method}"
  125. encoding="{$encoding}"
  126. indent="{$indent}"
  127. omit-xml-declaration="{$omit-xml-declaration}"
  128. cdata-section-elements="{$cdata-section-elements}"
  129. media-type="{$media-type}"
  130. doctype-public="{$doctype-public}"
  131. doctype-system="{$doctype-system}"
  132. standalone="{$standalone}">
  133. <xsl:copy-of select="$content"/>
  134. </exsl:document>
  135. </xsl:when>
  136. <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  137. <exsl:document href="{$filename}"
  138. method="{$method}"
  139. encoding="{$encoding}"
  140. indent="{$indent}"
  141. omit-xml-declaration="{$omit-xml-declaration}"
  142. cdata-section-elements="{$cdata-section-elements}"
  143. media-type="{$media-type}"
  144. doctype-public="{$doctype-public}"
  145. standalone="{$standalone}">
  146. <xsl:copy-of select="$content"/>
  147. </exsl:document>
  148. </xsl:when>
  149. <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  150. <exsl:document href="{$filename}"
  151. method="{$method}"
  152. encoding="{$encoding}"
  153. indent="{$indent}"
  154. omit-xml-declaration="{$omit-xml-declaration}"
  155. cdata-section-elements="{$cdata-section-elements}"
  156. media-type="{$media-type}"
  157. doctype-system="{$doctype-system}"
  158. standalone="{$standalone}">
  159. <xsl:copy-of select="$content"/>
  160. </exsl:document>
  161. </xsl:when>
  162. <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  163. <exsl:document href="{$filename}"
  164. method="{$method}"
  165. encoding="{$encoding}"
  166. indent="{$indent}"
  167. omit-xml-declaration="{$omit-xml-declaration}"
  168. cdata-section-elements="{$cdata-section-elements}"
  169. media-type="{$media-type}"
  170. standalone="{$standalone}">
  171. <xsl:copy-of select="$content"/>
  172. </exsl:document>
  173. </xsl:otherwise>
  174. </xsl:choose>
  175. </xsl:when>
  176. <xsl:otherwise>
  177. <xsl:choose>
  178. <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  179. <exsl:document href="{$filename}"
  180. method="{$method}"
  181. encoding="{$encoding}"
  182. indent="{$indent}"
  183. omit-xml-declaration="{$omit-xml-declaration}"
  184. cdata-section-elements="{$cdata-section-elements}"
  185. doctype-public="{$doctype-public}"
  186. doctype-system="{$doctype-system}"
  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-public="{$doctype-public}"
  199. standalone="{$standalone}">
  200. <xsl:copy-of select="$content"/>
  201. </exsl:document>
  202. </xsl:when>
  203. <xsl:when test="$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. doctype-system="{$doctype-system}"
  211. standalone="{$standalone}">
  212. <xsl:copy-of select="$content"/>
  213. </exsl:document>
  214. </xsl:when>
  215. <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  216. <exsl:document href="{$filename}"
  217. method="{$method}"
  218. encoding="{$encoding}"
  219. indent="{$indent}"
  220. omit-xml-declaration="{$omit-xml-declaration}"
  221. cdata-section-elements="{$cdata-section-elements}"
  222. standalone="{$standalone}">
  223. <xsl:copy-of select="$content"/>
  224. </exsl:document>
  225. </xsl:otherwise>
  226. </xsl:choose>
  227. </xsl:otherwise>
  228. </xsl:choose>
  229. </xsl:when>
  230. <xsl:when test="element-available('saxon:output')">
  231. <xsl:choose>
  232. <!-- Handle the permutations ... -->
  233. <xsl:when test="$media-type != ''">
  234. <xsl:choose>
  235. <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  236. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  237. href="{$filename}"
  238. method="{$method}"
  239. encoding="{$encoding}"
  240. indent="{$indent}"
  241. omit-xml-declaration="{$omit-xml-declaration}"
  242. cdata-section-elements="{$cdata-section-elements}"
  243. media-type="{$media-type}"
  244. doctype-public="{$doctype-public}"
  245. doctype-system="{$doctype-system}"
  246. standalone="{$standalone}">
  247. <xsl:copy-of select="$content"/>
  248. </saxon:output>
  249. </xsl:when>
  250. <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  251. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  252. href="{$filename}"
  253. method="{$method}"
  254. encoding="{$encoding}"
  255. indent="{$indent}"
  256. omit-xml-declaration="{$omit-xml-declaration}"
  257. cdata-section-elements="{$cdata-section-elements}"
  258. media-type="{$media-type}"
  259. doctype-public="{$doctype-public}"
  260. standalone="{$standalone}">
  261. <xsl:copy-of select="$content"/>
  262. </saxon:output>
  263. </xsl:when>
  264. <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  265. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  266. href="{$filename}"
  267. method="{$method}"
  268. encoding="{$encoding}"
  269. indent="{$indent}"
  270. omit-xml-declaration="{$omit-xml-declaration}"
  271. cdata-section-elements="{$cdata-section-elements}"
  272. media-type="{$media-type}"
  273. doctype-system="{$doctype-system}"
  274. standalone="{$standalone}">
  275. <xsl:copy-of select="$content"/>
  276. </saxon:output>
  277. </xsl:when>
  278. <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  279. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  280. href="{$filename}"
  281. method="{$method}"
  282. encoding="{$encoding}"
  283. indent="{$indent}"
  284. omit-xml-declaration="{$omit-xml-declaration}"
  285. cdata-section-elements="{$cdata-section-elements}"
  286. media-type="{$media-type}"
  287. standalone="{$standalone}">
  288. <xsl:copy-of select="$content"/>
  289. </saxon:output>
  290. </xsl:otherwise>
  291. </xsl:choose>
  292. </xsl:when>
  293. <xsl:otherwise>
  294. <xsl:choose>
  295. <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  296. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  297. href="{$filename}"
  298. method="{$method}"
  299. encoding="{$encoding}"
  300. indent="{$indent}"
  301. omit-xml-declaration="{$omit-xml-declaration}"
  302. cdata-section-elements="{$cdata-section-elements}"
  303. doctype-public="{$doctype-public}"
  304. doctype-system="{$doctype-system}"
  305. standalone="{$standalone}">
  306. <xsl:copy-of select="$content"/>
  307. </saxon:output>
  308. </xsl:when>
  309. <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  310. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  311. href="{$filename}"
  312. method="{$method}"
  313. encoding="{$encoding}"
  314. indent="{$indent}"
  315. omit-xml-declaration="{$omit-xml-declaration}"
  316. cdata-section-elements="{$cdata-section-elements}"
  317. doctype-public="{$doctype-public}"
  318. standalone="{$standalone}">
  319. <xsl:copy-of select="$content"/>
  320. </saxon:output>
  321. </xsl:when>
  322. <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  323. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  324. href="{$filename}"
  325. method="{$method}"
  326. encoding="{$encoding}"
  327. indent="{$indent}"
  328. omit-xml-declaration="{$omit-xml-declaration}"
  329. cdata-section-elements="{$cdata-section-elements}"
  330. doctype-system="{$doctype-system}"
  331. standalone="{$standalone}">
  332. <xsl:copy-of select="$content"/>
  333. </saxon:output>
  334. </xsl:when>
  335. <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  336. <saxon:output saxon:character-representation="{$saxon.character.representation}"
  337. href="{$filename}"
  338. method="{$method}"
  339. encoding="{$encoding}"
  340. indent="{$indent}"
  341. omit-xml-declaration="{$omit-xml-declaration}"
  342. cdata-section-elements="{$cdata-section-elements}"
  343. standalone="{$standalone}">
  344. <xsl:copy-of select="$content"/>
  345. </saxon:output>
  346. </xsl:otherwise>
  347. </xsl:choose>
  348. </xsl:otherwise>
  349. </xsl:choose>
  350. </xsl:when>
  351. <xsl:when test="element-available('redirect:write')">
  352. <!-- Xalan uses redirect -->
  353. <redirect:write file="{$filename}">
  354. <xsl:copy-of select="$content"/>
  355. </redirect:write>
  356. </xsl:when>
  357. <xsl:otherwise>
  358. <!-- it doesn't matter since we won't be making chunks... -->
  359. <xsl:message terminate="yes">
  360. <xsl:text>Can't make chunks with </xsl:text>
  361. <xsl:value-of select="system-property('xsl:vendor')"/>
  362. <xsl:text>'s processor.</xsl:text>
  363. </xsl:message>
  364. </xsl:otherwise>
  365. </xsl:choose>
  366. </xsl:template>
  367. <xsl:template name="write.chunk.with.doctype">
  368. <xsl:param name="filename" select="''"/>
  369. <xsl:param name="quiet" select="$chunk.quietly"/>
  370. <xsl:param name="method" select="$chunker.output.method"/>
  371. <xsl:param name="encoding" select="$chunker.output.encoding"/>
  372. <xsl:param name="indent" select="$chunker.output.indent"/>
  373. <xsl:param name="omit-xml-declaration"
  374. select="$chunker.output.omit-xml-declaration"/>
  375. <xsl:param name="standalone" select="$chunker.output.standalone"/>
  376. <xsl:param name="doctype-public" select="$chunker.output.doctype-public"/>
  377. <xsl:param name="doctype-system" select="$chunker.output.doctype-system"/>
  378. <xsl:param name="media-type" select="$chunker.output.media-type"/>
  379. <xsl:param name="cdata-section-elements"
  380. select="$chunker.output.cdata-section-elements"/>
  381. <xsl:param name="content"/>
  382. <xsl:call-template name="write.chunk">
  383. <xsl:with-param name="filename" select="$filename"/>
  384. <xsl:with-param name="quiet" select="$quiet"/>
  385. <xsl:with-param name="method" select="$method"/>
  386. <xsl:with-param name="encoding" select="$encoding"/>
  387. <xsl:with-param name="indent" select="$indent"/>
  388. <xsl:with-param name="omit-xml-declaration" select="$omit-xml-declaration"/>
  389. <xsl:with-param name="standalone" select="$standalone"/>
  390. <xsl:with-param name="doctype-public" select="$doctype-public"/>
  391. <xsl:with-param name="doctype-system" select="$doctype-system"/>
  392. <xsl:with-param name="media-type" select="$media-type"/>
  393. <xsl:with-param name="cdata-section-elements" select="$cdata-section-elements"/>
  394. <xsl:with-param name="content" select="$content"/>
  395. </xsl:call-template>
  396. </xsl:template>
  397. <xsl:template name="write.text.chunk">
  398. <xsl:param name="filename" select="''"/>
  399. <xsl:param name="quiet" select="$chunk.quietly"/>
  400. <xsl:param name="suppress-context-node-name" select="0"/>
  401. <xsl:param name="message-prolog"/>
  402. <xsl:param name="message-epilog"/>
  403. <xsl:param name="method" select="'text'"/>
  404. <xsl:param name="encoding" select="$chunker.output.encoding"/>
  405. <xsl:param name="media-type" select="$chunker.output.media-type"/>
  406. <xsl:param name="content"/>
  407. <xsl:call-template name="write.chunk">
  408. <xsl:with-param name="filename" select="$filename"/>
  409. <xsl:with-param name="quiet" select="$quiet"/>
  410. <xsl:with-param name="suppress-context-node-name" select="$suppress-context-node-name"/>
  411. <xsl:with-param name="message-prolog" select="$message-prolog"/>
  412. <xsl:with-param name="message-epilog" select="$message-epilog"/>
  413. <xsl:with-param name="method" select="$method"/>
  414. <xsl:with-param name="encoding" select="$encoding"/>
  415. <xsl:with-param name="indent" select="'no'"/>
  416. <xsl:with-param name="omit-xml-declaration" select="'yes'"/>
  417. <xsl:with-param name="standalone" select="'no'"/>
  418. <xsl:with-param name="doctype-public"/>
  419. <xsl:with-param name="doctype-system"/>
  420. <xsl:with-param name="media-type" select="$media-type"/>
  421. <xsl:with-param name="cdata-section-elements"/>
  422. <xsl:with-param name="content" select="$content"/>
  423. </xsl:call-template>
  424. </xsl:template>
  425. </xsl:stylesheet>