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/04 17:45:13 UTC

[xalan-java] branch xalan-j_xslt3.0 updated: improving the xpath 3.1 parser implementation, when parsing xpath 3.1 sequence constructor expression. 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 57aa7073 improving the xpath 3.1 parser implementation, when parsing xpath 3.1 sequence constructor expression. committing few new related working test cases as well.
     new 6a00e01d Merge pull request #43 from mukulga/xalan-j_xslt3.0_mukul
57aa7073 is described below

commit 57aa7073bed9e4f7689829d34e57f7e3bf7a89e0
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Fri Aug 4 23:09:51 2023 +0530

    improving the xpath 3.1 parser implementation, when parsing xpath 3.1 sequence constructor expression. committing few new related working test cases as well.
---
 src/org/apache/xpath/compiler/XPathParser.java    | 75 +++++++++++++++++------
 tests/org/apache/xalan/xslt3/XslIterateTests.java | 20 ++++++
 tests/xsl_iterate/gold/test21.out                 |  6 ++
 tests/xsl_iterate/gold/test22.out                 |  7 +++
 tests/xsl_iterate/test20.xsl                      | 22 +++----
 tests/xsl_iterate/{test20.xsl => test21.xsl}      | 30 ++++-----
 tests/xsl_iterate/{test20.xsl => test22.xsl}      | 39 +++++++-----
 7 files changed, 137 insertions(+), 62 deletions(-)

