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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. <!DOCTYPE html>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. https://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <html lang="en">
  17. <head>
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>XSLT Task</title>
  20. </head>
  21. <body>
  22. <h2 id="style">XSLT</h2>
  23. <p><em>The name <code>style</code> is a <u>deprecated</u> 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, or for generating code.</p>
  27. <p><strong>Note</strong>: If you are using JDK 1.4 or higher, this task does not require external
  28. libraries not supplied in the Apache Ant distribution. However, often the built in XSL engine is not
  29. as up to date as a fresh download, so an update is still highly recommended in particular since the
  30. built-in XSLT processors of Java 5 (and to a certain extent Java 6) are known to have serious
  31. issues. See <a href="../install.html#librarydependencies">Library Dependencies</a> for more
  32. information.</p>
  33. <p>It is possible to refine the set of files that are being processed. This can be done with
  34. the <var>includes</var>, <var>includesfile</var>, <var>excludes</var>, <var>excludesfile</var>
  35. and <var>defaultexcludes</var> attributes. With the <var>includes</var> or <var>includesfile</var>
  36. attribute you specify the files you want to have included by using patterns. The <var>exclude</var>
  37. or <var>excludesfile</var> attribute is used to specify the files you want to have excluded. This is
  38. also done with patterns. And finally with the <var>defaultexcludes</var> attribute, you can specify
  39. whether you want to use default exclusions or not. See the section
  40. on <a href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
  41. inclusion/exclusion of files works, and how to write patterns.</p>
  42. <p>This task forms an implicit <a href="../Types/fileset.html">FileSet</a> and supports all
  43. attributes of <code>&lt;fileset&gt;</code> (<var>dir</var> becomes <var>basedir</var>) as well
  44. as the nested <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code>
  45. and <code>&lt;patternset&gt;</code> elements.</p>
  46. <p><strong>Note</strong>: Unlike other similar tasks, this task treats directories that have been
  47. matched by the include/exclude patterns of the implicit fileset in a special way. It will apply the
  48. stylesheets to all files contain in them as well. Since the default <var>includes</var> pattern
  49. is <code>**</code> this means it will apply the stylesheet to all files. If you specify
  50. an <var>excludes</var> pattern, it may still work on the files matched by those patterns because the
  51. parent directory has been matched. If this behavior is not what you want, set
  52. the <var>scanincludedirectories</var> attribute to <q>false</q>.</p>
  53. <p><em>Since Ant 1.7</em>, this task supports
  54. nested <a href="../Types/resources.html#collection">resource collections</a> in addition to (or
  55. instead of, depending on the <var>useImplicitFileset</var> attribute) the implicit fileset formed by
  56. this task.</p>
  57. <p>This task supports the use of a nested <code>&lt;param&gt;</code> element which is used to pass
  58. values to an <code>&lt;xsl:param&gt;</code> declaration.</p>
  59. <p>This task supports the use of a nested <a href="../Types/xmlcatalog.html">xmlcatalog</a> element
  60. which is used to perform Entity and URI resolution.</p>
  61. <p><strong>Note on XSLT extension functions</strong>: when using the default TrAX implementation of
  62. the Java class library and a <code>SecurityManager</code> is active&mdash;e.g. when running from
  63. within an IDE&mdash;XSLT extension functions cannot be used as "secure processing" is active in Java
  64. 7 and above. Ant contains a special "hack" that allows XSLT extensions to be used in Java 7 and 8,
  65. but this hack fails for Java 9. If you want to use extensions like the redirect extension that are
  66. provided by the Java class library itself, you can allow them by enabling the
  67. feature <var>http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions</var> in Java 9 and
  68. above. If you need to use an extension function not provided by Java itself you can set the
  69. attribute <var>jdk.xml.transform.extensionClassLoader</var> to a classloader (reference to an Ant
  70. path-like structure).</p>
  71. <h3>Parameters</h3>
  72. <table class="attr">
  73. <tr>
  74. <th scope="col">Attribute</th>
  75. <th scope="col">Description</th>
  76. <th scope="col">Required</th>
  77. </tr>
  78. <tr>
  79. <td>basedir</td>
  80. <td>where to find the source XML file.</td>
  81. <td>No; defaults to the project's <var>basedir</var></td>
  82. </tr>
  83. <tr>
  84. <td>destdir</td>
  85. <td>directory in which to store the results.</td>
  86. <td>Yes, unless <var>in</var> and <var>out</var> have been specified.</td>
  87. </tr>
  88. <tr>
  89. <td>extension</td>
  90. <td>desired file extension to be used for the targets.</td>
  91. <td>No; default is <q>.html</q>, ignored if a nested <code>&lt;mapper&gt;</code> or
  92. both <var>in</var> and <var>out</var> have been specified</td>
  93. </tr>
  94. <tr>
  95. <td>style</td>
  96. <td>name of the stylesheet to use&mdash;given either relative to the
  97. project's <var>basedir</var> or as an absolute path.<br/> Alternatively, a nested element
  98. which Ant can interpret as a resource can be used to indicate where to find the
  99. stylesheet.<br/><em><u>Deprecated</u> variation</em>:<br/> If the stylesheet cannot be found,
  100. and if you have specified the attribute <var>basedir</var> for the task, Ant will assume that
  101. the <var>style</var> attribute is relative to the <var>basedir</var> of the task.</td>
  102. <td>No, if the location of the stylesheet is specified using a nested <code>&lt;style&gt;</code>
  103. element</td>
  104. </tr>
  105. <tr>
  106. <td>classpath</td>
  107. <td>the classpath to use when looking up the XSLT processor.</td>
  108. <td>No</td>
  109. </tr>
  110. <tr>
  111. <td>classpathref</td>
  112. <td>the classpath to use, given as <a href="../using.html#references">reference</a> to a path
  113. defined elsewhere.</td>
  114. <td>No</td>
  115. </tr>
  116. <tr>
  117. <td>force</td>
  118. <td>Recreate target files, even if they are newer than their corresponding source files or the
  119. stylesheet.</td>
  120. <td>No; default is <q>false</q></td>
  121. </tr>
  122. <tr>
  123. <td>processor</td>
  124. <td>name of the XSLT processor to use. Permissible value is:
  125. <ul>
  126. <li><q>trax</q> for a TraX compliant processor (ie JAXP interface implementation such as
  127. Xalan 2 or Saxon)</li>
  128. </ul>
  129. Support for Xalan 1 has been removed <em>since Ant 1.7</em>.
  130. </td>
  131. <td>No; defaults to <q>trax</q></td>
  132. </tr>
  133. <tr>
  134. <td>includes</td>
  135. <td>comma- or space-separated list of patterns of files that must be included.</td>
  136. <td>No; defaults to all (<q>**</q>)</td>
  137. </tr>
  138. <tr>
  139. <td>includesfile</td>
  140. <td>name of a file. Each line of this file is taken to be an include pattern</td>
  141. <td>No</td>
  142. </tr>
  143. <tr>
  144. <td>excludes</td>
  145. <td>comma- or space-separated list of patterns of files that must be excluded.</td>
  146. <td>No; defaults to default excludes or none if <var>defaultexcludes</var> is <q>no</q></td>
  147. </tr>
  148. <tr>
  149. <td>excludesfile</td>
  150. <td>name of a file. Each line of this file is taken to be an exclude pattern</td>
  151. <td>No</td>
  152. </tr>
  153. <tr>
  154. <td>defaultexcludes</td>
  155. <td>indicates whether default excludes should be used or not (<q>yes|no</q>).</td>
  156. <td>No; defaults to <q>yes</q></td>
  157. </tr>
  158. <tr>
  159. <td>in</td>
  160. <td>specifies a single XML document to be styled. Should be used
  161. with the <var>out</var> attribute.</td>
  162. <td>No</td>
  163. </tr>
  164. <tr>
  165. <td>out</td>
  166. <td>specifies the output name for the styled result from the <var>in</var> attribute.</td>
  167. <td>No</td>
  168. </tr>
  169. <tr>
  170. <td>scanincludeddirectories</td>
  171. <td>If any directories are matched by the <var>includes</var>/<var>excludes</var> patterns, try
  172. to transform all files in these directories.
  173. <td>No; default is <q>true</q></td>
  174. </tr>
  175. <tr>
  176. <td>reloadstylesheet</td>
  177. <td>Control whether the stylesheet transformer is created anew for every transform operation. If
  178. you set this to <q>true</q>, performance may suffer, but you may work around a bug in certain
  179. Xalan versions. <em>Since Ant 1.5.2</em>.</td>
  180. <td>No; default is <q>false</q></td>
  181. </tr>
  182. <tr>
  183. <td>useImplicitFileset</td>
  184. <td>Whether the implicit fileset formed by this task shall be used. If you set this
  185. to <q>false</q> you must use nested resource collections&mdash;or the <var>in</var> attribute,
  186. in which case this attribute has no impact anyway. <em>Since Ant 1.7</em>.</td>
  187. <td>No; default is <q>true</q></td>
  188. </tr>
  189. <tr>
  190. <td>filenameparameter</td>
  191. <td>Specifies an XSL parameter for accessing the name of the current processed file. If not set,
  192. the file name is not passed to the transformation. <em>Since Ant 1.7</em>.</td>
  193. <td>No</td>
  194. </tr>
  195. <tr>
  196. <td>filedirparameter</td>
  197. <td>Specifies a XSL parameter for accessing the directory of the current processed file. For
  198. files in the current directory, a value of <q>.</q> will be passed to the transformation. If
  199. not set, the directory is not passed to the transformation. <em>Since Ant 1.7</em>.</td>
  200. <td>No</td>
  201. </tr>
  202. <tr>
  203. <td>suppressWarnings</td>
  204. <td>Whether processor warnings shall be suppressed. This option requires support by the
  205. processor, it is supported by the TrAX processor bundled with Ant. <em>Since Ant
  206. 1.8.0</em>.</td>
  207. <td>No; default is <q>false</q></td>
  208. </tr>
  209. <tr>
  210. <td>failOnError</td>
  211. <td>Whether the build should fail if any error occurs. Note that transformation errors can
  212. still be suppressed by setting <var>failOnTransformationError</var> to <q>false</q> even if
  213. this attribute is <q>true</q>. <em>Since Ant 1.8.0</em>.</td>
  214. <td>No; default is <q>true</q></td>
  215. </tr>
  216. <tr>
  217. <td>failOnTransformationError</td>
  218. <td>Whether the build should fail if an error occurs while transforming the document. Note that
  219. this attribute has no effect if <var>failOnError</var> is <q>false</q>. <em>Since Ant
  220. 1.8.0</em>.</td>
  221. <td>No; default is <q>true</q></td>
  222. </tr>
  223. <tr>
  224. <td>failOnNoResources</td>
  225. <td>Whether the build should fail if the nested resource collection is empty. Note that this
  226. attribute has no effect of <var>failOnError</var> is <q>false</q>. <em>Since Ant
  227. 1.8.0</em>.</td>
  228. <td>No; default is <q>true</q></td>
  229. </tr>
  230. </table>
  231. <h3>Parameters specified as nested elements</h3>
  232. <h4>any <a href="../Types/resources.html#collection">resource collection</a></h4>
  233. <p><em>Since Ant 1.7</em></p>
  234. <p>Use resource collections to specify resources that the stylesheet should be applied to. Use a
  235. nested mapper and the task's <q>destdir</q> attribute to specify the output files.</p>
  236. <h4 id="classpath">classpath</h4>
  237. <p>The classpath to load the processor from can be specified via a
  238. nested <code>&lt;classpath&gt;</code>, as well&mdash;that is,
  239. a <a href="../using.html#path">path-like structure</a>.</p>
  240. <h4>xmlcatalog</h4>
  241. <p>The <a href="../Types/xmlcatalog.html">xmlcatalog</a> element is used to perform Entity and URI
  242. resolution.</p>
  243. <h4>param</h4>
  244. <p><code>Param</code> is used to pass a parameter to the XSL stylesheet.</p>
  245. <h5>Parameters</h5>
  246. <table class="attr">
  247. <tr>
  248. <th scope="col">Attribute</th>
  249. <th scope="col">Description</th>
  250. <th scope="col">Required</th>
  251. </tr>
  252. <tr>
  253. <td>name</td>
  254. <td>Name of the XSL parameter</td>
  255. <td>Yes</td>
  256. </tr>
  257. <tr>
  258. <td>expression</td>
  259. <td>The value to be placed into the param or an XPath expression (depending
  260. on <var>type</var>).</td>
  261. <td>Yes</td>
  262. </tr>
  263. <tr>
  264. <td>type</td>
  265. <td>Data type of the parameter. Possible values are:
  266. <ul>
  267. <li><q>STRING</q></li>
  268. <li><q>BOOLEAN</q></li>
  269. <li><q>INT</q></li>
  270. <li><q>LONG</q></li>
  271. <li><q>DOUBLE</q></li>
  272. <li><q>XPATH_STRING</q></li>
  273. <li><q>XPATH_BOOLEAN</q></li>
  274. <li><q>XPATH_NUMBER</q></li>
  275. <li><q>XPATH_NODE</q></li>
  276. <li><q>XPATH_NODESET</q></li>
  277. </ul><em>since Ant 1.9.3</em>
  278. </td>
  279. <td>No; default is <q>STRING</q></td>
  280. </tr>
  281. <tr>
  282. <td>if</td>
  283. <td>The param will only be passed <a href="../properties.html#if+unless">if this property is
  284. set</a>.</td>
  285. <td>No</td>
  286. </tr>
  287. <tr>
  288. <td>unless</td>
  289. <td>The param will not be passed <a href="../properties.html#if+unless">if this property is
  290. set</a>.</td>
  291. <td>No</td>
  292. </tr>
  293. </table>
  294. <p>The <q>XPATH_*</q> types says that the <var>expression</var> is not just a primitive-type value
  295. but an XPath expression. This expression will be evaluated on an empty XML document and the result
  296. will be passed to the XSLT transformer as a parameter of given type. In these expressions the
  297. declared Ant properties can be used as XPath variables e.g. <code>$someProperty</code>. So you can
  298. compute something using standard XPath functions and operators.</p>
  299. <p>If you write <code>${someProperty}</code> instead of <code>$someProperty</code>, the value will
  300. be simply substituted by Ant before evaluating the XPath expression (this substitution works also
  301. for primitive types).</p>
  302. <h4>outputproperty (<var>trax</var> processors only)</h4>
  303. <p>Used to specify how you wish the result tree to be output as specified in
  304. the <a href="https://www.w3.org/TR/xslt#output" target="_top">XSLT specifications</a>.
  305. <h5>Parameters</h5>
  306. <table class="attr">
  307. <tr>
  308. <th scope="col">Attribute</th>
  309. <th scope="col">Description</th>
  310. <th scope="col">Required</th>
  311. </tr>
  312. <tr>
  313. <td>name</td>
  314. <td>Name of the property</td>
  315. <td>Yes</td>
  316. </tr>
  317. <tr>
  318. <td>value</td>
  319. <td>Value of the property</td>
  320. <td>Yes</td>
  321. </tr>
  322. </table>
  323. <h4 id="factory">factory (<var>trax</var> processors only)</h4>
  324. <p><em>Since Ant 1.9.8</em></p>
  325. <p>Used to specify factory settings.</p>
  326. <h5>Parameters</h5>
  327. <table class="attr">
  328. <tr>
  329. <th scope="col">Attribute</th>
  330. <th scope="col">Description</th>
  331. <th scope="col">Required</th>
  332. </tr>
  333. <tr>
  334. <td>name</td>
  335. <td>fully qualified classname of the transformer factory to use. For
  336. example <code>org.apache.xalan.processor.TransformerFactoryImpl</code>
  337. or <code>org.apache.xalan.xsltc.trax.TransformerFactoryImpl</code>
  338. or <code>net.sf.saxon.TransformerFactoryImpl</code>...</td>
  339. <td>No; defaults to the JAXP lookup mechanism</td>
  340. </tr>
  341. </table>
  342. <h5>Parameters specified as nested elements</h5>
  343. <h6>attribute</h6>
  344. <p>Used to specify settings of the processor factory. The attribute names and values are entirely
  345. processor specific so you must be aware of the implementation to figure them out. Read the
  346. documentation of your processor. For example, in Xalan 2.x:</p>
  347. <ul>
  348. <li><var>http://xml.apache.org/xalan/features/optimize</var> (boolean)</li>
  349. <li><var>http://xml.apache.org/xalan/features/incremental</var> (boolean)</li>
  350. <li>...</li>
  351. </ul>
  352. <p>And in Saxon 7.x:</p>
  353. <ul>
  354. <li><var>http://saxon.sf.net/feature/allow-external-functions</var> (boolean)</li>
  355. <li><var>http://saxon.sf.net/feature/timing</var> (boolean)</li>
  356. <li><var>http://saxon.sf.net/feature/traceListener</var> (string)</li>
  357. <li><var>http://saxon.sf.net/feature/treeModel</var> (integer)</li>
  358. <li><var>http://saxon.sf.net/feature/linenumbering</var> (integer)</li>
  359. <li>...</li>
  360. </ul>
  361. <blockquote>
  362. <h6>Parameters</h6>
  363. <table class="attr">
  364. <tr>
  365. <th scope="col">Attribute</th>
  366. <th scope="col">Description</th>
  367. <th scope="col">Required</th>
  368. </tr>
  369. <tr>
  370. <td>name</td>
  371. <td>Name of the attribute</td>
  372. <td>Yes</td>
  373. </tr>
  374. <tr>
  375. <td>value</td>
  376. <td>Value of the attribute.</td>
  377. <td rowspan="3">Exactly one of these</td>
  378. </tr>
  379. <tr>
  380. <td>valueref</td>
  381. <td class="left">Value of the attribute is the value of the project reference with the given
  382. id. <em>since Ant 1.9.8</em></td>
  383. </tr>
  384. <tr>
  385. <td>classloaderforpath</td>
  386. <td class="left">Value of the attribute is a classloader that uses the classpath specified by a
  387. path that is the project reference with the given <var>id</var>. <em>since Ant 1.9.8</em></td>
  388. </tr>
  389. </table>
  390. </blockquote>
  391. <h5>Examples</h5>
  392. <pre>
  393. &lt;path id="extension-path"&gt;
  394. ...
  395. &lt;/path&gt;
  396. &lt;xslt ...&gt;
  397. &lt;factory&gt;
  398. &lt;attribute name="jdk.xml.transform.extensionClassLoader"
  399. classloaderforpath="extension-path"/&gt;
  400. &lt;/factory&gt;
  401. &lt;/xslt ...&gt;</pre>
  402. <p>Sets the classloader to use when loading extension functions to a classloader using
  403. the <code>path</code> with the id <code>extension-path</code>.</p>
  404. <h6>feature</h6>
  405. <p>Used to specify settings of the processor factory. The feature names are mostly processor
  406. specific so you must be aware of the implementation to figure them out. Read the documentation of
  407. your processor. The only feature all implementations are required to support
  408. is <var>http://javax.xml.XMLConstants/feature/secure-processing</var>.
  409. <blockquote>
  410. <h6>Parameters</h6>
  411. <table class="attr">
  412. <tr>
  413. <th scope="col">Attribute</th>
  414. <th scope="col">Description</th>
  415. <th scope="col">Required</th>
  416. </tr>
  417. <tr>
  418. <td>name</td>
  419. <td>Name of the feature</td>
  420. <td>Yes</td>
  421. </tr>
  422. <tr>
  423. <td>value</td>
  424. <td>Value of the feature. A boolean value (i.e. permitted values
  425. are <q>true</q>, <q>false</q>, <q>yes</q>, <q>no</q>, <q>on</q>, <q>off</q>).</td>
  426. <td>No; defaults to <q>false</q></td>
  427. </tr>
  428. </table>
  429. </blockquote>
  430. <h4>mapper</h4>
  431. <p><em>Since Ant 1.6.2</em></p>
  432. <p>You can define filename transformations by using a
  433. nested <a href="../Types/mapper.html">mapper</a> element. The default mapper used
  434. by <code>&lt;xslt&gt;</code> removes the file extension from the source file and adds the extension
  435. specified via the extension attribute.</p>
  436. <h4>style</h4>
  437. <p><em>Since Ant 1.7</em></p>
  438. <p>The nested <code>style</code> element can be used to specify your stylesheet in terms of
  439. Ant's <a href="../Types/resources.html">resource</a> types. With this element, the stylesheet
  440. should be specified as a nested resource or single-element collection. Alternatively, use
  441. the <var>refid</var> to specify the resource or collection as a reference.</p>
  442. <h4>sysproperty</h4>
  443. <p><em>Since Ant 1.8.0</em>.</p>
  444. <p>Use nested <code>&lt;sysproperty&gt;</code> elements to specify system properties required by the
  445. factory or transformation. These properties will be made available to JVM during the execution of
  446. the class. The attributes for this element are the same as for <a href="exec.html#env">environment
  447. variables</a>.</p>
  448. <h4>syspropertyset</h4>
  449. <p><em>Since Ant 1.8.0</em>.</p>
  450. <p>You can specify a set of properties to be used as system properties
  451. with <a href="../Types/propertyset.html">syspropertyset</a>s.</p>
  452. <h3>Examples</h3>
  453. <pre>
  454. &lt;xslt basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
  455. extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;/&gt;</pre>
  456. <h4>Using an xmlcatalog</h4>
  457. <pre>
  458. &lt;xslt basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
  459. extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;&gt;
  460. &lt;xmlcatalog refid=&quot;mycatalog&quot;/&gt;
  461. &lt;/xslt&gt;
  462. &lt;xslt basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
  463. extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;&gt;
  464. &lt;xmlcatalog&gt;
  465. &lt;dtd
  466. publicId=&quot;-//ArielPartners//DTD XML Article V1.0//EN&quot;
  467. location=&quot;com/arielpartners/knowledgebase/dtd/article.dtd&quot;/&gt;
  468. &lt;/xmlcatalog&gt;
  469. &lt;/xslt&gt;</pre>
  470. <h4>Using XSL parameters</h4>
  471. <p>Simple String parameter:</p>
  472. <pre>
  473. &lt;xslt basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
  474. extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;&gt;
  475. &lt;param name=&quot;date&quot; expression=&quot;07-01-2000&quot;/&gt;
  476. &lt;/xslt&gt;</pre>
  477. <p>Then if you declare a global parameter <q>date</q> with the top-level element <code>&lt;xsl:param
  478. name=&quot;date&quot;/&gt;</code>, the variable <code>$date</code> will subsequently have the value
  479. 07-01-2000.</p>
  480. <p>Various data types and XPath expressions:</p>
  481. <pre>
  482. &lt;property name="antProperty1" value="ANT_PROPERTY_1"/&gt;
  483. &lt;property name="antProperty2" value="ANT_PROPERTY_2"/&gt;
  484. &lt;property name="antProperty3" value="3"/&gt;
  485. &lt;property name="antProperty4" value="substring-before"/&gt;
  486. &lt;!--
  487. ${this} is substituted by Ant itself
  488. and $this is evaluated by XPath as a variable
  489. --&gt;
  490. &lt;xslt in="in.xml" out="out.xml" style="template.xsl"&gt;
  491. &lt;!-- Simple String parameter: --&gt;
  492. &lt;param name="p0" expression="some nice string" type="STRING"/&gt;
  493. &lt;!-- A value substituted by Ant --&gt;
  494. &lt;param name="p1" expression="some string with ${antProperty1} constructed by Ant" type="STRING"/&gt;
  495. &lt;!-- XPath resulting in: and this is done in XPath: ANT_PROPERTY_2 --&gt;
  496. &lt;param name="p2" expression="concat('and this is done in XPath: ', $antProperty2)" type="XPATH_STRING"/&gt;
  497. &lt;!-- Some XPath math, result: 42 --&gt;
  498. &lt;param name="p3" expression="64 * 64 div 128 + 10" type="XPATH_NUMBER"/&gt;
  499. &lt;!-- Some numeric parameter: --&gt;
  500. &lt;param name="p4" expression="123.45" type="DOUBLE"/&gt;
  501. &lt;!-- XPath expression, result: true boolean --&gt;
  502. &lt;param name="p5" expression="$antProperty1 = 'ANT_PROPERTY_1'" type="XPATH_BOOLEAN"/&gt;
  503. &lt;!-- First one is an XPath variable, second one is a text substituted by Ant, result: true boolean --&gt;
  504. &lt;param name="p6" expression="$antProperty2 = '${antProperty2}'" type="XPATH_BOOLEAN"/&gt;
  505. &lt;!-- Some XPath math with a variable, result: 64 --&gt;
  506. &lt;param name="p7" expression="$antProperty3 * 4 * 5 + 4" type="XPATH_NUMBER"/&gt;
  507. &lt;!--
  508. XPath expression with substituted function name and a variable:
  509. substring-before($antProperty2, '_')
  510. result: ANT
  511. --&gt;
  512. &lt;param name="p8" expression="${antProperty4}($antProperty2, '_')" type="XPATH_STRING"/&gt;
  513. &lt;!-- Without type attribute: --&gt;
  514. &lt;param name="p9" expression="default type is String"/&gt;
  515. &lt;/xslt&gt;</pre>
  516. <h4>Using output properties</h4>
  517. <pre>
  518. &lt;xslt in=&quot;doc.xml&quot; out=&quot;build/doc/output.xml&quot;
  519. style=&quot;style/apache.xsl&quot;&gt;
  520. &lt;outputproperty name=&quot;method&quot; value=&quot;xml&quot;/&gt;
  521. &lt;outputproperty name=&quot;standalone&quot; value=&quot;yes&quot;/&gt;
  522. &lt;outputproperty name=&quot;encoding&quot; value=&quot;iso8859_1&quot;/&gt;
  523. &lt;outputproperty name=&quot;indent&quot; value=&quot;yes&quot;/&gt;
  524. &lt;/xslt&gt;</pre>
  525. <h4>Using factory settings</h4>
  526. <pre>
  527. &lt;xslt in=&quot;doc.xml&quot; out=&quot;build/doc/output.xml&quot;
  528. style=&quot;style/apache.xsl&quot;&gt;
  529. &lt;factory name=&quot;org.apache.xalan.processor.TransformerFactoryImpl&quot;&gt;
  530. &lt;attribute name=&quot;http://xml.apache.org/xalan/features/optimize&quot; value=&quot;true&quot;/&gt;
  531. &lt;/factory&gt;
  532. &lt;/xslt&gt;</pre>
  533. <h4>Using a mapper</h4>
  534. <pre>
  535. &lt;xslt basedir=&quot;in&quot; destdir=&quot;out&quot;
  536. style=&quot;style/apache.xsl&quot;&gt;
  537. &lt;mapper type=&quot;glob&quot; from=&quot;*.xml.en&quot; to=&quot;*.html.en&quot;/&gt;
  538. &lt;/xslt&gt;</pre>
  539. <h4>Using a nested resource to define the stylesheet</h4>
  540. <pre>
  541. &lt;xslt in="data.xml" out="${out.dir}/out.xml"&gt;
  542. &lt;style&gt;
  543. &lt;url url="${printParams.xsl.url}"/&gt;
  544. &lt;/style&gt;
  545. &lt;param name="set" expression="value"/&gt;
  546. &lt;/xslt&gt;</pre>
  547. <h4>Print the current processed file name</h4>
  548. <pre>
  549. &lt;project&gt;
  550. &lt;xslt style=&quot;printFilename.xsl&quot; destdir=&quot;out&quot; basedir=&quot;in&quot; extension=&quot;.txt&quot;
  551. filenameparameter=&quot;filename&quot;
  552. filedirparameter=&quot;filedir&quot;/&gt;
  553. &lt;/project&gt;
  554. &lt;xsl:stylesheet
  555. version=&quot;1.0&quot;
  556. xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
  557. &lt;xsl:param name=&quot;filename&quot;&gt;&lt;/xsl:param&gt;
  558. &lt;xsl:param name=&quot;filedir&quot;&gt;.&lt;/xsl:param&gt;
  559. &lt;xsl:template match=&quot;/&quot;&gt;
  560. Current file is &lt;xsl:value-of select=&quot;$filename&quot;/&gt; in directory &lt;xsl:value-of select=&quot;$filedir&quot;/&gt;.
  561. &lt;/xsl:template&gt;
  562. &lt;/xsl:stylesheet&gt;
  563. </pre>
  564. <h4>Use an XInclude-aware version of Xerces while transforming</h4>
  565. <pre>
  566. &lt;xslt ...&gt;
  567. &lt;sysproperty key="org.apache.xerces.xni.parser.XMLParserConfiguration"
  568. value="org.apache.xerces.parsers.XIncludeParserConfiguration"/&gt;
  569. &lt;xslt&gt;
  570. </pre>
  571. </body>
  572. </html>