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"
8 exclude-result-prefixes="saxon lxslt redirect exsl doc"
9 extension-element-prefixes="saxon redirect lxslt exsl">
11 <!-- ********************************************************************
12 $Id: chunker.xsl 8526 2009-10-14 18:59:40Z bobstayton $
13 ********************************************************************
15 This file is part of the XSL DocBook Stylesheet distribution.
16 See ../README or http://docbook.sf.net/release/xsl/current/ for
17 copyright and other information.
19 ******************************************************************** -->
21 <!-- ==================================================================== -->
23 <!-- This stylesheet works with XSLT implementations that support -->
24 <!-- exsl:document, saxon:output, or Xalan's redirect:write -->
25 <!-- Note: Only Saxon 6.4.2 or later is supported. -->
27 <xsl:param name="chunker.output.method" select="'html'"/>
28 <xsl:param name="chunker.output.encoding" select="'ISO-8859-1'"/>
29 <xsl:param name="chunker.output.indent" select="'no'"/>
30 <xsl:param name="chunker.output.omit-xml-declaration" select="'no'"/>
31 <xsl:param name="chunker.output.standalone" select="'no'"/>
32 <xsl:param name="chunker.output.doctype-public" select="''"/>
33 <xsl:param name="chunker.output.doctype-system" select="''"/>
34 <xsl:param name="chunker.output.media-type" select="''"/>
35 <xsl:param name="chunker.output.cdata-section-elements" select="''"/>
36 <xsl:param name="chunker.output.quiet" select="0"/>
38 <xsl:param name="saxon.character.representation" select="'entity;decimal'"/>
40 <!-- ==================================================================== -->
42 <xsl:template name="make-relative-filename">
43 <xsl:param name="base.dir" select="'./'"/>
44 <xsl:param name="base.name" select="''"/>
47 <!-- put Saxon first to work around a bug in libxslt -->
48 <xsl:when test="element-available('saxon:output')">
49 <!-- Saxon doesn't make the chunks relative -->
50 <xsl:value-of select="concat($base.dir,$base.name)"/>
52 <xsl:when test="element-available('exsl:document')">
53 <!-- EXSL document does make the chunks relative, I think -->
55 <xsl:when test="count(parent::*) = 0">
56 <xsl:value-of select="concat($base.dir,$base.name)"/>
59 <xsl:value-of select="$base.name"/>
63 <xsl:when test="element-available('redirect:write')">
64 <!-- Xalan doesn't make the chunks relative -->
65 <xsl:value-of select="concat($base.dir,$base.name)"/>
68 <xsl:message terminate="yes">
69 <xsl:text>Don't know how to chunk with </xsl:text>
70 <xsl:value-of select="system-property('xsl:vendor')"/>
76 <xsl:template name="write.chunk">
77 <xsl:param name="filename" select="''"/>
78 <xsl:param name="quiet" select="$chunker.output.quiet"/>
79 <xsl:param name="suppress-context-node-name" select="0"/>
80 <xsl:param name="message-prolog"/>
81 <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"/>
95 <xsl:param name="content"/>
97 <xsl:if test="$quiet = 0">
99 <xsl:if test="not($message-prolog = '')">
100 <xsl:value-of select="$message-prolog"/>
102 <xsl:text>Writing </xsl:text>
103 <xsl:value-of select="$filename"/>
104 <xsl:if test="name(.) != '' and $suppress-context-node-name = 0">
105 <xsl:text> for </xsl:text>
106 <xsl:value-of select="name(.)"/>
107 <xsl:if test="@id or @xml:id">
108 <xsl:text>(</xsl:text>
109 <xsl:value-of select="(@id|@xml:id)[1]"/>
110 <xsl:text>)</xsl:text>
113 <xsl:if test="not($message-epilog = '')">
114 <xsl:value-of select="$message-epilog"/>
120 <xsl:when test="element-available('exsl:document')">
122 <!-- Handle the permutations ... -->
123 <xsl:when test="$media-type != ''">
125 <xsl:when test="$doctype-public != '' and $doctype-system != ''">
126 <exsl:document href="{$filename}"
128 encoding="{$encoding}"
130 omit-xml-declaration="{$omit-xml-declaration}"
131 cdata-section-elements="{$cdata-section-elements}"
132 media-type="{$media-type}"
133 doctype-public="{$doctype-public}"
134 doctype-system="{$doctype-system}"
135 standalone="{$standalone}">
136 <xsl:copy-of select="$content"/>
139 <xsl:when test="$doctype-public != '' and $doctype-system = ''">
140 <exsl:document href="{$filename}"
142 encoding="{$encoding}"
144 omit-xml-declaration="{$omit-xml-declaration}"
145 cdata-section-elements="{$cdata-section-elements}"
146 media-type="{$media-type}"
147 doctype-public="{$doctype-public}"
148 standalone="{$standalone}">
149 <xsl:copy-of select="$content"/>
152 <xsl:when test="$doctype-public = '' and $doctype-system != ''">
153 <exsl:document href="{$filename}"
155 encoding="{$encoding}"
157 omit-xml-declaration="{$omit-xml-declaration}"
158 cdata-section-elements="{$cdata-section-elements}"
159 media-type="{$media-type}"
160 doctype-system="{$doctype-system}"
161 standalone="{$standalone}">
162 <xsl:copy-of select="$content"/>
165 <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
166 <exsl:document href="{$filename}"
168 encoding="{$encoding}"
170 omit-xml-declaration="{$omit-xml-declaration}"
171 cdata-section-elements="{$cdata-section-elements}"
172 media-type="{$media-type}"
173 standalone="{$standalone}">
174 <xsl:copy-of select="$content"/>
181 <xsl:when test="$doctype-public != '' and $doctype-system != ''">
182 <exsl:document href="{$filename}"
184 encoding="{$encoding}"
186 omit-xml-declaration="{$omit-xml-declaration}"
187 cdata-section-elements="{$cdata-section-elements}"
188 doctype-public="{$doctype-public}"
189 doctype-system="{$doctype-system}"
190 standalone="{$standalone}">
191 <xsl:copy-of select="$content"/>
194 <xsl:when test="$doctype-public != '' and $doctype-system = ''">
195 <exsl:document href="{$filename}"
197 encoding="{$encoding}"
199 omit-xml-declaration="{$omit-xml-declaration}"
200 cdata-section-elements="{$cdata-section-elements}"
201 doctype-public="{$doctype-public}"
202 standalone="{$standalone}">
203 <xsl:copy-of select="$content"/>
206 <xsl:when test="$doctype-public = '' and $doctype-system != ''">
207 <exsl:document href="{$filename}"
209 encoding="{$encoding}"
211 omit-xml-declaration="{$omit-xml-declaration}"
212 cdata-section-elements="{$cdata-section-elements}"
213 doctype-system="{$doctype-system}"
214 standalone="{$standalone}">
215 <xsl:copy-of select="$content"/>
218 <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
219 <exsl:document href="{$filename}"
221 encoding="{$encoding}"
223 omit-xml-declaration="{$omit-xml-declaration}"
224 cdata-section-elements="{$cdata-section-elements}"
225 standalone="{$standalone}">
226 <xsl:copy-of select="$content"/>
234 <xsl:when test="element-available('saxon:output')">
236 <!-- Handle the permutations ... -->
237 <xsl:when test="$media-type != ''">
239 <xsl:when test="$doctype-public != '' and $doctype-system != ''">
240 <saxon:output saxon:character-representation="{$saxon.character.representation}"
243 encoding="{$encoding}"
245 omit-xml-declaration="{$omit-xml-declaration}"
246 cdata-section-elements="{$cdata-section-elements}"
247 media-type="{$media-type}"
248 doctype-public="{$doctype-public}"
249 doctype-system="{$doctype-system}"
250 standalone="{$standalone}">
251 <xsl:copy-of select="$content"/>
254 <xsl:when test="$doctype-public != '' and $doctype-system = ''">
255 <saxon:output saxon:character-representation="{$saxon.character.representation}"
258 encoding="{$encoding}"
260 omit-xml-declaration="{$omit-xml-declaration}"
261 cdata-section-elements="{$cdata-section-elements}"
262 media-type="{$media-type}"
263 doctype-public="{$doctype-public}"
264 standalone="{$standalone}">
265 <xsl:copy-of select="$content"/>
268 <xsl:when test="$doctype-public = '' and $doctype-system != ''">
269 <saxon:output saxon:character-representation="{$saxon.character.representation}"
272 encoding="{$encoding}"
274 omit-xml-declaration="{$omit-xml-declaration}"
275 cdata-section-elements="{$cdata-section-elements}"
276 media-type="{$media-type}"
277 doctype-system="{$doctype-system}"
278 standalone="{$standalone}">
279 <xsl:copy-of select="$content"/>
282 <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
283 <saxon:output saxon:character-representation="{$saxon.character.representation}"
286 encoding="{$encoding}"
288 omit-xml-declaration="{$omit-xml-declaration}"
289 cdata-section-elements="{$cdata-section-elements}"
290 media-type="{$media-type}"
291 standalone="{$standalone}">
292 <xsl:copy-of select="$content"/>
299 <xsl:when test="$doctype-public != '' and $doctype-system != ''">
300 <saxon:output saxon:character-representation="{$saxon.character.representation}"
303 encoding="{$encoding}"
305 omit-xml-declaration="{$omit-xml-declaration}"
306 cdata-section-elements="{$cdata-section-elements}"
307 doctype-public="{$doctype-public}"
308 doctype-system="{$doctype-system}"
309 standalone="{$standalone}">
310 <xsl:copy-of select="$content"/>
313 <xsl:when test="$doctype-public != '' and $doctype-system = ''">
314 <saxon:output saxon:character-representation="{$saxon.character.representation}"
317 encoding="{$encoding}"
319 omit-xml-declaration="{$omit-xml-declaration}"
320 cdata-section-elements="{$cdata-section-elements}"
321 doctype-public="{$doctype-public}"
322 standalone="{$standalone}">
323 <xsl:copy-of select="$content"/>
326 <xsl:when test="$doctype-public = '' and $doctype-system != ''">
327 <saxon:output saxon:character-representation="{$saxon.character.representation}"
330 encoding="{$encoding}"
332 omit-xml-declaration="{$omit-xml-declaration}"
333 cdata-section-elements="{$cdata-section-elements}"
334 doctype-system="{$doctype-system}"
335 standalone="{$standalone}">
336 <xsl:copy-of select="$content"/>
339 <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
340 <saxon:output saxon:character-representation="{$saxon.character.representation}"
343 encoding="{$encoding}"
345 omit-xml-declaration="{$omit-xml-declaration}"
346 cdata-section-elements="{$cdata-section-elements}"
347 standalone="{$standalone}">
348 <xsl:copy-of select="$content"/>
356 <xsl:when test="element-available('redirect:write')">
357 <!-- Xalan uses redirect -->
358 <redirect:write file="{$filename}">
359 <xsl:copy-of select="$content"/>
364 <!-- it doesn't matter since we won't be making chunks... -->
365 <xsl:message terminate="yes">
366 <xsl:text>Can't make chunks with </xsl:text>
367 <xsl:value-of select="system-property('xsl:vendor')"/>
368 <xsl:text>'s processor.</xsl:text>
374 <xsl:template name="write.chunk.with.doctype">
375 <xsl:param name="filename" select="''"/>
376 <xsl:param name="quiet" select="$chunker.output.quiet"/>
378 <xsl:param name="method" select="$chunker.output.method"/>
379 <xsl:param name="encoding" select="$chunker.output.encoding"/>
380 <xsl:param name="indent" select="$chunker.output.indent"/>
381 <xsl:param name="omit-xml-declaration"
382 select="$chunker.output.omit-xml-declaration"/>
383 <xsl:param name="standalone" select="$chunker.output.standalone"/>
384 <xsl:param name="doctype-public" select="$chunker.output.doctype-public"/>
385 <xsl:param name="doctype-system" select="$chunker.output.doctype-system"/>
386 <xsl:param name="media-type" select="$chunker.output.media-type"/>
387 <xsl:param name="cdata-section-elements"
388 select="$chunker.output.cdata-section-elements"/>
390 <xsl:param name="content"/>
392 <xsl:call-template name="write.chunk">
393 <xsl:with-param name="filename" select="$filename"/>
394 <xsl:with-param name="quiet" select="$quiet"/>
395 <xsl:with-param name="method" select="$method"/>
396 <xsl:with-param name="encoding" select="$encoding"/>
397 <xsl:with-param name="indent" select="$indent"/>
398 <xsl:with-param name="omit-xml-declaration" select="$omit-xml-declaration"/>
399 <xsl:with-param name="standalone" select="$standalone"/>
400 <xsl:with-param name="doctype-public" select="$doctype-public"/>
401 <xsl:with-param name="doctype-system" select="$doctype-system"/>
402 <xsl:with-param name="media-type" select="$media-type"/>
403 <xsl:with-param name="cdata-section-elements" select="$cdata-section-elements"/>
404 <xsl:with-param name="content" select="$content"/>
408 <xsl:template name="write.text.chunk">
409 <xsl:param name="filename" select="''"/>
410 <xsl:param name="quiet" select="$chunker.output.quiet"/>
411 <xsl:param name="suppress-context-node-name" select="0"/>
412 <xsl:param name="message-prolog"/>
413 <xsl:param name="message-epilog"/>
414 <xsl:param name="method" select="'text'"/>
415 <xsl:param name="encoding" select="$chunker.output.encoding"/>
416 <xsl:param name="media-type" select="$chunker.output.media-type"/>
417 <xsl:param name="content"/>
419 <xsl:call-template name="write.chunk">
420 <xsl:with-param name="filename" select="$filename"/>
421 <xsl:with-param name="quiet" select="$quiet"/>
422 <xsl:with-param name="suppress-context-node-name" select="$suppress-context-node-name"/>
423 <xsl:with-param name="message-prolog" select="$message-prolog"/>
424 <xsl:with-param name="message-epilog" select="$message-epilog"/>
425 <xsl:with-param name="method" select="$method"/>
426 <xsl:with-param name="encoding" select="$encoding"/>
427 <xsl:with-param name="indent" select="'no'"/>
428 <xsl:with-param name="omit-xml-declaration" select="'no'"/>
429 <xsl:with-param name="standalone" select="'no'"/>
430 <xsl:with-param name="doctype-public"/>
431 <xsl:with-param name="doctype-system"/>
432 <xsl:with-param name="media-type" select="$media-type"/>
433 <xsl:with-param name="cdata-section-elements"/>
434 <xsl:with-param name="content" select="$content"/>