source: trunk/lib/docbook/docbook/xsl/html/chunker.xsl @ 3316

Last change on this file since 3316 was 3316, checked in by Nicklas Nordborg, 16 years ago

It is not easier to see error/warning in the output from the docbook.

  • Property svn:eol-style set to native
File size: 20.6 KB
Line 
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<!-- ********************************************************************
12     $Id: chunker.xsl 6403 2006-11-12 08:23:54Z bobstayton $
13     ********************************************************************
14
15     This file is part of the XSL DocBook Stylesheet distribution.
16     See ../README or http://nwalsh.com/docbook/xsl/ for copyright
17     and other information.
18
19     ******************************************************************** -->
20
21<!-- ==================================================================== -->
22
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. -->
26
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"/>
37
38<xsl:param name="saxon.character.representation" select="'entity;decimal'"/>
39
40<!-- ==================================================================== -->
41
42<xsl:template name="make-relative-filename">
43  <xsl:param name="base.dir" select="'./'"/>
44  <xsl:param name="base.name" select="''"/>
45
46  <xsl:choose>
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)"/>
51    </xsl:when>
52    <xsl:when test="element-available('exsl:document')">
53      <!-- EXSL document does make the chunks relative, I think -->
54      <xsl:choose>
55        <xsl:when test="count(parent::*) = 0">
56          <xsl:value-of select="concat($base.dir,$base.name)"/>
57        </xsl:when>
58        <xsl:otherwise>
59          <xsl:value-of select="$base.name"/>
60        </xsl:otherwise>
61      </xsl:choose>
62    </xsl:when>
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)"/>
66    </xsl:when>
67    <xsl:otherwise>
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')"/>
71      </xsl:message>
72    </xsl:otherwise>
73  </xsl:choose>
74</xsl:template>
75
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"/>
82
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
95  <xsl:param name="content"/>
96
97  <xsl:if test="$quiet = 0">
98    <xsl:message>
99      <xsl:if test="not($message-prolog = '')">
100        <xsl:value-of select="$message-prolog"/>
101      </xsl:if>
102      <xsl:text>Writing </xsl:text>
103      <xsl:if test="$chunker.message.nofilename = 0">
104        <xsl:value-of select="$filename"/>
105   </xsl:if>
106      <xsl:if test="name(.) != '' and $suppress-context-node-name = 0">
107        <xsl:text> for </xsl:text>
108        <xsl:value-of select="name(.)"/>
109        <xsl:if test="@id or @xml:id">
110          <xsl:text>(</xsl:text>
111          <xsl:value-of select="(@id|@xml:id)[1]"/>
112          <xsl:text>)</xsl:text>
113        </xsl:if>
114      </xsl:if>
115      <xsl:if test="not($message-epilog = '')">
116        <xsl:value-of select="$message-epilog"/>
117      </xsl:if>
118    </xsl:message>
119  </xsl:if>
120
121  <xsl:choose>
122    <xsl:when test="element-available('exsl:document')">
123      <xsl:choose>
124        <!-- Handle the permutations ... -->
125        <xsl:when test="$media-type != ''">
126          <xsl:choose>
127            <xsl:when test="$doctype-public != '' and $doctype-system != ''">
128              <exsl:document href="{$filename}"
129                             method="{$method}"
130                             encoding="{$encoding}"
131                             indent="{$indent}"
132                             omit-xml-declaration="{$omit-xml-declaration}"
133                             cdata-section-elements="{$cdata-section-elements}"
134                             media-type="{$media-type}"
135                             doctype-public="{$doctype-public}"
136                             doctype-system="{$doctype-system}"
137                             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}"
143                             method="{$method}"
144                             encoding="{$encoding}"
145                             indent="{$indent}"
146                             omit-xml-declaration="{$omit-xml-declaration}"
147                             cdata-section-elements="{$cdata-section-elements}"
148                             media-type="{$media-type}"
149                             doctype-public="{$doctype-public}"
150                             standalone="{$standalone}">
151                <xsl:copy-of select="$content"/>
152              </exsl:document>
153            </xsl:when>
154            <xsl:when test="$doctype-public = '' and $doctype-system != ''">
155              <exsl:document href="{$filename}"
156                             method="{$method}"
157                             encoding="{$encoding}"
158                             indent="{$indent}"
159                             omit-xml-declaration="{$omit-xml-declaration}"
160                             cdata-section-elements="{$cdata-section-elements}"
161                             media-type="{$media-type}"
162                             doctype-system="{$doctype-system}"
163                             standalone="{$standalone}">
164                <xsl:copy-of select="$content"/>
165              </exsl:document>
166            </xsl:when>
167            <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
168              <exsl:document href="{$filename}"
169                             method="{$method}"
170                             encoding="{$encoding}"
171                             indent="{$indent}"
172                             omit-xml-declaration="{$omit-xml-declaration}"
173                             cdata-section-elements="{$cdata-section-elements}"
174                             media-type="{$media-type}"
175                             standalone="{$standalone}">
176                <xsl:copy-of select="$content"/>
177              </exsl:document>
178            </xsl:otherwise>
179          </xsl:choose>
180        </xsl:when>
181        <xsl:otherwise>
182          <xsl:choose>
183            <xsl:when test="$doctype-public != '' and $doctype-system != ''">
184              <exsl:document href="{$filename}"
185                             method="{$method}"
186                             encoding="{$encoding}"
187                             indent="{$indent}"
188                             omit-xml-declaration="{$omit-xml-declaration}"
189                             cdata-section-elements="{$cdata-section-elements}"
190                             doctype-public="{$doctype-public}"
191                             doctype-system="{$doctype-system}"
192                             standalone="{$standalone}">
193                <xsl:copy-of select="$content"/>
194              </exsl:document>
195            </xsl:when>
196            <xsl:when test="$doctype-public != '' and $doctype-system = ''">
197              <exsl:document href="{$filename}"
198                             method="{$method}"
199                             encoding="{$encoding}"
200                             indent="{$indent}"
201                             omit-xml-declaration="{$omit-xml-declaration}"
202                             cdata-section-elements="{$cdata-section-elements}"
203                             doctype-public="{$doctype-public}"
204                             standalone="{$standalone}">
205                <xsl:copy-of select="$content"/>
206              </exsl:document>
207            </xsl:when>
208            <xsl:when test="$doctype-public = '' and $doctype-system != ''">
209              <exsl:document href="{$filename}"
210                             method="{$method}"
211                             encoding="{$encoding}"
212                             indent="{$indent}"
213                             omit-xml-declaration="{$omit-xml-declaration}"
214                             cdata-section-elements="{$cdata-section-elements}"
215                             doctype-system="{$doctype-system}"
216                             standalone="{$standalone}">
217                <xsl:copy-of select="$content"/>
218              </exsl:document>
219            </xsl:when>
220            <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
221              <exsl:document href="{$filename}"
222                             method="{$method}"
223                             encoding="{$encoding}"
224                             indent="{$indent}"
225                             omit-xml-declaration="{$omit-xml-declaration}"
226                             cdata-section-elements="{$cdata-section-elements}"
227                             standalone="{$standalone}">
228                <xsl:copy-of select="$content"/>
229              </exsl:document>
230            </xsl:otherwise>
231          </xsl:choose>
232        </xsl:otherwise>
233      </xsl:choose>
234    </xsl:when>
235
236    <xsl:when test="element-available('saxon:output')">
237      <xsl:choose>
238        <!-- Handle the permutations ... -->
239        <xsl:when test="$media-type != ''">
240          <xsl:choose>
241            <xsl:when test="$doctype-public != '' and $doctype-system != ''">
242              <saxon:output saxon:character-representation="{$saxon.character.representation}"
243                            href="{$filename}"
244                            method="{$method}"
245                            encoding="{$encoding}"
246                            indent="{$indent}"
247                            omit-xml-declaration="{$omit-xml-declaration}"
248                            cdata-section-elements="{$cdata-section-elements}"
249                            media-type="{$media-type}"
250                            doctype-public="{$doctype-public}"
251                            doctype-system="{$doctype-system}"
252                            standalone="{$standalone}">
253                <xsl:copy-of select="$content"/>
254              </saxon:output>
255            </xsl:when>
256            <xsl:when test="$doctype-public != '' and $doctype-system = ''">
257              <saxon:output saxon:character-representation="{$saxon.character.representation}"
258                            href="{$filename}"
259                            method="{$method}"
260                            encoding="{$encoding}"
261                            indent="{$indent}"
262                            omit-xml-declaration="{$omit-xml-declaration}"
263                            cdata-section-elements="{$cdata-section-elements}"
264                            media-type="{$media-type}"
265                            doctype-public="{$doctype-public}"
266                            standalone="{$standalone}">
267                <xsl:copy-of select="$content"/>
268              </saxon:output>
269            </xsl:when>
270            <xsl:when test="$doctype-public = '' and $doctype-system != ''">
271              <saxon:output saxon:character-representation="{$saxon.character.representation}"
272                            href="{$filename}"
273                            method="{$method}"
274                            encoding="{$encoding}"
275                            indent="{$indent}"
276                            omit-xml-declaration="{$omit-xml-declaration}"
277                            cdata-section-elements="{$cdata-section-elements}"
278                            media-type="{$media-type}"
279                            doctype-system="{$doctype-system}"
280                            standalone="{$standalone}">
281                <xsl:copy-of select="$content"/>
282              </saxon:output>
283            </xsl:when>
284            <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
285              <saxon:output saxon:character-representation="{$saxon.character.representation}"
286                            href="{$filename}"
287                            method="{$method}"
288                            encoding="{$encoding}"
289                            indent="{$indent}"
290                            omit-xml-declaration="{$omit-xml-declaration}"
291                            cdata-section-elements="{$cdata-section-elements}"
292                            media-type="{$media-type}"
293                            standalone="{$standalone}">
294                <xsl:copy-of select="$content"/>
295              </saxon:output>
296            </xsl:otherwise>
297          </xsl:choose>
298        </xsl:when>
299        <xsl:otherwise>
300          <xsl:choose>
301            <xsl:when test="$doctype-public != '' and $doctype-system != ''">
302              <saxon:output saxon:character-representation="{$saxon.character.representation}"
303                            href="{$filename}"
304                            method="{$method}"
305                            encoding="{$encoding}"
306                            indent="{$indent}"
307                            omit-xml-declaration="{$omit-xml-declaration}"
308                            cdata-section-elements="{$cdata-section-elements}"
309                            doctype-public="{$doctype-public}"
310                            doctype-system="{$doctype-system}"
311                            standalone="{$standalone}">
312                <xsl:copy-of select="$content"/>
313              </saxon:output>
314            </xsl:when>
315            <xsl:when test="$doctype-public != '' and $doctype-system = ''">
316              <saxon:output saxon:character-representation="{$saxon.character.representation}"
317                            href="{$filename}"
318                            method="{$method}"
319                            encoding="{$encoding}"
320                            indent="{$indent}"
321                            omit-xml-declaration="{$omit-xml-declaration}"
322                            cdata-section-elements="{$cdata-section-elements}"
323                            doctype-public="{$doctype-public}"
324                            standalone="{$standalone}">
325                <xsl:copy-of select="$content"/>
326              </saxon:output>
327            </xsl:when>
328            <xsl:when test="$doctype-public = '' and $doctype-system != ''">
329              <saxon:output saxon:character-representation="{$saxon.character.representation}"
330                            href="{$filename}"
331                            method="{$method}"
332                            encoding="{$encoding}"
333                            indent="{$indent}"
334                            omit-xml-declaration="{$omit-xml-declaration}"
335                            cdata-section-elements="{$cdata-section-elements}"
336                            doctype-system="{$doctype-system}"
337                            standalone="{$standalone}">
338                <xsl:copy-of select="$content"/>
339              </saxon:output>
340            </xsl:when>
341            <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
342              <saxon:output saxon:character-representation="{$saxon.character.representation}"
343                            href="{$filename}"
344                            method="{$method}"
345                            encoding="{$encoding}"
346                            indent="{$indent}"
347                            omit-xml-declaration="{$omit-xml-declaration}"
348                            cdata-section-elements="{$cdata-section-elements}"
349                            standalone="{$standalone}">
350                <xsl:copy-of select="$content"/>
351              </saxon:output>
352            </xsl:otherwise>
353          </xsl:choose>
354        </xsl:otherwise>
355      </xsl:choose>
356    </xsl:when>
357
358    <xsl:when test="element-available('redirect:write')">
359      <!-- Xalan uses redirect -->
360      <redirect:write file="{$filename}">
361        <xsl:copy-of select="$content"/>
362      </redirect:write>
363    </xsl:when>
364
365    <xsl:otherwise>
366      <!-- it doesn't matter since we won't be making chunks... -->
367      <xsl:message terminate="yes">
368        <xsl:text>Can't make chunks with </xsl:text>
369        <xsl:value-of select="system-property('xsl:vendor')"/>
370        <xsl:text>'s processor.</xsl:text>
371      </xsl:message>
372    </xsl:otherwise>
373  </xsl:choose>
374</xsl:template>
375
376<xsl:template name="write.chunk.with.doctype">
377  <xsl:param name="filename" select="''"/>
378  <xsl:param name="quiet" select="$chunker.output.quiet"/>
379
380  <xsl:param name="method" select="$chunker.output.method"/>
381  <xsl:param name="encoding" select="$chunker.output.encoding"/>
382  <xsl:param name="indent" select="$chunker.output.indent"/>
383  <xsl:param name="omit-xml-declaration"
384             select="$chunker.output.omit-xml-declaration"/>
385  <xsl:param name="standalone" select="$chunker.output.standalone"/>
386  <xsl:param name="doctype-public" select="$chunker.output.doctype-public"/>
387  <xsl:param name="doctype-system" select="$chunker.output.doctype-system"/>
388  <xsl:param name="media-type" select="$chunker.output.media-type"/>
389  <xsl:param name="cdata-section-elements"
390             select="$chunker.output.cdata-section-elements"/>
391
392  <xsl:param name="content"/>
393
394  <xsl:call-template name="write.chunk">
395    <xsl:with-param name="filename" select="$filename"/>
396    <xsl:with-param name="quiet" select="$quiet"/>
397    <xsl:with-param name="method" select="$method"/>
398    <xsl:with-param name="encoding" select="$encoding"/>
399    <xsl:with-param name="indent" select="$indent"/>
400    <xsl:with-param name="omit-xml-declaration" select="$omit-xml-declaration"/>
401    <xsl:with-param name="standalone" select="$standalone"/>
402    <xsl:with-param name="doctype-public" select="$doctype-public"/>
403    <xsl:with-param name="doctype-system" select="$doctype-system"/>
404    <xsl:with-param name="media-type" select="$media-type"/>
405    <xsl:with-param name="cdata-section-elements" select="$cdata-section-elements"/>
406    <xsl:with-param name="content" select="$content"/>
407  </xsl:call-template>
408</xsl:template>
409
410<xsl:template name="write.text.chunk">
411  <xsl:param name="filename" select="''"/>
412  <xsl:param name="quiet" select="$chunker.output.quiet"/>
413  <xsl:param name="suppress-context-node-name" select="0"/>
414  <xsl:param name="message-prolog"/>
415  <xsl:param name="message-epilog"/>
416  <xsl:param name="method" select="'text'"/>
417  <xsl:param name="encoding" select="$chunker.output.encoding"/>
418  <xsl:param name="media-type" select="$chunker.output.media-type"/>
419  <xsl:param name="content"/>
420
421  <xsl:call-template name="write.chunk">
422    <xsl:with-param name="filename" select="$filename"/>
423    <xsl:with-param name="quiet" select="$quiet"/>
424    <xsl:with-param name="suppress-context-node-name" select="$suppress-context-node-name"/>
425    <xsl:with-param name="message-prolog" select="$message-prolog"/>
426    <xsl:with-param name="message-epilog" select="$message-epilog"/>
427    <xsl:with-param name="method" select="$method"/>
428    <xsl:with-param name="encoding" select="$encoding"/>
429    <xsl:with-param name="indent" select="'no'"/>
430    <xsl:with-param name="omit-xml-declaration" select="'no'"/>
431    <xsl:with-param name="standalone" select="'no'"/>
432    <xsl:with-param name="doctype-public"/>
433    <xsl:with-param name="doctype-system"/>
434    <xsl:with-param name="media-type" select="$media-type"/>
435    <xsl:with-param name="cdata-section-elements"/>
436    <xsl:with-param name="content" select="$content"/>
437  </xsl:call-template>
438</xsl:template>
439
440
441</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.