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/01 15:38:38 UTC
[xalan-java] branch xalan-j_xslt3.0 updated: committing few improvements to implementation of, function item inline function expressions, and improvements to implementations of xpath functions fn:for-each and fn:filter. fixing an issue with implementation file XSDate.java as well, that was discovered during xalanj xslt 3.0's tests regressions.
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 92003c6a committing few improvements to implementation of, function item inline function expressions, and improvements to implementations of xpath functions fn:for-each and fn:filter. fixing an issue with implementation file XSDate.java as well, that was discovered during xalanj xslt 3.0's tests regressions.
new 45b6639a Merge pull request #15 from mukulga/xalan-j_xslt3.0_mukul
92003c6a is described below
commit 92003c6a9ec775b875afb85741e79f92d48af130
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sat Jul 1 19:44:55 2023 +0530
committing few improvements to implementation of, function item inline function expressions, and improvements to implementations of xpath functions fn:for-each and fn:filter. fixing an issue with implementation file XSDate.java as well, that was discovered during xalanj xslt 3.0's tests regressions.
---
src/org/apache/xalan/templates/ElemCopyOf.java | 7 +--
src/org/apache/xpath/compiler/XPathParser.java | 33 +++++++++----
src/org/apache/xpath/functions/FuncFilter.java | 56 +++++++++++++---------
src/org/apache/xpath/functions/FuncForEach.java | 42 ++++++++++------
src/org/apache/xpath/objects/XObject.java | 3 ++
src/org/apache/xpath/operations/Mod.java | 34 ++++++++++---
src/org/apache/xpath/res/XPATHErrorResources.java | 7 +--
src/org/apache/xpath/xs/types/XSDate.java | 29 +++++------
tests/fn_filter/gold/test4.out | 1 +
tests/fn_filter/gold/test5.out | 0
tests/fn_filter/test4.xsl | 35 ++++++++++++++
tests/fn_filter/test5.xsl | 37 ++++++++++++++
tests/fn_filter/test6.xsl | 37 ++++++++++++++
tests/fn_foreach/gold/test9.out | 0
tests/fn_foreach/test10.xsl | 37 ++++++++++++++
tests/fn_foreach/test9.xsl | 37 ++++++++++++++
tests/inline_function_expr/gold/test1.out | 1 +
tests/inline_function_expr/test1.xsl | 37 ++++++++++++++
tests/inline_function_expr/test2.xsl | 37 ++++++++++++++
tests/inline_function_expr/test3.xsl | 37 ++++++++++++++
tests/org/apache/xalan/xpath3/FnFilterTests.java | 33 +++++++++++++
tests/org/apache/xalan/xpath3/FnForEachTests.java | 23 +++++++++
...Tests.java => InlineFunctionItemExprTests.java} | 23 ++++-----
tests/org/apache/xalan/xslt3/AllXsl3Tests.java | 4 +-
24 files changed, 500 insertions(+), 90 deletions(-)
diff --git a/src/org/apache/xalan/templates/ElemCopyOf.java b/src/org/apache/xalan/templates/ElemCopyOf.java
index 6acb612a..d0889369 100644
--- a/src/org/apache/xalan/templates/ElemCopyOf.java
+++ b/src/org/apache/xalan/templates/ElemCopyOf.java
@@ -201,15 +201,16 @@ public class ElemCopyOf extends ElemTemplateElement
case XObject.CLASS_RESULT_SEQUENCE :
// added for XSLT 3.0
ResultSequence resultSequence = (ResultSequence)value;
+ char[] spaceCharArr = new char[1];
+ spaceCharArr[0] = ' ';
for (int idx = 0; idx < resultSequence.size(); idx++) {
XObject sequenceItem = resultSequence.item(idx);
if (sequenceItem.getType() == XObject.CLASS_STRING) {
String str = sequenceItem.str();
handler.characters(str.toCharArray(), 0, str.length());
- if (idx < (resultSequence.size() - 1)) {
- String strSpace = " ";
- handler.characters(strSpace.toCharArray(), 0, strSpace.length());
+ if (idx < (resultSequence.size() - 1)) {
+ handler.characters(spaceCharArr, 0, 1);
}
continue;
}
diff --git a/src/org/apache/xpath/compiler/XPathParser.java b/src/org/apache/xpath/compiler/XPathParser.java
index 867a5813..3b49f83a 100644
--- a/src/org/apache/xpath/compiler/XPathParser.java
+++ b/src/org/apache/xpath/compiler/XPathParser.java
@@ -1620,18 +1620,13 @@ public class XPathParser
}
}
- if (funcParamNameList.size() > 1) {
- error(XPATHErrorResources.ER_INLINE_FUNCTION_PARAM_CARDINALITY, new Object[] {
- Integer.valueOf(funcParamNameList.size()) });
- }
-
inlineFunction.setFuncParamNameList(funcParamNameList);
consumeExpected(')');
consumeExpected('{');
- StringBuffer funcBodyXPathExprStrBuff = new StringBuffer();
+ List<String> funcBodyXPathExprStrPartsList = new ArrayList<String>();
if (tokenIs('}')) {
consumeExpected('}');
@@ -1639,15 +1634,37 @@ public class XPathParser
else {
while (!tokenIs('}') && m_token != null)
{
- funcBodyXPathExprStrBuff.append(m_token);
+ funcBodyXPathExprStrPartsList.add(m_token);
nextToken();
}
consumeExpected('}');
}
+ StringBuffer funcBodyXPathExprStrBuff = new StringBuffer();
+
+ Object[] funcBodyXPathExprStrPartsArr = funcBodyXPathExprStrPartsList.toArray();
+
+ for (int idx = 0; idx < funcBodyXPathExprStrPartsArr.length; idx++) {
+ String xpathExprStrPart = null;
+
+ if ("$".equals(funcBodyXPathExprStrPartsArr[idx]) && (idx <
+ (funcBodyXPathExprStrPartsArr.length - 1))) {
+ xpathExprStrPart = "$" + funcBodyXPathExprStrPartsArr[idx + 1];
+ idx += 1;
+ }
+ else {
+ xpathExprStrPart = (String)funcBodyXPathExprStrPartsArr[idx];
+ }
+
+ funcBodyXPathExprStrBuff.append(xpathExprStrPart + " ");
+ }
+
funcBodyXPathExprStr = funcBodyXPathExprStrBuff.toString();
- inlineFunction.setFuncBodyXPathExprStr(funcBodyXPathExprStr);
+ if (funcBodyXPathExprStr.length() > 0) {
+ funcBodyXPathExprStr = funcBodyXPathExprStr.substring(0, funcBodyXPathExprStr.length() - 1);
+ inlineFunction.setFuncBodyXPathExprStr(funcBodyXPathExprStr);
+ }
return inlineFunction;
}
diff --git a/src/org/apache/xpath/functions/FuncFilter.java b/src/org/apache/xpath/functions/FuncFilter.java
index 595f9fd6..933ce64e 100644
--- a/src/org/apache/xpath/functions/FuncFilter.java
+++ b/src/org/apache/xpath/functions/FuncFilter.java
@@ -36,10 +36,8 @@ import org.apache.xpath.objects.ResultSequence;
import org.apache.xpath.objects.XBoolean;
import org.apache.xpath.objects.XNodeSet;
import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XObjectFactory;
import org.apache.xpath.operations.Variable;
import org.apache.xpath.res.XPATHErrorResources;
-import org.w3c.dom.Node;
/**
* Execute the filter() function.
@@ -84,6 +82,8 @@ public class FuncFilter extends Function2Args {
XObject funcEvaluationResult = null;
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
final int contextNode = xctxt.getCurrentNode();
Expression arg0 = getArg0();
@@ -102,13 +102,17 @@ public class FuncFilter extends Function2Args {
ResultSequence resultSeq = new ResultSequence();
- if (arg1 instanceof InlineFunction) {
- resultSeq = evaluateFnFilter(xctxt, arg0XsObject, arg0DtmIterator, (InlineFunction)arg1);
+ if (arg1 instanceof InlineFunction) {
+ InlineFunction inlineFuncArg = (InlineFunction)arg1;
+ validateInlineFunctionParamCardinality(inlineFuncArg, srcLocator);
+ resultSeq = evaluateFnFilter(xctxt, arg0XsObject, arg0DtmIterator, inlineFuncArg);
}
else if (arg1 instanceof Variable) {
XObject arg1VarValue = arg1.execute(xctxt);
if (arg1VarValue instanceof InlineFunction) {
- resultSeq = evaluateFnFilter(xctxt, arg0XsObject, arg0DtmIterator, (InlineFunction)arg1VarValue);
+ InlineFunction inlineFuncArg = (InlineFunction)arg1VarValue;
+ validateInlineFunctionParamCardinality(inlineFuncArg, srcLocator);
+ resultSeq = evaluateFnFilter(xctxt, arg0XsObject, arg0DtmIterator, inlineFuncArg);
}
else {
throw new javax.xml.transform.TransformerException("FORG0006 : The second argument to function call filter(), "
@@ -150,31 +154,39 @@ public class FuncFilter extends Function2Args {
XPATHErrorResources.ER_TWO, null)); //"2"
}
+ /*
+ * Validate the, number of function parameters, that the inline function is allowed to have for fn:filter.
+ */
+ private void validateInlineFunctionParamCardinality(InlineFunction inlineFuncArg, SourceLocator srcLocator) throws
+ javax.xml.transform.TransformerException {
+ List<String> funcParamNameList = inlineFuncArg.getFuncParamNameList();
+ if (funcParamNameList.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The supplied function fn:filter's function item has " +
+ funcParamNameList.size() + " parameters. "
+ + "Expected 1.", srcLocator);
+ }
+ }
+
/*
* Evaluate the function call fn:filter.
*/
private ResultSequence evaluateFnFilter(XPathContext xctxt, XObject arg0XsObject,
DTMIterator arg0DtmIterator, InlineFunction arg1)
throws TransformerException {
-
ResultSequence resultSeq = new ResultSequence();
List<String> funcParamNameList = arg1.getFuncParamNameList();
+ QName varQname = new QName(funcParamNameList.get(0));
+
String funcBodyXPathExprStr = arg1.getFuncBodyXPathExprStr();
if (funcBodyXPathExprStr == null || "".equals(funcBodyXPathExprStr)) {
return resultSeq;
- }
-
- QName varQname = null;
-
- if (funcParamNameList.size() == 1) {
- varQname = new QName(funcParamNameList.get(0));
- }
+ }
SourceLocator srcLocator = xctxt.getSAXLocator();
- XPath xpathInlineFn = new XPath(funcBodyXPathExprStr, srcLocator, null, XPath.SELECT, null);
+ XPath inlineFnXpath = new XPath(funcBodyXPathExprStr, srcLocator, null, XPath.SELECT, null);
if (arg0XsObject instanceof ResultSequence) {
XPathContext xpathContextNew = new XPathContext(false);
@@ -187,7 +199,7 @@ public class FuncFilter extends Function2Args {
inlineFunctionVarMap.put(varQname, inpSeqItem);
}
- XObject resultObj = xpathInlineFn.execute(xpathContextNew, DTM.NULL, null);
+ XObject resultObj = inlineFnXpath.execute(xpathContextNew, DTM.NULL, null);
if (resultObj instanceof XBoolean) {
if (((XBoolean)resultObj).bool()) {
resultSeq.add(inpSeqItem);
@@ -201,25 +213,23 @@ public class FuncFilter extends Function2Args {
inlineFunctionVarMap.clear();
}
- else if (arg0DtmIterator != null) {
+ else if (arg0DtmIterator != null) {
Map<QName, XObject> inlineFunctionVarMap = xctxt.getInlineFunctionVarMap();
+ final int contextNode = xctxt.getCurrentNode();
+
int dtmNodeHandle;
while (DTM.NULL != (dtmNodeHandle = arg0DtmIterator.nextNode())) {
- DTM dtm = xctxt.getDTM(dtmNodeHandle);
- Node node = dtm.getNode(dtmNodeHandle);
- XObject inpSeqItem = XObjectFactory.create(node, xctxt);
+ XNodeSet inpSeqItem = new XNodeSet(dtmNodeHandle, xctxt.getDTMManager());
if (varQname != null) {
inlineFunctionVarMap.put(varQname, inpSeqItem);
}
-
- xctxt.pushCurrentNode(dtmNodeHandle);
- XObject resultObj = xpathInlineFn.execute(xctxt, dtmNodeHandle, null);
+ XObject resultObj = inlineFnXpath.execute(xctxt, contextNode, null);
if (resultObj instanceof XBoolean) {
if (((XBoolean)resultObj).bool()) {
- resultSeq.add(new XNodeSet(dtmNodeHandle, xctxt));
+ resultSeq.add(inpSeqItem);
}
}
else {
diff --git a/src/org/apache/xpath/functions/FuncForEach.java b/src/org/apache/xpath/functions/FuncForEach.java
index 113b1335..15d6aeaa 100644
--- a/src/org/apache/xpath/functions/FuncForEach.java
+++ b/src/org/apache/xpath/functions/FuncForEach.java
@@ -78,6 +78,8 @@ public class FuncForEach extends Function2Args {
XObject funcEvaluationResult = null;
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
final int contextNode = xctxt.getCurrentNode();
Expression arg0 = getArg0();
@@ -96,13 +98,17 @@ public class FuncForEach extends Function2Args {
ResultSequence resultSeq = new ResultSequence();
- if (arg1 instanceof InlineFunction) {
- resultSeq = evaluateFnForEach(xctxt, arg0XsObject, arg0DtmIterator, (InlineFunction)arg1);
+ if (arg1 instanceof InlineFunction) {
+ InlineFunction inlineFuncArg = (InlineFunction)arg1;
+ validateInlineFunctionParamCardinality(inlineFuncArg, srcLocator);
+ resultSeq = evaluateFnForEach(xctxt, arg0XsObject, arg0DtmIterator, inlineFuncArg);
}
else if (arg1 instanceof Variable) {
XObject arg1VarValue = arg1.execute(xctxt);
if (arg1VarValue instanceof InlineFunction) {
- resultSeq = evaluateFnForEach(xctxt, arg0XsObject, arg0DtmIterator, (InlineFunction)arg1VarValue);
+ InlineFunction inlineFuncArg = (InlineFunction)arg1VarValue;
+ validateInlineFunctionParamCardinality(inlineFuncArg, srcLocator);
+ resultSeq = evaluateFnForEach(xctxt, arg0XsObject, arg0DtmIterator, inlineFuncArg);
}
else {
throw new javax.xml.transform.TransformerException("FORG0006 : The second argument to function call for-each(), "
@@ -144,31 +150,39 @@ public class FuncForEach extends Function2Args {
XPATHErrorResources.ER_TWO, null)); //"2"
}
+ /*
+ * Validate the, number of function parameters, that the inline function is allowed to have for fn:for-each.
+ */
+ private void validateInlineFunctionParamCardinality(InlineFunction inlineFuncArg, SourceLocator srcLocator) throws
+ javax.xml.transform.TransformerException {
+ List<String> funcParamNameList = inlineFuncArg.getFuncParamNameList();
+ if (funcParamNameList.size() != 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The supplied function fn:for-each's function item has " +
+ funcParamNameList.size() + " parameters. "
+ + "Expected 1.", srcLocator);
+ }
+ }
+
/*
* Evaluate the function call fn:for-each.
*/
private ResultSequence evaluateFnForEach(XPathContext xctxt, XObject arg0XsObject,
DTMIterator arg0DtmIterator, InlineFunction arg1)
throws TransformerException {
-
ResultSequence resultSeq = new ResultSequence();
List<String> funcParamNameList = arg1.getFuncParamNameList();
+ QName varQname = new QName(funcParamNameList.get(0));
+
String funcBodyXPathExprStr = arg1.getFuncBodyXPathExprStr();
if (funcBodyXPathExprStr == null || "".equals(funcBodyXPathExprStr)) {
return resultSeq;
- }
-
- QName varQname = null;
-
- if (funcParamNameList.size() == 1) {
- varQname = new QName(funcParamNameList.get(0));
- }
+ }
SourceLocator srcLocator = xctxt.getSAXLocator();
- XPath xpathInlineFn = new XPath(funcBodyXPathExprStr, srcLocator, null, XPath.SELECT, null);
+ XPath inlineFnXpath = new XPath(funcBodyXPathExprStr, srcLocator, null, XPath.SELECT, null);
if (arg0XsObject instanceof ResultSequence) {
XPathContext xpathContextNew = new XPathContext(false);
@@ -181,7 +195,7 @@ public class FuncForEach extends Function2Args {
inlineFunctionVarMap.put(varQname, inpSeqItem);
}
- XObject resultObj = xpathInlineFn.execute(xpathContextNew, DTM.NULL, null);
+ XObject resultObj = inlineFnXpath.execute(xpathContextNew, DTM.NULL, null);
resultSeq.add(resultObj);
}
@@ -199,7 +213,7 @@ public class FuncForEach extends Function2Args {
inlineFunctionVarMap.put(varQname, xObject);
}
- XObject resultObj = xpathInlineFn.execute(xctxt, dtmNodeHandle, null);
+ XObject resultObj = inlineFnXpath.execute(xctxt, dtmNodeHandle, null);
resultSeq.add(resultObj);
}
diff --git a/src/org/apache/xpath/objects/XObject.java b/src/org/apache/xpath/objects/XObject.java
index de688eeb..1fc75f6f 100644
--- a/src/org/apache/xpath/objects/XObject.java
+++ b/src/org/apache/xpath/objects/XObject.java
@@ -610,6 +610,9 @@ public class XObject extends Expression implements Serializable, Cloneable
else if ((this instanceof XSDate) && (obj2 instanceof XSDate)) {
return ((XSDate)this).lt((XSDate)obj2);
}
+ else if ((this instanceof XNumber) && (obj2 instanceof XNumber)) {
+ return ((XNumber)this).num() < ((XNumber)obj2).num();
+ }
boolean isOperandNodeSet1 = false;
boolean isOperandNodeSet2 = false;
diff --git a/src/org/apache/xpath/operations/Mod.java b/src/org/apache/xpath/operations/Mod.java
index 3dee1ca1..f979b849 100644
--- a/src/org/apache/xpath/operations/Mod.java
+++ b/src/org/apache/xpath/operations/Mod.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.XSInteger;
/**
* The 'mod' operation expression executer.
@@ -42,10 +43,31 @@ public class Mod extends Operation
*
* @throws javax.xml.transform.TransformerException
*/
- public XObject operate(XObject left, XObject right)
- throws javax.xml.transform.TransformerException
+ public XObject operate(XObject left, XObject right) throws javax.xml.transform.TransformerException
{
- return new XNumber(left.num() % right.num());
+ XObject result = null;
+
+ if ((left instanceof XSInteger) && (right instanceof XSInteger)) {
+ result = ((XSInteger)left).multiply((XSInteger)right);
+ double lDouble = (((XSInteger)left).intValue()).doubleValue();
+ double rDouble = (((XSInteger)right).intValue()).doubleValue();
+ result = new XNumber(lDouble % rDouble);
+ }
+ else if ((left instanceof XSInteger) && (right instanceof XNumber)) {
+ double lDouble = (((XSInteger)left).intValue()).doubleValue();
+ double rDouble = ((XNumber)right).num();
+ result = new XNumber(lDouble % rDouble);
+ }
+ else if ((left instanceof XNumber) && (right instanceof XSInteger)) {
+ double lDouble = ((XNumber)left).num();
+ double rDouble = (((XSInteger)right).intValue()).doubleValue();
+ result = new XNumber(lDouble % rDouble);
+ }
+ else {
+ result = new XNumber(left.num() % right.num());
+ }
+
+ return result;
}
/**
@@ -57,11 +79,9 @@ public class Mod extends Operation
*
* @throws javax.xml.transform.TransformerException
*/
- public double num(XPathContext xctxt)
- throws javax.xml.transform.TransformerException
+ public double num(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
-
- return (m_left.num(xctxt) % m_right.num(xctxt));
+ return (m_left.num(xctxt) % m_right.num(xctxt));
}
}
diff --git a/src/org/apache/xpath/res/XPATHErrorResources.java b/src/org/apache/xpath/res/XPATHErrorResources.java
index c28a9094..b340990f 100644
--- a/src/org/apache/xpath/res/XPATHErrorResources.java
+++ b/src/org/apache/xpath/res/XPATHErrorResources.java
@@ -152,9 +152,7 @@ public class XPATHErrorResources extends ListResourceBundle
public static final String ER_FOUND_COMMA_BUT_NO_FOLLOWING_ARG =
"ER_FOUND_COMMA_BUT_NO_FOLLOWING_ARG";
public static final String ER_FOUND_COMMA_BUT_NO_FOLLOWING_PARAM =
- "ER_FOUND_COMMA_BUT_NO_FOLLOWING_PARAM";
- public static final String ER_INLINE_FUNCTION_PARAM_CARDINALITY =
- "ER_INLINE_FUNCTION_PARAM_CARDINALITY";
+ "ER_FOUND_COMMA_BUT_NO_FOLLOWING_PARAM";
public static final String ER_PREDICATE_ILLEGAL_SYNTAX =
"ER_PREDICATE_ILLEGAL_SYNTAX";
public static final String ER_ILLEGAL_AXIS_NAME = "ER_ILLEGAL_AXIS_NAME";
@@ -505,9 +503,6 @@ public static final String ER_IGNORABLE_WHITESPACE_NOT_HANDLED =
{ ER_FOUND_COMMA_BUT_NO_FOLLOWING_PARAM,
"Found ',' but no following function parameter definition."},
-
- { ER_INLINE_FUNCTION_PARAM_CARDINALITY,
- "XPTY0004 : The inline function definition has {0} parameters. Expected 0 or 1."},
{ ER_PREDICATE_ILLEGAL_SYNTAX,
"'..[predicate]' or '.[predicate]' is illegal syntax. Use 'self::node()[predicate]' instead."},
diff --git a/src/org/apache/xpath/xs/types/XSDate.java b/src/org/apache/xpath/xs/types/XSDate.java
index ec3a5ea2..6700515d 100644
--- a/src/org/apache/xpath/xs/types/XSDate.java
+++ b/src/org/apache/xpath/xs/types/XSDate.java
@@ -17,6 +17,7 @@
package org.apache.xpath.xs.types;
import java.util.Calendar;
+import java.util.Date;
import java.util.GregorianCalendar;
import org.apache.xpath.objects.ResultSequence;
@@ -255,17 +256,14 @@ public class XSDate extends XSCalendarType {
boolean isDateBefore = false;
Calendar cal1 = getCalendar();
- Calendar cal2 = xsDate.getCalendar();
-
- int year1 = cal1.get(Calendar.YEAR);
- int month1 = cal1.get(Calendar.MONTH);
- int date1 = cal1.get(Calendar.DATE);
+ Calendar cal2 = xsDate.getCalendar();
- int year2 = cal2.get(Calendar.YEAR);
- int month2 = cal2.get(Calendar.MONTH);
- int date2 = cal2.get(Calendar.DATE);
+ Date date1 = new Date(cal1.get(Calendar.YEAR), cal1.get(Calendar.MONTH),
+ cal1.get(Calendar.DATE));
+ Date date2 = new Date(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH),
+ cal2.get(Calendar.DATE));
- isDateBefore = ((year1 + month1 + date1) < (year2 + month2 + date2));
+ isDateBefore = date1.before(date2);
return isDateBefore;
}
@@ -280,15 +278,12 @@ public class XSDate extends XSCalendarType {
Calendar cal1 = getCalendar();
Calendar cal2 = xsDate.getCalendar();
- int year1 = cal1.get(Calendar.YEAR);
- int month1 = cal1.get(Calendar.MONTH);
- int date1 = cal1.get(Calendar.DATE);
-
- int year2 = cal2.get(Calendar.YEAR);
- int month2 = cal2.get(Calendar.MONTH);
- int date2 = cal2.get(Calendar.DATE);
+ Date date1 = new Date(cal1.get(Calendar.YEAR), cal1.get(Calendar.MONTH),
+ cal1.get(Calendar.DATE));
+ Date date2 = new Date(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH),
+ cal2.get(Calendar.DATE));
- isDateAfter = ((year1 + month1 + date1) > (year2 + month2 + date2));
+ isDateAfter = date1.after(date2);
return isDateAfter;
}
diff --git a/tests/fn_filter/gold/test4.out b/tests/fn_filter/gold/test4.out
new file mode 100644
index 00000000..4797743b
--- /dev/null
+++ b/tests/fn_filter/gold/test4.out
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><result>2 4 6 8 10</result>
diff --git a/tests/fn_filter/gold/test5.out b/tests/fn_filter/gold/test5.out
new file mode 100644
index 00000000..e69de29b
diff --git a/tests/fn_filter/test4.xsl b/tests/fn_filter/test4.xsl
new file mode 100644
index 00000000..199f9968
--- /dev/null
+++ b/tests/fn_filter/test4.xsl
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- Test for the XPath 3.1 fn:filter() function -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:value-of select="filter(1 to 10, function($a) { $a mod 2 = 0 })"/>
+ </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/fn_filter/test5.xsl b/tests/fn_filter/test5.xsl
new file mode 100644
index 00000000..316feae0
--- /dev/null
+++ b/tests/fn_filter/test5.xsl
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT stylesheet test, to test function item parameter count,
+ when using with fn:filter. fn:filter's function item argument
+ can have only one parameter. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:value-of select="filter(1 to 5, function() { true() })"/>
+ </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/fn_filter/test6.xsl b/tests/fn_filter/test6.xsl
new file mode 100644
index 00000000..63ab65d8
--- /dev/null
+++ b/tests/fn_filter/test6.xsl
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT stylesheet test, to test function item parameter count,
+ when using with fn:filter. fn:filter's function item argument
+ can have only one parameter. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:value-of select="filter(1 to 5, function($a, $b) { true() })"/>
+ </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/fn_foreach/gold/test9.out b/tests/fn_foreach/gold/test9.out
new file mode 100644
index 00000000..e69de29b
diff --git a/tests/fn_foreach/test10.xsl b/tests/fn_foreach/test10.xsl
new file mode 100644
index 00000000..71c932d6
--- /dev/null
+++ b/tests/fn_foreach/test10.xsl
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT stylesheet test, to test function item parameter count,
+ when using with fn:for-each. fn:for-each's function item argument
+ can have only one parameter. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:value-of select="for-each(1 to 5, function($a, $b) { $a * $b })"/>
+ </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/fn_foreach/test9.xsl b/tests/fn_foreach/test9.xsl
new file mode 100644
index 00000000..5f754431
--- /dev/null
+++ b/tests/fn_foreach/test9.xsl
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT stylesheet test, to test function item parameter count,
+ when using with fn:for-each. fn:for-each's function item argument
+ can have only one parameter. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:value-of select="for-each(1 to 5, function() { 1 + 2 })"/>
+ </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/inline_function_expr/gold/test1.out b/tests/inline_function_expr/gold/test1.out
new file mode 100644
index 00000000..fc8ec82e
--- /dev/null
+++ b/tests/inline_function_expr/gold/test1.out
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><result>no error</result>
diff --git a/tests/inline_function_expr/test1.xsl b/tests/inline_function_expr/test1.xsl
new file mode 100644
index 00000000..fa70a67b
--- /dev/null
+++ b/tests/inline_function_expr/test1.xsl
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT stylesheet to test, syntax of XPath inline
+ function item expression. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:variable name="func1" select="function() { }"/>
+ <xsl:text>no error</xsl:text>
+ </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/inline_function_expr/test2.xsl b/tests/inline_function_expr/test2.xsl
new file mode 100644
index 00000000..40fd8824
--- /dev/null
+++ b/tests/inline_function_expr/test2.xsl
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT stylesheet to test, syntax of XPath inline
+ function item expression. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:variable name="func1" select="function($x) { $x * $x }"/>
+ <xsl:text>no error</xsl:text>
+ </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/inline_function_expr/test3.xsl b/tests/inline_function_expr/test3.xsl
new file mode 100644
index 00000000..d57141be
--- /dev/null
+++ b/tests/inline_function_expr/test3.xsl
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSLT stylesheet to test, syntax of XPath inline
+ function item expression. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:variable name="func1" select="function($x, $y) { $x + $y }"/>
+ <xsl:text>no error</xsl:text>
+ </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/FnFilterTests.java b/tests/org/apache/xalan/xpath3/FnFilterTests.java
index 12546eb3..67b9e53e 100644
--- a/tests/org/apache/xalan/xpath3/FnFilterTests.java
+++ b/tests/org/apache/xalan/xpath3/FnFilterTests.java
@@ -16,6 +16,7 @@
*/
package org.apache.xalan.xpath3;
+import org.apache.xalan.util.XslTestsErrorHandler;
import org.apache.xalan.util.XslTransformTestsUtil;
import org.apache.xalan.xslt3.XSLConstants;
import org.junit.AfterClass;
@@ -76,5 +77,37 @@ public class FnFilterTests extends XslTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslFnFilterTest4() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test4.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test4.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test4.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslFnFilterTest5() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test5.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test5.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test5.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath,
+ new XslTestsErrorHandler());
+ }
+
+ @Test
+ public void xslFnFilterTest6() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test6.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test6.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test5.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath,
+ new XslTestsErrorHandler());
+ }
}
diff --git a/tests/org/apache/xalan/xpath3/FnForEachTests.java b/tests/org/apache/xalan/xpath3/FnForEachTests.java
index 07bf68fb..9ecd7584 100644
--- a/tests/org/apache/xalan/xpath3/FnForEachTests.java
+++ b/tests/org/apache/xalan/xpath3/FnForEachTests.java
@@ -16,6 +16,7 @@
*/
package org.apache.xalan.xpath3;
+import org.apache.xalan.util.XslTestsErrorHandler;
import org.apache.xalan.util.XslTransformTestsUtil;
import org.apache.xalan.xslt3.XSLConstants;
import org.junit.AfterClass;
@@ -126,5 +127,27 @@ public class FnForEachTests extends XslTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslFnForEachTest9() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test9.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test9.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test9.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath,
+ new XslTestsErrorHandler());
+ }
+
+ @Test
+ public void xslFnForEachTest10() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test10.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test10.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test9.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath,
+ new XslTestsErrorHandler());
+ }
}
diff --git a/tests/org/apache/xalan/xpath3/FnFilterTests.java b/tests/org/apache/xalan/xpath3/InlineFunctionItemExprTests.java
similarity index 83%
copy from tests/org/apache/xalan/xpath3/FnFilterTests.java
copy to tests/org/apache/xalan/xpath3/InlineFunctionItemExprTests.java
index 12546eb3..1a5d3081 100644
--- a/tests/org/apache/xalan/xpath3/FnFilterTests.java
+++ b/tests/org/apache/xalan/xpath3/InlineFunctionItemExprTests.java
@@ -23,17 +23,18 @@ import org.junit.BeforeClass;
import org.junit.Test;
/**
- * XPath 3.1 function fn:filter test cases.
+ * XPath 3.1 "function item" inline function expression test
+ * cases.
*
* @author Mukul Gandhi <mu...@apache.org>
*
* @xsl.usage advanced
*/
-public class FnFilterTests extends XslTransformTestsUtil {
+public class InlineFunctionItemExprTests extends XslTransformTestsUtil {
- private static final String XSL_TRANSFORM_INPUT_DIRPATH = XSLConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX + "fn_filter/";
+ private static final String XSL_TRANSFORM_INPUT_DIRPATH = XSLConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX + "inline_function_expr/";
- private static final String XSL_TRANSFORM_GOLD_DIRPATH = XSLConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX + "fn_filter/gold/";
+ private static final String XSL_TRANSFORM_GOLD_DIRPATH = XSLConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX + "inline_function_expr/gold/";
@BeforeClass
public static void setUpBeforeClass() throws Exception {
@@ -48,7 +49,7 @@ public class FnFilterTests extends XslTransformTestsUtil {
}
@Test
- public void xslFnFilterTest1() {
+ public void xslInlineFunctionExprTest1() {
String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl";
String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl";
@@ -58,21 +59,21 @@ public class FnFilterTests extends XslTransformTestsUtil {
}
@Test
- public void xslFnFilterTest2() {
- String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_a.xml";
+ public void xslInlineFunctionExprTest2() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl";
String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl";
- String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test2.out";
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test1.out";
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
@Test
- public void xslFnFilterTest3() {
- String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_b.xml";
+ public void xslInlineFunctionExprTest3() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl";
String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl";
- String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test3.out";
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test1.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 26604646..248daa7d 100644
--- a/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
+++ b/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
@@ -23,6 +23,7 @@ import org.apache.xalan.xpath3.FnIndexOfTests;
import org.apache.xalan.xpath3.FnStringJoinTests;
import org.apache.xalan.xpath3.FnTokenizeTests;
import org.apache.xalan.xpath3.FnUnparsedTextTests;
+import org.apache.xalan.xpath3.InlineFunctionItemExprTests;
import org.apache.xalan.xpath3.RangeExprTests;
import org.apache.xalan.xpath3.SequenceTests;
import org.apache.xalan.xpath3.StringTests;
@@ -51,7 +52,8 @@ import org.junit.runners.Suite.SuiteClasses;
FnAbsTests.class, StringTests.class, XsConstructorFunctions.class,
FnIndexOfTests.class, SequenceTests.class, RangeExprTests.class,
W3c_xslt30_IterateTests.class, W3c_xslt30_AxesTests.class, XslIterateTests.class,
- ValueComparisonTests.class, FnForEachTests.class, FnFilterTests.class })
+ ValueComparisonTests.class, InlineFunctionItemExprTests.class, FnForEachTests.class,
+ FnFilterTests.class })
public class AllXsl3Tests {
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org