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/10 08:29:05 UTC

[xalan-java] branch xalan-j_xslt3.0 updated: committing minor improvements to xalanj codebase on this branch, and a new relevant working 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 6cb296ae committing minor improvements to xalanj codebase on this branch, and a new relevant working test case.
     new 00c172e1 Merge pull request #81 from mukulga/xalan-j_xslt3.0_mukul
6cb296ae is described below

commit 6cb296aefe76ee2c66bfc063d716eb5711935402
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sun Sep 10 13:55:36 2023 +0530

    committing minor improvements to xalanj codebase on this branch, and a new relevant working test case.
---
 .../apache/xalan/templates/ElemApplyTemplates.java | 14 +++----
 src/org/apache/xalan/templates/ElemCopyOf.java     | 12 +++++-
 src/org/apache/xalan/templates/ElemTemplate.java   | 12 +++---
 src/org/apache/xpath/objects/InlineFunction.java   |  5 +++
 src/org/apache/xpath/objects/XObject.java          | 29 +++++++------
 .../xalan/xslt3/XslTemplateAttributeAsTests.java   | 10 +++++
 tests/xsl_template_attribute_as/gold/test9.out     | 22 ++++++++++
 tests/xsl_template_attribute_as/test1_b.xml        | 22 ++++++++++
 tests/xsl_template_attribute_as/test9.xsl          | 47 ++++++++++++++++++++++
 9 files changed, 145 insertions(+), 28 deletions(-)

diff --git a/src/org/apache/xalan/templates/ElemApplyTemplates.java b/src/org/apache/xalan/templates/ElemApplyTemplates.java
index ac1b07ca..ef1a57b1 100644
--- a/src/org/apache/xalan/templates/ElemApplyTemplates.java
+++ b/src/org/apache/xalan/templates/ElemApplyTemplates.java
@@ -251,7 +251,7 @@ public class ElemApplyTemplates extends ElemCallTemplate
       if(nParams > 0)
       {
         // This code will create a section on the stack that is all the 
-        // evaluated arguments.  These will be copied into the real params 
+        // evaluated arguments. These will be copied into the real params 
         // section of each called template.
         argsFrame = vars.link(nParams);
         vars.setStackFrame(thisframe);
@@ -434,18 +434,18 @@ public class ElemApplyTemplates extends ElemCallTemplate
                    QName m_name = template.getName();
                    String m_matchPatternStr = (template.getMatch()).getPatternString();
                    String errTemplateStr = (m_name != null) ? m_name.toString() : m_matchPatternStr; 
-                   throw new TransformerException("XTTE0505 : The required item type of the result of template " + 
-                                                                                                           errTemplateStr + " is " + templateAsAttrVal + ". But the template "
-                                                                                                           + "result doesn't conform to this required item type.", srcLocator);  
+                   throw new TransformerException("XTTE0505 : The required result type of template " + errTemplateStr 
+                                                                                                 + " is " + templateAsAttrVal + ". But the template "
+                                                                                                 + "result doesn't conform to this required type.", srcLocator);  
                }
             }
             catch (TransformerException ex) {
                QName m_name = template.getName();
                String m_matchPatternStr = (template.getMatch()).getPatternString();
                String errTemplateStr = (m_name != null) ? m_name.toString() : m_matchPatternStr; 
-               throw new TransformerException("XTTE0505 : The required item type of the result of template " + 
-                                                                                                       errTemplateStr + " is " + templateAsAttrVal + ". But the template "
-                                                                                                       + "result doesn't conform to this required item type.", srcLocator); 
+               throw new TransformerException("XTTE0505 : The required result type of template " + errTemplateStr 
+                                                                                                 + " is " + templateAsAttrVal + ". But the template "
+                                                                                                 + "result doesn't conform to this required type.", srcLocator); 
             }  
         }
         else {
diff --git a/src/org/apache/xalan/templates/ElemCopyOf.java b/src/org/apache/xalan/templates/ElemCopyOf.java
index 3e93bba8..7deb8502 100644
--- a/src/org/apache/xalan/templates/ElemCopyOf.java
+++ b/src/org/apache/xalan/templates/ElemCopyOf.java
@@ -22,6 +22,7 @@ package org.apache.xalan.templates;
 
 import java.util.Vector;
 
+import javax.xml.transform.SourceLocator;
 import javax.xml.transform.TransformerException;
 
 import org.apache.xalan.res.XSLTErrorResources;
@@ -34,6 +35,7 @@ import org.apache.xml.dtm.ref.DTMTreeWalker;
 import org.apache.xml.serializer.SerializationHandler;
 import org.apache.xpath.XPath;
 import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.InlineFunction;
 import org.apache.xpath.objects.ResultSequence;
 import org.apache.xpath.objects.XBoolean;
 import org.apache.xpath.objects.XNodeSet;
@@ -159,6 +161,8 @@ public class ElemCopyOf extends ElemTemplateElement
     try
     {
       XPathContext xctxt = transformer.getXPathContext();
+      
+      SourceLocator srcLocator = xctxt.getSAXLocator();
               
       int sourceNode = xctxt.getCurrentNode();
       
@@ -173,8 +177,8 @@ public class ElemCopyOf extends ElemTemplateElement
       }
 
       if (transformer.getDebug()) {
-        transformer.getTraceManager().fireSelectedEvent(sourceNode, this,
-                                                        "select", m_selectExpression, value);
+         transformer.getTraceManager().fireSelectedEvent(sourceNode, this,
+                                                                        "select", m_selectExpression, value);
       }
 
       SerializationHandler handler = transformer.getSerializationHandler();
@@ -208,6 +212,10 @@ public class ElemCopyOf extends ElemTemplateElement
                 strVal = ((XSAnyAtomicType)value).stringValue();
                 handler.characters(strVal.toCharArray(), 0, strVal.length());
             }
