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 2025/02/22 12:07:09 UTC
(xalan-java) branch xalan-j_xslt3.0_mvn updated: improving implementation a bit and adding a new xsl 3 working test case
This is an automated email from the ASF dual-hosted git repository.
mukulg pushed a commit to branch xalan-j_xslt3.0_mvn
in repository https://gitbox.apache.org/repos/asf/xalan-java.git
The following commit(s) were added to refs/heads/xalan-j_xslt3.0_mvn by this push:
new a72dfe545 improving implementation a bit and adding a new xsl 3 working test case
a72dfe545 is described below
commit a72dfe545c6ec3eae5e699454795dc9b1fec9fb4
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sat Feb 22 17:36:48 2025 +0530
improving implementation a bit and adding a new xsl 3 working test case
---
.../java/org/apache/xpath/objects/XObject.java | 20 ++++++-
.../org/apache/xpath/res/XPATHErrorResources.java | 5 ++
.../apache/xalan/tests/xslt3/XslGroupingTests.java | 10 ++++
src/test/resources/xsl_grouping/gold/test34.out | 26 ++++++++
src/test/resources/xsl_grouping/test34.xsl | 69 ++++++++++++++++++++++
5 files changed, 129 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/xpath/objects/XObject.java b/src/main/java/org/apache/xpath/objects/XObject.java
index d91db4ba9..a605ff1f5 100644
--- a/src/main/java/org/apache/xpath/objects/XObject.java
+++ b/src/main/java/org/apache/xpath/objects/XObject.java
@@ -45,6 +45,7 @@ import org.w3c.dom.DocumentFragment;
import org.w3c.dom.NodeList;
import org.w3c.dom.traversal.NodeIterator;
+import xml.xpath31.processor.types.XSAnyAtomicType;
import xml.xpath31.processor.types.XSAnySimpleType;
import xml.xpath31.processor.types.XSAnyURI;
import xml.xpath31.processor.types.XSBoolean;
@@ -830,6 +831,9 @@ public class XObject extends Expression implements Serializable, Cloneable
return (comparisonResult < 0) ? true : false;
}
+ else if ((this instanceof XSAnyAtomicType) && (obj2 instanceof XSAnyAtomicType)) {
+ emitXsAnyAtomicTypeError(obj2, expressionOwner);
+ }
boolean isOperandNodeSet1 = false;
boolean isOperandNodeSet2 = false;
@@ -908,7 +912,7 @@ public class XObject extends Expression implements Serializable, Cloneable
}
else if ((this instanceof XSDateTime) && (obj2 instanceof XSDateTime)) {
return ((XSDateTime)this).gt((XSDateTime)obj2);
- }
+ }
else if ((this instanceof XSTime) && (obj2 instanceof XSTime)) {
return ((XSTime)this).gt((XSTime)obj2);
}
@@ -982,6 +986,9 @@ public class XObject extends Expression implements Serializable, Cloneable
collationUri);
return (comparisonResult > 0) ? true : false;
+ }
+ else if ((this instanceof XSAnyAtomicType) && (obj2 instanceof XSAnyAtomicType)) {
+ emitXsAnyAtomicTypeError(obj2, expressionOwner);
}
boolean isOperandNodeSet1 = false;
@@ -1421,6 +1428,9 @@ public class XObject extends Expression implements Serializable, Cloneable
result = false;
}
}
+ else if ((this instanceof XSAnyAtomicType) && (obj2 instanceof XSAnyAtomicType)) {
+ emitXsAnyAtomicTypeError(obj2, expressionOwner);
+ }
else if (this.getType() == XObject.CLASS_NODESET) {
if ((((XNodeSet)this).getLength() > 1)) {
error(isEqTest ? XPATHErrorResources.ER_EQ_OPERAND_CARDINALITY_ERROR :
@@ -1614,5 +1624,13 @@ public class XObject extends Expression implements Serializable, Cloneable
public boolean isTreatAs() {
return isTreatAs;
}
+
+ private void emitXsAnyAtomicTypeError(XObject xObject, ExpressionNode expressionOwner) throws TransformerException {
+ String typeName1 = ((XSAnyAtomicType)this).typeName();
+ String typeName2 = ((XSAnyAtomicType)xObject).typeName();
+
+ error(XPATHErrorResources.ER_TYPE_COMPARISON_ERROR, new Object[] {"xs:" + typeName1,
+ "xs:" + typeName2}, expressionOwner);
+ }
}
diff --git a/src/main/java/org/apache/xpath/res/XPATHErrorResources.java b/src/main/java/org/apache/xpath/res/XPATHErrorResources.java
index ebaedda30..857e3624c 100644
--- a/src/main/java/org/apache/xpath/res/XPATHErrorResources.java
+++ b/src/main/java/org/apache/xpath/res/XPATHErrorResources.java
@@ -387,6 +387,8 @@ public static final String ER_IGNORABLE_WHITESPACE_NOT_HANDLED =
public static final String ER_LE_OPERAND_CARDINALITY_ERROR = "ER_LE_OPERAND_CARDINALITY_ERROR";
public static final String ER_GE_OPERAND_CARDINALITY_ERROR = "ER_GE_OPERAND_CARDINALITY_ERROR";
+
+ public static final String ER_TYPE_COMPARISON_ERROR = "ER_TYPE_COMPARISON_ERROR";
// Error messages...
@@ -652,6 +654,9 @@ public static final String ER_IGNORABLE_WHITESPACE_NOT_HANDLED =
{ ER_FASTSTRINGBUFFER_CANNOT_BE_NULL,
"The FastStringBuffer argument can not be null"},
+
+ { ER_TYPE_COMPARISON_ERROR,
+ "Value of type {0} cannot be compared with value of type {1}"},
{ ER_ZERO, "0"},
diff --git a/src/test/java/org/apache/xalan/tests/xslt3/XslGroupingTests.java b/src/test/java/org/apache/xalan/tests/xslt3/XslGroupingTests.java
index cc151b6c9..8b6774183 100644
--- a/src/test/java/org/apache/xalan/tests/xslt3/XslGroupingTests.java
+++ b/src/test/java/org/apache/xalan/tests/xslt3/XslGroupingTests.java
@@ -380,5 +380,15 @@ public class XslGroupingTests extends XSLTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslGroupingTest34() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test34.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test34.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test34.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
}
diff --git a/src/test/resources/xsl_grouping/gold/test34.out b/src/test/resources/xsl_grouping/gold/test34.out
new file mode 100644
index 000000000..f9e714f2f
--- /dev/null
+++ b/src/test/resources/xsl_grouping/gold/test34.out
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <group key="lt_1980-01-01T00-00-00">
+ <info id="1">
+ <color>Red</color>
+ <timestamp>1972-10-12T10:30:00</timestamp>
+ </info>
+ <info id="3">
+ <color>Blue</color>
+ <timestamp>1973-10-12T10:30:00</timestamp>
+ </info>
+ <info id="5">
+ <color>Pink</color>
+ <timestamp>1974-10-12T10:30:00</timestamp>
+ </info>
+ </group>
+ <group key="gt_1980-01-01T00-00-00">
+ <info id="2">
+ <color>Red</color>
+ <timestamp>2007-10-12T10:30:00</timestamp>
+ </info>
+ <info id="4">
+ <color>Yellow</color>
+ <timestamp>2005-10-12T10:30:00</timestamp>
+ </info>
+ </group>
+</result>
diff --git a/src/test/resources/xsl_grouping/test34.xsl b/src/test/resources/xsl_grouping/test34.xsl
new file mode 100644
index 000000000..deca4a2b2
--- /dev/null
+++ b/src/test/resources/xsl_grouping/test34.xsl
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ exclude-result-prefixes="xs"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- An XSL stylesheet test case, to test grouping of XML instance elements
+ based on xs:dateTime values using xsl:for-each-group instruction. -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <result>
+ <xsl:variable name="infoRecords">
+ <details>
+ <info id="1">
+ <color>Red</color>
+ <timestamp>1972-10-12T10:30:00</timestamp>
+ </info>
+ <info id="2">
+ <color>Red</color>
+ <timestamp>2007-10-12T10:30:00</timestamp>
+ </info>
+ <info id="3">
+ <color>Blue</color>
+ <timestamp>1973-10-12T10:30:00</timestamp>
+ </info>
+ <info id="4">
+ <color>Yellow</color>
+ <timestamp>2005-10-12T10:30:00</timestamp>
+ </info>
+ <info id="5">
+ <color>Pink</color>
+ <timestamp>1974-10-12T10:30:00</timestamp>
+ </info>
+ </details>
+ </xsl:variable>
+ <xsl:for-each-group select="$infoRecords/details/info" group-by="xs:dateTime(timestamp) gt xs:dateTime('1980-01-01T00:00:00')">
+ <!-- ':' has special meaning in XML (for e.g, its part of reserved
+ string like xmlns:... etc), therefore we translate that to '-'. -->
+ <group key="{if (current-grouping-key() eq true()) then ('gt_' || translate('1980-01-01T00:00:00',':','-'))
+ else ('lt_' || translate('1980-01-01T00:00:00',':','-'))}">
+ <xsl:copy-of select="current-group()"/>
+ </group>
+ </xsl:for-each-group>
+ </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