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/09/26 15:14:15 UTC

[xalan-java] branch xalan-j_xslt3.0 updated: committing bug fixes for xpath data type conversion, when using attribute 'as' on xsl:variable instruction, and xsl:function parameters. also committing few new working relevant test cases.

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 4079daaa committing bug fixes for xpath data type conversion, when using attribute 'as' on xsl:variable instruction, and xsl:function parameters. also committing few new working relevant test cases.
     new 540df306 Merge pull request #91 from mukulga/xalan-j_xslt3.0_mukul
4079daaa is described below

commit 4079daaa8ac67ca68a941ff52fd761da0aca2e9b
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Tue Sep 26 20:35:38 2023 +0530

    committing bug fixes for xpath data type conversion, when using attribute 'as' on xsl:variable instruction, and xsl:function parameters. also committing few new working relevant test cases.
---
 .../xpath/composite/SequenceTypeSupport.java       | 11 ++--
 src/org/apache/xpath/operations/Minus.java         |  3 ++
 src/org/apache/xpath/operations/Plus.java          |  3 ++
 .../xalan/xpath3/XsConstructorFunctionTests.java   | 20 ++++++++
 tests/xs_constructor_functions/gold/test14.out     | 22 ++++++++
 tests/xs_constructor_functions/test19.xsl          | 51 +++++++++++++++++++
 tests/xs_constructor_functions/test1_e.xml         |  3 ++
 tests/xs_constructor_functions/test20.xsl          | 58 ++++++++++++++++++++++
 8 files changed, 168 insertions(+), 3 deletions(-)

diff --git a/src/org/apache/xpath/composite/SequenceTypeSupport.java b/src/org/apache/xpath/composite/SequenceTypeSupport.java
index bfce0006..e1fa6cff 100644
--- a/src/org/apache/xpath/composite/SequenceTypeSupport.java
+++ b/src/org/apache/xpath/composite/SequenceTypeSupport.java
@@ -380,9 +380,14 @@ public class SequenceTypeSupport {
                                                                                                                        sequenceTypeKindTest);
             }
             else if (srcValue instanceof ResultSequence) {
-               result = castResultSequenceInstance(srcValue, sequenceTypeXPathExprStr,
-                                                                                   seqExpectedTypeDataInp, xctxt, srcLocator,
-                                                                                   expectedType, itemTypeOccurenceIndicator);
+               ResultSequence srcResultSeq = (ResultSequence)srcValue;
+               if (srcResultSeq.size() == 1) {
+                   result = convertXDMValueToAnotherType(srcResultSeq.item(0), sequenceTypeXPathExprStr, seqExpectedTypeDataInp, xctxt);   
+               }
+               else {
+                   result = castResultSequenceInstance(srcValue, sequenceTypeXPathExprStr, seqExpectedTypeDataInp, xctxt, srcLocator, 
+                                                                                                               expectedType, itemTypeOccurenceIndicator);
+               }
             }
         }
         catch (TransformerException ex) {
diff --git a/src/org/apache/xpath/operations/Minus.java b/src/org/apache/xpath/operations/Minus.java
index 898da4d0..243a23ea 100644
--- a/src/org/apache/xpath/operations/Minus.java
+++ b/src/org/apache/xpath/operations/Minus.java
@@ -249,6 +249,9 @@ public class Minus extends Operation
              result = new XNumber(lDouble - rDouble);
           }
       }
+      else if (left instanceof XSDate) {
+          result = ((XSDate)left).subtract(right);  
+      }
       else if ((left instanceof ResultSequence) && (right instanceof ResultSequence)) {
           ResultSequence rsLeft = (ResultSequence)left;          
           if (rsLeft.size() > 1) {
diff --git a/src/org/apache/xpath/operations/Plus.java b/src/org/apache/xpath/operations/Plus.java
index 73426a11..94cf4b8d 100644
--- a/src/org/apache/xpath/operations/Plus.java
+++ b/src/org/apache/xpath/operations/Plus.java
@@ -282,6 +282,9 @@ public class Plus extends Operation
              result = new XNumber(lDouble + rDouble);
           }
       }