+            else if (value instanceof InlineFunction) {
+                throw new TransformerException("XTDE0450 : Cannot add a function item to an XDM result tree, "
+                                                                                                     + "via xsl:copy-of instruction.", srcLocator);
+            }
       }
 
     }
diff --git a/src/org/apache/xalan/templates/ElemTemplate.java b/src/org/apache/xalan/templates/ElemTemplate.java
index 4411745a..29a8114c 100644
--- a/src/org/apache/xalan/templates/ElemTemplate.java
+++ b/src/org/apache/xalan/templates/ElemTemplate.java
@@ -424,16 +424,16 @@ public class ElemTemplate extends ElemTemplateElement
                                                                                                                    null, xctxt);
            if (templateEvalResultForAsAttr == null) {
               String errTemplateStr = (m_name != null) ? m_name.toString() : m_matchPattern.getPatternString(); 
-              throw new TransformerException("XTTE0505 : The required item type of the result of template " + 
-                                                                                     errTemplateStr + " is " + m_asAttr + ". But the template result "
-                                                                                     + "doesn't conform to this required item type.", srcLocator);   
+              throw new TransformerException("XTTE0505 : The required result type of template " + errTemplateStr 
+                                                                                                + " is " + m_asAttr + ". But the template result "
+                                                                                                + "doesn't conform to this required type.", srcLocator);   
            }
         }
         catch (TransformerException ex) {
            String errTemplateStr = (m_name != null) ? m_name.toString() : m_matchPattern.getPatternString(); 
-           throw new TransformerException("XTTE0505 : The required item type of the result of template " + 
-                                                                                  errTemplateStr + " is " + m_asAttr + ". But the template result "
-                                                                                  + "doesn't conform to this required item type.", srcLocator); 
+           throw new TransformerException("XTTE0505 : The required result type of template " + errTemplateStr 
+                                                                                             + " is " + m_asAttr + ". But the template result "
+                                                                                             + "doesn't conform to this required type.", srcLocator); 
         }
     }
     
diff --git a/src/org/apache/xpath/objects/InlineFunction.java b/src/org/apache/xpath/objects/InlineFunction.java
index 1fed50e6..21f4e4c0 100644
--- a/src/org/apache/xpath/objects/InlineFunction.java
+++ b/src/org/apache/xpath/objects/InlineFunction.java
@@ -71,4 +71,9 @@ public class InlineFunction extends XObject {
         // no op
     }
     
+    public int getType()
+    {
+      return CLASS_FUNCTION_ITEM;
+    }
+    
 }
diff --git a/src/org/apache/xpath/objects/XObject.java b/src/org/apache/xpath/objects/XObject.java
index c3d96e8e..429c6c1b 100644
--- a/src/org/apache/xpath/objects/XObject.java
+++ b/src/org/apache/xpath/objects/XObject.java
@@ -216,44 +216,47 @@ public class XObject extends Expression implements Serializable, Cloneable
   /** Constant for XPath 3.1 sequence object type */
   public static final int CLASS_RESULT_SEQUENCE = 6;
   
+  /** Constant for XPath 3.1 function item object type */
+  public static final int CLASS_FUNCTION_ITEM = 7;
+  
   /** Constant for XPath 3.1 xs:untypedAtomic object type */
-  public static final int CLASS_XS_UNTYPED_ATOMIC = 7;
+  public static final int CLASS_XS_UNTYPED_ATOMIC = 8;
   
   /** Constant for XPath 3.1 xs:date object type */
-  public static final int CLASS_XS_DATE = 8;
+  public static final int CLASS_XS_DATE = 9;
   
   /** Constant for XPath 3.1 xs:dateTime object type */
-  public static final int CLASS_XS_DATETIME = 9;
+  public static final int CLASS_XS_DATETIME = 10;
   
   /** Constant for XPath 3.1 xs:time object type */
-  public static final int CLASS_XS_TIME = 10;
+  public static final int CLASS_XS_TIME = 11;
   
   /** Constant for XPath 3.1 xs:duration object type */
-  public static final int CLASS_XS_DURATION = 11;
+  public static final int CLASS_XS_DURATION = 12;
   
   /** Constant for XPath 3.1 xs:dayTimeDuration object type */
