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 18 KiB

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