From f0565366fe94c3cdf2a35c881ce385a67bc0b88d Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
type).
+ STRINGBOOLEANINTLONGDOUBLEXPATH_STRINGXPATH_BOOLEANXPATH_NUMBERXPATH_NODEXPATH_NODESETSTRING
+ The XPATH_* types says that the expression is not just a primitive-type value but an XPath expression.
+ 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.
+ In these expressions the declared Ant properties can be used as XPath variables e.g. $someProperty.
+ So you can compute something using standard XPath functions and operators.
+
+ If you write ${someProperty} instead of $someProperty,
+ the value will be simply substituted by Ant before evaluating the XPath expression
+ (this substitution works also for primitive types).
+
Used to specify how you wish the result tree to be output as specified in the @@ -459,6 +493,7 @@ with syspropertysets.
</xslt>Simple String parameter:
<xslt basedir="doc" destdir="build/doc"
extension=".html" style="style/apache.xsl">
@@ -469,6 +504,55 @@ with syspropertysets.
element <xsl:param name="date"/>, the variable
$date will subsequently have the value 07-01-2000.
+
+ Various data types and XPath expressions:
+
+ <property name="antProperty1" value="ANT_PROPERTY_1"/>
+<property name="antProperty2" value="ANT_PROPERTY_2"/>
+<property name="antProperty3" value="3"/>
+<property name="antProperty4" value="substring-before"/>
+
+<!--
+ ${this} is substituted by Ant itself
+ and $this is evaluated by XPath as a variable
+-->
+
+<xslt in="in.xml" out="out.xml" style="template.xsl">
+
+ <!-- Simple String parameter: -->
+ <param name="p0" expression="some nice string" type="STRING"/>
+
+ <!-- A value substituted by Ant -->
+ <param name="p1" expression="some string with ${antProperty1} constructed by Ant" type="STRING"/>
+
+ <!-- XPath resulting in: and this is done in XPath: ANT_PROPERTY_2 -->
+ <param name="p2" expression="concat('and this is done in XPath: ', $antProperty2)" type="XPATH_STRING"/>
+
+ <!-- Some XPath math, result: 42 -->
+ <param name="p3" expression="64 * 64 div 128 + 10" type="XPATH_NUMBER"/>
+
+ <!-- Some numeric parameter: -->
+ <param name="p4" expression="123.45" type="DOUBLE"/>
+
+ <!-- XPath expression, result: true boolean -->
+ <param name="p5" expression="$antProperty1 = 'ANT_PROPERTY_1'" type="XPATH_BOOLEAN"/>
+
+ <!-- First one is an XPath variable, second one is a text substituted by Ant, result: true boolean -->
+ <param name="p6" expression="$antProperty2 = '${antProperty2}'" type="XPATH_BOOLEAN"/>
+
+ <!-- Some XPath math with a variable, result: 64 -->
+ <param name="p7" expression="$antProperty3 * 4 * 5 + 4" type="XPATH_NUMBER"/>
+
+ <!--
+ XPath expression with substituted function name and a variable:
+ substring-before($antProperty2, '_')
+ result: ANT
+ -->
+ <param name="p8" expression="${antProperty4}($antProperty2, '_')" type="XPATH_STRING"/>
+
+ <!-- Without type attribute: -->
+ <param name="p9" expression="default type is String"/>
+</xslt>
Using output properties
diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTLiaison.java b/src/main/org/apache/tools/ant/taskdefs/XSLTLiaison.java
index 71e1def7e..df22cf2d3 100644
--- a/src/main/org/apache/tools/ant/taskdefs/XSLTLiaison.java
+++ b/src/main/org/apache/tools/ant/taskdefs/XSLTLiaison.java
@@ -51,6 +51,7 @@ public interface XSLTLiaison {
* @param name the parameter name.
* @param expression the parameter value as an expression string.
* @throws Exception thrown if any problems happens.
+ * @see XSLTLiaison4#addParam(java.lang.String, java.lang.Object)
* @since Ant 1.3
*/
void addParam(String name, String expression) throws Exception;
diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTLiaison4.java b/src/main/org/apache/tools/ant/taskdefs/XSLTLiaison4.java
new file mode 100644
index 000000000..5de380b70
--- /dev/null
+++ b/src/main/org/apache/tools/ant/taskdefs/XSLTLiaison4.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs;
+
+/**
+ * Extends Proxy interface for XSLT processors: adds support for XSLT parameters
+ * of various types (not only String)
+ *
+ *
+ * @see XSLTProcess
+ * @author Frantisek Kucera (xkucf03)
+ * @since Ant 1.9.3
+ */
+public interface XSLTLiaison4 extends XSLTLiaison3 {
+
+ /**
+ * Add a parameter to be set during the XSL transformation.
+ *
+ * @param name the parameter name.
+ * @param value the parameter value as String, Boolean, int, etc.
+ * @throws Exception thrown if any problems happens.
+ * @since Ant 1.9.3
+ * @see Transformer#setParameter(java.lang.String, java.lang.Object)
+ */
+ void addParam(String name, Object value) throws Exception;
+}
diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
index bde1c55dc..92f4ef1ce 100644
--- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
+++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
@@ -18,8 +18,20 @@
package org.apache.tools.ant.taskdefs;
import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumMap;
import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
import java.util.Vector;
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import javax.xml.xpath.XPathVariableResolver;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
@@ -76,7 +88,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
private String fileDirParameter = null;
/** additional parameters to be passed to the stylesheets */
- private Vector params = new Vector();
+ private List params = new ArrayList();
/** Input XML document to be used */
private File inFile = null;
@@ -196,6 +208,19 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @since Ant 1.8.0
*/
private boolean failOnNoResources = true;
+
+ /**
+ * For evaluating template params
+ *
+ * @since Ant 1.9.3
+ */
+ private XPathFactory xpathFactory;
+ /**
+ * For evaluating template params
+ *
+ * @since Ant 1.9.3
+ */
+ private XPath xpath;
/**
* System properties to set during transformation.
@@ -305,8 +330,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* Executes the task.
*
* @exception BuildException if there is an execution problem.
- * @todo validate that if either in or our is defined, then both are
+ * @todo validate that if either in or out is defined, then both are
*/
+ @Override
public void execute() throws BuildException {
if ("style".equals(getTaskType())) {
log("Warning: the task name
+
+
+
+
+