You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mu...@apache.org on 2023/10/04 15:26:12 UTC

[xalan-java] branch xalan-j_xslt3.0 updated: improvements to implementation of xsl:for-each-group instruction, where now grouping of input data by xs:date values is supported. committing few new related working 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 ff3a5eb6 improvements to implementation of xsl:for-each-group instruction, where now grouping of input data by xs:date values is supported. committing few new related working test cases as well.
     new 943fdabf Merge pull request #97 from mukulga/xalan-j_xslt3.0_mukul
ff3a5eb6 is described below

commit ff3a5eb69724cbeaf55cc483eb2a2fa87ad2cc56
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Wed Oct 4 20:49:19 2023 +0530

    improvements to implementation of xsl:for-each-group instruction, where now grouping of input data by xs:date values is supported. committing few new related working test cases as well.
---
 .../apache/xalan/templates/ElemForEachGroup.java   | 12 +++--
 src/org/apache/xpath/xs/types/XSDate.java          | 18 ++++++++
 tests/grouping/gold/test26.out                     | 31 +++++++++++++
 tests/grouping/gold/test27.out                     | 26 +++++++++++
 tests/grouping/test1_h.xml                         | 27 ++++++++++++
 tests/grouping/test1_i.xml                         | 27 ++++++++++++
 tests/grouping/test26.xsl                          | 47 ++++++++++++++++++++
 tests/grouping/test27.xsl                          | 51 ++++++++++++++++++++++
 tests/org/apache/xalan/xslt3/GroupingTests.java    | 20 +++++++++
 9 files changed, 255 insertions(+), 4 deletions(-)

diff --git a/src/org/apache/xalan/templates/ElemForEachGroup.java b/src/org/apache/xalan/templates/ElemForEachGroup.java
index ec1aae95..58f833f7 100644
--- a/src/org/apache/xalan/templates/ElemForEachGroup.java
+++ b/src/org/apache/xalan/templates/ElemForEachGroup.java
@@ -49,6 +49,7 @@ import org.apache.xpath.objects.XObject;
 import org.apache.xpath.objects.XString;
 import org.apache.xpath.operations.Variable;
 import org.apache.xpath.xs.types.XSBoolean;
+import org.apache.xpath.xs.types.XSDate;
 import org.apache.xpath.xs.types.XSNumericType;
 import org.apache.xpath.xs.types.XSString;
 
