You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mu...@apache.org on 2023/10/10 15:07:20 UTC
[xalan-java] branch xalan-j_xslt3.0 updated: committing few improvements to xpath 3.1 math function implementations. committing as well, few new working test cases related to xslt 3.0 xsl:function element and xpath 3.1 inline function expressions.
This is an automated email from the ASF dual-hosted git repository.
mukulg pushed a commit to branch xalan-j_xslt3.0
in repository https://gitbox.apache.org/repos/asf/xalan-java.git
The following commit(s) were added to refs/heads/xalan-j_xslt3.0 by this push:
new e31e7144 committing few improvements to xpath 3.1 math function implementations. committing as well, few new working test cases related to xslt 3.0 xsl:function element and xpath 3.1 inline function expressions.
new deb5da8a Merge pull request #99 from mukulga/xalan-j_xslt3.0_mukul
e31e7144 is described below
commit e31e71445d6b5d297be604b001d5b315775d9caf
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Tue Oct 10 20:33:24 2023 +0530
committing few improvements to xpath 3.1 math function implementations. committing as well, few new working test cases related to xslt 3.0 xsl:function element and xpath 3.1 inline function expressions.
---
src/org/apache/xpath/functions/FuncData.java | 4 +-
.../apache/xpath/functions/math/FuncMathAcos.java | 23 ++++++
.../apache/xpath/functions/math/FuncMathAsin.java | 23 ++++++
.../apache/xpath/functions/math/FuncMathAtan.java | 23 ++++++
.../apache/xpath/functions/math/FuncMathAtan2.java | 26 +++++++
.../apache/xpath/functions/math/FuncMathCos.java | 23 ++++++
.../apache/xpath/functions/math/FuncMathExp.java | 23 ++++++
.../apache/xpath/functions/math/FuncMathExp10.java | 23 ++++++
.../apache/xpath/functions/math/FuncMathLog.java | 23 ++++++
.../apache/xpath/functions/math/FuncMathLog10.java | 23 ++++++
.../apache/xpath/functions/math/FuncMathPow.java | 26 +++++++
.../apache/xpath/functions/math/FuncMathSin.java | 23 ++++++
.../apache/xpath/functions/math/FuncMathSqrt.java | 23 ++++++
.../apache/xpath/functions/math/FuncMathTan.java | 23 ++++++
tests/higher_order_functions/gold/test1.out | 5 ++
tests/higher_order_functions/gold/test2.out | 5 ++
tests/higher_order_functions/gold/test3.out | 5 ++
tests/higher_order_functions/test1.xsl | 62 +++++++++++++++++
tests/higher_order_functions/test1_a.xml | 6 ++
tests/higher_order_functions/test2.xsl | 64 +++++++++++++++++
tests/higher_order_functions/test3.xsl | 62 +++++++++++++++++
.../xalan/xslt3/HigherOrderFunctionTests.java | 81 ++++++++++++++++++++++
tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java | 3 +-
23 files changed, 599 insertions(+), 3 deletions(-)
diff --git a/src/org/apache/xpath/functions/FuncData.java b/src/org/apache/xpath/functions/FuncData.java
index 18ee945b..43bbf1f2 100644
--- a/src/org/apache/xpath/functions/FuncData.java
+++ b/src/org/apache/xpath/functions/FuncData.java
@@ -41,8 +41,8 @@ import org.apache.xpath.xs.types.XSUntypedAtomic;
* Ref : https://www.w3.org/TR/xpath-functions-31/#func-data
*
* This implementation of function fn:data() assumes that,
- * an XML input document (whose xdm information has been
- * constructed) has not been validated with an XML schema.
+ * an XML input document has not been validated with an
+ * XML schema.
*
* @author Mukul Gandhi <mu...@apache.org>
*
diff --git a/src/org/apache/xpath/functions/math/FuncMathAcos.java b/src/org/apache/xpath/functions/math/FuncMathAcos.java
index 23ccd8ee..f8ee2e2b 100644
--- a/src/org/apache/xpath/functions/math/FuncMathAcos.java
+++ b/src/org/apache/xpath/functions/math/FuncMathAcos.java
@@ -19,6 +19,7 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -94,6 +95,28 @@ public class FuncMathAcos extends FunctionOneArg
result = new XSDouble(Math.acos(arg));
}
}
+ else if (arg0Result instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)arg0Result;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:acos "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Cannot convert the string \"" + strVal + "\" to "
+ + "a double value.", srcLocator);
+ }
+
+ result = new XSDouble(Math.acos(arg));
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of first argument to function math:acos is not "
+ "xs:double.", srcLocator);
diff --git a/src/org/apache/xpath/functions/math/FuncMathAsin.java b/src/org/apache/xpath/functions/math/FuncMathAsin.java
index 6659c1ec..76094eb1 100644
--- a/src/org/apache/xpath/functions/math/FuncMathAsin.java
+++ b/src/org/apache/xpath/functions/math/FuncMathAsin.java
@@ -19,6 +19,7 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -94,6 +95,28 @@ public class FuncMathAsin extends FunctionOneArg
result = new XSDouble(Math.asin(arg));
}
}
+ else if (arg0Result instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)arg0Result;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:asin "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Cannot convert the string \"" + strVal + "\" to "
+ + "a double value.", srcLocator);
+ }
+
+ result = new XSDouble(Math.asin(arg));
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of first argument to function math:asin is not "
+ "xs:double.", srcLocator);
diff --git a/src/org/apache/xpath/functions/math/FuncMathAtan.java b/src/org/apache/xpath/functions/math/FuncMathAtan.java
index 8fa01600..47f31315 100644
--- a/src/org/apache/xpath/functions/math/FuncMathAtan.java
+++ b/src/org/apache/xpath/functions/math/FuncMathAtan.java
@@ -19,6 +19,7 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -94,6 +95,28 @@ public class FuncMathAtan extends FunctionOneArg
result = new XSDouble(Math.atan(arg));
}
}
+ else if (arg0Result instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)arg0Result;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:atan "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Cannot convert the string \"" + strVal + "\" to "
+ + "a double value.", srcLocator);
+ }
+
+ result = new XSDouble(Math.atan(arg));
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of first argument to function math:atan is not "
+ "xs:double.", srcLocator);
diff --git a/src/org/apache/xpath/functions/math/FuncMathAtan2.java b/src/org/apache/xpath/functions/math/FuncMathAtan2.java
index 4db282a2..5c487ddf 100644
--- a/src/org/apache/xpath/functions/math/FuncMathAtan2.java
+++ b/src/org/apache/xpath/functions/math/FuncMathAtan2.java
@@ -18,8 +18,10 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.Function2Args;
+import org.apache.xpath.objects.ResultSequence;
import org.apache.xpath.objects.XNodeSet;
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
@@ -53,6 +55,7 @@ public class FuncMathAtan2 extends Function2Args {
return result;
}
+
/*
* Get an 'double' value from an object of type XObject.
*/
@@ -90,6 +93,29 @@ public class FuncMathAtan2 extends Function2Args {
resultVal = arg;
}
}
+ else if (xObject instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)xObject;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The " + argNumStr + " argument to math:atan2 "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Error with the " + argNumStr + " argument of "
+ + "math:atan2. Cannot convert the string \"" + strVal + "\" "
+ + "to a double value.", srcLocator);
+ }
+
+ resultVal = arg;
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of " + argNumStr + " argument to function "
+ "math:atan2 is not xs:double.", srcLocator);
diff --git a/src/org/apache/xpath/functions/math/FuncMathCos.java b/src/org/apache/xpath/functions/math/FuncMathCos.java
index 36f50aa2..38afb34b 100644
--- a/src/org/apache/xpath/functions/math/FuncMathCos.java
+++ b/src/org/apache/xpath/functions/math/FuncMathCos.java
@@ -19,6 +19,7 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -94,6 +95,28 @@ public class FuncMathCos extends FunctionOneArg
result = new XSDouble(Math.cos(arg));
}
}
+ else if (arg0Result instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)arg0Result;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:cos "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Cannot convert the string \"" + strVal + "\" to "
+ + "a double value.", srcLocator);
+ }
+
+ result = new XSDouble(Math.cos(arg));
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of first argument to function math:cos is not "
+ "xs:double.", srcLocator);
diff --git a/src/org/apache/xpath/functions/math/FuncMathExp.java b/src/org/apache/xpath/functions/math/FuncMathExp.java
index b370645a..1032ba76 100644
--- a/src/org/apache/xpath/functions/math/FuncMathExp.java
+++ b/src/org/apache/xpath/functions/math/FuncMathExp.java
@@ -19,6 +19,7 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -94,6 +95,28 @@ public class FuncMathExp extends FunctionOneArg
result = new XSDouble(Math.exp(arg));
}
}
+ else if (arg0Result instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)arg0Result;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:exp "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Cannot convert the string \"" + strVal + "\" to "
+ + "a double value.", srcLocator);
+ }
+
+ result = new XSDouble(Math.exp(arg));
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of first argument to function math:exp is not "
+ "xs:double.", srcLocator);
diff --git a/src/org/apache/xpath/functions/math/FuncMathExp10.java b/src/org/apache/xpath/functions/math/FuncMathExp10.java
index 449b9526..d0d94af0 100644
--- a/src/org/apache/xpath/functions/math/FuncMathExp10.java
+++ b/src/org/apache/xpath/functions/math/FuncMathExp10.java
@@ -19,6 +19,7 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -94,6 +95,28 @@ public class FuncMathExp10 extends FunctionOneArg
result = new XSDouble(Math.pow(10, arg));
}
}
+ else if (arg0Result instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)arg0Result;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:exp10 "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Cannot convert the string \"" + strVal + "\" to "
+ + "a double value.", srcLocator);
+ }
+
+ result = new XSDouble(Math.pow(10, arg));
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of first argument to function "
+ "math:exp10 is not xs:double.", srcLocator);
diff --git a/src/org/apache/xpath/functions/math/FuncMathLog.java b/src/org/apache/xpath/functions/math/FuncMathLog.java
index 44721c48..a3eafbc0 100644
--- a/src/org/apache/xpath/functions/math/FuncMathLog.java
+++ b/src/org/apache/xpath/functions/math/FuncMathLog.java
@@ -19,6 +19,7 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -94,6 +95,28 @@ public class FuncMathLog extends FunctionOneArg
result = new XSDouble(Math.log(arg));
}
}
+ else if (arg0Result instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)arg0Result;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:log "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Cannot convert the string \"" + strVal + "\" to "
+ + "a double value.", srcLocator);
+ }
+
+ result = new XSDouble(Math.log(arg));
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of first argument to function math:log is not "
+ "xs:double.", srcLocator);
diff --git a/src/org/apache/xpath/functions/math/FuncMathLog10.java b/src/org/apache/xpath/functions/math/FuncMathLog10.java
index 205c7a2d..e291db7f 100644
--- a/src/org/apache/xpath/functions/math/FuncMathLog10.java
+++ b/src/org/apache/xpath/functions/math/FuncMathLog10.java
@@ -19,6 +19,7 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -94,6 +95,28 @@ public class FuncMathLog10 extends FunctionOneArg
result = new XSDouble(Math.log10(arg));
}
}
+ else if (arg0Result instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)arg0Result;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:log10 "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Cannot convert the string \"" + strVal + "\" to "
+ + "a double value.", srcLocator);
+ }
+
+ result = new XSDouble(Math.log10(arg));
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of first argument to function math:log10 is not "
+ "xs:double.", srcLocator);
diff --git a/src/org/apache/xpath/functions/math/FuncMathPow.java b/src/org/apache/xpath/functions/math/FuncMathPow.java
index 7eb7fffc..698430fb 100644
--- a/src/org/apache/xpath/functions/math/FuncMathPow.java
+++ b/src/org/apache/xpath/functions/math/FuncMathPow.java
@@ -18,8 +18,10 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.Function2Args;
+import org.apache.xpath.objects.ResultSequence;
import org.apache.xpath.objects.XNodeSet;
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
@@ -53,6 +55,7 @@ public class FuncMathPow extends Function2Args {
return result;
}
+
/*
* Get an 'double' value from an object of type XObject.
*/
@@ -90,6 +93,29 @@ public class FuncMathPow extends Function2Args {
resultVal = arg;
}
}
+ else if (xObject instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)xObject;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The " + argNumStr + " argument to math:pow "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Error with the " + argNumStr + " argument of "
+ + "math:pow. Cannot convert the string \"" + strVal + "\" "
+ + "to a double value.", srcLocator);
+ }
+
+ resultVal = arg;
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of " + argNumStr + " argument to function "
+ "math:pow is not xs:double.", srcLocator);
diff --git a/src/org/apache/xpath/functions/math/FuncMathSin.java b/src/org/apache/xpath/functions/math/FuncMathSin.java
index d5c78aae..5d49b33c 100644
--- a/src/org/apache/xpath/functions/math/FuncMathSin.java
+++ b/src/org/apache/xpath/functions/math/FuncMathSin.java
@@ -19,6 +19,7 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -94,6 +95,28 @@ public class FuncMathSin extends FunctionOneArg
result = new XSDouble(Math.sin(arg));
}
}
+ else if (arg0Result instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)arg0Result;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:sin "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Cannot convert the string \"" + strVal + "\" to "
+ + "a double value.", srcLocator);
+ }
+
+ result = new XSDouble(Math.sin(arg));
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of first argument to function math:sin is not "
+ "xs:double.", srcLocator);
diff --git a/src/org/apache/xpath/functions/math/FuncMathSqrt.java b/src/org/apache/xpath/functions/math/FuncMathSqrt.java
index f3114009..bb0dafce 100644
--- a/src/org/apache/xpath/functions/math/FuncMathSqrt.java
+++ b/src/org/apache/xpath/functions/math/FuncMathSqrt.java
@@ -19,6 +19,7 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -94,6 +95,28 @@ public class FuncMathSqrt extends FunctionOneArg
result = new XSDouble(Math.sqrt(arg));
}
}
+ else if (arg0Result instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)arg0Result;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:sqrt "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Cannot convert the string \"" + strVal + "\" to "
+ + "a double value.", srcLocator);
+ }
+
+ result = new XSDouble(Math.sqrt(arg));
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of first argument to function math:sqrt is not "
+ "xs:double.", srcLocator);
diff --git a/src/org/apache/xpath/functions/math/FuncMathTan.java b/src/org/apache/xpath/functions/math/FuncMathTan.java
index dd32ae32..f81f518d 100644
--- a/src/org/apache/xpath/functions/math/FuncMathTan.java
+++ b/src/org/apache/xpath/functions/math/FuncMathTan.java
@@ -19,6 +19,7 @@ package org.apache.xpath.functions.math;
import javax.xml.transform.SourceLocator;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.FunctionOneArg;
@@ -94,6 +95,28 @@ public class FuncMathTan extends FunctionOneArg
result = new XSDouble(Math.tan(arg));
}
}
+ else if (arg0Result instanceof ResultSequence) {
+ ResultSequence resultSeq = (ResultSequence)arg0Result;
+ if (resultSeq.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:tan "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ XObject val = resultSeq.item(0);
+ String strVal = XslTransformEvaluationHelper.getStrVal(val);
+
+ double arg = 0.0;
+ try {
+ arg = (new XSDouble(strVal)).doubleValue();
+ }
+ catch (Exception ex) {
+ throw new javax.xml.transform.TransformerException("FORG0001 : Cannot convert the string \"" + strVal + "\" to "
+ + "a double value.", srcLocator);
+ }
+
+ result = new XSDouble(Math.tan(arg));
+ }
+ }
else {
throw new javax.xml.transform.TransformerException("XPTY0004 : The item type of first argument to function math:tan is not "
+ "xs:double.", srcLocator);
diff --git a/tests/higher_order_functions/gold/test1.out b/tests/higher_order_functions/gold/test1.out
new file mode 100644
index 00000000..5570dea1
--- /dev/null
+++ b/tests/higher_order_functions/gold/test1.out
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <one>4</one>
+ <two>6</two>
+ <three>81</three>
+</result>
diff --git a/tests/higher_order_functions/gold/test2.out b/tests/higher_order_functions/gold/test2.out
new file mode 100644
index 00000000..5e2f6dc6
--- /dev/null
+++ b/tests/higher_order_functions/gold/test2.out
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <one>4</one>
+ <two>6</two>
+ <three>8</three>
+</result>
diff --git a/tests/higher_order_functions/gold/test3.out b/tests/higher_order_functions/gold/test3.out
new file mode 100644
index 00000000..901ab1a7
--- /dev/null
+++ b/tests/higher_order_functions/gold/test3.out
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <one>7</one>
+ <two>5.5</two>
+ <three>385</three>
+</result>
diff --git a/tests/higher_order_functions/test1.xsl b/tests/higher_order_functions/test1.xsl
new file mode 100644
index 00000000..cb5a0786
--- /dev/null
+++ b/tests/higher_order_functions/test1.xsl
@@ -0,0 +1,62 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:math="http://www.w3.org/2005/xpath-functions/math"
+ xmlns:fn0="http://fn0"
+ exclude-result-prefixes="xs math fn0"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT 3.0 test case, where we pass a function item as
+ an argument to a stylesheet function xsl:function.
+ -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <one>
+ <xsl:value-of select="fn0:eval(function($a, $b) { $a + $b }, 1, 3)"/>
+ </one>
+ <two>
+ <xsl:value-of select="fn0:eval(function($a, $b) { $a * $b }, 2, 3)"/>
+ </two>
+ <three>
+ <xsl:value-of select="fn0:eval(function($a, $b) { math:pow($a, $b) }, 3, 4)"/>
+ </three>
+ </result>
+ </xsl:template>
+
+ <!-- A stylesheet function, that takes a function item as an argument,
+ and other arguments as well that are further used as arguments
+ within a dynamic function call. The dynamic function call, is a
+ call to a function that was passed as a function item argument
+ to this xsl:function function.
+ -->
+ <xsl:function name="fn0:eval" as="xs:double">
+ <xsl:param name="f1"/>
+ <xsl:param name="a" as="xs:double"/>
+ <xsl:param name="b" as="xs:double"/>
+
+ <xsl:sequence select="$f1($a, $b)"/>
+ </xsl:function>
+
+ <!--
+ * 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.
+ -->
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/tests/higher_order_functions/test1_a.xml b/tests/higher_order_functions/test1_a.xml
new file mode 100644
index 00000000..6bb7f865
--- /dev/null
+++ b/tests/higher_order_functions/test1_a.xml
@@ -0,0 +1,6 @@
+<info>
+ <a>1</a>
+ <b>3</b>
+ <c>2</c>
+ <d>3</d>
+</info>
\ No newline at end of file
diff --git a/tests/higher_order_functions/test2.xsl b/tests/higher_order_functions/test2.xsl
new file mode 100644
index 00000000..7e912dd6
--- /dev/null
+++ b/tests/higher_order_functions/test2.xsl
@@ -0,0 +1,64 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:math="http://www.w3.org/2005/xpath-functions/math"
+ xmlns:fn0="http://fn0"
+ exclude-result-prefixes="xs math fn0"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- use with test1_a.xml -->
+
+ <!-- An XSLT 3.0 test case, where we pass a function item as
+ an argument to a stylesheet function xsl:function.
+ -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/info">
+ <result>
+ <one>
+ <xsl:value-of select="fn0:eval(function($a, $b) { $a + $b }, a, b)"/>
+ </one>
+ <two>
+ <xsl:value-of select="fn0:eval(function($a, $b) { $a * $b }, c, d)"/>
+ </two>
+ <three>
+ <xsl:value-of select="fn0:eval(function($a, $b) { math:pow($a, $b) }, c, d)"/>
+ </three>
+ </result>
+ </xsl:template>
+
+ <!-- A stylesheet function, that takes a function item as an argument,
+ and other arguments as well that are further used as arguments
+ within a dynamic function call. The dynamic function call, is a
+ call to a function that was passed as a function item argument
+ to this xsl:function function.
+ -->
+ <xsl:function name="fn0:eval" as="xs:double">
+ <xsl:param name="f1"/>
+ <xsl:param name="a" as="xs:double"/>
+ <xsl:param name="b" as="xs:double"/>
+
+ <xsl:sequence select="$f1($a, $b)"/>
+ </xsl:function>
+
+ <!--
+ * 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.
+ -->
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/tests/higher_order_functions/test3.xsl b/tests/higher_order_functions/test3.xsl
new file mode 100644
index 00000000..6b543684
--- /dev/null
+++ b/tests/higher_order_functions/test3.xsl
@@ -0,0 +1,62 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:math="http://www.w3.org/2005/xpath-functions/math"
+ xmlns:fn0="http://fn0"
+ exclude-result-prefixes="xs math fn0"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT 3.0 test case, where we pass a function item as
+ an argument to a stylesheet function xsl:function.
+ -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <one>
+ <xsl:value-of select="fn0:eval(function($a, $b) { $a + $b }, 2, 5)"/>
+ </one>
+ <two>
+ <xsl:value-of select="fn0:eval(function($a, $b) { avg(for $x in $a to $b return $x) }, 1, 10)"/>
+ </two>
+ <three>
+ <xsl:value-of select="fn0:eval(function($a, $b) { sum(for $x in $a to $b return math:pow($x, 2)) }, 1, 10)"/>
+ </three>
+ </result>
+ </xsl:template>
+
+ <!-- A stylesheet function, that takes a function item as an argument,
+ and other arguments as well that are further used as arguments
+ within a dynamic function call. The dynamic function call, is a
+ call to a function that was passed as a function item argument
+ to this xsl:function function.
+ -->
+ <xsl:function name="fn0:eval" as="xs:double">
+ <xsl:param name="f1"/>
+ <xsl:param name="a" as="xs:integer"/>
+ <xsl:param name="b" as="xs:integer"/>
+
+ <xsl:sequence select="$f1($a, $b)"/>
+ </xsl:function>
+
+ <!--
+ * 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.
+ -->
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/tests/org/apache/xalan/xslt3/HigherOrderFunctionTests.java b/tests/org/apache/xalan/xslt3/HigherOrderFunctionTests.java
new file mode 100644
index 00000000..31774962
--- /dev/null
+++ b/tests/org/apache/xalan/xslt3/HigherOrderFunctionTests.java
@@ -0,0 +1,81 @@
+/*
+ * 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.xalan.xslt3;
+
+import org.apache.xalan.util.XslTransformTestsUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * XSLT 3.0 and XPath 3.1 higher order function tests.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class HigherOrderFunctionTests extends XslTransformTestsUtil {
+
+ private static final String XSL_TRANSFORM_INPUT_DIRPATH = XSLConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX +
+ "higher_order_functions/";
+
+ private static final String XSL_TRANSFORM_GOLD_DIRPATH = XSLConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX +
+ "higher_order_functions/gold/";
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ // no op
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ xmlDocumentBuilderFactory = null;
+ xmlDocumentBuilder = null;
+ xslTransformerFactory = null;
+ }
+
+ @Test
+ public void xslHigherOrderFunctionTest1() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test1.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslHigherOrderFunctionTest2() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_a.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test2.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslHigherOrderFunctionTest3() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test3.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+}
diff --git a/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java b/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java
index 37991e0f..2bcab3c6 100644
--- a/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java
+++ b/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java
@@ -30,7 +30,8 @@ import org.junit.runners.Suite.SuiteClasses;
* @xsl.usage advanced
*/
@RunWith(Suite.class)
-@SuiteClasses({ FnDocTests.class, FnDataTests.class, RecursiveFunctionTests.class })
+@SuiteClasses({ FnDocTests.class, FnDataTests.class, RecursiveFunctionTests.class,
+ HigherOrderFunctionTests.class })
public class Xsl3TestSuite1 {
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org