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/08/08 14:05:20 UTC

[xalan-java] branch xalan-j_xslt3.0 updated: committing improvements to, xpath 3.1 parser implementation for parsing xpath dynamic function call expressions. also adding 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 fe2be0c0 committing improvements to, xpath 3.1 parser implementation for parsing xpath dynamic function call expressions. also adding few new working related test cases as well.
     new d64d0fda Merge pull request #46 from mukulga/xalan-j_xslt3.0_mukul
fe2be0c0 is described below

commit fe2be0c0d6005904ec230679e18866a34c0e0927
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Tue Aug 8 19:30:50 2023 +0530

    committing improvements to, xpath 3.1 parser implementation for parsing xpath dynamic function call expressions. also adding few new working related test cases as well.
---
 src/org/apache/xpath/compiler/XPathParser.java     | 37 +++++++++++++---
 tests/dynamic_function_call/gold/test11.out        |  4 ++
 tests/dynamic_function_call/gold/test12.out        |  7 +++
 tests/dynamic_function_call/gold/test13.out        |  3 ++
 tests/dynamic_function_call/gold/test14.out        |  3 ++
 tests/dynamic_function_call/test11.xsl             | 42 ++++++++++++++++++
 tests/dynamic_function_call/test12.xsl             | 51 ++++++++++++++++++++++
 tests/dynamic_function_call/test13.xsl             | 48 ++++++++++++++++++++
 tests/dynamic_function_call/test14.xsl             | 48 ++++++++++++++++++++
 tests/dynamic_function_call/test1_f.xml            |  4 ++
 .../xalan/xpath3/DynamicFunctionCallTests.java     | 40 +++++++++++++++++
 11 files changed, 282 insertions(+), 5 deletions(-)

diff --git a/src/org/apache/xpath/compiler/XPathParser.java b/src/org/apache/xpath/compiler/XPathParser.java
index 2705af45..e4bffc99 100644
--- a/src/org/apache/xpath/compiler/XPathParser.java
+++ b/src/org/apache/xpath/compiler/XPathParser.java
@@ -647,12 +647,19 @@ public class XPathParser
       return (funcBodyXPathExprStrBuff.toString()).trim();
   }
   
