source: other-projects/trunk/realistic-books/packages/AntInstaller/web/manual1.7.0/manual/CoreTasks/style.html@ 19253

Last change on this file since 19253 was 19253, checked in by davidb, 15 years ago

Establishing a source code repository for Veronica's Realistic Book's software

File size: 18.5 KB
Line 
1<!--
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17<html>
18
19<head>
20<meta http-equiv="Content-Language" content="en-us">
21<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
22<title>XSLT Task</title>
23</head>
24
25<body>
26
27<h2><a name="style">XSLT</a></h2>
28<p><em>The name <code>style</code> is a deprecated name for the same task.</em></p>
29<h3>Description</h3>
30<p>Process a set of documents via XSLT.</p>
31<p>This is useful for building views of XML based documentation,
32or for generating code.</p>
33<p><b>Note:</b> If you are using JDK 1.4 or higher, this task does not require external libraries
34not supplied in the Ant distribution. However, often the built in XSL engine is not as up
35to date as a fresh download, so an update is still highly recommended.
36See <a href="../install.html#librarydependencies">Library Dependencies</a> for more information.</p>
37<p>It is possible to refine the set of files that are being processed. This can be
38done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
39attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
40have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
41the files you want to have excluded. This is also done with patterns. And
42finally with the <i>defaultexcludes</i> attribute, you can specify whether you
43want to use default exclusions or not. See the section on <a
44href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
45inclusion/exclusion of files works, and how to write patterns.</p>
46<p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and supports all
47 attributes of <code>&lt;fileset&gt;</code> (<code>dir</code> becomes <code>basedir</code>)
48 as well as the nested <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code>
49 and <code>&lt;patternset&gt;</code> elements.</p>
50
51<p><b>Note</b>: Unlike other similar tasks, this task treats
52directories that have been matched by the include/exclude patterns of
53the implicit fileset in a special way. It will apply the stylesheets
54to all files contain in them as well. Since the default include
55pattern is <code>**</code> this means it will apply the stylesheet to
56all files. If you specify an excludes pattern, it may still work on
57the files matched by those patterns because the parent directory has
58been matched. If this behavior is not what you want, set the
59scanincludedirectories attribute to false.</p>
60
61<p>Starting with Ant 1.7 this task supports nested <a
62href="../CoreTypes/resources.html#collection">resource collection</a>s
63in addition to (or instead of, depending on the useImplicitFileset
64attribute) the implicit fileset formed by this task.</p>
65
66<p>This task supports the use of a nested <code>&lt;param&gt;</code> element which is used to pass values
67 to an <code>&lt;xsl:param&gt;</code> declaration.</p>
68<p>This task supports the use of a nested <a href="../CoreTypes/xmlcatalog.html">xmlcatalog</a>
69element which is used to perform Entity and URI resolution.</p>
70<h3>Parameters</h3>
71<table border="1" cellpadding="2" cellspacing="0">
72 <tr>
73 <td valign="top"><b>Attribute</b></td>
74 <td valign="top"><b>Description</b></td>
75 <td align="center" valign="top"><b>Required</b></td>
76 </tr>
77 <tr>
78 <td valign="top">basedir</td>
79 <td valign="top">where to find the source XML file, default is the
80 project's basedir.</td>
81 <td align="center" valign="top">No</td>
82 </tr>
83 <tr>
84 <td valign="top">destdir</td>
85 <td valign="top">directory in which to store the results.</td>
86 <td align="center" valign="top">Yes, unless in and out have been
87 specified.</td>
88 </tr>
89 <tr>
90 <td valign="top">extension</td>
91 <td valign="top">desired file extension to be used for the targets. If not
92 specified, the default is &quot;.html&quot;. Will be ignored if
93 a nested <code>&lt;mapper&gt;</code> has been specified.</td>
94 <td align="center" valign="top">No</td>
95 </tr>
96 <tr>
97 <td valign="top">style</td>
98 <td valign="top">name of the stylesheet to use - given either relative
99 to the project's basedir or as an absolute path.<br/>
100 <br/>
101 Alternatively, a nested element which ant can interpret as a resource
102 can be used to indicate where to find the stylesheet<br/>
103 <em>deprecated variation :</em> <br/>
104 If the stylesheet cannot be found, and if you have specified the
105 attribute basedir for the task, ant will assume that the style
106 attribute is relative to the basedir of the task.
107 </td>
108 <td align="center" valign="top">No, if the location of
109 the stylesheet is specified using a nested &lt;style&gt; element</td>
110 </tr>
111 <tr>
112 <td valign="top">classpath</td>
113 <td valign="top">the classpath to use when looking up the XSLT
114 processor.</td>
115 <td align="center" valign="top">No</td>
116 </tr>
117 <tr>
118 <td valign="top">classpathref</td>
119 <td valign="top">the classpath to use, given as <a
120 href="../using.html#references">reference</a> to a path defined elsewhere.</td>
121 <td align="center" valign="top">No</td>
122 </tr>
123 <tr>
124 <td valign="top">force</td>
125 <td valign="top">Recreate target files, even if they are newer
126 than their corresponding source files or the stylesheet.</td>
127 <td valign="top" align="center">No; default is false</td>
128 </tr>
129 <tr>
130 <td valign="top">processor</td>
131
132 <td valign="top">name of the XSLT processor to use.
133 Permissible value is :<ul>
134 <li>&quot;trax&quot; for a TraX compliant processor (ie JAXP interface
135 implementation such as Xalan 2 or Saxon)</li></ul>
136 Defaults to trax.
137 <br/>
138 Support for xalan1 has been removed in ant 1.7.
139 </td>
140 <td align="center" valign="top">No</td>
141 </tr>
142 <tr>
143 <td valign="top">includes</td>
144 <td valign="top">comma- or space-separated list of patterns of files that must be included.
145 All files are included when omitted.</td>
146 <td valign="top" align="center">No</td>
147 </tr>
148 <tr>
149 <td valign="top">includesfile</td>
150 <td valign="top">the name of a file. Each line of this file is taken to be
151 an include pattern</td>
152 <td valign="top" align="center">No</td>
153 </tr>
154 <tr>
155 <td valign="top">excludes</td>
156 <td valign="top">comma- or space-separated list of patterns of files that must be excluded.
157 No files (except default excludes) are excluded when omitted.</td>
158 <td valign="top" align="center">No</td>
159 </tr>
160 <tr>
161 <td valign="top">excludesfile</td>
162 <td valign="top">the name of a file. Each line of this file is taken to be
163 an exclude pattern</td>
164 <td valign="top" align="center">No</td>
165 </tr>
166 <tr>
167 <td valign="top">defaultexcludes</td>
168 <td valign="top">indicates whether default excludes should be used or not
169 (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
170 <td valign="top" align="center">No</td>
171 </tr>
172 <tr>
173 <td valign="top">in</td>
174 <td valign="top">specifies a single XML document to be styled. Should be used
175 with the out attribute.</td>
176 <td valign="top" align="center">No</td>
177 </tr>
178 <tr>
179 <td valign="top">out</td>
180 <td valign="top">specifies the output name for the styled result from the
181 in attribute.</td>
182 <td valign="top" align="center">No</td>
183 </tr>
184 <tr>
185 <td valign="top">scanincludeddirectories</td>
186 <td valign="top">If any directories are matched by the
187 includes/excludes patterns, try to transform all files in these
188 directories. Default is <code>true</code></td>
189 <td valign="top" align="center">No</td>
190 </tr>
191 <tr>
192 <td valign="top">reloadstylesheet</td>
193 <td valign="top">Control whether the stylesheet transformer is created
194 anew for every transform opertaion. If you set this to true, performance may
195 suffer, but you may work around a bug in certain Xalan-J versions.
196 Default is <code>false</code>. <em>Since Ant 1.5.2</em>.</td>
197 <td valign="top" align="center">No</td>
198 </tr>
199 <tr>
200 <td valign="top">useImplicitFileset</td>
201 <td valign="top">Whether the implicit fileset formed by this task
202 shall be used. If you set this to false you must use nested
203 resource collections - or the in attribute, in which case this
204 attribute has no impact anyway. Default is <code>true</code>.
205 <em>Since Ant 1.7</em>.</td>
206 <td valign="top" align="center">No</td>
207 </tr>
208 <tr>
209 <td valign="top">filenameparameter</td>
210 <td valign="top">Specifies a xsl parameter for accessing the name
211 of the current processed file. If not set, the file name is not
212 passed to the transformation.
213 <em>Since Ant 1.7</em>.</td>
214 <td valign="top" align="center">No</td>
215 </tr>
216 <tr>
217 <td valign="top">filedirparameter</td>
218 <td valign="top">Specifies a xsl parameter for accessing the directory
219 of the current processed file. For files in the current directory a
220 value of '.' will be passed to the transformation.
221 If not set, the directory is not passed to the transformation.
222 <em>Since Ant 1.7</em>.</td>
223 <td valign="top" align="center">No</td>
224 </tr>
225</table>
226<h3>Parameters specified as nested elements</h3>
227
228<h4>any <a href="../CoreTypes/resources.html#collection">resource
229collection</a></h4>
230
231<p><em>since Ant 1.7</em></p>
232
233<p>Use resource collections to specify resources that the stylesheet
234should be applied to. Use a nested mapper and the task's destdir
235attribute to specify the output files.</p>
236
237<h4>classpath</h4>
238<p>The classpath to load the processor from can be specified via a
239nested <code>&lt;classpath&gt;</code>, as well - that is, a
240<a href="../using.html#path">path</a>-like structure.</p>
241
242<h4>xmlcatalog</h4>
243<p>The <a href="../CoreTypes/xmlcatalog.html">xmlcatalog</a>
244element is used to perform Entity and URI resolution.</p>
245
246<h4>param</h4>
247<p>Param is used to pass a parameter to the XSL stylesheet.</p>
248<blockquote>
249<h4>Parameters</h4>
250<table width="60%" border="1" cellpadding="2" cellspacing="0">
251 <tr>
252 <td valign="top"><b>Attribute</b></td>
253 <td valign="top"><b>Description</b></td>
254 <td align="center" valign="top"><b>Required</b></td>
255 </tr>
256 <tr>
257 <td valign="top">name</td>
258 <td valign="top">Name of the XSL parameter</td>
259 <td align="center" valign="top">Yes</td>
260 </tr>
261 <tr>
262 <td valign="top">expression</td>
263 <td valign="top">Text value to be placed into the param.<br>
264 Was originally intended to be an XSL expression.</td>
265 <td align="center" valign="top">Yes</td>
266 </tr>
267 <tr>
268 <td valign="top">if</td>
269 <td valign="top">The param will only passed if this property is set.</td>
270 <td align="center" valign="top">No</td>
271 </tr>
272 <tr>
273 <td valign="top">unless</td>
274 <td valign="top">The param will only passed unless this property is set.</td>
275 <td align="center" valign="top">No</td>
276 </tr>
277
278</table>
279</blockquote>
280
281<h4>outputproperty ('trax' processors only)</h4>
282<p>Used to specify how you wish the result tree to be output
283as specified in the <a href="http://www.w3.org/TR/xslt#output">
284XSLT specifications</a>.
285<blockquote>
286<h4>Parameters</h4>
287<table width="60%" border="1" cellpadding="2" cellspacing="0">
288 <tr>
289 <td valign="top"><b>Attribute</b></td>
290 <td valign="top"><b>Description</b></td>
291 <td align="center" valign="top"><b>Required</b></td>
292 </tr>
293 <tr>
294 <td valign="top">name</td>
295 <td valign="top">Name of the property</td>
296 <td align="center" valign="top">Yes</td>
297 </tr>
298 <tr>
299 <td valign="top">value</td>
300 <td valign="top">value of the property.</td>
301 <td align="center" valign="top">Yes</td>
302 </tr>
303</table>
304</blockquote>
305
306<h4>factory ('trax' processors only)</h4>
307Used to specify factory settings.
308<blockquote>
309<h4>Parameters</h4>
310<table width="60%" border="1" cellpadding="2" cellspacing="0">
311 <tr>
312 <td valign="top"><b>Attribute</b></td>
313 <td valign="top"><b>Description</b></td>
314 <td align="center" valign="top"><b>Required</b></td>
315 </tr>
316 <tr>
317 <td valign="top">name</td>
318 <td valign="top">fully qualified classname of the
319 transformer factory to use. For example
320 <tt>org.apache.xalan.processor.TransformerFactoryImpl</tt>
321 or <tt>org.apache.xalan.xsltc.trax.TransformerFactoryImpl</tt>
322 or <tt>net.sf.saxon.TransformerFactoryImpl</tt>...
323 </td>
324 <td align="center" valign="top">No. Defaults to the JAXP lookup mechanism.</td>
325 </tr>
326</table>
327<h3>Parameters specified as nested elements</h3>
328<h4>attribute </h4>
329<p>Used to specify settings of the processor factory.
330The attribute names and values are entirely processor specific
331so you must be aware of the implementation to figure them out.
332Read the documentation of your processor.
333For example, in Xalan 2.x:
334<ul>
335<li>http://xml.apache.org/xalan/features/optimize (boolean)</li>
336<li>http://xml.apache.org/xalan/features/incremental (boolean)</li>
337<li>...</li>
338</ul>
339And in Saxon 7.x:
340<ul>
341<li>http://saxon.sf.net/feature/allow-external-functions (boolean)</li>
342<li>http://saxon.sf.net/feature/timing (boolean)</li>
343<li>http://saxon.sf.net/feature/traceListener (string)</li>
344<li>http://saxon.sf.net/feature/treeModel (integer)</li>
345<li>http://saxon.sf.net/feature/linenumbering (integer)</li>
346<li>...</li>
347</ul>
348<blockquote>
349<h4>Parameters</h4>
350<table width="60%" border="1" cellpadding="2" cellspacing="0">
351 <tr>
352 <td valign="top"><b>Attribute</b></td>
353 <td valign="top"><b>Description</b></td>
354 <td align="center" valign="top"><b>Required</b></td>
355 </tr>
356 <tr>
357 <td valign="top">name</td>
358 <td valign="top">Name of the attribute</td>
359 <td align="center" valign="top">Yes</td>
360 </tr>
361 <tr>
362 <td valign="top">value</td>
363 <td valign="top">value of the attribute.</td>
364 <td align="center" valign="top">Yes</td>
365 </tr>
366</table>
367</blockquote>
368</blockquote>
369<h4>mapper</h4>
370
371<p><em>since Ant 1.6.2</em></p>
372
373<p>You can define filename transformations by using a nested <a
374href="../CoreTypes/mapper.html">mapper</a> element. The default mapper
375used by <code>&lt;xslt&gt;</code> removes the file extension from the
376source file and adds the extension specified via the extension
377attribute.</p>
378
379<h4>style</h4>
380
381<p><em>Since Ant 1.7</em></p>
382
383<p>The nested style element can be used to specify your stylesheet in terms
384of Ant's <a href="../CoreTypes/resources.html">resource</a> types. With
385this element, the stylesheet should be specified as a nested resource or
386single-element collection. Alternatively, use the <code>refid</code> to
387specify the resource or collection as a reference.</p>
388
389<h3>Examples</h3>
390<blockquote>
391 <pre>
392&lt;style basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
393 extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;/&gt;</pre>
394 <h4>Using an xmlcatalog</h4>
395 <pre>
396&lt;xslt basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
397 extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;&gt;
398 &lt;xmlcatalog refid=&quot;mycatalog&quot;/&gt;
399&lt;/xslt&gt;
400
401&lt;xslt basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
402 extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;&gt;
403 &lt;xmlcatalog&gt;
404 &lt;dtd
405 publicId=&quot;-//ArielPartners//DTD XML Article V1.0//EN&quot;
406 location=&quot;com/arielpartners/knowledgebase/dtd/article.dtd&quot;/&gt;
407 &lt;/xmlcatalog&gt;
408&lt;/xslt&gt;
409</pre>
410 <h4>Using XSL parameters</h4>
411<pre>
412&lt;xslt basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
413 extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;&gt;
414 &lt;param name=&quot;date&quot; expression=&quot;07-01-2000&quot;/&gt;
415&lt;/xslt&gt;</pre>
416
417 <p>Then if you declare a global parameter &quot;date&quot; with the top-level
418 element &lt;xsl:param name=&quot;date&quot;/&gt;, the variable
419 <code>$date</code> will subsequently have the value 07-01-2000.
420 </p>
421
422 <h4>Using output properties</h4>
423<pre>
424&lt;xslt in=&quot;doc.xml&quot; out=&quot;build/doc/output.xml&quot;
425 style=&quot;style/apache.xsl&quot;&gt;
426 &lt;outputproperty name=&quot;method&quot; value=&quot;xml&quot;/&gt;
427 &lt;outputproperty name=&quot;standalone&quot; value=&quot;yes&quot;/&gt;
428 &lt;outputproperty name=&quot;encoding&quot; value=&quot;iso8859_1&quot;/&gt;
429 &lt;outputproperty name=&quot;indent&quot; value=&quot;yes&quot;/&gt;
430&lt;/xslt&gt;
431</pre>
432
433 <h4>Using factory settings</h4>
434<pre>
435&lt;xslt in=&quot;doc.xml&quot; out=&quot;build/doc/output.xml&quot;
436 style=&quot;style/apache.xsl&quot;&gt;
437 &lt;factory name=&quot;org.apache.xalan.processor.TransformerFactoryImpl&quot;&gt;
438 &lt;attribute name=&quot;http://xml.apache.org/xalan/features/optimize&quot; value=&quot;true&quot;/&gt;
439 &lt;/factory&gt;
440&lt;/xslt&gt;</pre>
441
442 <h4>Using a mapper</h4>
443<pre>
444&lt;xslt basedir=&quot;in&quot; destdir=&quot;out&quot;
445 style=&quot;style/apache.xsl&quot;&gt;
446 &lt;mapper type=&quot;glob&quot; from=&quot;*.xml.en&quot; to=&quot;*.html.en&quot;/&gt;
447&lt;/xslt&gt;</pre>
448
449 <h4>Using a nested resource to define the stylesheet</h4>
450 <pre>
451&lt;xslt in="data.xml" out="${out.dir}/out.xml"&gt;
452 &lt;style&gt;
453 &lt;url url="${printParams.xsl.url}"/&gt;
454 &lt;/style&gt;
455 &lt;param name="set" expression="value"/&gt;
456&lt;/xslt&gt;</pre>
457
458 <h4>Print the current processed file name</h4>
459<pre>
460&lt;project&gt;
461 &lt;xslt style=&quot;printFilename.xsl&quot; destdir=&quot;out&quot; basedir=&quot;in&quot; extension=&quot;.txt&quot;
462 filenameparameter=&quot;filename&quot;
463 filedirparameter=&quot;filedir&quot;
464 /&gt;
465&lt;/project&gt;
466
467&lt;xsl:stylesheet
468 version=&quot;1.0&quot;
469 xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
470
471 &lt;xsl:param name=&quot;filename&quot;&gt;&lt;/xsl:param&gt;
472 &lt;xsl:param name=&quot;filedir&quot;&gt;.&lt;/xsl:param&gt;
473
474&lt;xsl:template match=&quot;/&quot;&gt;
475 Current file is &lt;xsl:value-of select=&quot;$filename&quot;/&gt; in directory &lt;xsl:value-of select=&quot;$filedir&quot;/&gt;.
476&lt;/xsl:template&gt;
477
478&lt;/xsl:stylesheet&gt;
479</pre>
480
481</blockquote>
482
483
484</body>
485</html>
Note: See TracBrowser for help on using the repository browser.