diff --git a/src/org/apache/xpath/compiler/XPathParser.java b/src/org/apache/xpath/compiler/XPathParser.java
index 9312a3e4..f7718b44 100644
--- a/src/org/apache/xpath/compiler/XPathParser.java
+++ b/src/org/apache/xpath/compiler/XPathParser.java
@@ -945,8 +945,8 @@ public class XPathParser
   protected void Expr() throws javax.xml.transform.TransformerException
   {
       if (fIsBeginParse && tokenIs("(")) {
-          // We implement within this 'if' branch, the XPath parsing with following 
-          // mentioned two pass approach,
+          // We implement within this 'if' branch, the XPath expression parse 
+          // with following mentioned two pass approach,
           // 1) The first pass, determines whether XPath 3.1's sequence (using comma
           //    operator, to separate each of the sequence operands mentioned with 
           //    this syntax) constructor parsing needs to be used, or to use this 
@@ -959,27 +959,62 @@ public class XPathParser
           List<String> sequenceConstructorXPathParts = new ArrayList<String>();
           
           while (m_token != null)
-          {
-              List<String> seqItemXPathStrPartsList = new ArrayList<String>();
-              
-              while (!tokenIs(",") && m_token != null) {
-                 if (getTokenRelative(0) != null) {
+          {                            
+              if (tokenIs("function")) {
+                 // XPath expression parse from here, till the token '}' shall get 
+                 // an 'inline function expression' string. The XPath expression
+                 // parse here, can use the token ',' as part of 'inline function 
+                 // expression' (for e.g, to specify more than one function parameter
+                 // for the function item).
+                 List<String> seqItemXPathStrPartsList = new ArrayList<String>();
+                 
+                 while (!tokenIs('}') && m_token != null) {
+                    if (getTokenRelative(0) != null) {
+                       seqItemXPathStrPartsList.add(m_token);
+                    }
+                    nextToken();
+                 }
+                 if (tokenIs('}')) {
                     seqItemXPathStrPartsList.add(m_token);
+                    nextToken();
+                    if (tokenIs(',')) {
+                       nextToken();    
+                    }
+                 }
+                 
+                 if (seqItemXPathStrPartsList.size() > 0) {
+                    String seqItemXPathExprStr = getXPathStrFromComponentParts(
+                                                                       seqItemXPathStrPartsList);                 
+                    sequenceConstructorXPathParts.add(seqItemXPathExprStr);
                  }
-                 nextToken();
-              }
-              
-              String seqItemXPathExprStr = getXPathStrFromComponentParts(seqItemXPathStrPartsList);              
-              if (seqItemXPathExprStr.endsWith(")")) {
-                  seqItemXPathExprStr = seqItemXPathExprStr.substring(0, 
-                                                                 seqItemXPathExprStr.length());    
-              }
-              
-              sequenceConstructorXPathParts.add(seqItemXPathExprStr);
-              
-              if (m_token != null) {
-                 nextToken();   
               }
+              else {
+                 // XPath expression parse from here, till the token ',' (which we assume 
+                 // here, as an XPath sequence constructor's operand delimiter) shall get
+                 // an XPath sub-expression that represents anything else than an XPath
+                 // 'inline function expression'.
+                 List<String> seqItemXPathStrPartsList = new ArrayList<String>();
+                  
+                 while (!tokenIs(",") && m_token != null) {
+                    if (getTokenRelative(0) != null) {
+                       seqItemXPathStrPartsList.add(m_token);
+                    }
+                    nextToken();
+                 }
+                 
+                 if (seqItemXPathStrPartsList.size() > 0) {
+                    String seqItemXPathExprStr = getXPathStrFromComponentParts(seqItemXPathStrPartsList);
+                    if (seqItemXPathExprStr.endsWith(")")) {
+                        seqItemXPathExprStr = seqItemXPathExprStr.substring(0, 
+                                                                       seqItemXPathExprStr.length());    
+                    }
+                    sequenceConstructorXPathParts.add(seqItemXPathExprStr);
+                 }
+                 
+                 if (m_token != null) {
+                    nextToken();   
+                 }
+              }                            
           }
           
           boolean isXPathExprOkToProceed = true;
diff --git a/tests/org/apache/xalan/xslt3/XslIterateTests.java b/tests/org/apache/xalan/xslt3/XslIterateTests.java
index bd7d98fb..761bba01 100644
--- a/tests/org/apache/xalan/xslt3/XslIterateTests.java
+++ b/tests/org/apache/xalan/xslt3/XslIterateTests.java
@@ -270,5 +270,25 @@ public class XslIterateTests extends XslTransformTestsUtil {
         
         runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
     }
+    
+    @Test
+    public void xslIterateTest23() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test21.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test21.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test21.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xslIterateTest24() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test22.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test22.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test22.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
 
 }
diff --git a/tests/xsl_iterate/gold/test21.out b/tests/xsl_iterate/gold/test21.out
new file mode 100644
index 00000000..2a2ce6a0
--- /dev/null
+++ b/tests/xsl_iterate/gold/test21.out
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <val>10</val>
+  <val>4</val>
+  <val>21</val>
+  <val>2.3333333333333335</val>
+</result>
diff --git a/tests/xsl_iterate/gold/test22.out b/tests/xsl_iterate/gold/test22.out
new file mode 100644
index 00000000..32d23c6e
--- /dev/null
+++ b/tests/xsl_iterate/gold/test22.out
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <val>10</val>
+  <valPi>3.141592653589793</valPi>
+  <val>4</val>
+  <val>21</val>
+  <val>2.3333333333333335</val>
+</result>
diff --git a/tests/xsl_iterate/test20.xsl b/tests/xsl_iterate/test20.xsl
index 6820a6c8..ddaf3848 100644
--- a/tests/xsl_iterate/test20.xsl
+++ b/tests/xsl_iterate/test20.xsl
@@ -6,26 +6,26 @@
    
    <!-- use with test1_f.xml -->
    
-   <!-- An XSLT stylesheet, to test xsl:iterate instruction,
-        when xsl:iterate's select attribute evaluates to a 
-        sequence of atomic values. -->                
+   <!-- An XSLT stylesheet, to test xsl:iterate instruction, when xsl:iterate's 
+        select attribute evaluates to a sequence of atomic values. -->                
 
    <xsl:output method="xml" indent="yes"/>
    
-   <!-- A variable, referring to an XPath sequence constructor having various function items. -->
+   <!-- A variable, referring to an XPath sequence constructor having various 
+        function item XPath expressions. -->
    <xsl:variable name="fnItemsSeq" select="(function($a) { $a + 2 }, function($a) { $a - 3 }, 
-                                                 function($a) { $a * 4 }, function($a) { $a div 4 })"/>
+                                               function($a) { $a * 4 }, function($a) { $a div 4 })"/>
                                                
    <xsl:variable name="num" select="7"/>                                               
       
    <xsl:template match="/">
       <result>
-          <xsl:iterate select="$fnItemsSeq">
-             <xsl:variable name="fnItem" select="."/>
-             <!-- make a dynamic function call to respective function item,
-                  and pass an argument as well to function call. -->
-             <val><xsl:value-of select="$fnItem($num)"/></val>
-          </xsl:iterate>
+         <xsl:iterate select="$fnItemsSeq">
+            <xsl:variable name="fnItem" select="."/>
+            <!-- Make a dynamic function call to respective function
+                 item, and pass an argument as well to function call. -->
+            <val><xsl:value-of select="$fnItem($num)"/></val>
+         </xsl:iterate>
       </result>
    </xsl:template>
    
diff --git a/tests/xsl_iterate/test20.xsl b/tests/xsl_iterate/test21.xsl
similarity index 57%
copy from tests/xsl_iterate/test20.xsl
copy to tests/xsl_iterate/test21.xsl
index 6820a6c8..64e0c887 100644
--- a/tests/xsl_iterate/test20.xsl
+++ b/tests/xsl_iterate/test21.xsl
@@ -4,28 +4,28 @@
                 
    <!-- Author: mukulg@apache.org -->
    
-   <!-- use with test1_f.xml -->
-   
-   <!-- An XSLT stylesheet, to test xsl:iterate instruction,
-        when xsl:iterate's select attribute evaluates to a 
-        sequence of atomic values. -->                
+   <!-- An XSLT stylesheet, to test xsl:iterate instruction, when xsl:iterate's 
+        select attribute evaluates to a sequence of atomic values. -->                 
 
    <xsl:output method="xml" indent="yes"/>
    
-   <!-- A variable, referring to an XPath sequence constructor having various function items. -->
-   <xsl:variable name="fnItemsSeq" select="(function($a) { $a + 2 }, function($a) { $a - 3 }, 
-                                                 function($a) { $a * 4 }, function($a) { $a div 4 })"/>
+   <!-- A variable, referring to an XPath sequence constructor having various 
+        function item XPath expressions. -->                                            
+   <xsl:variable name="fnItemsSeq" select="(function($a, $b) { $a + $b }, function($a, $b) { $a - $b }, 
+                                               function($a, $b) { $a * $b }, function($a, $b) { $a div $b })"/>                                               
                                                
