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