@@ -795,12 +796,12 @@ public class ElemForEachGroup extends ElemTemplateElement
   }
   
   /* 
-   * This method, converts initial value of xsl:for-each-group's grouping key value,
-   * into a normalized data typed value.
+   * This method, converts xsl:for-each-group grouping key's initial computed value, 
+   * into a normalized data typed value of type java.lang.Object.
    * 
    * For the purpose of, evaluating grouping key XPath expressions for xsl:for-each-group, 
-   * the grouping keys are treated as of type string, number or boolean. Any other data 
-   * type for grouping key is converted to a string value.
+   * the grouping keys are treated as of type string, number, boolean or xs:date. Any other 
+   * data type for grouping key is converted to a string value.
    */
   private Object getXPathEvaluationRawResult(XObject xpathEvalResult) {
       Object xpathRawResult = null;
@@ -824,6 +825,9 @@ public class ElemForEachGroup extends ElemTemplateElement
       else if (xpathEvalResult instanceof XSBoolean) {
           xpathRawResult = Boolean.valueOf(((XSBoolean)xpathEvalResult).value());
       }
+      else if (xpathEvalResult instanceof XSDate) {
+          xpathRawResult = xpathEvalResult;
+      }
       else {
           // Any other data type for grouping key, is treated as string
           xpathRawResult = XslTransformEvaluationHelper.getStrVal(xpathEvalResult);  
diff --git a/src/org/apache/xpath/xs/types/XSDate.java b/src/org/apache/xpath/xs/types/XSDate.java
index e4a88b7d..bc19218c 100644
--- a/src/org/apache/xpath/xs/types/XSDate.java
+++ b/src/org/apache/xpath/xs/types/XSDate.java
@@ -270,6 +270,24 @@ public class XSDate extends XSCalendarType {
         return isDateEqual; 
     }
     
+    @Override
+    public boolean equals(Object obj) {
+       boolean isDateEqual = false;
+        
+       if (obj instanceof XSDate) {
+          isDateEqual = this.equals((XSDate)obj);  
+       }
+       
+       return isDateEqual;
+    }
+    
+    @Override
+    public int hashCode() {       
+       String strVal = stringValue();       
+       
+       return strVal.hashCode();
+    }
+    
     /*
      * Determine whether, this XSDate object is less that, the 
      * XSDate object provided as an argument to this method. 
diff --git a/tests/grouping/gold/test26.out b/tests/grouping/gold/test26.out
new file mode 100644
index 00000000..7d692c0b
--- /dev/null
+++ b/tests/grouping/gold/test26.out
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <PARTS expired="false">
+    <part>
+    <id>1</id>
+    <name>A1</name>
+    <expiryDate>2510-10-08</expiryDate>
+  </part>
+    <part>
+    <id>5</id>
+    <name>E1</name>
+    <expiryDate>2730-10-09</expiryDate>
+  </part>
+  </PARTS>
+  <PARTS expired="true">
+    <part>
+    <id>2</id>
+    <name>B1</name>
+    <expiryDate>2006-10-06</expiryDate>
+  </part>
+    <part>
+    <id>3</id>
+    <name>C1</name>
+    <expiryDate>2007-10-07</expiryDate>
+  </part>
+    <part>
+    <id>4</id>
+    <name>D1</name>
+    <expiryDate>2006-10-05</expiryDate>
+  </part>
+  </PARTS>
+</result>
diff --git a/tests/grouping/gold/test27.out b/tests/grouping/gold/test27.out
new file mode 100644
index 00000000..b14a6bf0
--- /dev/null
+++ b/tests/grouping/gold/test27.out
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?><RESULT>
+  <PARTS expiryDate="2006-10-06">
+    <part>
+      <id>1</id>
+      <name>A1</name>
+    </part>
+    <part>
+      <id>2</id>
+      <name>B1</name>
+    </part>
+    <part>
+      <id>4</id>
+      <name>D1</name>
+    </part>
+  </PARTS>
+  <PARTS expiryDate="2572-10-06">
+    <part>
+      <id>3</id>
+      <name>C1</name>
+    </part>
+    <part>
+      <id>5</id>
+      <name>E1</name>
+    </part>
+  </PARTS>
+</RESULT>
diff --git a/tests/grouping/test1_h.xml b/tests/grouping/test1_h.xml
new file mode 100644
index 00000000..665d93a8
--- /dev/null
+++ b/tests/grouping/test1_h.xml
@@ -0,0 +1,27 @@
+<parts>
+  <part>
+    <id>1</id>
+    <name>A1</name>
+    <expiryDate>2510-10-08</expiryDate>
+  </part>
+  <part>
+    <id>2</id>
+    <name>B1</name>
+    <expiryDate>2006-10-06</expiryDate>
+  </part>
+  <part>
+    <id>3</id>
+    <name>C1</name>
+    <expiryDate>2007-10-07</expiryDate>
+  </part>
+  <part>
+    <id>4</id>
+    <name>D1</name>
+    <expiryDate>2006-10-05</expiryDate>
+  </part>
+  <part>
+    <id>5</id>
+    <name>E1</name>
+    <expiryDate>2730-10-09</expiryDate>
+  </part>
+</parts>
\ No newline at end of file
diff --git a/tests/grouping/test1_i.xml b/tests/grouping/test1_i.xml
new file mode 100644
index 00000000..a596c90a
--- /dev/null
+++ b/tests/grouping/test1_i.xml
@@ -0,0 +1,27 @@
+<parts>
+  <part>
+    <id>1</id>
+    <name>A1</name>
+    <expiryDate>2006-10-06</expiryDate>
+  </part>
+  <part>
+    <id>2</id>
+    <name>B1</name>
+    <expiryDate>2006-10-06</expiryDate>
+  </part>
+  <part>
+    <id>3</id>
+    <name>C1</name>
+    <expiryDate>2572-10-06</expiryDate>
+  </part>
+  <part>
+    <id>4</id>
+    <name>D1</name>
+    <expiryDate>2006-10-06</expiryDate>
+  </part>
+  <part>
+    <id>5</id>
+    <name>E1</name>
+    <expiryDate>2572-10-06</expiryDate>
+  </part>
+</parts>
\ No newline at end of file
diff --git a/tests/grouping/test26.xsl b/tests/grouping/test26.xsl
new file mode 100644
index 00000000..7d6623c9
--- /dev/null
+++ b/tests/grouping/test26.xsl
@@ -0,0 +1,47 @@
+<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 -->
+   
+  <!-- use with test1_h.xml -->
+  
+  <!-- An XSLT stylesheet to test, xsl:for-each-group instruction. Within this
+       stylesheet example, from an XML input document, all "part" elements are
+       transformed into two groups, with one group having part's expiryDate
+       xs:date value less than current date, and remaining XML "part" elements
+       are put into the second group.    
+  -->                
+                
+  <xsl:output method="xml" indent="yes"/>
+  
+  <xsl:template match="/parts">     
+     <result>
+       <xsl:for-each-group select="part" group-by="xs:date(expiryDate) lt current-date()">
+          <PARTS expired="{current-grouping-key()}">           
+             <xsl:copy-of select="current-group()"/>
+          </PARTS>
+       </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
diff --git a/tests/grouping/test27.xsl b/tests/grouping/test27.xsl
new file mode 100644
index 00000000..c2050bd2
--- /dev/null
+++ b/tests/grouping/test27.xsl
@@ -0,0 +1,51 @@
+<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 -->
+   
+  <!-- use with test1_i.xml -->
+  
+  <!-- An XSLT stylesheet to test, xsl:for-each-group instruction. Within this
+       stylesheet example, from an XML input document, "part" elements are
+       grouped as per "part" element's expiryDate xs:date value.   
+  -->                
+                
+  <xsl:output method="xml" indent="yes"/>
+  
+  <xsl:template match="/parts">     
+     <RESULT>
+        <xsl:for-each-group select="part" group-by="xs:date(expiryDate)">
+           <PARTS expiryDate="{current-grouping-key()}">           
+              <xsl:apply-templates select="current-group()"/>
+           </PARTS>
+        </xsl:for-each-group>
+     </RESULT>
+  </xsl:template>
+  
+  <xsl:template match="part">
+    <part>
+       <xsl:copy-of select="id | name"/>
+    </part>
+  </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/xslt3/GroupingTests.java b/tests/org/apache/xalan/xslt3/GroupingTests.java
index 99cc4b9e..ab4c1d8e 100644
--- a/tests/org/apache/xalan/xslt3/GroupingTests.java
+++ b/tests/org/apache/xalan/xslt3/GroupingTests.java
@@ -299,5 +299,25 @@ public class GroupingTests extends XslTransformTestsUtil {
         
         runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
     }
+    
+    @Test
+    public void xslGroupingTest26() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_h.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test26.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test26.out";
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xslGroupingTest27() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_i.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test27.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test27.out";
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
 
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org