-   <xsl:variable name="num" select="7"/>                                               
+   <xsl:variable name="num1" select="7"/> 
+   
+   <xsl:variable name="num2" select="3"/>
       
    <xsl:template match="/">
       <result>
-          <xsl:iterate select="$fnItemsSeq">
-             <xsl:variable name="fnItem" select="."/>
-             <!-- make a dynamic function call to respective function item,
-                  and pass an argument as well to function call. -->
-             <val><xsl:value-of select="$fnItem($num)"/></val>
-          </xsl:iterate>
+         <xsl:iterate select="$fnItemsSeq">
+            <xsl:variable name="fnItem" select="."/>
+            <!-- Make a dynamic function call to respective function
+                 item, and pass arguments as well to function call. -->
+            <val><xsl:value-of select="$fnItem($num1, $num2)"/></val>
+         </xsl:iterate>
       </result>
    </xsl:template>
    
diff --git a/tests/xsl_iterate/test20.xsl b/tests/xsl_iterate/test22.xsl
similarity index 52%
copy from tests/xsl_iterate/test20.xsl
copy to tests/xsl_iterate/test22.xsl
index 6820a6c8..6055837b 100644
--- a/tests/xsl_iterate/test20.xsl
+++ b/tests/xsl_iterate/test22.xsl
@@ -1,31 +1,38 @@
 <?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 xsl:iterate instruction,
-        when xsl:iterate's select attribute evaluates to a 
-        sequence of atomic values. -->                
+   <!-- An XSLT stylesheet, to test xsl:iterate instruction, when xsl:iterate's 
+        select attribute evaluates to a sequence of atomic values. -->                
 
    <xsl:output method="xml" indent="yes"/>
-   
-   <!-- A variable, referring to an XPath sequence constructor having various function items. -->
-   <xsl:variable name="fnItemsSeq" select="(function($a) { $a + 2 }, function($a) { $a - 3 }, 
-                                                 function($a) { $a * 4 }, function($a) { $a div 4 })"/>
+
+   <!-- A variable, referring to an XPath sequence constructor having various 
+        function item expressions and non-function item expression as well. --> 
+   <xsl:variable name="sequenceVar" select="(function($a, $b) { $a + $b }, math:pi(), function($a, $b) { $a - $b }, 
+                                               function($a, $b) { $a * $b }, function($a, $b) { $a div $b })"/>                                             
                                                
-   <xsl:variable name="num" select="7"/>                                               
+   <xsl:variable name="num1" select="7"/> 
+   
+   <xsl:variable name="num2" select="3"/>
       
    <xsl:template match="/">
       <result>
-          <xsl:iterate select="$fnItemsSeq">
-             <xsl:variable name="fnItem" select="."/>
-             <!-- make a dynamic function call to respective function item,
-                  and pass an argument as well to function call. -->
-             <val><xsl:value-of select="$fnItem($num)"/></val>
-          </xsl:iterate>
+        <xsl:iterate select="$sequenceVar">        
+          <xsl:choose>
+             <xsl:when test="position() = 2">
+                <valPi><xsl:value-of select="."/></valPi>
+             </xsl:when>
+             <xsl:otherwise>
+                <xsl:variable name="fnItem" select="."/>
+                <val><xsl:value-of select="$fnItem($num1, $num2)"/></val>
+             </xsl:otherwise>
+          </xsl:choose>
+        </xsl:iterate>
       </result>
    </xsl:template>
    


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