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/12/27 16:06:13 UTC

(xalan-java) branch xalan-j_xslt3.0 updated: committing implementation of xml schema data type xs:QName, and related working xsl:for-each-group test case

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 89f5c8c4 committing implementation of xml schema data type xs:QName, and related working xsl:for-each-group test case
     new 28991d8e Merge pull request #144 from mukulga/xalan-j_xslt3.0_mukul
89f5c8c4 is described below

commit 89f5c8c4a198b93af9cdac61d3ff4b54a5fd3874
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Wed Dec 27 21:31:31 2023 +0530

    committing implementation of xml schema data type xs:QName, and related working xsl:for-each-group test case
---
 lib/xpath31_types.jar                              | Bin 50256 -> 51525 bytes
 .../apache/xalan/templates/ElemForEachGroup.java   |   3 +-
 src/org/apache/xpath/compiler/FunctionTable.java   |  10 ++-
 src/org/apache/xpath/compiler/Keywords.java        |   3 +
 src/org/apache/xpath/functions/FuncNodeName.java   |  67 +++++++++++++++++++++
 tests/grouping/gold/test28.out                     |  10 +++
 tests/grouping/test28.xml                          |  24 ++++++++
 tests/grouping/test28.xsl                          |  37 ++++++++++++
 tests/org/apache/xalan/xslt3/GroupingTests.java    |  10 +++
 tests/org/apache/xalan/xslt3/XSLConstants.java     |   4 +-
 10 files changed, 164 insertions(+), 4 deletions(-)

diff --git a/lib/xpath31_types.jar b/lib/xpath31_types.jar
index f0a9c1fe..e142252e 100644
Binary files a/lib/xpath31_types.jar and b/lib/xpath31_types.jar differ
diff --git a/src/org/apache/xalan/templates/ElemForEachGroup.java b/src/org/apache/xalan/templates/ElemForEachGroup.java
index 2bbc8f09..0bc49b66 100644
--- a/src/org/apache/xalan/templates/ElemForEachGroup.java
+++ b/src/org/apache/xalan/templates/ElemForEachGroup.java
@@ -53,6 +53,7 @@ import xml.xpath31.processor.types.XSBoolean;
 import xml.xpath31.processor.types.XSDate;
 import xml.xpath31.processor.types.XSDateTime;
 import xml.xpath31.processor.types.XSNumericType;
+import xml.xpath31.processor.types.XSQName;
 import xml.xpath31.processor.types.XSString;
 import xml.xpath31.processor.types.XSTime;
 
