View | Details | Raw Unified | Return to bug 21525
Collapse All | Expand All

(-)src/tests/antunit/taskdefs/xslt-test.xml (+40 lines)
Lines 34-40 Link Here
34
       resource="${output}/out.xml"
34
       resource="${output}/out.xml"
35
       value="set='myvalue'"/>
35
       value="set='myvalue'"/>
36
  </target>
36
  </target>
37
  
38
  <target name="testParameterTypes" depends="setUp" description="parameters of various data types and XPath expressions">
37
39
40
    <property name="antProperty1" value="ANT_PROPERTY_1"/>
41
    <property name="antProperty2" value="ANT_PROPERTY_2"/>
42
    <property name="antProperty3" value="3"/>
43
    <property name="antProperty4" value="substring-before"/>
44
    
45
    <xslt in="${legacy.dir}/data.xml"
46
          out="${output}/out.xml">
47
      <param name="p1" expression="123" type="INT"/>
48
      <param name="p2" expression="64 * 64 div 128 + 10" type="XPATH_NUMBER"/>
49
      <param name="p3" expression="${antProperty4}($antProperty2, '_')" type="XPATH_STRING"/>
50
      
51
      <style>
52
        <string><![CDATA[<xsl:stylesheet
53
  version="1.0"
54
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
55
  xmlns:fo="http://www.w3.org/1999/XSL/Format">
56
57
<!-- get the xsl-parameter -->
58
<xsl:param name="p1"/>
59
<xsl:param name="p2"/>
60
<xsl:param name="p3"/>
61
62
<!-- use the xsl-parameter -->
63
<xsl:template match="/">
64
p1_result='<xsl:value-of select="$p1 + 321"/>'
65
p2_result='<xsl:value-of select="$p2"/>'
66
p3_result='<xsl:value-of select="$p3"/>'
67
</xsl:template>
68
69
</xsl:stylesheet>
70
]]></string>
71
      </style>
72
    </xslt>
73
    <au:assertResourceContains resource="${output}/out.xml" value="p1_result='444'"/>
74
    <au:assertResourceContains resource="${output}/out.xml" value="p2_result='42'"/>
75
    <au:assertResourceContains resource="${output}/out.xml" value="p3_result='ANT'"/>
76
  </target>
77
38
  <target name="testInlineStyleSheet" depends="setUp">
78
  <target name="testInlineStyleSheet" depends="setUp">
39
    <xslt in="${legacy.dir}/data.xml"
79
    <xslt in="${legacy.dir}/data.xml"
40
          out="${output}/out.xml">
80
          out="${output}/out.xml">
(-)src/main/org/apache/tools/ant/taskdefs/XSLTLiaison4.java (+41 lines)
Line 0 Link Here
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
 */
18
package org.apache.tools.ant.taskdefs;
19
20
/**
21
 * Extends Proxy interface for XSLT processors: adds support for XSLT parameters
22
 * of various types (not only String)
23
 *
24
 *
25
 * @see XSLTProcess
26
 * @author Frantisek Kucera (xkucf03)
27
 * @since Ant 1.9.3
28
 */
29
public interface XSLTLiaison4 extends XSLTLiaison3 {
30
31
    /**
32
     * Add a parameter to be set during the XSL transformation.
33
     *
34
     * @param name the parameter name.
35
     * @param value the parameter value as String, Boolean, int, etc.
36
     * @throws Exception thrown if any problems happens.
37
     * @since Ant 1.9.3
38
     * @see Transformer#setParameter(java.lang.String, java.lang.Object)
39
     */
40
    void addParam(String name, Object value) throws Exception;
41
}
(-)src/main/org/apache/tools/ant/taskdefs/XSLTLiaison.java (+1 lines)
Lines 51-56 Link Here
51
     * @param name the parameter name.
51
     * @param name the parameter name.
52
     * @param expression the parameter value as an expression string.
52
     * @param expression the parameter value as an expression string.
53
     * @throws Exception thrown if any problems happens.
53
     * @throws Exception thrown if any problems happens.