+      else if (left instanceof XSDate) {
+          result = ((XSDate)left).add(right);  
+      }
       else if ((left instanceof ResultSequence) && (right instanceof ResultSequence)) {
           ResultSequence rsLeft = (ResultSequence)left;          
           if (rsLeft.size() > 1) {
diff --git a/tests/org/apache/xalan/xpath3/XsConstructorFunctionTests.java b/tests/org/apache/xalan/xpath3/XsConstructorFunctionTests.java
index a7a29afb..a6a85db4 100644
--- a/tests/org/apache/xalan/xpath3/XsConstructorFunctionTests.java
+++ b/tests/org/apache/xalan/xpath3/XsConstructorFunctionTests.java
@@ -227,5 +227,25 @@ public class XsConstructorFunctionTests extends XslTransformTestsUtil {
         
         runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
     }
+    
+    @Test
+    public void XsConstructorFunctionsTest19() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_e.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test19.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test14.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void XsConstructorFunctionsTest20() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_e.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test20.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test14.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
 
 }
diff --git a/tests/xs_constructor_functions/gold/test14.out b/tests/xs_constructor_functions/gold/test14.out
new file mode 100644
index 00000000..f40ec704
--- /dev/null
+++ b/tests/xs_constructor_functions/gold/test14.out
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?><result dt="2007-10-05">
+  <val>
+    <one>2007-10-05</one>
+    <two>2007-10-05</two>
+  </val>
+  <val>
+    <one>2007-10-07</one>
+    <two>2009-10-05</two>
+  </val>
+  <val>
+    <one>2007-10-09</one>
+    <two>2011-10-05</two>
+  </val>
+  <val>
+    <one>2007-10-11</one>
+    <two>2013-10-05</two>
+  </val>
+  <val>
+    <one>2007-10-13</one>
+    <two>2015-10-05</two>
+  </val>
+</result>
diff --git a/tests/xs_constructor_functions/test19.xsl b/tests/xs_constructor_functions/test19.xsl
new file mode 100644
index 00000000..4ca2958e
--- /dev/null
+++ b/tests/xs_constructor_functions/test19.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_e.xml -->
+  
+  <!-- An XSLT stylesheet test case, to test XPath
+       date arithmetic.
+  -->                
+                
+  <xsl:output method="xml" indent="yes"/>
+
+  <xsl:template match="/info">
+     <xsl:variable name="var1" select="str" as="xs:date"/>
+     <result dt="{$var1}">               
+       <xsl:for-each select="1 to 5">
+         <xsl:variable name="num" select="(. - 1) * 2"/>
+         <val>
+           <one>
+             <xsl:value-of select="$var1 + xs:dayTimeDuration('P' || $num || 'D')"/>
+           </one>
+           <two>
+             <xsl:value-of select="$var1 + xs:yearMonthDuration('P' || $num || 'Y')"/>
+           </two>
+         </val>
+       </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
diff --git a/tests/xs_constructor_functions/test1_e.xml b/tests/xs_constructor_functions/test1_e.xml
new file mode 100644
index 00000000..b57a2040
--- /dev/null
+++ b/tests/xs_constructor_functions/test1_e.xml
@@ -0,0 +1,3 @@
+<info>
+  <str>2007-10-05</str>
+</info>
\ No newline at end of file
diff --git a/tests/xs_constructor_functions/test20.xsl b/tests/xs_constructor_functions/test20.xsl
new file mode 100644
index 00000000..c5c6d4d6
--- /dev/null
+++ b/tests/xs_constructor_functions/test20.xsl
@@ -0,0 +1,58 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                xmlns:fn0="http://fn0"
+                exclude-result-prefixes="xs fn0"
+                version="3.0">
+                
+  <!-- Author: mukulg@apache.org -->
+  
+  <!-- use with test1_e.xml -->
+  
+  <!-- An XSLT stylesheet test case, to test XPath
+       date arithmetic.
+  -->                
+                
+  <xsl:output method="xml" indent="yes"/>
+
+  <xsl:template match="/info">
+     <xsl:variable name="var1" select="str" as="xs:date"/>
+     <result dt="{$var1}">               
+       <xsl:for-each select="1 to 5">
+         <xsl:variable name="num" select="(. - 1) * 2"/>
+         <xsl:copy-of select="fn0:procDate($var1, xs:integer($num))"/>
+       </xsl:for-each>
+     </result>
+  </xsl:template>
+  
+  <xsl:function name="fn0:procDate" as="element(val)">
+     <xsl:param name="dt" as="xs:date"/>
+     <xsl:param name="shiftVal" as="xs:integer"/>
+     <val>
+       <one>
+         <xsl:value-of select="$dt + xs:dayTimeDuration('P' || $shiftVal || 'D')"/>
+       </one>
+       <two>
+         <xsl:value-of select="$dt + xs:yearMonthDuration('P' || $shiftVal || 'Y')"/>
+       </two>
+     </val>
+  </xsl:function>
+  
+  <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+  -->
+
+</xsl:stylesheet>
\ No newline at end of file


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