@@ -811,7 +812,7 @@ public class ElemForEachGroup extends ElemTemplateElement
   private Object getXPathEvaluationRawResult(XObject xpathEvalResult) {
       Object xpathRawResult = null;
       
-      if (xpathEvalResult instanceof XString) {
+      if ((xpathEvalResult instanceof XString) || (xpathEvalResult instanceof XSQName)) {
           xpathRawResult = xpathEvalResult.str();    
       }
       else if (xpathEvalResult instanceof XSString) {
diff --git a/src/org/apache/xpath/compiler/FunctionTable.java b/src/org/apache/xpath/compiler/FunctionTable.java
index f42d0654..af53ca94 100644
--- a/src/org/apache/xpath/compiler/FunctionTable.java
+++ b/src/org/apache/xpath/compiler/FunctionTable.java
@@ -326,6 +326,9 @@ public class FunctionTable
   
   /** The 'data()' id. */
   public static final int FUNC_DATA = 100;
+  
+  /** The 'node-name()' id. */
+  public static final int FUNC_NODE_NAME = 101;
 
   // Proprietary
 
@@ -383,7 +386,7 @@ public class FunctionTable
    * Number of built in functions. Be sure to update this as
    * built-in functions are added.
    */
-  private static final int NUM_BUILT_IN_FUNCS = 101;
+  private static final int NUM_BUILT_IN_FUNCS = 102;
 
   /**
    * Number of built-in functions that may be added.
@@ -585,6 +588,8 @@ public class FunctionTable
     m_functions[FUNC_MIN] = org.apache.xpath.functions.FuncMin.class;
     
     m_functions[FUNC_DOC] = org.apache.xpath.functions.FuncDoc.class;
+    
+    m_functions[FUNC_NODE_NAME] = org.apache.xpath.functions.FuncNodeName.class;
   }
 
   static{
@@ -798,6 +803,9 @@ public class FunctionTable
          
          m_functionID.put(Keywords.FUNC_DOC,
                          new Integer(FunctionTable.FUNC_DOC));
+         
+         m_functionID.put(Keywords.FUNC_NODE_NAME,
+                         new Integer(FunctionTable.FUNC_NODE_NAME));
   }
   
   public FunctionTable(){
diff --git a/src/org/apache/xpath/compiler/Keywords.java b/src/org/apache/xpath/compiler/Keywords.java
index a7cb4b29..720013fc 100644
--- a/src/org/apache/xpath/compiler/Keywords.java
+++ b/src/org/apache/xpath/compiler/Keywords.java
@@ -460,6 +460,9 @@ public class Keywords
   /** doc function string. */
   public static final String FUNC_DOC = "doc";
   
+  /** node-name function string. */
+  public static final String FUNC_NODE_NAME = "node-name";
+  
   // Proprietary, built in functions
 
   /** current function string (Proprietary). */
diff --git a/src/org/apache/xpath/functions/FuncNodeName.java b/src/org/apache/xpath/functions/FuncNodeName.java
new file mode 100644
index 00000000..7e7e4fb7
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncNodeName.java
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+/*
+ * $Id$
+ */
+package org.apache.xpath.functions;
+
+import org.apache.xml.dtm.DTM;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XObject;
+import org.w3c.dom.Node;
+
+import xml.xpath31.processor.types.XSQName;
+
+/**
+ * Execute the node-name() function.
+ * 
+ * @author Mukul Gandhi <mu...@apache.org>
+ * 
+ * @xsl.usage advanced
+ */
+public class FuncNodeName extends FunctionDef1Arg {
+
+   private static final long serialVersionUID = -6613114399818352830L;
+
+   /**
+   * Execute the function. The function must return a valid object.
+   * 
+   * @param xctxt The current execution context
+   * @return A valid XObject
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
+
+	    int nodeHandle = getArg0AsNode(xctxt);
+	    
+	    XObject result = null;
+	
+	    if (nodeHandle != DTM.NULL) {
+	       DTM dtm = xctxt.getDTM(nodeHandle);
+	       Node node = dtm.getNode(nodeHandle);
+	       String nodeLocalName = node.getLocalName();
+	       String namespaceUri = node.getNamespaceURI();
+	       String nodeNamePrefix = node.getPrefix();
+	       result = new XSQName(nodeLocalName, namespaceUri, nodeNamePrefix);
+	    }
+	
+	    return result;
+  }
+  
+}
diff --git a/tests/grouping/gold/test28.out b/tests/grouping/gold/test28.out
new file mode 100644
index 00000000..08eccc74
--- /dev/null
+++ b/tests/grouping/gold/test28.out
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?><a>
+  <m/>
+  <o/>
+  <p/>
+  <q/>
+</a><b>
+  <n/>
+  <r/>
+  <s/>
+</b>
diff --git a/tests/grouping/test28.xml b/tests/grouping/test28.xml
new file mode 100644
index 00000000..8703cf33
--- /dev/null
+++ b/tests/grouping/test28.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <a>
+    <m/>
+  </a>
+  <b>
+    <n/>
+  </b>
+  <a>
+    <o/>
+  </a>
+  <a>
+    <p/>
+  </a>
+  <a>
+    <q/>
+  </a>
+  <b>
+    <r/>
+  </b>
+  <b>
+    <s/>
+  </b>
+</root>
diff --git a/tests/grouping/test28.xsl b/tests/grouping/test28.xsl
new file mode 100644
index 00000000..8de4e603
--- /dev/null
+++ b/tests/grouping/test28.xsl
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"                
+                version="3.0">
+                
+  <!-- Author: mukulg@apache.org -->
+  
+  <!-- use with test28.xml -->                
+
+  <xsl:output method="xml" indent="yes"/>
+
+  <xsl:template match="/root">
+     <xsl:for-each-group select="*" group-by="node-name()">
+        <xsl:element name="{current-grouping-key()}">
+           <xsl:copy-of select="current-group()/*"/>
+        </xsl:element>
+     </xsl:for-each-group>
+  </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 ab4c1d8e..a137b398 100644
--- a/tests/org/apache/xalan/xslt3/GroupingTests.java
+++ b/tests/org/apache/xalan/xslt3/GroupingTests.java
@@ -319,5 +319,15 @@ public class GroupingTests extends XslTransformTestsUtil {
         
         runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
     }
+    
+    @Test
+    public void xslGroupingTest28() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test28.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test28.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test28.out";
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
 
 }
diff --git a/tests/org/apache/xalan/xslt3/XSLConstants.java b/tests/org/apache/xalan/xslt3/XSLConstants.java
index 468e4480..c56eae41 100644
--- a/tests/org/apache/xalan/xslt3/XSLConstants.java
+++ b/tests/org/apache/xalan/xslt3/XSLConstants.java
@@ -36,8 +36,8 @@ public class XSLConstants {
     // the values of following, two variables are host specific where this test suite shall be run. the values of
     // following two variables may be modified, accordingly.
     
-    public static final String XSL_TRANSFORM_INPUT_DIRPATH_PREFIX = "file:///E:/eclipseWorkspace/xalanj/xalan-j_xslt3.0_mukul/tests/";
+    public static final String XSL_TRANSFORM_INPUT_DIRPATH_PREFIX = "file:///E:/eclipseWorkspace/xalanj/xalan-j_xslt3.0/tests/";
     
-    public static final String XSL_TRANSFORM_GOLD_DIRPATH_PREFIX = "E:/eclipseWorkspace/xalanj/xalan-j_xslt3.0_mukul/tests/";
+    public static final String XSL_TRANSFORM_GOLD_DIRPATH_PREFIX = "E:/eclipseWorkspace/xalanj/xalan-j_xslt3.0/tests/";
 
 }


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