54
     * @see XSLTLiaison4#addParam(java.lang.String, java.lang.Object) 
54
     * @since Ant 1.3
55
     * @since Ant 1.3
55
     */
56
     */
56
    void addParam(String name, String expression) throws Exception;
57
    void addParam(String name, String expression) throws Exception;
(-)src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java (-10 / +182 lines)
Lines 18-25 Link Here
18
package org.apache.tools.ant.taskdefs;
18
package org.apache.tools.ant.taskdefs;
19
19
20
import java.io.File;
20
import java.io.File;
21
import java.util.ArrayList;
22
import java.util.Collections;
23
import java.util.EnumMap;
21
import java.util.Enumeration;
24
import java.util.Enumeration;
25
import java.util.List;
26
import java.util.Map;
22
import java.util.Vector;
27
import java.util.Vector;
28
import javax.xml.namespace.QName;
29
import javax.xml.xpath.XPath;
30
import javax.xml.xpath.XPathConstants;
31
import javax.xml.xpath.XPathExpression;
32
import javax.xml.xpath.XPathExpressionException;
33
import javax.xml.xpath.XPathFactory;
34
import javax.xml.xpath.XPathVariableResolver;
23
import org.apache.tools.ant.AntClassLoader;
35
import org.apache.tools.ant.AntClassLoader;
24
import org.apache.tools.ant.BuildException;
36
import org.apache.tools.ant.BuildException;
25
import org.apache.tools.ant.DirectoryScanner;
37
import org.apache.tools.ant.DirectoryScanner;
Lines 76-82 Link Here
76
    private String fileDirParameter = null;
88
    private String fileDirParameter = null;
77
89
78
    /** additional parameters to be passed to the stylesheets */
90
    /** additional parameters to be passed to the stylesheets */
79
    private Vector params = new Vector();
91
    private List<Param> params = new ArrayList<Param>();
80
92
81
    /** Input XML document to be used */
93
    /** Input XML document to be used */
82
    private File inFile = null;
94
    private File inFile = null;
Lines 196-201 Link Here
196
     * @since Ant 1.8.0
208
     * @since Ant 1.8.0
197
     */
209
     */
198
    private boolean failOnNoResources = true;
210
    private boolean failOnNoResources = true;
211
    
212
    /**
213
     * For evaluating template params
214
     *
215
     * @since Ant 1.9.3
216
     */
217
    private XPathFactory xpathFactory;
218
    /**
219
     * For evaluating template params
220
     *
221
     * @since Ant 1.9.3
222
     */
223
    private XPath xpath;
199
224
200
    /**
225
    /**
201
     * System properties to set during transformation.
226
     * System properties to set during transformation.
Lines 305-312 Link Here
305
     * Executes the task.
330
     * Executes the task.
306
     *
331
     *
307
     * @exception BuildException if there is an execution problem.
332
     * @exception BuildException if there is an execution problem.
308
     * @todo validate that if either in or our is defined, then both are
333
     * @todo validate that if either in or out is defined, then both are
309
     */
334
     */
335
    @Override
