You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

style.html 14 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Xslt/Style Task</title>
  5. </head>
  6. <body>
  7. <h2><a name="style">Xslt/Style</a></h2>
  8. <h3>Description</h3>
  9. <p>Process a set of documents via XSLT.</p>
  10. <p>This is useful for building views of XML based documentation,
  11. or for generating code.</p>
  12. <p><b>Note:</b> If you are using JDK 1.4 or higher, this task does not require external libraries
  13. not supplied in the Ant distribution. Otherwise,
  14. see <a href="../install.html#librarydependencies">Library Dependencies</a> for more information.</p>
  15. <p>It is possible to refine the set of files that are being processed. This can be
  16. done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
  17. attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
  18. have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
  19. the files you want to have excluded. This is also done with patterns. And
  20. finally with the <i>defaultexcludes</i> attribute, you can specify whether you
  21. want to use default exclusions or not. See the section on <a
  22. href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
  23. inclusion/exclusion of files works, and how to write patterns.</p>
  24. <p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and supports all
  25. attributes of <code>&lt;fileset&gt;</code> (<code>dir</code> becomes <code>basedir</code>)
  26. as well as the nested <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code>
  27. and <code>&lt;patternset&gt;</code> elements.</p>
  28. <p>This task supports the use of a nested <code>&lt;param&gt;</code> element which is used to pass values
  29. to an <code>&lt;xsl:param&gt;</code> declaration.</p>
  30. <p>This task supports the use of a nested <a href="../CoreTypes/xmlcatalog.html">xmlcatalog</a>
  31. element which is used to perform Entity and URI resolution</p>
  32. <p><i><code>&lt;style&gt;</code> and <code>&lt;xslt&gt;</code> refer to the same Ant task and can be used interchangeably.</i></p>
  33. <p>If you want to use Xalan-J 1 or XSL:P, you also need Ant's optional.jar</p>
  34. <h3>Parameters</h3>
  35. <table border="1" cellpadding="2" cellspacing="0">
  36. <tr>
  37. <td valign="top"><b>Attribute</b></td>
  38. <td valign="top"><b>Description</b></td>
  39. <td align="center" valign="top"><b>Required</b></td>
  40. </tr>
  41. <tr>
  42. <td valign="top">basedir</td>
  43. <td valign="top">where to find the source XML file, default is the
  44. project's basedir.</td>
  45. <td align="center" valign="top">No</td>
  46. </tr>
  47. <tr>
  48. <td valign="top">destdir</td>
  49. <td valign="top">directory in which to store the results.</td>
  50. <td align="center" valign="top">Yes, unless in and out have been
  51. specified.</td>
  52. </tr>
  53. <tr>
  54. <td valign="top">extension</td>
  55. <td valign="top">desired file extension to be used for the targets. If not
  56. specified, the default is &quot;.html&quot;. Will be ignored if
  57. a nested <code>&lt;mapper&gt;</code> has been specified.</td>
  58. <td align="center" valign="top">No</td>
  59. </tr>
  60. <tr>
  61. <td valign="top">style</td>
  62. <td valign="top">name of the stylesheet to use - given either relative
  63. to the project's basedir or as an absolute path
  64. <em><strong>DEPRECATED</strong> - can be specified as a path relative
  65. to the basedir attribute of this task as well</em>.
  66. </td>
  67. <td align="center" valign="top">Yes</td>
  68. </tr>
  69. <tr>
  70. <td valign="top">classpath</td>
  71. <td valign="top">the classpath to use when looking up the XSLT
  72. processor.</td>
  73. <td align="center" valign="top">No</td>
  74. </tr>
  75. <tr>
  76. <td valign="top">classpathref</td>
  77. <td valign="top">the classpath to use, given as <a
  78. href="../using.html#references">reference</a> to a path defined elsewhere.</td>
  79. <td align="center" valign="top">No</td>
  80. </tr>
  81. <tr>
  82. <td valign="top">force</td>
  83. <td valign="top">Recreate target files, even if they are newer
  84. than their corresponding source files or the stylesheet.</td>
  85. <td valign="top" align="center">No; default is false</td>
  86. </tr>
  87. <tr>
  88. <td valign="top">processor</td>
  89. <td valign="top">name of the XSLT processor to use. Permissible values are
  90. &quot;trax&quot; for a TraX compliant processor (ie JAXP interface
  91. implementation such as Xalan 2 or Saxon),
  92. &quot;xslp&quot; for the XSL:P processor, &quot;xalan&quot; for
  93. the Apache XML Xalan (version 1) processor the name of an
  94. arbitrary XSLTLiaison class. Defaults to trax, followed by xalan
  95. and then xslp (in that order). The first one found in your class
  96. path is the one that is used.
  97. <em><strong>DEPRECATED</strong> - XSL:P and xalan are deprecated and no
  98. more supported.</em>.
  99. </td>
  100. <td align="center" valign="top">No</td>
  101. </tr>
  102. <tr>
  103. <td valign="top">includes</td>
  104. <td valign="top">comma- or space-separated list of patterns of files that must be included.
  105. All files are included when omitted.</td>
  106. <td valign="top" align="center">No</td>
  107. </tr>
  108. <tr>
  109. <td valign="top">includesfile</td>
  110. <td valign="top">the name of a file. Each line of this file is taken to be
  111. an include pattern</td>
  112. <td valign="top" align="center">No</td>
  113. </tr>
  114. <tr>
  115. <td valign="top">excludes</td>
  116. <td valign="top">comma- or space-separated list of patterns of files that must be excluded.
  117. No files (except default excludes) are excluded when omitted.</td>
  118. <td valign="top" align="center">No</td>
  119. </tr>
  120. <tr>
  121. <td valign="top">excludesfile</td>
  122. <td valign="top">the name of a file. Each line of this file is taken to be
  123. an exclude pattern</td>
  124. <td valign="top" align="center">No</td>
  125. </tr>
  126. <tr>
  127. <td valign="top">defaultexcludes</td>
  128. <td valign="top">indicates whether default excludes should be used or not
  129. (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
  130. <td valign="top" align="center">No</td>
  131. </tr>
  132. <tr>
  133. <td valign="top">in</td>
  134. <td valign="top">specifies a single XML document to be styled. Should be used
  135. with the out attribute.</td>
  136. <td valign="top" align="center">No</td>
  137. </tr>
  138. <tr>
  139. <td valign="top">out</td>
  140. <td valign="top">specifies the output name for the styled result from the
  141. in attribute.</td>
  142. <td valign="top" align="center">No</td>
  143. </tr>
  144. <tr>
  145. <td valign="top">scanincludeddirectories</td>
  146. <td valign="top">If any directories are matched by the
  147. includes/excludes patterns, try to transform all files in these
  148. directories. Default is <code>true</code></td>
  149. <td valign="top" align="center">No</td>
  150. </tr>
  151. <tr>
  152. <td valign="top">reloadstylesheet</td>
  153. <td valign="top">Control whether the stylesheet transformer is created
  154. anew for every transform opertaion. If you set this to true, performance may
  155. suffer, but you may work around a bug in certain Xalan-J versions.
  156. Default is <code>false</code>. <em>Since Ant 1.5.2</em>.</td>
  157. <td valign="top" align="center">No</td>
  158. </tr>
  159. </table>
  160. <h3>Parameters specified as nested elements</h3>
  161. <h4>classpath</h4>
  162. <p>The classpath to load the processor from can be specified via a
  163. nested <code>&lt;classpath&gt;</code>, as well - that is, a
  164. <a href="../using.html#path">path</a>-like structure.</p>
  165. <h4>xmlcatalog</h4>
  166. <p>The <a href="../CoreTypes/xmlcatalog.html">xmlcatalog</a>
  167. element is used to perform Entity and URI resolution.</p>
  168. <h4>param</h4>
  169. <p>Param is used to pass a parameter to the XSL stylesheet.</p>
  170. <h4>Parameters</h4>
  171. <table width="60%" border="1" cellpadding="2" cellspacing="0">
  172. <tr>
  173. <td valign="top"><b>Attribute</b></td>
  174. <td valign="top"><b>Description</b></td>
  175. <td align="center" valign="top"><b>Required</b></td>
  176. </tr>
  177. <tr>
  178. <td valign="top">name</td>
  179. <td valign="top">Name of the XSL parameter</td>
  180. <td align="center" valign="top">Yes</td>
  181. </tr>
  182. <tr>
  183. <td valign="top">expression</td>
  184. <td valign="top">Text value to be placed into the param.<br/>
  185. Was originally intended to be an XSL expression.</td>
  186. <td align="center" valign="top">Yes</td>
  187. </tr>
  188. <tr>
  189. <td valign="top">if</td>
  190. <td valign="top">The param will only passed if this property is set.</td>
  191. <td align="center" valign="top">No</td>
  192. </tr>
  193. <tr>
  194. <td valign="top">unless</td>
  195. <td valign="top">The param will only passed unless this property is set.</td>
  196. <td align="center" valign="top">No</td>
  197. </tr>
  198. </table>
  199. <h4>outputproperty ('trax' processors only)</h4>
  200. <p>Used to specify how you wish the result tree to be output
  201. as specified in the <a href="http://www.w3.org/TR/xslt#output">
  202. XSLT specifications</a>.
  203. <h4>Parameters</h4>
  204. <table width="60%" border="1" cellpadding="2" cellspacing="0">
  205. <tr>
  206. <td valign="top"><b>Attribute</b></td>
  207. <td valign="top"><b>Description</b></td>
  208. <td align="center" valign="top"><b>Required</b></td>
  209. </tr>
  210. <tr>
  211. <td valign="top">name</td>
  212. <td valign="top">Name of the property</td>
  213. <td align="center" valign="top">Yes</td>
  214. </tr>
  215. <tr>
  216. <td valign="top">value</td>
  217. <td valign="top">value of the property.</td>
  218. <td align="center" valign="top">Yes</td>
  219. </tr>
  220. </table>
  221. <h4>factory ('trax' processors only)</h4>
  222. Used to specify factory settings.
  223. <h4>Parameters</h4>
  224. <table width="60%" border="1" cellpadding="2" cellspacing="0">
  225. <tr>
  226. <td valign="top"><b>Attribute</b></td>
  227. <td valign="top"><b>Description</b></td>
  228. <td align="center" valign="top"><b>Required</b></td>
  229. </tr>
  230. <tr>
  231. <td valign="top">name</td>
  232. <td valign="top">fully qualified classname of the
  233. transformer factory to use. For example
  234. <tt>org.apache.xalan.processor.TransformerFactoryImpl</tt>
  235. or <tt>org.apache.xalan.xsltc.trax.TransformerFactoryImpl</tt>
  236. or <tt>net.sf.saxon.TransformerFactoryImpl</tt>...
  237. </td>
  238. <td align="center" valign="top">No. Defaults to the JAXP lookup mechanism.</td>
  239. </tr>
  240. </table>
  241. <blockquote>
  242. <h4>attribute </h4>
  243. <p>Used to specify settings of the processor factory.
  244. The attribute names and values are entirely processor specific
  245. so you must be aware of the implementation to figure them out.
  246. Read the documentation of your processor.
  247. For example, in Xalan 2.x:
  248. <ul>
  249. <li>http://xml.apache.org/xalan/features/optimize (boolean)</li>
  250. <li>http://xml.apache.org/xalan/features/incremental (boolean)</li>
  251. <li>...</li>
  252. </ul>
  253. And in Saxon 7.x:
  254. <ul>
  255. <li>http://saxon.sf.net/feature/allow-external-functions (boolean)</li>
  256. <li>http://saxon.sf.net/feature/timing (boolean)</li>
  257. <li>http://saxon.sf.net/feature/traceListener (string)</li>
  258. <li>http://saxon.sf.net/feature/treeModel (integer)</li>
  259. <li>http://saxon.sf.net/feature/linenumbering (integer)</li>
  260. <li>...</li>
  261. </ul>
  262. <h4>Parameters</h4>
  263. <table width="60%" border="1" cellpadding="2" cellspacing="0">
  264. <tr>
  265. <td valign="top"><b>Attribute</b></td>
  266. <td valign="top"><b>Description</b></td>
  267. <td align="center" valign="top"><b>Required</b></td>
  268. </tr>
  269. <tr>
  270. <td valign="top">name</td>
  271. <td valign="top">Name of the attribute</td>
  272. <td align="center" valign="top">Yes</td>
  273. </tr>
  274. <tr>
  275. <td valign="top">value</td>
  276. <td valign="top">value of the attribute.</td>
  277. <td align="center" valign="top">Yes</td>
  278. </tr>
  279. </table>
  280. </blockquote>
  281. <h4>mapper</h4>
  282. <p><em>since Ant 1.6.2</em></p>
  283. <p>You can define filename transformations by using a nested <a
  284. href="../CoreTypes/mapper.html">mapper</a> element. The default mapper
  285. used by <code>&lt;xslt&gt;</code> removes the file extension from the
  286. source file and adds the extension specified via the extension
  287. attribute.</p>
  288. <h3>Examples</h3>
  289. <blockquote>
  290. <pre>
  291. &lt;style basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
  292. extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;/&gt;</pre>
  293. <h4>Using an xmlcatalog</h4>
  294. <pre>&lt;xslt basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
  295. extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;&gt;
  296. &lt;xmlcatalog refid=&quot;mycatalog&quot;/&gt;
  297. &lt;/xslt&gt;
  298. &lt;xslt basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
  299. extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;&gt;
  300. &lt;xmlcatalog&gt;
  301. &lt;dtd
  302. publicId=&quot;-//ArielPartners//DTD XML Article V1.0//EN&quot;
  303. location=&quot;com/arielpartners/knowledgebase/dtd/article.dtd&quot;/&gt;
  304. &lt;/xmlcatalog&gt;
  305. &lt;/xslt&gt;</pre>
  306. <h4>Using XSL parameters</h4>
  307. <pre>&lt;xslt basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
  308. extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;&gt;
  309. &lt;param name=&quot;date&quot; expression=&quot;07-01-2000&quot;/&gt;
  310. &lt;/xslt&gt;</pre>
  311. <p>Then if you declare a global parameter &quot;date&quot; with the top-level
  312. element &lt;xsl:param name=&quot;date&quot;/&gt;, the variable
  313. <code>$date</code> will subsequently have the value 07-01-2000.
  314. </p>
  315. <h4>Using output properties</h4>
  316. <pre>&lt;xslt in=&quot;doc.xml&quot; out=&quot;build/doc/output.xml&quot;
  317. style=&quot;style/apache.xsl&quot;&gt;
  318. &lt;outputproperty name=&quot;method&quot; value=&quot;xml&quot;;/&gt;
  319. &lt;outputproperty name=&quot;standalone&quot; value=&quot;yes&quot;/&gt;
  320. &lt;outputproperty name=&quot;encoding&quot; value=&quot;iso8859_1&quot;/&gt;
  321. &lt;outputproperty name=&quot;indent&quot; value=&quot;yes&quot;/&gt;
  322. &lt;/xslt&gt;</pre>
  323. <h4>Using factory settings</h4>
  324. <pre>&lt;xslt in=&quot;doc.xml&quot; out=&quot;build/doc/output.xml&quot;
  325. style=&quot;style/apache.xsl&quot;&gt;
  326. &lt;factory name=&quot;org.apache.xalan.processor.TransformerFactoryImpl&quot;&gt;
  327. &lt;attribute name=&quot;http://xml.apache.org/xalan/features/optimize&quot; value=&quot;true&quot;/&gt;
  328. &lt;/factory&gt;
  329. &lt;/xslt&gt;</pre>
  330. <h4>Using a mapper</h4>
  331. <pre>&lt;xslt basedir=&quot;in&quot; destdir=&quot;out&quot;
  332. style=&quot;style/apache.xsl&quot;&gt;
  333. &lt;mapper type=&quot;glob&quot; from=&quot;*.xml.en&quot; to=&quot;*.html.en&quot;/&gt;
  334. &lt;/xslt&gt;</pre>
  335. </blockquote>
  336. <hr>
  337. <p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
  338. Reserved.</p>
  339. </body>
  340. </html>