-  public static final int CLASS_XS_DAYTIME_DURATION = 12;
+  public static final int CLASS_XS_DAYTIME_DURATION = 13;
   
   /** Constant for XPath 3.1 xs:yearMonthDuration object type */
-  public static final int CLASS_XS_YEARMONTH_DURATION = 13;
+  public static final int CLASS_XS_YEARMONTH_DURATION = 14;
   
   /** Constant for XPath 3.1 xs:decimal object type */
-  public static final int CLASS_XS_DECIMAL = 14;
+  public static final int CLASS_XS_DECIMAL = 15;
   
   /** Constant for XPath 3.1 xs:integer object type */
-  public static final int CLASS_XS_INTEGER = 15;
+  public static final int CLASS_XS_INTEGER = 16;
   
   /** Constant for XPath 3.1 xs:long object type */
-  public static final int CLASS_XS_LONG = 16;
+  public static final int CLASS_XS_LONG = 17;
   
   /** Constant for XPath 3.1 xs:int object type */
-  public static final int CLASS_XS_INT = 17;
+  public static final int CLASS_XS_INT = 18;
   
   /** Constant for XPath 3.1 xs:double object type */
-  public static final int CLASS_XS_DOUBLE = 18;
+  public static final int CLASS_XS_DOUBLE = 19;
   
   /** Constant for XPath 3.1 xs:float object type */
-  public static final int CLASS_XS_FLOAT = 19;
+  public static final int CLASS_XS_FLOAT = 20;
 
   /** Represents an unresolved variable type as an integer. */
   public static final int CLASS_UNRESOLVEDVARIABLE = 600;
diff --git a/tests/org/apache/xalan/xslt3/XslTemplateAttributeAsTests.java b/tests/org/apache/xalan/xslt3/XslTemplateAttributeAsTests.java
index fa8c3264..e81330dc 100644
--- a/tests/org/apache/xalan/xslt3/XslTemplateAttributeAsTests.java
+++ b/tests/org/apache/xalan/xslt3/XslTemplateAttributeAsTests.java
@@ -130,5 +130,15 @@ public class XslTemplateAttributeAsTests extends XslTransformTestsUtil {
         
         runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);   
     }
+    
+    @Test
+    public void xslTemplateAttributeAsTest9() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_b.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test9.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test9.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);   
+    }
 
 }
diff --git a/tests/xsl_template_attribute_as/gold/test9.out b/tests/xsl_template_attribute_as/gold/test9.out
new file mode 100644
index 00000000..e65ff59d
--- /dev/null
+++ b/tests/xsl_template_attribute_as/gold/test9.out
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <personDetails id="1">
+    <fName>Gary</fName>
+    <lName>Gregory</lName>
+  </personDetails>
+  <personDetails id="2">
+    <fName>Mukul</fName>
+    <lName>Gandhi</lName>
+  </personDetails>
+  <personDetails id="3">
+    <fName>Joseph</fName>
+    <lName>Kessselman</lName>
+  </personDetails>
+  <personDetails id="4">
+    <fName>Noah</fName>
+    <lName>Mendelsohn</lName>
+  </personDetails>
+  <personDetails id="5">
+    <fName>Michael</fName>
+    <lName>Glavassevich</lName>
+  </personDetails>
+</result>
diff --git a/tests/xsl_template_attribute_as/test1_b.xml b/tests/xsl_template_attribute_as/test1_b.xml
new file mode 100644
index 00000000..19201b4c
--- /dev/null
+++ b/tests/xsl_template_attribute_as/test1_b.xml
@@ -0,0 +1,22 @@
+<info>
+  <person id="1">
+    <fName>Gary</fName>
+    <lName>Gregory</lName>
+  </person>
+  <person id="2">
+    <fName>Mukul</fName>
+    <lName>Gandhi</lName>
+  </person>
+  <person id="3">
+    <fName>Joseph</fName>
+    <lName>Kessselman</lName>
+  </person>
+  <person id="4">
+    <fName>Noah</fName>
+    <lName>Mendelsohn</lName>
+  </person>
+  <person id="5">
+    <fName>Michael</fName>
+    <lName>Glavassevich</lName>
+  </person>
+</info>
\ No newline at end of file
diff --git a/tests/xsl_template_attribute_as/test9.xsl b/tests/xsl_template_attribute_as/test9.xsl
new file mode 100644
index 00000000..005e2f97
--- /dev/null
+++ b/tests/xsl_template_attribute_as/test9.xsl
@@ -0,0 +1,47 @@
+<?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 test1_b.xml -->                
+    
+    <!-- An XSLT stylesheet test case, to test the sequence type
+         declaration attribute "as" on an element xsl:template
+         when the template is invoked via xsl:apply-templates 
+         instruction.
+    -->                 
+    
+    <xsl:output method="xml" indent="yes"/>
+    
+    <xsl:template match="/info">       
+       <result>
+         <xsl:apply-templates select="person"/>
+       </result>
+    </xsl:template>
+    
+    <xsl:template match="person" as="element(personDetails)">
+       <personDetails>
+          <xsl:copy-of select="@id | node()"/>
+       </personDetails>
+    </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


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