310
    public void execute() throws BuildException {
336
    public void execute() throws BuildException {
311
        if ("style".equals(getTaskType())) {
337
        if ("style".equals(getTaskType())) {
312
            log("Warning: the task name <style> is deprecated. Use <xslt> instead.",
338
            log("Warning: the task name <style> is deprecated. Use <xslt> instead.",
Lines 937-943 Link Here
937
     */
963
     */
938
    public Param createParam() {
964
    public Param createParam() {
939
        Param p = new Param();
965
        Param p = new Param();
940
        params.addElement(p);
966
        params.add(p);
941
        return p;
967
        return p;
942
    }
968
    }
943
969
Lines 950-955 Link Here
950
976
951
        /** The parameter's value */
977
        /** The parameter's value */
952
        private String expression = null;
978
        private String expression = null;
979
        
980
        /**
981
         * Type of the expression.
982
         * @see ParamType
983
         */
984
        private String type;
953
985
954
        private Object ifCond;
986
        private Object ifCond;
955
        private Object unlessCond;
987
        private Object unlessCond;
Lines 974-988 Link Here
974
        }
1006
        }
975
1007
976
        /**
1008
        /**
977
         * The parameter value
1009
         * The parameter value -
978
         * NOTE : was intended to be an XSL expression.
1010
         * can be a primitive type value or an XPath expression.
979
         * @param expression the parameter's value.
1011
         * @param expression the parameter's value/expression.
1012
         * @see #setType(java.lang.String) 
980
         */
1013
         */
981
        public void setExpression(String expression) {
1014
        public void setExpression(String expression) {
982
            this.expression = expression;
1015
            this.expression = expression;
983
        }
1016
        }
984
1017
985
        /**
1018
        /**
1019
         * @see ParamType
1020
         * @since Ant 1.9.3
1021
         */
1022
        public void setType(String type) {
1023
            this.type = type;
1024
        }
1025
        
1026
        /**
986
         * Get the parameter name
1027
         * Get the parameter name
987
         *
1028
         *
988
         * @return the parameter name
1029
         * @return the parameter name
Lines 1000-1005 Link Here
1000
         *
1041
         *
1001
         * @return the parameter value
1042
         * @return the parameter value
1002
         * @exception BuildException if the value is not set.
1043
         * @exception BuildException if the value is not set.
1044
         * @see #getType()
1003
         */
1045
         */
1004
        public String getExpression() throws BuildException {
1046
        public String getExpression() throws BuildException {
1005
            if (expression == null) {
1047
            if (expression == null) {
Lines 1009-1014 Link Here
1009
        }
1051
        }
1010
1052
1011
        /**
1053
        /**
1054
         * @see ParamType
1055
         * @since Ant 1.9.3
1056
         */
1057
        public String getType() {
1058
            return type;
1059
        }
1060
1061
        /**
1012
         * Set whether this param should be used.  It will be used if
1062
         * Set whether this param should be used.  It will be used if
1013
         * the expression evaluates to true or the name of a property
1063
         * the expression evaluates to true or the name of a property
1014
         * which has been set, otherwise it won't.
1064
         * which has been set, otherwise it won't.
Lines 1061-1067 Link Here
1061
                && ph.testUnlessCondition(unlessCond);
1111
                && ph.testUnlessCondition(unlessCond);
1062
        }
1112
        }
1063
    } // Param
1113
    } // Param
1114
    
1115
    /**
1116
     * Enum for types of the parameter expression.
1117
     *
1118
     * <p>The expression can be:</p>
1119
     * <ul>
1120
     * <li>primitive type that will be parsed from the string value e.g.
1121
     * {@linkplain Integer#parseInt(java.lang.String)}</li>
1122
     * <li>XPath expression that will be evaluated (outside of the transformed
1123
     * document - on empty one) and casted to given type. Inside XPath
1124
     * expressions the Ant variables (properties) can be used (as XPath
1125
     * variables - e.g. $variable123). n.b. placeholders in form of
1126
     * ${variable123} will be substituted with their values before evaluating the
1127
     * XPath expression (so it can be used for dynamic XPath function names and
1128
     * other hacks).</li>
1129
     * </ul>
1130
     * <p>The parameter will be then passed to the XSLT template.</p>
1131
     *
1132
     * <p>Default type (if omited) is primitive String. So if the expression is e.g
1133
     * "true" with no type, in XSLT it will be only a text string, not true
1134
     * boolean.</p>
1135
     * 
1136
     * @see Param#setType(java.lang.String)
1137
     * @see Param#setExpression(java.lang.String)
1138
     * @since Ant 1.9.3
1139
     */
1140
    public enum ParamType {
1064
1141
1142
        STRING,
1143
        BOOLEAN,
1144
        INT,
1145
        LONG,
1146
        DOUBLE,
1147
        XPATH_STRING,
1148
        XPATH_BOOLEAN,
1149
        XPATH_NUMBER,
1150
        XPATH_NODE,
1151
        XPATH_NODESET;
1152
        
1153
        public static final Map<ParamType, QName> XPATH_TYPES;
1154
1155
        static {
1156
            Map<ParamType, QName> m = new EnumMap<ParamType, QName>(ParamType.class);
1157
            m.put(XPATH_STRING, XPathConstants.STRING);
1158
            m.put(XPATH_BOOLEAN, XPathConstants.BOOLEAN);
1159
            m.put(XPATH_NUMBER, XPathConstants.NUMBER);
1160
            m.put(XPATH_NODE, XPathConstants.NODE);
1161
            m.put(XPATH_NODESET, XPathConstants.NODESET);
1162
            XPATH_TYPES = Collections.unmodifiableMap(m);
1163
        }
1164
    }
1165
1065
    /**
1166
    /**
1066
     * Create an instance of an output property to be configured.
1167
     * Create an instance of an output property to be configured.
1067
     * @return the newly created output property.
1168
     * @return the newly created output property.
Lines 1119-1130 Link Here
1119
    }
1220
    }
1120
1221
1121
    /**
1222
    /**
1122
     * Initialize internal instance of XMLCatalog
1223
     * Initialize internal instance of XMLCatalog.
1224
     * Initialize XPath for parameter evaluation.
1123
     * @throws BuildException on error
1225
     * @throws BuildException on error
1124
     */
1226
     */
1227
    @Override
1125
    public void init() throws BuildException {
1228
    public void init() throws BuildException {
1126
        super.init();
1229
        super.init();
1127
        xmlCatalog.setProject(getProject());
1230
        xmlCatalog.setProject(getProject());
1231
        
1232
        xpathFactory = XPathFactory.newInstance();
1233
        xpath = xpathFactory.newXPath();
1234
        xpath.setXPathVariableResolver(new XPathVariableResolver() {
1235
            public Object resolveVariable(QName variableName) {
1236
                return getProject().getProperty(variableName.toString());
1237
            }
1238
        });
1128
    }
1239
    }
1129
1240
1130
    /**
1241
    /**
Lines 1179-1188 Link Here
1179
                    return;
1290
                    return;
1180
                }
1291
                }
1181
            }
1292
            }
1182
            for (Enumeration e = params.elements(); e.hasMoreElements();) {
1293
            for (Param p : params) {
1183
                Param p = (Param) e.nextElement();
1184
                if (p.shouldUse()) {
1294
                if (p.shouldUse()) {
1185
                    liaison.addParam(p.getName(), p.getExpression());
1295
                    Object evaluatedParam = evaluateParam(p);
1296
                    if (liaison instanceof XSLTLiaison4) {
1297
                        ((XSLTLiaison4)liaison).addParam(p.getName(), evaluatedParam);
1298
                    } else {
1299
                        if (evaluatedParam == null || evaluatedParam instanceof String) {
1300
                            liaison.addParam(p.getName(), (String)evaluatedParam);
1301
                        } else {
1302
                            log("XSLTLiaison '" + liaison.getClass().getName()
1303
                                    + "' supports only String parameters. Converting parameter '" + p.getName()
1304
                                    + "' to its String value '" + evaluatedParam, Project.MSG_WARN);
1305
                            liaison.addParam(p.getName(), String.valueOf(evaluatedParam));
1306
                        }
1307
                    }
1186
                }
1308
                }
1187
            }
1309
            }
1188
        } catch (Exception ex) {
1310
        } catch (Exception ex) {
Lines 1190-1196 Link Here
1190
            handleTransformationError(ex);
1312
            handleTransformationError(ex);
1191
        }
1313
        }
1192
    }
1314
    }
1315
    
1316
    /**
1317
     * Evaluates parameter expression according to its type.
1318
     *
1319
     * @param param parameter from Ant build file
1320
     * @return value to be passed to XSLT as parameter
1321
     * @throws IllegalArgumentException if param type is unsupported
1322
     * @throws NumberFormatException if expression of numeric type is not
1323
     * desired numeric type
1324
     * @throws XPathExpressionException if XPath expression can not be compiled
1325
     * @since Ant 1.9.3
1326
     */
1327
    private Object evaluateParam(Param param) throws XPathExpressionException {
1328
        String typeName = param.getType();
1329
        String expression = param.getExpression();
1193
1330
1331
        ParamType type;
1332
1333
        if (typeName == null || typeName.isEmpty()) {
1334
            type = ParamType.STRING; // String is default
1335
        } else {
1336
            try {
1337
                type = ParamType.valueOf(typeName);
1338
            } catch (IllegalArgumentException e) {
1339
                throw new IllegalArgumentException("Invalid XSLT parameter type: " + typeName, e);
1340
            }
1341
        }
1342
1343
        switch (type) {
1344
            case STRING:
1345
                return expression;
1346
            case BOOLEAN:
1347
                return Boolean.parseBoolean(expression);
1348
            case DOUBLE:
1349
                return Double.parseDouble(expression);
1350
            case INT:
1351
                return Integer.parseInt(expression);
1352
            case LONG:
1353
                return Long.parseLong(expression);
1354
            default: // XPath expression
1355
                QName xpathType = ParamType.XPATH_TYPES.get(type);
1356
                if (xpathType == null) {
1357
                    throw new IllegalArgumentException("Invalid XSLT parameter type: " + typeName);
1358
                } else {
1359
                    XPathExpression xpe = xpath.compile(expression);
1360
                    // null = evaluate XPath on empty XML document
1361
                    return xpe.evaluate((Object) null, xpathType);
1362
                }
1363
        }
1364
    }
1365
1194
    /**
1366
    /**
1195
     * Sets file parameter(s) for directory and filename if the attribute
1367
     * Sets file parameter(s) for directory and filename if the attribute
1196
     * 'filenameparameter' or 'filedirparameter' are set in the task.
1368
     * 'filenameparameter' or 'filedirparameter' are set in the task.
(-)src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java (-4 / +14 lines)
Lines 47-53 Link Here
47
import javax.xml.transform.TransformerConfigurationException;
47
import javax.xml.transform.TransformerConfigurationException;
48
import org.apache.tools.ant.BuildException;
48
import org.apache.tools.ant.BuildException;
49
import org.apache.tools.ant.Project;
49
import org.apache.tools.ant.Project;
50
import org.apache.tools.ant.taskdefs.XSLTLiaison3;
50
import org.apache.tools.ant.taskdefs.XSLTLiaison4;
51
import org.apache.tools.ant.taskdefs.XSLTLogger;
51
import org.apache.tools.ant.taskdefs.XSLTLogger;
52
import org.apache.tools.ant.taskdefs.XSLTLoggerAware;
52
import org.apache.tools.ant.taskdefs.XSLTLoggerAware;
53
import org.apache.tools.ant.taskdefs.XSLTProcess;
53
import org.apache.tools.ant.taskdefs.XSLTProcess;
Lines 68-74 Link Here
68
 *
68
 *
69
 * @since Ant 1.3
69
 * @since Ant 1.3
70
 */
70
 */
71
public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware {
71
public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware {
72
72
73
    /**
73
    /**
74
     * Helper for transforming filenames to URIs.
74
     * Helper for transforming filenames to URIs.
Lines 118-124 Link Here
118
    private Vector outputProperties = new Vector();
118
    private Vector outputProperties = new Vector();
119
119
120
    /** stylesheet parameters */
120
    /** stylesheet parameters */
121
    private Hashtable params = new Hashtable();
121
    private Hashtable<String, Object> params = new Hashtable<String, Object>();
122
122
123
    /** factory attributes */
123
    /** factory attributes */
124
    private Vector attributes = new Vector();
124
    private Vector attributes = new Vector();
Lines 369-375 Link Here
369
        for (final Enumeration enumeration = params.keys();
369
        for (final Enumeration enumeration = params.keys();
370
             enumeration.hasMoreElements();) {
370
             enumeration.hasMoreElements();) {
371
            final String name = (String) enumeration.nextElement();
371
            final String name = (String) enumeration.nextElement();
372
            final String value = (String) params.get(name);
372
            final Object value = params.get(name);
373
            transformer.setParameter(name, value);
373
            transformer.setParameter(name, value);
374
        }
374
        }
375
    }
375
    }
Lines 505-510 Link Here
505
    public void addParam(String name, String value) {
505
    public void addParam(String name, String value) {
506
        params.put(name, value);
506
        params.put(name, value);
507
    }
507
    }
508
    
509
    /**
510
     * Add a parameter.
511
     * @param name the name of the parameter
512
     * @param value the value of the parameter
513
     * @since Ant 1.9.3
514
     */
515
    public void addParam(String name, Object value) {
516
        params.put(name, value);
517
    }
508
518
509
    /**
519
    /**
510
     * Set a logger.
520
     * Set a logger.
(-)manual/Tasks/style.html (-2 / +86 lines)
Lines 295-305 Link Here
295
  </tr>
295
  </tr>
296
  <tr>
296
  <tr>
297
    <td valign="top">expression</td>
297
    <td valign="top">expression</td>
298
    <td valign="top">Text value to be placed into the param.<br>
298
    <td valign="top">
299
    Was originally intended to be an XSL expression.</td>
299
        The value to be placed into the param or an XPath expression
300
        (depending on <code>type</code>).
301
    </td>
300
    <td align="center" valign="top">Yes</td>
302
    <td align="center" valign="top">Yes</td>
301
  </tr>
303
  </tr>
302
  <tr>
304
  <tr>
305
    <td valign="top">type</td>
306
    <td valign="top">
307
        Data type of the parameter. Possible values are:
308
        <ul>
309
            <li><code>STRING</code></li>
310
            <li><code>BOOLEAN</code></li>
311
            <li><code>INT</code></li>
312
            <li><code>LONG</code></li>
313
            <li><code>DOUBLE</code></li>
314
            <li><code>XPATH_STRING</code></li>
315
            <li><code>XPATH_BOOLEAN</code></li>
316
            <li><code>XPATH_NUMBER</code></li>
317
            <li><code>XPATH_NODE</code></li>
318
            <li><code>XPATH_NODESET</code></li>
319
        </ul>
320
        <em>since Ant 1.9.3</em>
321
    </td>
322
    <td align="center" valign="top">No; default is <code>STRING</code></td>
323
  </tr>
324
  <tr>
303
    <td valign="top">if</td>
325
    <td valign="top">if</td>
304
    <td valign="top">The param will only be passed <a href="../properties.html#if+unless">if this property is set</a>.</td>
326
    <td valign="top">The param will only be passed <a href="../properties.html#if+unless">if this property is set</a>.</td>
305
    <td align="center" valign="top">No</td>
327
    <td align="center" valign="top">No</td>
Lines 313-318 Link Here
313
</table>
335
</table>
314
</blockquote>
336
</blockquote>
315
337
338
  <p>      
339
      The <code>XPATH_*</code> types says that the <code>expression</code> is not just a primitive-type value but an XPath expression.
340
      This expression will be evaluated on an empty XML document and the result will be passed to the XSLT transformer as a parameter of given type.
341
      In these expressions the declared Ant properties can be used as XPath variables e.g. <code>$someProperty</code>.
342
      So you can compute something using standard XPath functions and operators.
343
  </p>
344
  <p>
345
      If you write <code>${someProperty}</code> instead of <code>$someProperty</code>,
346
      the value will be simply substituted by Ant before evaluating the XPath expression
347
      (this substitution works also for primitive types).
348
  </p>
349
316
<h4>outputproperty ('trax' processors only)</h4>
350
<h4>outputproperty ('trax' processors only)</h4>
317
<p>Used to specify how you wish the result tree to be output
351
<p>Used to specify how you wish the result tree to be output
318
as specified in the <a href="http://www.w3.org/TR/xslt#output">
352
as specified in the <a href="http://www.w3.org/TR/xslt#output">
Lines 459-464 Link Here
459
&lt;/xslt&gt;
493
&lt;/xslt&gt;
460
</pre>
494
</pre>
461
  <h4>Using XSL parameters</h4>
495
  <h4>Using XSL parameters</h4>
496
  <p>Simple String parameter:</p>
462
<pre>
497
<pre>
463
&lt;xslt basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
498
&lt;xslt basedir=&quot;doc&quot; destdir=&quot;build/doc&quot;
464
      extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;&gt;
499
      extension=&quot;.html&quot; style=&quot;style/apache.xsl&quot;&gt;
Lines 469-475 Link Here
469
  element &lt;xsl:param name=&quot;date&quot;/&gt;, the variable
504
  element &lt;xsl:param name=&quot;date&quot;/&gt;, the variable
470
  <code>$date</code> will subsequently have the value 07-01-2000.
505
  <code>$date</code> will subsequently have the value 07-01-2000.
471
  </p>
506
  </p>
507
  
508
  <p>Various data types and XPath expressions:</p>
509
  
510
  <pre>&lt;property name="antProperty1" value="ANT_PROPERTY_1"/&gt;
511
&lt;property name="antProperty2" value="ANT_PROPERTY_2"/&gt;
512
&lt;property name="antProperty3" value="3"/&gt;
513
&lt;property name="antProperty4" value="substring-before"/&gt;
472
514
515
&lt;!--
516
  ${this} is substituted by Ant itself
517
  and $this is evaluated by XPath as a variable
518
--&gt;
519
520
&lt;xslt in="in.xml" out="out.xml" style="template.xsl"&gt;
521
  
522
  &lt;!-- Simple String parameter: --&gt;
523
  &lt;param name="p0" expression="some nice string" type="STRING"/&gt;
524
  
525
  &lt;!-- A value substituted by Ant --&gt;
526
  &lt;param name="p1" expression="some string with ${antProperty1} constructed by Ant" type="STRING"/&gt;
527
  
528
  &lt;!-- XPath resulting in: and this is done in XPath: ANT_PROPERTY_2 --&gt;
529
  &lt;param name="p2" expression="concat('and this is done in XPath: ', $antProperty2)" type="XPATH_STRING"/&gt;
530
  
531
  &lt;!-- Some XPath math, result: 42 --&gt;
532
  &lt;param name="p3" expression="64 * 64 div 128 + 10" type="XPATH_NUMBER"/&gt;
533
  
534
  &lt;!-- Some numeric parameter: --&gt;
535
  &lt;param name="p4" expression="123.45" type="DOUBLE"/&gt;
536
  
537
  &lt;!-- XPath expression, result: true boolean --&gt;
538
  &lt;param name="p5" expression="$antProperty1 = 'ANT_PROPERTY_1'" type="XPATH_BOOLEAN"/&gt;
539
  
540
  &lt;!-- First one is an XPath variable, second one is a text substituted by Ant, result: true boolean --&gt;
541
  &lt;param name="p6" expression="$antProperty2 = '${antProperty2}'" type="XPATH_BOOLEAN"/&gt;
542
  
543
  &lt;!-- Some XPath math with a variable, result: 64 --&gt;
544
  &lt;param name="p7" expression="$antProperty3 * 4 * 5 + 4" type="XPATH_NUMBER"/&gt;
545
  
546
  &lt;!-- 
547
    XPath expression with substituted function name and a variable:
548
    substring-before($antProperty2, '_')
549
    result: ANT
550
  --&gt;
551
  &lt;param name="p8" expression="${antProperty4}($antProperty2, '_')" type="XPATH_STRING"/&gt;
552
  
553
  &lt;!-- Without type attribute: --&gt;
554
  &lt;param name="p9" expression="default type is String"/&gt;
555
&lt;/xslt&gt;</pre>
556
473
  <h4>Using output properties</h4>
557
  <h4>Using output properties</h4>
474
<pre>
558
<pre>
475
&lt;xslt in=&quot;doc.xml&quot; out=&quot;build/doc/output.xml&quot;
559
&lt;xslt in=&quot;doc.xml&quot; out=&quot;build/doc/output.xml&quot;

Return to bug 21525