+  /**
+   * While traversing XPath expression's token list, we determine within this method,
+   * whether the parse of dynamic function call argument details should continue or
+   * not. We simultaneously accumulate function call argument details within a list 
+   * 'argDetailsStrPartsList' (that has been passed as an argument to this method) 
+   * whose contents are accessible to the caller of this method.
+   */
   private boolean isXPathDynamicFuncCallParseAhead(List<String> argDetailsStrPartsList, 
                                                                                   String delim) {
       boolean isXpathDynamicFuncCallParseAhead = false;
 
       if (lookahead('(', 1)) {
-         // handles the case, where the function call argument
+         // Handles the case, where the function call argument
          // is itself another function call.
          fDynamicFunctionCallArgumentMarker = true;
          argDetailsStrPartsList.add(m_token);
@@ -685,14 +692,34 @@ public class XPathParser
          nextToken();
          isXpathDynamicFuncCallParseAhead = true; 
       }
-      else if (fDynamicFunctionCallArgumentMarker) {
-         argDetailsStrPartsList.add(m_token);
-         nextToken();
+      else {
+         String argDetailsAccumulatedStrSoFar = "(" + getStrValueFromStrList(
+                                                                  argDetailsStrPartsList) + ")";         
+         if (!isStrHasBalancedParentheses(argDetailsAccumulatedStrSoFar)) {
+            argDetailsStrPartsList.add(m_token);
+            nextToken();
+            isXpathDynamicFuncCallParseAhead = true;
+         }         
       }
 
       return isXpathDynamicFuncCallParseAhead; 
   }
   
+  /**
+   * Given a list of strings, concatenate list items to form
+   * a string and return the string formed to the caller of 
+   * this method.
+   */
+  private String getStrValueFromStrList(List<String> strList) {
+      String concatenatedStrInfo = "";
+      
+      for (int idx = 0; idx < strList.size(); idx++) {
+         concatenatedStrInfo = concatenatedStrInfo + strList.get(idx);   
+      }
+      
+      return concatenatedStrInfo; 
+  }
+  
   /**
    * Check whether a, string has balanced parentheses pairs 
    * '(' and ')'.
@@ -2281,7 +2308,7 @@ public class XPathParser
        
        List<String> argDetailsStrPartsList = new ArrayList<String>();
        
-       // we create here a temporary function call argument delimiter 
+       // We create here a temporary function call argument delimiter 
        // string, for this processing.
        long currentTimeMills = System.currentTimeMillis();
        String delimSuffix = (Long.valueOf(currentTimeMills)).toString();
diff --git a/tests/dynamic_function_call/gold/test11.out b/tests/dynamic_function_call/gold/test11.out
new file mode 100644
index 00000000..73710c60
--- /dev/null
+++ b/tests/dynamic_function_call/gold/test11.out
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <val1>30</val1>
+  <val2>130</val2>
+</result>
diff --git a/tests/dynamic_function_call/gold/test12.out b/tests/dynamic_function_call/gold/test12.out
new file mode 100644
index 00000000..c388aa36
--- /dev/null
+++ b/tests/dynamic_function_call/gold/test12.out
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <val1>40</val1>
+  <val2>60</val2>
+  <val3>44</val3>
+  <val4>46.283185307179586</val4>
+  <val5>79</val5>
+</result>
diff --git a/tests/dynamic_function_call/gold/test13.out b/tests/dynamic_function_call/gold/test13.out
new file mode 100644
index 00000000..6429fd91
--- /dev/null
+++ b/tests/dynamic_function_call/gold/test13.out
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <val>74.2831853071796</val>
+</result>
diff --git a/tests/dynamic_function_call/gold/test14.out b/tests/dynamic_function_call/gold/test14.out
new file mode 100644
index 00000000..69cb9d37
--- /dev/null
+++ b/tests/dynamic_function_call/gold/test14.out
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <val>110.84955592153875</val>
+</result>
diff --git a/tests/dynamic_function_call/test11.xsl b/tests/dynamic_function_call/test11.xsl
new file mode 100644
index 00000000..9613858d
--- /dev/null
+++ b/tests/dynamic_function_call/test11.xsl
@@ -0,0 +1,42 @@
+<?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 the XPath 3.1 dynamic function 
+        call. Within this stylesheet example, the result of one
+        function call is an argument of another function call. -->                
+
+   <xsl:output method="xml" indent="yes"/>
+   
+   <xsl:variable name="func1" select="function($a) { $a * 2 }"/>
+   
+   <xsl:variable name="func2" select="function($a) { $a + 5 }"/>
+
+   <xsl:template match="/">
+      <result>
+         <val1><xsl:value-of select="$func1($func2(10))"/></val1>
+         <val2><xsl:value-of select="$func1($func2(10)) + 100"/></val2> 
+      </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/dynamic_function_call/test12.xsl b/tests/dynamic_function_call/test12.xsl
new file mode 100644
index 00000000..4a991d32
--- /dev/null
+++ b/tests/dynamic_function_call/test12.xsl
@@ -0,0 +1,51 @@
+<?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 -->
+   
+   <!-- An XSLT stylesheet, to test the XPath 3.1 dynamic function 
+        call. We illustrate within this stylesheet example, that
+        the argument information passed to dynamic function call  
+        are significantly complex XPath expressions. -->                
+
+   <xsl:output method="xml" indent="yes"/>
+   
+   <xsl:variable name="func1" select="function($a) { $a * 2 }"/>
+   
+   <xsl:variable name="func2" select="function($a) { $a + 5 }"/>
+   
+   <xsl:variable name="x1" select="5"/>
+      
+   <xsl:template match="/">
+      <xsl:variable name="x2" select="7"/>           
+      <result>
+        <val1><xsl:value-of select="$func1($func2(10) + 5)"/></val1>
+        <val2><xsl:value-of select="$func1(abs(-10) + 20)"/></val2>
+        <val3><xsl:value-of select="$func1($func2(10) + abs(-7))"/></val3>
+        <val4><xsl:value-of select="$func1(($func2(10) + $x1) + math:pi())"/></val4>
+        <val5><xsl:value-of select="$func1($func2(10) + abs(-7)) + ($x1 * $x2)"/></val5>
+      </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/dynamic_function_call/test13.xsl b/tests/dynamic_function_call/test13.xsl
new file mode 100644
index 00000000..3cca8ad0
--- /dev/null
+++ b/tests/dynamic_function_call/test13.xsl
@@ -0,0 +1,48 @@
+<?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_f.xml -->
+   
+   <!-- An XSLT stylesheet, to test the XPath 3.1 dynamic function 
+        call. We illustrate within this stylesheet example, that
+        the argument information passed to dynamic function call  
+        are significantly complex XPath expressions. -->                  
+
+   <xsl:output method="xml" indent="yes"/>
+      
+   <xsl:template match="/temp">      
+      <result>
+        <xsl:variable name="x1" select="val1 + 2"/>
+        <xsl:variable name="x2" select="val1 + 3"/>
+        
+        <xsl:variable name="func1" select="function($a) { ($a * 2) + $x1 }"/>
+        <xsl:variable name="func2" select="function($b) { $b + $x2 }"/>
+        
+        <val><xsl:value-of select="$func1(($func2(val1) + val2) + math:pi())"/></val>
+      </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/dynamic_function_call/test14.xsl b/tests/dynamic_function_call/test14.xsl
new file mode 100644
index 00000000..57c069e9
--- /dev/null
+++ b/tests/dynamic_function_call/test14.xsl
@@ -0,0 +1,48 @@
+<?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_f.xml -->
+   
+   <!-- An XSLT stylesheet, to test the XPath 3.1 dynamic function 
+        call. We illustrate within this stylesheet example, that
+        the argument information passed to dynamic function call  
+        are significantly complex XPath expressions. -->                 
+
+   <xsl:output method="xml" indent="yes"/>
+      
+   <xsl:template match="/temp">      
+      <result>
+        <xsl:variable name="x1" select="val1 + 2"/>
+        <xsl:variable name="x2" select="val1 + 3"/>
+        
+        <xsl:variable name="func1" select="function($a) { ($a * 2) + $x1 }"/>
+        <xsl:variable name="func2" select="function($b) { $b + $x2 + $func1(math:pi()) }"/>
+        
+        <val><xsl:value-of select="$func1(($func2(val1) + val2) + math:pi())"/></val>
+      </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/dynamic_function_call/test1_f.xml b/tests/dynamic_function_call/test1_f.xml
new file mode 100644
index 00000000..ef34b2cb
--- /dev/null
+++ b/tests/dynamic_function_call/test1_f.xml
@@ -0,0 +1,4 @@
+<temp>
+  <val1>10</val1>
+  <val2>5</val2>
+</temp>
\ No newline at end of file
diff --git a/tests/org/apache/xalan/xpath3/DynamicFunctionCallTests.java b/tests/org/apache/xalan/xpath3/DynamicFunctionCallTests.java
index c69a4974..1d7940cf 100644
--- a/tests/org/apache/xalan/xpath3/DynamicFunctionCallTests.java
+++ b/tests/org/apache/xalan/xpath3/DynamicFunctionCallTests.java
@@ -146,5 +146,45 @@ public class DynamicFunctionCallTests extends XslTransformTestsUtil {
         
         runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
     }
+    
+    @Test
+    public void xslDynamicFunctionCallTest11() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test11.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test11.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test11.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xslDynamicFunctionCallTest12() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test12.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test12.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test12.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xslDynamicFunctionCallTest13() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_f.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test13.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test13.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xslDynamicFunctionCallTest14() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_f.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test14.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test14.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