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

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