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/07/20 12:34:07 UTC
[xalan-java] branch xalan-j_xslt3.0 updated: committing implementation of XPath 3.1 built-in functions namespace uri http://www.w3.org/2005/xpath-functions. also committing implementation of XPath 3.1 built-in math functions within namespace uri http://www.w3.org/2005/xpath-functions/math. committing few other related xalanj xslt 3.0 implementation changes, and few new working related test cases as well.
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 0f82f270 committing implementation of XPath 3.1 built-in functions namespace uri http://www.w3.org/2005/xpath-functions. also committing implementation of XPath 3.1 built-in math functions within namespace uri http://www.w3.org/2005/xpath-functions/math. committing few other related xalanj xslt 3.0 implementation changes, and few new working related test cases as well.
new 2c0dcbc7 Merge pull request #33 from mukulga/xalan-j_xslt3.0_mukul
0f82f270 is described below
commit 0f82f270449569ab08f3237fa4fccff78acfdc69
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Thu Jul 20 17:54:50 2023 +0530
committing implementation of XPath 3.1 built-in functions namespace uri http://www.w3.org/2005/xpath-functions. also committing implementation of XPath 3.1 built-in math functions within namespace uri http://www.w3.org/2005/xpath-functions/math. committing few other related xalanj xslt 3.0 implementation changes, and few new working related test cases as well.
---
src/org/apache/xpath/compiler/FunctionTable.java | 138 ++++++++++++++++++++-
src/org/apache/xpath/compiler/Keywords.java | 42 +++++++
src/org/apache/xpath/compiler/XPathParser.java | 115 ++++++++++++++---
src/org/apache/xpath/functions/FunctionOneArg.java | 11 +-
.../apache/xpath/functions/math/FuncMathAcos.java | 104 ++++++++++++++++
.../apache/xpath/functions/math/FuncMathAsin.java | 104 ++++++++++++++++
.../apache/xpath/functions/math/FuncMathAtan.java | 104 ++++++++++++++++
.../apache/xpath/functions/math/FuncMathAtan2.java | 101 +++++++++++++++
.../apache/xpath/functions/math/FuncMathCos.java | 104 ++++++++++++++++
.../apache/xpath/functions/math/FuncMathExp.java | 104 ++++++++++++++++
.../apache/xpath/functions/math/FuncMathExp10.java | 104 ++++++++++++++++
.../apache/xpath/functions/math/FuncMathLog.java | 104 ++++++++++++++++
.../apache/xpath/functions/math/FuncMathLog10.java | 104 ++++++++++++++++
.../Neg.java => functions/math/FuncMathPi.java} | 49 ++++----
.../apache/xpath/functions/math/FuncMathPow.java | 101 +++++++++++++++
.../apache/xpath/functions/math/FuncMathSin.java | 104 ++++++++++++++++
.../apache/xpath/functions/math/FuncMathSqrt.java | 104 ++++++++++++++++
.../apache/xpath/functions/math/FuncMathTan.java | 104 ++++++++++++++++
src/org/apache/xpath/operations/Div.java | 28 ++++-
src/org/apache/xpath/operations/Mult.java | 18 ++-
src/org/apache/xpath/operations/Neg.java | 12 +-
tests/built_in_functions_namespace/gold/test1.out | 6 +
tests/built_in_functions_namespace/test1.xsl | 41 ++++++
.../xpath3/BuiltinFunctionsNamespceTests.java | 61 +++++++++
.../TrignometricAndExponentialFunctionTests.java | 91 ++++++++++++++
tests/org/apache/xalan/xslt3/AllXsl3Tests.java | 5 +-
.../gold/test1.out | 35 ++++++
.../gold/test2.out | 29 +++++
.../gold/test3.out | 20 +++
.../gold/test4.out | 11 ++
.../trigonometric_and_exponential_funcs/test1.xsl | 78 ++++++++++++
.../test1_a.xml | 7 ++
.../trigonometric_and_exponential_funcs/test2.xsl | 69 +++++++++++
.../trigonometric_and_exponential_funcs/test3.xsl | 65 ++++++++++
.../trigonometric_and_exponential_funcs/test4.xsl | 74 +++++++++++
35 files changed, 2295 insertions(+), 56 deletions(-)
diff --git a/src/org/apache/xpath/compiler/FunctionTable.java b/src/org/apache/xpath/compiler/FunctionTable.java
index 1ddedf23..dc40716e 100644
--- a/src/org/apache/xpath/compiler/FunctionTable.java
+++ b/src/org/apache/xpath/compiler/FunctionTable.java
@@ -20,7 +20,10 @@
*/
package org.apache.xpath.compiler;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
+
import javax.xml.transform.TransformerException;
import org.apache.xpath.functions.Function;
@@ -188,11 +191,82 @@ public class FunctionTable
/** The 'distinct-values()' id. */
public static final int FUNC_DISTINCT_VALUES = 55;
+
+ /** The 'math:pi()' id. */
+ public static final int FUNC_MATH_PI = 56;
+
+ /** The 'math:exp()' id. */
+ public static final int FUNC_MATH_EXP = 57;
+
+ /** The 'math:exp10()' id. */
+ public static final int FUNC_MATH_EXP10 = 58;
+
+ /** The 'math:log()' id. */
+ public static final int FUNC_MATH_LOG = 59;
+
+ /** The 'math:log10()' id. */
+ public static final int FUNC_MATH_LOG10 = 60;
+
+ /** The 'math:pow()' id. */
+ public static final int FUNC_MATH_POW = 61;
+
+ /** The 'math:sqrt()' id. */
+ public static final int FUNC_MATH_SQRT = 62;
+
+ /** The 'math:sin()' id. */
+ public static final int FUNC_MATH_SIN = 63;
+
+ /** The 'math:cos()' id. */
+ public static final int FUNC_MATH_COS = 64;
+
+ /** The 'math:tan()' id. */
+ public static final int FUNC_MATH_TAN = 65;
+
+ /** The 'math:asin()' id. */
+ public static final int FUNC_MATH_ASIN = 66;
+
+ /** The 'math:acos()' id. */
+ public static final int FUNC_MATH_ACOS = 67;
+
+ /** The 'math:atan()' id. */
+ public static final int FUNC_MATH_ATAN = 68;
+
+ /** The 'math:atan2()' id. */
+ public static final int FUNC_MATH_ATAN2 = 69;
// Proprietary
/** The 'document-location()' id (Proprietary). */
public static final int FUNC_DOCLOCATION = 35;
+
+ /**
+ * XPath 3.1 built-in functions namespace uri, for most of the functions
+ * available to XPath 3.1 language users. The XPath functions available within
+ * this namespace, may be used without binding the function name with an XML
+ * namespace, or binding with a non-null XML namespace (the commonly used XML
+ * namespace prefix for this namespace uri is "fn", as suggested by
+ * XPath 3.1 spec).
+ */
+ static final String XPATH_BUILT_IN_FUNCS_NS_URI = "http://www.w3.org/2005/xpath-functions";
+
+ /**
+ * XPath 3.1 built-in functions namespace uri, for maths trigonometric and exponential
+ * functions. The XPath functions available within this namespace, must be used by
+ * qualifying the function name with an XML namespace bound to this uri (the commonly
+ * used XML namespace prefix for this namespace uri is "math", as suggested by
+ * XPath 3.1 spec).
+ */
+ static final String XPATH_BUILT_IN_MATH_FUNCS_NS_URI = "http://www.w3.org/2005/xpath-functions/math";
+
+ static final Integer[] XPATH_MATH_FUNC_IDS = new Integer[] { new Integer(FUNC_MATH_PI), new Integer(FUNC_MATH_EXP),
+ new Integer(FUNC_MATH_EXP10), new Integer(FUNC_MATH_LOG),
+ new Integer(FUNC_MATH_LOG10), new Integer(FUNC_MATH_POW),
+ new Integer(FUNC_MATH_SQRT), new Integer(FUNC_MATH_SIN),
+ new Integer(FUNC_MATH_COS), new Integer(FUNC_MATH_TAN),
+ new Integer(FUNC_MATH_ASIN), new Integer(FUNC_MATH_ACOS),
+ new Integer(FUNC_MATH_ATAN), new Integer(FUNC_MATH_ATAN2) };
+
+ static final List<Integer> XPATH_MATH_FUNC_IDS_ARR = Arrays.asList(XPATH_MATH_FUNC_IDS);
/**
* The function table.
@@ -216,7 +290,7 @@ public class FunctionTable
* Number of built in functions. Be sure to update this as
* built-in functions are added.
*/
- private static final int NUM_BUILT_IN_FUNCS = 56;
+ private static final int NUM_BUILT_IN_FUNCS = 70;
/**
* Number of built-in functions that may be added.
@@ -320,6 +394,37 @@ public class FunctionTable
org.apache.xpath.functions.FuncFilter.class;
m_functions[FUNC_DISTINCT_VALUES] =
org.apache.xpath.functions.FuncDistinctValues.class;
+
+ // XPath 3.1 functions configurations for the namespace
+ // http://www.w3.org/2005/xpath-functions/math.
+ m_functions[FUNC_MATH_PI] =
+ org.apache.xpath.functions.math.FuncMathPi.class;
+ m_functions[FUNC_MATH_EXP] =
+ org.apache.xpath.functions.math.FuncMathExp.class;
+ m_functions[FUNC_MATH_EXP10] =
+ org.apache.xpath.functions.math.FuncMathExp10.class;
+ m_functions[FUNC_MATH_LOG] =
+ org.apache.xpath.functions.math.FuncMathLog.class;
+ m_functions[FUNC_MATH_LOG10] =
+ org.apache.xpath.functions.math.FuncMathLog10.class;
+ m_functions[FUNC_MATH_POW] =
+ org.apache.xpath.functions.math.FuncMathPow.class;
+ m_functions[FUNC_MATH_SQRT] =
+ org.apache.xpath.functions.math.FuncMathSqrt.class;
+ m_functions[FUNC_MATH_SIN] =
+ org.apache.xpath.functions.math.FuncMathSin.class;
+ m_functions[FUNC_MATH_COS] =
+ org.apache.xpath.functions.math.FuncMathCos.class;
+ m_functions[FUNC_MATH_TAN] =
+ org.apache.xpath.functions.math.FuncMathTan.class;
+ m_functions[FUNC_MATH_ASIN] =
+ org.apache.xpath.functions.math.FuncMathAsin.class;
+ m_functions[FUNC_MATH_ACOS] =
+ org.apache.xpath.functions.math.FuncMathAcos.class;
+ m_functions[FUNC_MATH_ATAN] =
+ org.apache.xpath.functions.math.FuncMathAtan.class;
+ m_functions[FUNC_MATH_ATAN2] =
+ org.apache.xpath.functions.math.FuncMathAtan2.class;
}
static{
@@ -431,6 +536,37 @@ public class FunctionTable
new Integer(FunctionTable.FUNC_FILTER));
m_functionID.put(Keywords.FUNC_DISTINCT_VALUES,
new Integer(FunctionTable.FUNC_DISTINCT_VALUES));
+
+ // XPath 3.1 functions configurations for the namespace
+ // http://www.w3.org/2005/xpath-functions/math.
+ m_functionID.put(Keywords.FUNC_MATH_PI,
+ new Integer(FunctionTable.FUNC_MATH_PI));
+ m_functionID.put(Keywords.FUNC_MATH_EXP,
+ new Integer(FunctionTable.FUNC_MATH_EXP));
+ m_functionID.put(Keywords.FUNC_MATH_EXP10,
+ new Integer(FunctionTable.FUNC_MATH_EXP10));
+ m_functionID.put(Keywords.FUNC_MATH_LOG,
+ new Integer(FunctionTable.FUNC_MATH_LOG));
+ m_functionID.put(Keywords.FUNC_MATH_LOG10,
+ new Integer(FunctionTable.FUNC_MATH_LOG10));
+ m_functionID.put(Keywords.FUNC_MATH_POW,
+ new Integer(FunctionTable.FUNC_MATH_POW));
+ m_functionID.put(Keywords.FUNC_MATH_SQRT,
+ new Integer(FunctionTable.FUNC_MATH_SQRT));
+ m_functionID.put(Keywords.FUNC_MATH_SIN,
+ new Integer(FunctionTable.FUNC_MATH_SIN));
+ m_functionID.put(Keywords.FUNC_MATH_COS,
+ new Integer(FunctionTable.FUNC_MATH_COS));
+ m_functionID.put(Keywords.FUNC_MATH_TAN,
+ new Integer(FunctionTable.FUNC_MATH_TAN));
+ m_functionID.put(Keywords.FUNC_MATH_ASIN,
+ new Integer(FunctionTable.FUNC_MATH_ASIN));
+ m_functionID.put(Keywords.FUNC_MATH_ACOS,
+ new Integer(FunctionTable.FUNC_MATH_ACOS));
+ m_functionID.put(Keywords.FUNC_MATH_ATAN,
+ new Integer(FunctionTable.FUNC_MATH_ATAN));
+ m_functionID.put(Keywords.FUNC_MATH_ATAN2,
+ new Integer(FunctionTable.FUNC_MATH_ATAN2));
}
public FunctionTable(){
diff --git a/src/org/apache/xpath/compiler/Keywords.java b/src/org/apache/xpath/compiler/Keywords.java
index 04e76e38..bde7edd8 100644
--- a/src/org/apache/xpath/compiler/Keywords.java
+++ b/src/org/apache/xpath/compiler/Keywords.java
@@ -268,6 +268,48 @@ public class Keywords
/** distinct-values function string. */
public static final String FUNC_DISTINCT_VALUES = "distinct-values";
+
+ /** math:pi function string. */
+ public static final String FUNC_MATH_PI = "pi";
+
+ /** math:exp function string. */
+ public static final String FUNC_MATH_EXP = "exp";
+
+ /** math:exp10 function string. */
+ public static final String FUNC_MATH_EXP10 = "exp10";
+
+ /** math:log function string. */
+ public static final String FUNC_MATH_LOG = "log";
+
+ /** math:log10 function string. */
+ public static final String FUNC_MATH_LOG10 = "log10";
+
+ /** math:pow function string. */
+ public static final String FUNC_MATH_POW = "pow";
+
+ /** math:sqrt function string. */
+ public static final String FUNC_MATH_SQRT = "sqrt";
+
+ /** math:sin function string. */
+ public static final String FUNC_MATH_SIN = "sin";
+
+ /** math:cos function string. */
+ public static final String FUNC_MATH_COS = "cos";
+
+ /** math:tan function string. */
+ public static final String FUNC_MATH_TAN = "tan";
+
+ /** math:asin function string. */
+ public static final String FUNC_MATH_ASIN = "asin";
+
+ /** math:acos function string. */
+ public static final String FUNC_MATH_ACOS = "acos";
+
+ /** math:atan function string. */
+ public static final String FUNC_MATH_ATAN = "atan";
+
+ /** math:atan2 function string. */
+ public static final String FUNC_MATH_ATAN2 = "atan2";
// Proprietary, built in functions
diff --git a/src/org/apache/xpath/compiler/XPathParser.java b/src/org/apache/xpath/compiler/XPathParser.java
index 2965598b..5df2f127 100644
--- a/src/org/apache/xpath/compiler/XPathParser.java
+++ b/src/org/apache/xpath/compiler/XPathParser.java
@@ -2221,16 +2221,86 @@ public class XPathParser
if (lookahead(':', 1))
{
- appendOp(4, OpCodes.OP_EXTFUNCTION);
+ if (tokenIs(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI))
+ {
+ nextToken();
+ consumeExpected(':');
+
+ int funcTok = getFunctionToken(m_token);
- m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 1, m_queueMark - 1);
+ if (-1 == funcTok)
+ {
+ error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
+ new Object[] {"{" + FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI + "}" + m_token + "()"});
+ }
+ else if ((FunctionTable.XPATH_MATH_FUNC_IDS_ARR).contains(Integer.valueOf(funcTok))) {
+ funcTok = -1;
+ error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
+ new Object[] {"{" + FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI + "}" + m_token + "()"});
+ }
- nextToken();
- consumeExpected(':');
+ switch (funcTok)
+ {
+ case OpCodes.NODETYPE_PI :
+ case OpCodes.NODETYPE_COMMENT :
+ case OpCodes.NODETYPE_TEXT :
+ case OpCodes.NODETYPE_NODE :
+ // Node type tests look like function calls, but they're not
+ return false;
+ default :
+ appendOp(3, OpCodes.OP_FUNCTION);
+
+ m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 1, funcTok);
+ }
- m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 2, m_queueMark - 1);
+ nextToken();
+ }
+ else if (tokenIs(FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI))
+ {
+ nextToken();
+ consumeExpected(':');
+
+ int funcTok = getFunctionToken(m_token);
- nextToken();
+ if (-1 == funcTok)
+ {
+ error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
+ new Object[] {"{" + FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI + "}" + m_token + "()"});
+ }
+ else if (!(FunctionTable.XPATH_MATH_FUNC_IDS_ARR).contains(Integer.valueOf(funcTok))) {
+ funcTok = -1;
+ error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
+ new Object[] {"{" + FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI + "}" + m_token + "()"});
+ }
+
+ switch (funcTok)
+ {
+ case OpCodes.NODETYPE_PI :
+ case OpCodes.NODETYPE_COMMENT :
+ case OpCodes.NODETYPE_TEXT :
+ case OpCodes.NODETYPE_NODE :
+ // Node type tests look like function calls, but they're not
+ return false;
+ default :
+ appendOp(3, OpCodes.OP_FUNCTION);
+
+ m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 1, funcTok);
+ }
+
+ nextToken();
+ }
+ else {
+ appendOp(4, OpCodes.OP_EXTFUNCTION);
+
+ m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 1, m_queueMark - 1);
+
+ nextToken();
+ consumeExpected(':');
+
+ m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 2, m_queueMark - 1);
+
+ nextToken();
+ }
}
else
{
@@ -2238,22 +2308,27 @@ public class XPathParser
if (-1 == funcTok)
{
- error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
- new Object[]{ m_token }); //"Could not find function: "+m_token+"()");
+ error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
+ new Object[]{"{" + FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI + "}" + m_token + "()"});
+ }
+ else if ((FunctionTable.XPATH_MATH_FUNC_IDS_ARR).contains(Integer.valueOf(funcTok))) {
+ funcTok = -1;
+ error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
+ new Object[] {"{" + FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI + "}" + m_token + "()"});
}
switch (funcTok)
{
- case OpCodes.NODETYPE_PI :
- case OpCodes.NODETYPE_COMMENT :
- case OpCodes.NODETYPE_TEXT :
- case OpCodes.NODETYPE_NODE :
- // Node type tests look like function calls, but they're not
- return false;
- default :
- appendOp(3, OpCodes.OP_FUNCTION);
+ case OpCodes.NODETYPE_PI :
+ case OpCodes.NODETYPE_COMMENT :
+ case OpCodes.NODETYPE_TEXT :
+ case OpCodes.NODETYPE_NODE :
+ // Node type tests look like function calls, but they're not
+ return false;
+ default :
+ appendOp(3, OpCodes.OP_FUNCTION);
- m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 1, funcTok);
+ m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 1, funcTok);
}
nextToken();
@@ -2802,9 +2877,9 @@ public class XPathParser
try
{
- // XPath 1.0 does not support number in exp notation
- if ((m_token.indexOf('e') > -1)||(m_token.indexOf('E') > -1))
- throw new NumberFormatException();
+ // XPath 3.1 requires support for numbers in exp notation
+ /*if ((m_token.indexOf('e') > -1)||(m_token.indexOf('E') > -1))
+ throw new NumberFormatException();*/
num = Double.valueOf(m_token).doubleValue();
}
catch (NumberFormatException nfe)
diff --git a/src/org/apache/xpath/functions/FunctionOneArg.java b/src/org/apache/xpath/functions/FunctionOneArg.java
index acae5402..dd9a9bab 100644
--- a/src/org/apache/xpath/functions/FunctionOneArg.java
+++ b/src/org/apache/xpath/functions/FunctionOneArg.java
@@ -37,6 +37,8 @@ public class FunctionOneArg extends Function implements ExpressionOwner
*
*/
Expression m_arg0;
+
+ private boolean fArgCountErr = false;
/**
* Return the first argument passed to the function (at index 0).
@@ -67,8 +69,10 @@ public class FunctionOneArg extends Function implements ExpressionOwner
m_arg0 = arg;
arg.exprSetParent(this);
}
- else
+ else {
+ fArgCountErr = true;
reportWrongNumberArgs();
+ }
}
/**
@@ -95,6 +99,10 @@ public class FunctionOneArg extends Function implements ExpressionOwner
throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("one", null));
}
+ protected boolean isArgCountErr() {
+ return fArgCountErr;
+ }
+
/**
* Tell if this expression or it's subexpressions can traverse outside
* the current subtree.
@@ -171,5 +179,4 @@ public class FunctionOneArg extends Function implements ExpressionOwner
return true;
}
-
}
diff --git a/src/org/apache/xpath/functions/math/FuncMathAcos.java b/src/org/apache/xpath/functions/math/FuncMathAcos.java
new file mode 100644
index 00000000..23ccd8ee
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathAcos.java
@@ -0,0 +1,104 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.FunctionOneArg;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:acos() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathAcos extends FunctionOneArg
+{
+
+ private static final long serialVersionUID = 8892228442916107939L;
+
+ /**
+ * Execute the function. The function must return a valid object.
+ *
+ * @param xctxt The current execution context.
+ * @return A valid XObject.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ Expression arg0 = getArg0();
+
+ if (arg0 == null || isArgCountErr()) {
+ ResultSequence resultSeq = new ResultSequence();
+ return resultSeq;
+ }
+
+ XObject arg0Result = arg0.execute(xctxt);
+
+ if (arg0Result instanceof XNumber) {
+ double resultVal = Math.acos(((XNumber)arg0Result).num());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XSNumericType) {
+ String strVal = ((XSNumericType)arg0Result).stringValue();
+ double resultVal = Math.acos((new XSDouble(strVal)).doubleValue());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)arg0Result;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:acos "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return result;
+ }
+}
diff --git a/src/org/apache/xpath/functions/math/FuncMathAsin.java b/src/org/apache/xpath/functions/math/FuncMathAsin.java
new file mode 100644
index 00000000..6659c1ec
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathAsin.java
@@ -0,0 +1,104 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.FunctionOneArg;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:asin() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathAsin extends FunctionOneArg
+{
+
+ private static final long serialVersionUID = 5661596185872339942L;
+
+ /**
+ * Execute the function. The function must return a valid object.
+ *
+ * @param xctxt The current execution context.
+ * @return A valid XObject.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ Expression arg0 = getArg0();
+
+ if (arg0 == null || isArgCountErr()) {
+ ResultSequence resultSeq = new ResultSequence();
+ return resultSeq;
+ }
+
+ XObject arg0Result = arg0.execute(xctxt);
+
+ if (arg0Result instanceof XNumber) {
+ double resultVal = Math.asin(((XNumber)arg0Result).num());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XSNumericType) {
+ String strVal = ((XSNumericType)arg0Result).stringValue();
+ double resultVal = Math.asin((new XSDouble(strVal)).doubleValue());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)arg0Result;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:asin "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return result;
+ }
+}
diff --git a/src/org/apache/xpath/functions/math/FuncMathAtan.java b/src/org/apache/xpath/functions/math/FuncMathAtan.java
new file mode 100644
index 00000000..8fa01600
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathAtan.java
@@ -0,0 +1,104 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.FunctionOneArg;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:atan() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathAtan extends FunctionOneArg
+{
+
+ private static final long serialVersionUID = 7279664663962212944L;
+
+ /**
+ * Execute the function. The function must return a valid object.
+ *
+ * @param xctxt The current execution context.
+ * @return A valid XObject.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ Expression arg0 = getArg0();
+
+ if (arg0 == null || isArgCountErr()) {
+ ResultSequence resultSeq = new ResultSequence();
+ return resultSeq;
+ }
+
+ XObject arg0Result = arg0.execute(xctxt);
+
+ if (arg0Result instanceof XNumber) {
+ double resultVal = Math.atan(((XNumber)arg0Result).num());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XSNumericType) {
+ String strVal = ((XSNumericType)arg0Result).stringValue();
+ double resultVal = Math.atan((new XSDouble(strVal)).doubleValue());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)arg0Result;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:atan "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return result;
+ }
+}
diff --git a/src/org/apache/xpath/functions/math/FuncMathAtan2.java b/src/org/apache/xpath/functions/math/FuncMathAtan2.java
new file mode 100644
index 00000000..4db282a2
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathAtan2.java
@@ -0,0 +1,101 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.Function2Args;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:atan2() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathAtan2 extends Function2Args {
+
+ private static final long serialVersionUID = 1342863964649663483L;
+
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ XObject arg0Result = (getArg0()).execute(xctxt);
+ XObject arg1Result = (getArg1()).execute(xctxt);
+
+ double lDouble = getDoubleValue(arg0Result, srcLocator, "first");
+ double rDouble = getDoubleValue(arg1Result, srcLocator, "second");
+
+ result = new XSDouble(Math.atan2(lDouble, rDouble));
+
+ return result;
+ }
+ /*
+ * Get an 'double' value from an object of type XObject.
+ */
+ private double getDoubleValue(XObject xObject, SourceLocator srcLocator, String argNumStr)
+ throws javax.xml.transform.TransformerException {
+
+ double resultVal = 0.0;
+
+ if (xObject instanceof XNumber) {
+ resultVal = ((XNumber)xObject).num();
+ }
+ else if (xObject instanceof XSNumericType) {
+ String strVal = ((XSNumericType)xObject).stringValue();
+ resultVal = (new XSDouble(strVal)).doubleValue();
+ }
+ else if (xObject instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)xObject;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The " + argNumStr + " argument to math:atan2 "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return resultVal;
+ }
+
+}
diff --git a/src/org/apache/xpath/functions/math/FuncMathCos.java b/src/org/apache/xpath/functions/math/FuncMathCos.java
new file mode 100644
index 00000000..36f50aa2
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathCos.java
@@ -0,0 +1,104 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.FunctionOneArg;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:cos() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathCos extends FunctionOneArg
+{
+
+ private static final long serialVersionUID = -5932797004954199817L;
+
+ /**
+ * Execute the function. The function must return a valid object.
+ *
+ * @param xctxt The current execution context.
+ * @return A valid XObject.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ Expression arg0 = getArg0();
+
+ if (arg0 == null || isArgCountErr()) {
+ ResultSequence resultSeq = new ResultSequence();
+ return resultSeq;
+ }
+
+ XObject arg0Result = arg0.execute(xctxt);
+
+ if (arg0Result instanceof XNumber) {
+ double resultVal = Math.cos(((XNumber)arg0Result).num());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XSNumericType) {
+ String strVal = ((XSNumericType)arg0Result).stringValue();
+ double resultVal = Math.cos((new XSDouble(strVal)).doubleValue());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)arg0Result;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:cos "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return result;
+ }
+}
diff --git a/src/org/apache/xpath/functions/math/FuncMathExp.java b/src/org/apache/xpath/functions/math/FuncMathExp.java
new file mode 100644
index 00000000..b370645a
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathExp.java
@@ -0,0 +1,104 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.FunctionOneArg;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:exp() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathExp extends FunctionOneArg
+{
+
+ private static final long serialVersionUID = -605243297781530421L;
+
+ /**
+ * Execute the function. The function must return a valid object.
+ *
+ * @param xctxt The current execution context.
+ * @return A valid XObject.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ Expression arg0 = getArg0();
+
+ if (arg0 == null || isArgCountErr()) {
+ ResultSequence resultSeq = new ResultSequence();
+ return resultSeq;
+ }
+
+ XObject arg0Result = arg0.execute(xctxt);
+
+ if (arg0Result instanceof XNumber) {
+ double resultVal = Math.exp(((XNumber)arg0Result).num());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XSNumericType) {
+ String strVal = ((XSNumericType)arg0Result).stringValue();
+ double resultVal = Math.exp((new XSDouble(strVal)).doubleValue());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)arg0Result;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:exp "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return result;
+ }
+}
diff --git a/src/org/apache/xpath/functions/math/FuncMathExp10.java b/src/org/apache/xpath/functions/math/FuncMathExp10.java
new file mode 100644
index 00000000..449b9526
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathExp10.java
@@ -0,0 +1,104 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.FunctionOneArg;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:exp10() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathExp10 extends FunctionOneArg
+{
+
+ private static final long serialVersionUID = -9091454668780154373L;
+
+ /**
+ * Execute the function. The function must return a valid object.
+ *
+ * @param xctxt The current execution context.
+ * @return A valid XObject.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ Expression arg0 = getArg0();
+
+ if (arg0 == null || isArgCountErr()) {
+ ResultSequence resultSeq = new ResultSequence();
+ return resultSeq;
+ }
+
+ XObject arg0Result = arg0.execute(xctxt);
+
+ if (arg0Result instanceof XNumber) {
+ double resultVal = Math.pow(10, ((XNumber)arg0Result).num());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XSNumericType) {
+ String strVal = ((XSNumericType)arg0Result).stringValue();
+ double resultVal = Math.pow(10, (new XSDouble(strVal)).doubleValue());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)arg0Result;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:exp10 "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return result;
+ }
+}
diff --git a/src/org/apache/xpath/functions/math/FuncMathLog.java b/src/org/apache/xpath/functions/math/FuncMathLog.java
new file mode 100644
index 00000000..44721c48
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathLog.java
@@ -0,0 +1,104 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.FunctionOneArg;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:log() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathLog extends FunctionOneArg
+{
+
+ private static final long serialVersionUID = -2616839360135167252L;
+
+ /**
+ * Execute the function. The function must return a valid object.
+ *
+ * @param xctxt The current execution context.
+ * @return A valid XObject.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ Expression arg0 = getArg0();
+
+ if (arg0 == null || isArgCountErr()) {
+ ResultSequence resultSeq = new ResultSequence();
+ return resultSeq;
+ }
+
+ XObject arg0Result = arg0.execute(xctxt);
+
+ if (arg0Result instanceof XNumber) {
+ double resultVal = Math.log(((XNumber)arg0Result).num());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XSNumericType) {
+ String strVal = ((XSNumericType)arg0Result).stringValue();
+ double resultVal = Math.log((new XSDouble(strVal)).doubleValue());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)arg0Result;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:log "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return result;
+ }
+}
diff --git a/src/org/apache/xpath/functions/math/FuncMathLog10.java b/src/org/apache/xpath/functions/math/FuncMathLog10.java
new file mode 100644
index 00000000..205c7a2d
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathLog10.java
@@ -0,0 +1,104 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.FunctionOneArg;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:log10() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathLog10 extends FunctionOneArg
+{
+
+ private static final long serialVersionUID = -4624379163066277285L;
+
+ /**
+ * Execute the function. The function must return a valid object.
+ *
+ * @param xctxt The current execution context.
+ * @return A valid XObject.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ Expression arg0 = getArg0();
+
+ if (arg0 == null || isArgCountErr()) {
+ ResultSequence resultSeq = new ResultSequence();
+ return resultSeq;
+ }
+
+ XObject arg0Result = arg0.execute(xctxt);
+
+ if (arg0Result instanceof XNumber) {
+ double resultVal = Math.log10(((XNumber)arg0Result).num());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XSNumericType) {
+ String strVal = ((XSNumericType)arg0Result).stringValue();
+ double resultVal = Math.log10((new XSDouble(strVal)).doubleValue());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)arg0Result;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:log10 "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return result;
+ }
+}
diff --git a/src/org/apache/xpath/operations/Neg.java b/src/org/apache/xpath/functions/math/FuncMathPi.java
similarity index 50%
copy from src/org/apache/xpath/operations/Neg.java
copy to src/org/apache/xpath/functions/math/FuncMathPi.java
index 2200104e..cebe6286 100644
--- a/src/org/apache/xpath/operations/Neg.java
+++ b/src/org/apache/xpath/functions/math/FuncMathPi.java
@@ -15,51 +15,46 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/*
- * $Id$
- */
-package org.apache.xpath.operations;
+package org.apache.xpath.functions.math;
import org.apache.xpath.XPathContext;
-import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.functions.Function;
import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
/**
- * The unary '-' operation expression executer.
+ * Implementation of the math:pi() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
*/
-public class Neg extends UnaryOperation
+public class FuncMathPi extends Function
{
- static final long serialVersionUID = -6280607702375702291L;
+
+ private static final long serialVersionUID = -5588383515962377796L;
+
+ private final double PI = 3.141592653589793;
/**
- * Apply the operation to two operands, and return the result.
- *
- *
- * @param right non-null reference to the evaluated right operand.
- *
- * @return non-null reference to the XObject that represents the result of the operation.
+ * Execute the function. The function must return a valid object.
+ *
+ * @param xctxt The current execution context.
+ * @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
- public XObject operate(XObject right) throws javax.xml.transform.TransformerException
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
- return new XNumber(-right.num());
+ return new XSDouble(PI);
}
/**
- * Evaluate this operation directly to a double.
- *
- * @param xctxt The runtime execution context.
- *
- * @return The result of the operation as a double.
- *
- * @throws javax.xml.transform.TransformerException
+ * No arguments to process, so this does nothing.
*/
- public double num(XPathContext xctxt)
- throws javax.xml.transform.TransformerException
+ public void fixupVariables(java.util.Vector vars, int globalsSize)
{
-
- return -(m_right.num(xctxt));
+ // no-op
}
}
diff --git a/src/org/apache/xpath/functions/math/FuncMathPow.java b/src/org/apache/xpath/functions/math/FuncMathPow.java
new file mode 100644
index 00000000..7eb7fffc
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathPow.java
@@ -0,0 +1,101 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.Function2Args;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:pow() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathPow extends Function2Args {
+
+ private static final long serialVersionUID = 1342863964649663483L;
+
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ XObject arg0Result = (getArg0()).execute(xctxt);
+ XObject arg1Result = (getArg1()).execute(xctxt);
+
+ double lDouble = getDoubleValue(arg0Result, srcLocator, "first");
+ double rDouble = getDoubleValue(arg1Result, srcLocator, "second");
+
+ result = new XSDouble(Math.pow(lDouble, rDouble));
+
+ return result;
+ }
+ /*
+ * Get an 'double' value from an object of type XObject.
+ */
+ private double getDoubleValue(XObject xObject, SourceLocator srcLocator, String argNumStr)
+ throws javax.xml.transform.TransformerException {
+
+ double resultVal = 0.0;
+
+ if (xObject instanceof XNumber) {
+ resultVal = ((XNumber)xObject).num();
+ }
+ else if (xObject instanceof XSNumericType) {
+ String strVal = ((XSNumericType)xObject).stringValue();
+ resultVal = (new XSDouble(strVal)).doubleValue();
+ }
+ else if (xObject instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)xObject;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The " + argNumStr + " argument to math:pow "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return resultVal;
+ }
+
+}
diff --git a/src/org/apache/xpath/functions/math/FuncMathSin.java b/src/org/apache/xpath/functions/math/FuncMathSin.java
new file mode 100644
index 00000000..d5c78aae
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathSin.java
@@ -0,0 +1,104 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.FunctionOneArg;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:sin() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathSin extends FunctionOneArg
+{
+
+ private static final long serialVersionUID = -5033967904807150569L;
+
+ /**
+ * Execute the function. The function must return a valid object.
+ *
+ * @param xctxt The current execution context.
+ * @return A valid XObject.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ Expression arg0 = getArg0();
+
+ if (arg0 == null || isArgCountErr()) {
+ ResultSequence resultSeq = new ResultSequence();
+ return resultSeq;
+ }
+
+ XObject arg0Result = arg0.execute(xctxt);
+
+ if (arg0Result instanceof XNumber) {
+ double resultVal = Math.sin(((XNumber)arg0Result).num());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XSNumericType) {
+ String strVal = ((XSNumericType)arg0Result).stringValue();
+ double resultVal = Math.sin((new XSDouble(strVal)).doubleValue());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)arg0Result;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:sin "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return result;
+ }
+}
diff --git a/src/org/apache/xpath/functions/math/FuncMathSqrt.java b/src/org/apache/xpath/functions/math/FuncMathSqrt.java
new file mode 100644
index 00000000..f3114009
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathSqrt.java
@@ -0,0 +1,104 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.FunctionOneArg;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:sqrt() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathSqrt extends FunctionOneArg
+{
+
+ private static final long serialVersionUID = 5691792456759543428L;
+
+ /**
+ * Execute the function. The function must return a valid object.
+ *
+ * @param xctxt The current execution context.
+ * @return A valid XObject.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ Expression arg0 = getArg0();
+
+ if (arg0 == null || isArgCountErr()) {
+ ResultSequence resultSeq = new ResultSequence();
+ return resultSeq;
+ }
+
+ XObject arg0Result = arg0.execute(xctxt);
+
+ if (arg0Result instanceof XNumber) {
+ double resultVal = Math.sqrt(((XNumber)arg0Result).num());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XSNumericType) {
+ String strVal = ((XSNumericType)arg0Result).stringValue();
+ double resultVal = Math.sqrt((new XSDouble(strVal)).doubleValue());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)arg0Result;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:sqrt "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return result;
+ }
+}
diff --git a/src/org/apache/xpath/functions/math/FuncMathTan.java b/src/org/apache/xpath/functions/math/FuncMathTan.java
new file mode 100644
index 00000000..dd32ae32
--- /dev/null
+++ b/src/org/apache/xpath/functions/math/FuncMathTan.java
@@ -0,0 +1,104 @@
+/*
+ * 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.xpath.functions.math;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.FunctionOneArg;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
+import org.apache.xpath.xs.types.XSNumericType;
+
+/**
+ * Implementation of the math:tan() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncMathTan extends FunctionOneArg
+{
+
+ private static final long serialVersionUID = -3352805345293481131L;
+
+ /**
+ * Execute the function. The function must return a valid object.
+ *
+ * @param xctxt The current execution context.
+ * @return A valid XObject.
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
+ Expression arg0 = getArg0();
+
+ if (arg0 == null || isArgCountErr()) {
+ ResultSequence resultSeq = new ResultSequence();
+ return resultSeq;
+ }
+
+ XObject arg0Result = arg0.execute(xctxt);
+
+ if (arg0Result instanceof XNumber) {
+ double resultVal = Math.tan(((XNumber)arg0Result).num());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XSNumericType) {
+ String strVal = ((XSNumericType)arg0Result).stringValue();
+ double resultVal = Math.tan((new XSDouble(strVal)).doubleValue());
+ result = new XSDouble(resultVal);
+ }
+ else if (arg0Result instanceof XNodeSet) {
+ XNodeSet xNodeSet = (XNodeSet)arg0Result;
+ if (xNodeSet.getLength() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The argument to math:tan "
+ + "function must be a sequence of length one.", srcLocator);
+ }
+ else {
+ String strVal = xNodeSet.str();
+
+ 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);
+ }
+
+ return result;
+ }
+}
diff --git a/src/org/apache/xpath/operations/Div.java b/src/org/apache/xpath/operations/Div.java
index 8953444a..7eab3956 100644
--- a/src/org/apache/xpath/operations/Div.java
+++ b/src/org/apache/xpath/operations/Div.java
@@ -23,6 +23,7 @@ package org.apache.xpath.operations;
import org.apache.xpath.XPathContext;
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
/**
* The 'div' operation expression executer.
@@ -43,9 +44,30 @@ public class Div extends Operation
* @throws javax.xml.transform.TransformerException
*/
public XObject operate(XObject left, XObject right)
- throws javax.xml.transform.TransformerException
- {
- return new XNumber(left.num() / right.num());
+ throws javax.xml.transform.TransformerException
+ {
+ XObject result = null;
+
+ if ((left instanceof XSDouble) && (right instanceof XSDouble)) {
+ double lDouble = ((XSDouble)left).doubleValue();
+ double rDouble = ((XSDouble)right).doubleValue();
+ result = new XNumber(lDouble / rDouble);
+ }
+ else if ((left instanceof XNumber) && (right instanceof XSDouble)) {
+ double lDouble = ((XNumber)left).num();
+ double rDouble = ((XSDouble)right).doubleValue();
+ result = new XNumber(lDouble / rDouble);
+ }
+ else if ((left instanceof XSDouble) && (right instanceof XNumber)) {
+ double lDouble = ((XSDouble)left).doubleValue();
+ double rDouble = ((XNumber)right).num();
+ result = new XNumber(lDouble / rDouble);
+ }
+ else {
+ result = new XNumber(left.num() / right.num());
+ }
+
+ return result;
}
/**
diff --git a/src/org/apache/xpath/operations/Mult.java b/src/org/apache/xpath/operations/Mult.java
index 39ae15f2..a42502b7 100644
--- a/src/org/apache/xpath/operations/Mult.java
+++ b/src/org/apache/xpath/operations/Mult.java
@@ -23,6 +23,7 @@ package org.apache.xpath.operations;
import org.apache.xpath.XPathContext;
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
import org.apache.xpath.xs.types.XSInteger;
/**
@@ -44,7 +45,7 @@ public class Mult extends Operation
* @throws javax.xml.transform.TransformerException
*/
public XObject operate(XObject left, XObject right)
- throws javax.xml.transform.TransformerException
+ throws javax.xml.transform.TransformerException
{
XObject result = null;
@@ -61,6 +62,21 @@ public class Mult extends Operation
double rDouble = (((XSInteger)right).intValue()).doubleValue();
result = new XNumber(lDouble * rDouble);
}
+ else if ((left instanceof XSDouble) && (right instanceof XSDouble)) {
+ double lDouble = ((XSDouble)left).doubleValue();
+ double rDouble = ((XSDouble)right).doubleValue();
+ result = new XNumber(lDouble * rDouble);
+ }
+ else if ((left instanceof XNumber) && (right instanceof XSDouble)) {
+ double lDouble = ((XNumber)left).num();
+ double rDouble = ((XSDouble)right).doubleValue();
+ result = new XNumber(lDouble * rDouble);
+ }
+ else if ((left instanceof XSDouble) && (right instanceof XNumber)) {
+ double lDouble = ((XSDouble)left).doubleValue();
+ double rDouble = ((XNumber)right).num();
+ result = new XNumber(lDouble * rDouble);
+ }
else {
result = new XNumber(left.num() * right.num());
}
diff --git a/src/org/apache/xpath/operations/Neg.java b/src/org/apache/xpath/operations/Neg.java
index 2200104e..bf96ef9d 100644
--- a/src/org/apache/xpath/operations/Neg.java
+++ b/src/org/apache/xpath/operations/Neg.java
@@ -23,6 +23,7 @@ package org.apache.xpath.operations;
import org.apache.xpath.XPathContext;
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSDouble;
/**
* The unary '-' operation expression executer.
@@ -43,7 +44,16 @@ public class Neg extends UnaryOperation
*/
public XObject operate(XObject right) throws javax.xml.transform.TransformerException
{
- return new XNumber(-right.num());
+ XObject result = null;
+
+ if (right instanceof XSDouble) {
+ result = new XNumber(-(((XSDouble)right).doubleValue()));
+ }
+ else {
+ result = new XNumber(-right.num());
+ }
+
+ return result;
}
/**
diff --git a/tests/built_in_functions_namespace/gold/test1.out b/tests/built_in_functions_namespace/gold/test1.out
new file mode 100644
index 00000000..461e73b6
--- /dev/null
+++ b/tests/built_in_functions_namespace/gold/test1.out
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <one>hello world</one>
+ <two>hello world</two>
+ <three>10</three>
+ <four>10</four>
+</result>
diff --git a/tests/built_in_functions_namespace/test1.xsl b/tests/built_in_functions_namespace/test1.xsl
new file mode 100644
index 00000000..b0b5eeb8
--- /dev/null
+++ b/tests/built_in_functions_namespace/test1.xsl
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:fn="http://www.w3.org/2005/xpath-functions"
+ exclude-result-prefixes="fn"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT stylesheet, to test the XPath 3.1 built-in
+ functions namespace http://www.w3.org/2005/xpath-functions. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <one><xsl:value-of select="concat('hello', ' ', 'world')"/></one>
+ <two><xsl:value-of select="fn:concat('hello', ' ', 'world')"/></two>
+ <three><xsl:value-of select="abs(-10)"/></three>
+ <four><xsl:value-of select="fn:abs(-10)"/></four>
+ </result>
+ </xsl:template>
+
+ <!--
+ * 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/xpath3/BuiltinFunctionsNamespceTests.java b/tests/org/apache/xalan/xpath3/BuiltinFunctionsNamespceTests.java
new file mode 100644
index 00000000..427e0645
--- /dev/null
+++ b/tests/org/apache/xalan/xpath3/BuiltinFunctionsNamespceTests.java
@@ -0,0 +1,61 @@
+/*
+ * 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.xpath3;
+
+import org.apache.xalan.util.XslTransformTestsUtil;
+import org.apache.xalan.xslt3.XSLConstants;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * XPath 3.1 test cases, to test use of built-in functions namespace
+ * uri http://www.w3.org/2005/xpath-functions.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class BuiltinFunctionsNamespceTests extends XslTransformTestsUtil {
+
+ private static final String XSL_TRANSFORM_INPUT_DIRPATH = XSLConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX + "built_in_functions_namespace/";
+
+ private static final String XSL_TRANSFORM_GOLD_DIRPATH = XSLConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX + "built_in_functions_namespace/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 xslBuiltinFunctionsNamespceTest1() {
+ 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);
+ }
+
+}
diff --git a/tests/org/apache/xalan/xpath3/TrignometricAndExponentialFunctionTests.java b/tests/org/apache/xalan/xpath3/TrignometricAndExponentialFunctionTests.java
new file mode 100644
index 00000000..dd92d255
--- /dev/null
+++ b/tests/org/apache/xalan/xpath3/TrignometricAndExponentialFunctionTests.java
@@ -0,0 +1,91 @@
+/*
+ * 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.xpath3;
+
+import org.apache.xalan.util.XslTransformTestsUtil;
+import org.apache.xalan.xslt3.XSLConstants;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * XPath 3.1 function test cases, for trigonometric and exponential functions
+ * defined within XPath 3.1's XML namespace http://www.w3.org/2005/xpath-functions/math.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class TrignometricAndExponentialFunctionTests extends XslTransformTestsUtil {
+
+ private static final String XSL_TRANSFORM_INPUT_DIRPATH = XSLConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX + "trigonometric_and_exponential_funcs/";
+
+ private static final String XSL_TRANSFORM_GOLD_DIRPATH = XSLConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX + "trigonometric_and_exponential_funcs/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 xslTrignometricAndExponentialFunctionTest1() {
+ 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 xslTrignometricAndExponentialFunctionTest2() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test2.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslTrignometricAndExponentialFunctionTest3() {
+ 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);
+ }
+
+ @Test
+ public void xslTrignometricAndExponentialFunctionTest4() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_a.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test4.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test4.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+}
diff --git a/tests/org/apache/xalan/xslt3/AllXsl3Tests.java b/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
index b155fc67..613d438c 100644
--- a/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
+++ b/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
@@ -16,6 +16,7 @@
*/
package org.apache.xalan.xslt3;
+import org.apache.xalan.xpath3.BuiltinFunctionsNamespceTests;
import org.apache.xalan.xpath3.DynamicFunctionCallTests;
import org.apache.xalan.xpath3.FnAbsTests;
import org.apache.xalan.xpath3.FnDistinctValuesTests;
@@ -33,6 +34,7 @@ import org.apache.xalan.xpath3.QuantifiedExprTests;
import org.apache.xalan.xpath3.RangeExprTests;
import org.apache.xalan.xpath3.SequenceTests;
import org.apache.xalan.xpath3.StringTests;
+import org.apache.xalan.xpath3.TrignometricAndExponentialFunctionTests;
import org.apache.xalan.xpath3.ValueComparisonTests;
import org.apache.xalan.xpath3.XsConstructorFunctionTests;
import org.junit.runner.RunWith;
@@ -60,7 +62,8 @@ import org.junit.runners.Suite.SuiteClasses;
W3c_xslt30_IterateTests.class, W3c_xslt30_AxesTests.class, XslIterateTests.class,
ValueComparisonTests.class, InlineFunctionItemExprTests.class, FnForEachTests.class,
FnFilterTests.class, DynamicFunctionCallTests.class, IfExprTests.class,
- ForExprTests.class, LetExprTests.class, FnDistinctValuesTests.class })
+ ForExprTests.class, LetExprTests.class, FnDistinctValuesTests.class,
+ TrignometricAndExponentialFunctionTests.class, BuiltinFunctionsNamespceTests.class })
public class AllXsl3Tests {
}
diff --git a/tests/trigonometric_and_exponential_funcs/gold/test1.out b/tests/trigonometric_and_exponential_funcs/gold/test1.out
new file mode 100644
index 00000000..82bf5d45
--- /dev/null
+++ b/tests/trigonometric_and_exponential_funcs/gold/test1.out
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <pi>3.141592653589793</pi>
+ <pi_expr>1.0471975511965976</pi_expr>
+ <exp>1</exp>
+ <exp>2.718281828459045</exp>
+ <exp>7.38905609893065</exp>
+ <exp>0.3678794411714423</exp>
+ <exp>23.140692632779267</exp>
+ <exp>NaN</exp>
+ <exp>INF</exp>
+ <exp>0</exp>
+ <exp10>1</exp10>
+ <exp10>10</exp10>
+ <exp10>3.1622776601683795</exp10>
+ <exp10>0.1</exp10>
+ <exp10>NaN</exp10>
+ <exp10>INF</exp10>
+ <exp10>0</exp10>
+ <log>-INF</log>
+ <log>1</log>
+ <log>-6.907755278982137</log>
+ <log>0.6931471805599453</log>
+ <log>NaN</log>
+ <log>NaN</log>
+ <log>INF</log>
+ <log>NaN</log>
+ <log10>-INF</log10>
+ <log10>3</log10>
+ <log10>-3</log10>
+ <log10>0.3010299956639812</log10>
+ <log10>NaN</log10>
+ <log10>NaN</log10>
+ <log10>INF</log10>
+ <log10>NaN</log10>
+</result>
diff --git a/tests/trigonometric_and_exponential_funcs/gold/test2.out b/tests/trigonometric_and_exponential_funcs/gold/test2.out
new file mode 100644
index 00000000..a76cec57
--- /dev/null
+++ b/tests/trigonometric_and_exponential_funcs/gold/test2.out
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <pow>8</pow>
+ <pow>-8</pow>
+ <pow>0.125</pow>
+ <pow>-0.125</pow>
+ <pow>1</pow>
+ <pow>1</pow>
+ <pow>1</pow>
+ <pow>1</pow>
+ <pow>1</pow>
+ <pow>0</pow>
+ <pow>0</pow>
+ <pow>-0</pow>
+ <pow>0</pow>
+ <pow>INF</pow>
+ <pow>INF</pow>
+ <pow>-INF</pow>
+ <pow>4</pow>
+ <pow>2</pow>
+ <pow>6.25</pow>
+ <sqrt>0</sqrt>
+ <sqrt>-0</sqrt>
+ <sqrt>1000</sqrt>
+ <sqrt>1.4142135623730951</sqrt>
+ <sqrt>NaN</sqrt>
+ <sqrt>NaN</sqrt>
+ <sqrt>INF</sqrt>
+ <sqrt>NaN</sqrt>
+</result>
diff --git a/tests/trigonometric_and_exponential_funcs/gold/test3.out b/tests/trigonometric_and_exponential_funcs/gold/test3.out
new file mode 100644
index 00000000..c572fb44
--- /dev/null
+++ b/tests/trigonometric_and_exponential_funcs/gold/test3.out
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <sin>0</sin>
+ <sin>-0</sin>
+ <sin>1</sin>
+ <sin>-1</sin>
+ <sin>0.0000000000000001</sin>
+ <cos>1</cos>
+ <cos>-1</cos>
+ <tan>0</tan>
+ <tan>-0.0000000000000001</tan>
+ <asin>0</asin>
+ <asin>1.5707963267948966</asin>
+ <asin>-1.5707963267948966</asin>
+ <acos>1.5707963267948966</acos>
+ <acos>3.141592653589793</acos>
+ <atan>0.7853981633974483</atan>
+ <atan>-0.7853981633974483</atan>
+ <atan2>-3.141592653589793</atan2>
+ <atan2>-3.141592653589793</atan2>
+</result>
diff --git a/tests/trigonometric_and_exponential_funcs/gold/test4.out b/tests/trigonometric_and_exponential_funcs/gold/test4.out
new file mode 100644
index 00000000..e08b0cba
--- /dev/null
+++ b/tests/trigonometric_and_exponential_funcs/gold/test4.out
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <exp inp="1">2.718281828459045</exp>
+ <sin inp="1">0.8414709848078965</sin>
+ <atan inp="1">0.7853981633974483</atan>
+ <exp inp="2">7.38905609893065</exp>
+ <sin inp="2">0.9092974268256817</sin>
+ <atan inp="2">1.1071487177940904</atan>
+ <exp inp="3">20.085536923187668</exp>
+ <sin inp="3">0.1411200080598672</sin>
+ <atan inp="3">1.2490457723982544</atan>
+</result>
diff --git a/tests/trigonometric_and_exponential_funcs/test1.xsl b/tests/trigonometric_and_exponential_funcs/test1.xsl
new file mode 100644
index 00000000..d5a78866
--- /dev/null
+++ b/tests/trigonometric_and_exponential_funcs/test1.xsl
@@ -0,0 +1,78 @@
+<?xml version="1.0"?>
+<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"
+ exclude-result-prefixes="xs math"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- This XSLT stylesheet, has various XPath 3.1 expressions involving
+ functions within the XML namespace http://www.w3.org/2005/xpath-functions/math.
+
+ The XPath expressions mentioned within this XSLT stylesheet test, are borrowed
+ from XPath 3.1 spec. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <pi><xsl:value-of select="math:pi()"/></pi>
+ <pi_expr><xsl:value-of select="60 * (math:pi() div 180)"/></pi_expr>
+
+ <exp><xsl:value-of select="math:exp(0)"/></exp>
+ <exp><xsl:value-of select="math:exp(1)"/></exp>
+ <exp><xsl:value-of select="math:exp(2)"/></exp>
+ <exp><xsl:value-of select="math:exp(-1)"/></exp>
+ <exp><xsl:value-of select="math:exp(math:pi())"/></exp>
+ <exp><xsl:value-of select="math:exp(xs:double('NaN'))"/></exp>
+ <exp><xsl:value-of select="math:exp(xs:double('INF'))"/></exp>
+ <exp><xsl:value-of select="math:exp(xs:double('-INF'))"/></exp>
+
+ <exp10><xsl:value-of select="math:exp10(0)"/></exp10>
+ <exp10><xsl:value-of select="math:exp10(1)"/></exp10>
+ <exp10><xsl:value-of select="math:exp10(0.5)"/></exp10>
+ <exp10><xsl:value-of select="math:exp10(-1)"/></exp10>
+ <exp10><xsl:value-of select="math:exp10(xs:double('NaN'))"/></exp10>
+ <exp10><xsl:value-of select="math:exp10(xs:double('INF'))"/></exp10>
+ <exp10><xsl:value-of select="math:exp10(xs:double('-INF'))"/></exp10>
+
+ <log><xsl:value-of select="math:log(0)"/></log>
+ <log><xsl:value-of select="math:log(math:exp(1))"/></log>
+ <log><xsl:value-of select="math:log(1.0e-3)"/></log>
+ <log><xsl:value-of select="math:log(2)"/></log>
+ <log><xsl:value-of select="math:log(-1)"/></log>
+ <log><xsl:value-of select="math:log(xs:double('NaN'))"/></log>
+ <log><xsl:value-of select="math:log(xs:double('INF'))"/></log>
+ <log><xsl:value-of select="math:log(xs:double('-INF'))"/></log>
+
+ <log10><xsl:value-of select="math:log10(0)"/></log10>
+ <log10><xsl:value-of select="math:log10(1.0e3)"/></log10>
+ <log10><xsl:value-of select="math:log10(1.0e-3)"/></log10>
+ <log10><xsl:value-of select="math:log10(2)"/></log10>
+ <log10><xsl:value-of select="math:log10(-1)"/></log10>
+ <log10><xsl:value-of select="math:log10(xs:double('NaN'))"/></log10>
+ <log10><xsl:value-of select="math:log10(xs:double('INF'))"/></log10>
+ <log10><xsl:value-of select="math:log10(xs:double('-INF'))"/></log10>
+ </result>
+ </xsl:template>
+
+ <!--
+ * 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/trigonometric_and_exponential_funcs/test1_a.xml b/tests/trigonometric_and_exponential_funcs/test1_a.xml
new file mode 100644
index 00000000..f3a1d198
--- /dev/null
+++ b/tests/trigonometric_and_exponential_funcs/test1_a.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<list>
+ <a>1</a>
+ <a val="2"/>
+ <a>3</a>
+</list>
+
\ No newline at end of file
diff --git a/tests/trigonometric_and_exponential_funcs/test2.xsl b/tests/trigonometric_and_exponential_funcs/test2.xsl
new file mode 100644
index 00000000..2eeb6f4a
--- /dev/null
+++ b/tests/trigonometric_and_exponential_funcs/test2.xsl
@@ -0,0 +1,69 @@
+<?xml version="1.0"?>
+<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"
+ exclude-result-prefixes="xs math"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- This XSLT stylesheet, has various XPath 3.1 expressions involving
+ functions within the XML namespace http://www.w3.org/2005/xpath-functions/math.
+
+ The XPath expressions mentioned within this XSLT stylesheet test, are borrowed
+ from XPath 3.1 spec. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <pow><xsl:value-of select="math:pow(2, 3)"/></pow>
+ <pow><xsl:value-of select="math:pow(-2, 3)"/></pow>
+ <pow><xsl:value-of select="math:pow(2, -3)"/></pow>
+ <pow><xsl:value-of select="math:pow(-2, -3)"/></pow>
+ <pow><xsl:value-of select="math:pow(2, 0)"/></pow>
+ <pow><xsl:value-of select="math:pow(0, 0)"/></pow>
+ <pow><xsl:value-of select="math:pow(xs:double('INF'), 0)"/></pow>
+ <pow><xsl:value-of select="math:pow(xs:double('NaN'), 0)"/></pow>
+ <pow><xsl:value-of select="math:pow(-math:pi(), 0)"/></pow>
+ <pow><xsl:value-of select="math:pow(0e0, 3)"/></pow>
+ <pow><xsl:value-of select="math:pow(0e0, 4)"/></pow>
+ <pow><xsl:value-of select="math:pow(-0e0, 3)"/></pow>
+ <pow><xsl:value-of select="math:pow(0, 4)"/></pow>
+ <pow><xsl:value-of select="math:pow(0e0, -3)"/></pow>
+ <pow><xsl:value-of select="math:pow(0e0, -4)"/></pow>
+ <pow><xsl:value-of select="math:pow(-0e0, -3)"/></pow>
+ <pow><xsl:value-of select="math:pow(16, 0.5e0)"/></pow>
+ <pow><xsl:value-of select="math:pow(16, 0.25e0)"/></pow>
+ <pow><xsl:value-of select="math:pow(-2.5e0, 2.0e0)"/></pow>
+
+ <sqrt><xsl:value-of select="math:sqrt(0.0e0)"/></sqrt>
+ <sqrt><xsl:value-of select="math:sqrt(-0.0e0)"/></sqrt>
+ <sqrt><xsl:value-of select="math:sqrt(1.0e6)"/></sqrt>
+ <sqrt><xsl:value-of select="math:sqrt(2.0e0)"/></sqrt>
+ <sqrt><xsl:value-of select="math:sqrt(-2.0e0)"/></sqrt>
+ <sqrt><xsl:value-of select="math:sqrt(xs:double('NaN'))"/></sqrt>
+ <sqrt><xsl:value-of select="math:sqrt(xs:double('INF'))"/></sqrt>
+ <sqrt><xsl:value-of select="math:sqrt(xs:double('-INF'))"/></sqrt>
+ </result>
+ </xsl:template>
+
+ <!--
+ * 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/trigonometric_and_exponential_funcs/test3.xsl b/tests/trigonometric_and_exponential_funcs/test3.xsl
new file mode 100644
index 00000000..bf45d06a
--- /dev/null
+++ b/tests/trigonometric_and_exponential_funcs/test3.xsl
@@ -0,0 +1,65 @@
+<?xml version="1.0"?>
+<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"
+ exclude-result-prefixes="xs math"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- This XSLT stylesheet, has various XPath 3.1 expressions involving
+ functions within the XML namespace http://www.w3.org/2005/xpath-functions/math.
+
+ The XPath expressions mentioned within this XSLT stylesheet test, are borrowed
+ from XPath 3.1 spec. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <sin><xsl:value-of select="math:sin(0)"/></sin>
+ <sin><xsl:value-of select="math:sin(-0.0e0)"/></sin>
+ <sin><xsl:value-of select="math:sin(math:pi() div 2)"/></sin>
+ <sin><xsl:value-of select="math:sin(-math:pi() div 2)"/></sin>
+ <sin><xsl:value-of select="math:sin(math:pi())"/></sin>
+
+ <cos><xsl:value-of select="math:cos(0)"/></cos>
+ <cos><xsl:value-of select="math:cos(math:pi())"/></cos>
+
+ <tan><xsl:value-of select="math:tan(0)"/></tan>
+ <tan><xsl:value-of select="math:tan(math:pi())"/></tan>
+
+ <asin><xsl:value-of select="math:asin(0)"/></asin>
+ <asin><xsl:value-of select="math:asin(1.0e0)"/></asin>
+ <asin><xsl:value-of select="math:asin(-1.0e0)"/></asin>
+
+ <acos><xsl:value-of select="math:acos(0)"/></acos>
+ <acos><xsl:value-of select="math:acos(-1.0e0)"/></acos>
+
+ <atan><xsl:value-of select="math:atan(1.0e0)"/></atan>
+ <atan><xsl:value-of select="math:atan(-1.0e0)"/></atan>
+
+ <atan2><xsl:value-of select="math:atan2(-0.0e0, -0.0e0)"/></atan2>
+ <atan2><xsl:value-of select="math:atan2(-0.0e0, -1)"/></atan2>
+ </result>
+ </xsl:template>
+
+ <!--
+ * 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/trigonometric_and_exponential_funcs/test4.xsl b/tests/trigonometric_and_exponential_funcs/test4.xsl
new file mode 100644
index 00000000..59a41e62
--- /dev/null
+++ b/tests/trigonometric_and_exponential_funcs/test4.xsl
@@ -0,0 +1,74 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:math="http://www.w3.org/2005/xpath-functions/math"
+ exclude-result-prefixes="math"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- use with test1_a.xml -->
+
+ <!-- This XSLT stylesheet test, has various XPath 3.1 expressions involving
+ functions within the XML namespace http://www.w3.org/2005/xpath-functions/math.
+
+ This stylesheet takes as input, the data from an external XML document.
+ -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/list">
+ <result>
+ <xsl:for-each select="a">
+ <exp inp="{if (@val) then @val else .}">
+ <xsl:choose>
+ <xsl:when test="@val">
+ <xsl:value-of select="math:exp(@val)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="math:exp(.)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </exp>
+ <sin inp="{if (@val) then @val else .}">
+ <xsl:choose>
+ <xsl:when test="@val">
+ <xsl:value-of select="math:sin(@val)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="math:sin(.)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </sin>
+ <atan inp="{if (@val) then @val else .}">
+ <xsl:choose>
+ <xsl:when test="@val">
+ <xsl:value-of select="math:atan(@val)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="math:atan(.)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </atan>
+ </xsl:for-each>
+ </result>
+ </xsl:template>
+
+ <!--
+ * 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org