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/01 16:49:19 UTC

[xalan-java] branch xalan-j_xslt3.0 updated: committing implementation of xpath 3.1 predicate/index operator evaluations on sequence. also 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 6faaad90 committing implementation of xpath 3.1 predicate/index operator evaluations on sequence. also committing few new, related working test cases as well.
     new 1cd2faeb Merge pull request #40 from mukulga/xalan-j_xslt3.0_mukul
6faaad90 is described below

commit 6faaad90c6f800f6beb567f4c23c6c6003e56981
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Tue Aug 1 22:14:07 2023 +0530

    committing implementation of xpath 3.1 predicate/index operator evaluations on sequence. also committing few new, related working test cases as well.
---
 src/org/apache/xalan/templates/ElemValueOf.java    | 136 ++++++++++++++++----
 src/org/apache/xalan/templates/ElemVariable.java   | 132 ++++++++++++++++++-
 .../xpath/composite/SimpleSequenceConstructor.java | 143 +++++++++++++++++----
 src/org/apache/xpath/operations/Div.java           |  91 +++++++++++++
 src/org/apache/xpath/operations/Minus.java         |  91 +++++++++++++
 src/org/apache/xpath/operations/Mult.java          |  91 +++++++++++++
 src/org/apache/xpath/operations/Plus.java          |  89 +++++++++++++
 tests/grouping/test5.xsl                           |   6 +-
 .../xalan/xpath3/SequenceConstructorTests.java     |  30 +++++
 tests/sequence_constructor/gold/test8.out          |  10 ++
 .../test5.xsl => sequence_constructor/test10.xsl}  |  45 +++----
 tests/sequence_constructor/test1_c.xml             |   8 ++
 tests/sequence_constructor/test1_d.xml             |   8 ++
 .../test5.xsl => sequence_constructor/test8.xsl}   |  44 +++----
 .../test5.xsl => sequence_constructor/test9.xsl}   |  45 +++----
 15 files changed, 851 insertions(+), 118 deletions(-)

diff --git a/src/org/apache/xalan/templates/ElemValueOf.java b/src/org/apache/xalan/templates/ElemValueOf.java
index 278b653d..76c74f6a 100644
--- a/src/org/apache/xalan/templates/ElemValueOf.java
+++ b/src/org/apache/xalan/templates/ElemValueOf.java
@@ -17,10 +17,14 @@
  */
 package org.apache.xalan.templates;
 
+import java.util.List;
+
+import javax.xml.transform.SourceLocator;
 import javax.xml.transform.TransformerException;
 
 import org.apache.xalan.res.XSLTErrorResources;
 import org.apache.xalan.transformer.TransformerImpl;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMIterator;
 import org.apache.xml.serializer.SerializationHandler;
@@ -34,6 +38,7 @@ import org.apache.xpath.functions.FuncExtFunction;
 import org.apache.xpath.functions.Function;
 import org.apache.xpath.objects.ResultSequence;
 import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.objects.XObject;
 import org.apache.xpath.objects.XString;
 import org.apache.xpath.operations.Operation;
@@ -41,6 +46,7 @@ import org.apache.xpath.operations.Range;
 import org.apache.xpath.operations.StrConcat;
 import org.apache.xpath.operations.Variable;
 import org.apache.xpath.xs.types.XSAnyType;
+import org.apache.xpath.xs.types.XSNumericType;
 import org.w3c.dom.DOMException;
 import org.xml.sax.SAXException;
 
@@ -226,6 +232,9 @@ public class ElemValueOf extends ElemTemplateElement {
   {
 
     XPathContext xctxt = transformer.getXPathContext();
+    
+    SourceLocator srcLocator = xctxt.getSAXLocator();
+    
     SerializationHandler rth = transformer.getResultTreeHandler();
 
     if (transformer.getDebug())
@@ -397,35 +406,118 @@ public class ElemValueOf extends ElemTemplateElement {
                   else if (expr instanceof LocPathIterator) {
                      LocPathIterator locPathIterator = (LocPathIterator)expr;
                      
-                     DTMIterator dtmIter = locPathIterator.asIterator(xctxt, current);
-                     int nextNode;
-                     StringBuffer strBuff = new StringBuffer();
-                     while ((nextNode = dtmIter.nextNode()) != DTM.NULL)
-                     {
-                         XNodeSet singletonXPathNode = new XNodeSet(nextNode, xctxt);
-                         String nodeStrVal = singletonXPathNode.str();
-                         strBuff.append(nodeStrVal + " ");
+                     DTMIterator dtmIter = null;                     
+                     try {
+                        dtmIter = locPathIterator.asIterator(xctxt, current);
+                     }
+                     catch (ClassCastException ex) {
+                        // no op
                      }
                      
-                     String nodeSetStrValue = strBuff.toString();
-                     if (nodeSetStrValue.length() > 1) {
-                        nodeSetStrValue = nodeSetStrValue.substring(0, 
-                                                             nodeSetStrValue.length() - 1);
-                        (new XString(nodeSetStrValue)).dispatchCharactersEvents(rth);
+                     if (dtmIter != null) {
+                        int nextNode;
+                        StringBuffer strBuff = new StringBuffer();
+                        while ((nextNode = dtmIter.nextNode()) != DTM.NULL)
+                        {
+                           XNodeSet singletonXPathNode = new XNodeSet(nextNode, xctxt);
+                           String nodeStrVal = singletonXPathNode.str();
+                           strBuff.append(nodeStrVal + " ");
+                        }
+                         
+                        String nodeSetStrValue = strBuff.toString();
+                        if (nodeSetStrValue.length() > 1) {
+                           nodeSetStrValue = nodeSetStrValue.substring(0, 
+                                                                 nodeSetStrValue.length() - 1);
+                           (new XString(nodeSetStrValue)).dispatchCharactersEvents(rth);
+                        }
+                     }
+                     else {
+                        String xpathPatternStr = m_selectExpression.getPatternString();
+                        
+                        if (xpathPatternStr.startsWith("$") && xpathPatternStr.contains("[") && 
+                                                                                    xpathPatternStr.endsWith("]")) {
+                           String varRefXPathExprStr = "$" + xpathPatternStr.substring(1, xpathPatternStr.indexOf('['));
+                           String xpathIndexExprStr = xpathPatternStr.substring(xpathPatternStr.indexOf('[') + 1, 
+                                                                                                 xpathPatternStr.indexOf(']'));
+                           
+                           ElemTemplateElement elemTemplateElement = (ElemTemplateElement)xctxt.getNamespaceContext();
+                           List<XMLNSDecl> prefixTable = null;
+                           if (elemTemplateElement != null) {
+                              prefixTable = (List<XMLNSDecl>)elemTemplateElement.getPrefixTable();
+                           }
+                           
+                           // evaluate the, variable reference XPath expression
+                           if (prefixTable != null) {
+                              varRefXPathExprStr = XslTransformEvaluationHelper.replaceNsUrisWithPrefixesOnXPathStr(
+                                                                                                             varRefXPathExprStr, 
+                                                                                                             prefixTable);
+                           }
+                           
+                           XPath xpathObj = new XPath(varRefXPathExprStr, srcLocator, 
+                                                                                 xctxt.getNamespaceContext(), XPath.SELECT, null);
+                           XObject varEvalResult = xpathObj.execute(xctxt, xctxt.getCurrentNode(), xctxt.getNamespaceContext());
+                           
+                           // evaluate the, xdm sequence index XPath expression
+                           if (prefixTable != null) {
+                              xpathIndexExprStr = XslTransformEvaluationHelper.replaceNsUrisWithPrefixesOnXPathStr(
+                                                                                                              xpathIndexExprStr, 
+                                                                                                              prefixTable);
+                           }
+                           
+                           // There may be a possibility, of a variable reference within the xpath expression 
+                           // string 'xpathIndexExprStr'. To try, resolve those variable references.
+                           // REVISIT 
+                           xpathObj = new XPath(xpathIndexExprStr, srcLocator, xctxt.getNamespaceContext(), XPath.SELECT, null);
+                           
+                           XObject seqIndexEvalResult = xpathObj.execute(xctxt, xctxt.getCurrentNode(), 
+                                                                                                  xctxt.getNamespaceContext());
+                           if (varEvalResult instanceof ResultSequence) {
+                              ResultSequence resultSeq = (ResultSequence)varEvalResult; 
+                              
+                              if (seqIndexEvalResult instanceof XNumber) {
+                                 double dValIndex = ((XNumber)seqIndexEvalResult).num();
+                                 if (dValIndex == (int)dValIndex) {
+                                    XObject evalResult = resultSeq.item((int)dValIndex - 1);
+                                    String strValue = XslTransformEvaluationHelper.getStrVal(evalResult);
+                                    (new XString(strValue)).dispatchCharactersEvents(rth);
+                                 }
+                                 else {
+                                    throw new javax.xml.transform.TransformerException("XPTY0004 : an index value used with an xdm "
+                                                                                                        + "sequence reference, is not an integer.", 
+                                                                                                             srcLocator); 
+                                 }
+                              }
+                              else if (seqIndexEvalResult instanceof XSNumericType) {
+                                 String indexStrVal = ((XSNumericType)seqIndexEvalResult).stringValue();
+                                 double dValIndex = (Double.valueOf(indexStrVal)).doubleValue();
+                                 if (dValIndex == (int)dValIndex) {
+                                    XObject evalResult = resultSeq.item((int)dValIndex - 1);
+                                    String strValue = XslTransformEvaluationHelper.getStrVal(evalResult);
+                                    (new XString(strValue)).dispatchCharactersEvents(rth);                                    
+                                 }
+                                 else {
+                                     throw new javax.xml.transform.TransformerException("XPTY0004 : an index value used with an xdm "
+                                                                                                        + "sequence reference, is not an integer.", 
+                                                                                                             srcLocator); 
+                                 }
+                              }
+                              else {
+                                 throw new javax.xml.transform.TransformerException("XPTY0004 : an index value used with an xdm sequence "
+                                                                                                       + "reference, is not numeric.", srcLocator);  
+                              }
+                           }                           
+                        }
+                        else {
+                           // The implementation behavior is not known here.
+                           // REVISIT
+                        }
                      }
                   }
                   else if (expr instanceof LetExpr) {
                      LetExpr letExpr = (LetExpr)expr;
                       
-                     XObject evalResult = letExpr.execute(xctxt);
-                     
-                     String strValue = null;                     
-                     if (evalResult instanceof XSAnyType) {
-                        strValue = ((XSAnyType)evalResult).stringValue();
-                     }
-                     else {
-                        strValue = evalResult.str();
-                     }
+                     XObject evalResult = letExpr.execute(xctxt);                     
+                     String strValue = XslTransformEvaluationHelper.getStrVal(evalResult);
                      
                      (new XString(strValue)).dispatchCharactersEvents(rth);
                   }
diff --git a/src/org/apache/xalan/templates/ElemVariable.java b/src/org/apache/xalan/templates/ElemVariable.java
index 5532a629..ef811e18 100644
--- a/src/org/apache/xalan/templates/ElemVariable.java
+++ b/src/org/apache/xalan/templates/ElemVariable.java
@@ -17,28 +17,37 @@
  */
 package org.apache.xalan.templates;
 
+import java.util.List;
 import java.util.Map;
+import java.util.Vector;
 
+import javax.xml.transform.SourceLocator;
 import javax.xml.transform.TransformerException;
 
 import org.apache.xalan.res.XSLTErrorResources;
 import org.apache.xalan.transformer.TransformerImpl;
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
+import org.apache.xml.dtm.DTMIterator;
 import org.apache.xml.utils.QName;
 import org.apache.xpath.Expression;
 import org.apache.xpath.XPath;
 import org.apache.xpath.XPathContext;
+import org.apache.xpath.axes.LocPathIterator;
 import org.apache.xpath.axes.SelfIteratorNoPredicate;
 import org.apache.xpath.functions.FuncExtFunction;
 import org.apache.xpath.functions.Function;
 import org.apache.xpath.objects.InlineFunction;
 import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XNodeSetForDOM;
+import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.objects.XObject;
 import org.apache.xpath.objects.XRTreeFrag;
 import org.apache.xpath.objects.XRTreeFragSelectWrapper;
 import org.apache.xpath.objects.XString;
 import org.apache.xpath.operations.Operation;
 import org.apache.xpath.xs.types.XSAnyType;
+import org.apache.xpath.xs.types.XSNumericType;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
@@ -80,7 +89,12 @@ public class ElemVariable extends ElemTemplateElement
    * of variables that can be declared in the variable at one time.
    */
   int m_frameSize = -1;
-
+  
+  // the following two fields of this class, are used during 
+  // XPath.fixupVariables(..) action as performed within object of 
+  // this class.    
+  private Vector fVars;    
+  private int fGlobalsSize;
   
   /**
    * Sets the relative position of this variable within the stack frame (if local)
@@ -297,6 +311,8 @@ public class ElemVariable extends ElemTemplateElement
     XPathContext xctxt = transformer.getXPathContext();
 
     xctxt.pushCurrentNode(sourceNode);
+    
+    SourceLocator srcLocator = xctxt.getSAXLocator(); 
  
     try {        
       if (m_selectPattern != null) {          
@@ -334,11 +350,119 @@ public class ElemVariable extends ElemTemplateElement
                return xpath3ContextItem;     
             }
         }
+        else if (selectExpression instanceof LocPathIterator) {                        
+            int contextNode = xctxt.getContextNode();
+            
+            LocPathIterator locPathIterator = (LocPathIterator)selectExpression;
+            
+            DTMIterator dtmIter = null;                     
+            try {
+                dtmIter = locPathIterator.asIterator(xctxt, contextNode);
+            }
+            catch (ClassCastException ex) {
+                // no op
+            }
+            
+            if (dtmIter != null) {               
+               var = new XNodeSet(dtmIter);
+                
+               return var; 
+            }
+            else {
+               ResultSequence resultSeq = new ResultSequence();
+                
+               String xpathExprStr = m_selectPattern.getPatternString();
+               
+               if (xpathExprStr.startsWith("$") && xpathExprStr.contains("[") && 
+                                                                       xpathExprStr.endsWith("]")) {
+                   ElemTemplateElement elemTemplateElement = (ElemTemplateElement)xctxt.getNamespaceContext();
+                   List<XMLNSDecl> prefixTable = null;
+                   if (elemTemplateElement != null) {
+                       prefixTable = (List<XMLNSDecl>)elemTemplateElement.getPrefixTable();
+                   }                                      
+                   
+                   String varRefXPathExprStr = "$" + xpathExprStr.substring(1, xpathExprStr.indexOf('['));
+                   String xpathIndexExprStr = xpathExprStr.substring(xpathExprStr.indexOf('[') + 1, 
+                                                                                        xpathExprStr.indexOf(']'));
+
+                   // evaluate the, variable reference XPath expression
+                   if (prefixTable != null) {
+                       varRefXPathExprStr = XslTransformEvaluationHelper.replaceNsUrisWithPrefixesOnXPathStr(
+                                                                                                 varRefXPathExprStr, 
+                                                                                                 prefixTable);
+                   }                                      
+
+                   XPath varXPathObj = new XPath(varRefXPathExprStr, srcLocator, xctxt.getNamespaceContext(), 
+                                                                                                    XPath.SELECT, null);
+                   if (fVars != null) {
+                      varXPathObj.fixupVariables(fVars, fGlobalsSize);  
+                   }
+                   
+                   XObject varEvalResult = varXPathObj.execute(xctxt, xctxt.getCurrentNode(), xctxt.getNamespaceContext());
+
+                   // evaluate the, xdm sequence index XPath expression
+                   if (prefixTable != null) {
+                       xpathIndexExprStr = XslTransformEvaluationHelper.replaceNsUrisWithPrefixesOnXPathStr(
+                                                                                                     xpathIndexExprStr, 
+                                                                                                     prefixTable);
+                   }
+
+                   XPath xpathIndexObj = new XPath(xpathIndexExprStr, srcLocator, xctxt.getNamespaceContext(), 
+                                                                                                    XPath.SELECT, null);
+                   
+                   if (fVars != null) {
+                      xpathIndexObj.fixupVariables(fVars, fGlobalsSize);  
+                   }
+                   
+                   XObject seqIndexEvalResult = xpathIndexObj.execute(xctxt, xctxt.getCurrentNode(), 
+                                                                                             xctxt.getNamespaceContext());
+
+                   if (varEvalResult instanceof ResultSequence) {
+                       ResultSequence varEvalResultSeq = (ResultSequence)varEvalResult; 
+
+                       if (seqIndexEvalResult instanceof XNumber) {
+                           double dValIndex = ((XNumber)seqIndexEvalResult).num();
+                           if (dValIndex == (int)dValIndex) {
+                               XObject evalResult = varEvalResultSeq.item((int)dValIndex - 1);
+                               resultSeq.add(evalResult);
+                           }
+                           else {
+                               throw new javax.xml.transform.TransformerException("XPTY0004 : an index value used with an xdm "
+                                                                                       + "sequence reference, is not an integer.", 
+                                                                                                        srcLocator); 
+                           }
+                       }
+                       else if (seqIndexEvalResult instanceof XSNumericType) {
+                           String indexStrVal = ((XSNumericType)seqIndexEvalResult).stringValue();
+                           double dValIndex = (Double.valueOf(indexStrVal)).doubleValue();
+                           if (dValIndex == (int)dValIndex) {
+                               XObject evalResult = varEvalResultSeq.item((int)dValIndex - 1);
+                               resultSeq.add(evalResult);
+                           }
+                           else {
+                               throw new javax.xml.transform.TransformerException("XPTY0004 : an index value used with an xdm "
+                                                                                       + "sequence reference, is not an integer.", 
+                                                                                                        srcLocator);  
+                           }
+                       }
+                       else {
+                           throw new javax.xml.transform.TransformerException("XPTY0004 : an index value used with an xdm sequence "
+                                                                                                + "reference, is not numeric.", 
+                                                                                                        srcLocator);   
+                       }
+                   }
+               }
+               
+               var = resultSeq;
+               
+               return var;
+            }
+        }
   
         if (var == null) {
            var = m_selectPattern.execute(xctxt, sourceNode, this);
         }
-
+        
         var.allowDetachToRelease(false);
 
         if (transformer.getDebug()) {
@@ -412,6 +536,10 @@ public class ElemVariable extends ElemTemplateElement
     // This should be done before addVariableName, so we don't have visibility 
     // to the variable now being defined.
     java.util.Vector vnames = cstate.getVariableNames();
+    
+    fVars = (Vector)vnames.clone();
+    fGlobalsSize = cstate.getGlobalsSize();
+    
     if(null != m_selectPattern)
       m_selectPattern.fixupVariables(vnames, cstate.getGlobalsSize());
       
diff --git a/src/org/apache/xpath/composite/SimpleSequenceConstructor.java b/src/org/apache/xpath/composite/SimpleSequenceConstructor.java
index 8ebaa471..d2026c82 100644
--- a/src/org/apache/xpath/composite/SimpleSequenceConstructor.java
+++ b/src/org/apache/xpath/composite/SimpleSequenceConstructor.java
@@ -34,9 +34,12 @@ import org.apache.xpath.ExpressionOwner;
 import org.apache.xpath.XPath;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.axes.LocPathIterator;
 import org.apache.xpath.objects.ResultSequence;
 import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.objects.XObject;
+import org.apache.xpath.xs.types.XSNumericType;
 
 /*
  * The XalanJ XPath parser, creates and populates an object of this class, 
@@ -98,38 +101,130 @@ public class SimpleSequenceConstructor extends Expression {
                                                                                                      prefixTable);
            }
            
-           XPath xpathObj = new XPath(xpathExprStr, srcLocator, xctxt.getNamespaceContext(), XPath.SELECT, null);
+           XPath xpathObj = new XPath(xpathExprStr, srcLocator, xctxt.getNamespaceContext(), 
+                                                                                      XPath.SELECT, null);
            if (fVars != null) {
               xpathObj.fixupVariables(fVars, fGlobalsSize);
            }
-
-           XObject xPathExprPartResult = xpathObj.execute(xctxt, contextNode, xctxt.getNamespaceContext());
            
-           if (xPathExprPartResult instanceof XNodeSet) {
-               DTMManager dtmMgr = (DTMManager)xctxt;
+           Expression xpathExpr = xpathObj.getExpression();
+           
+           if (xpathExpr instanceof LocPathIterator) {
+               LocPathIterator locPathIterator = (LocPathIterator)xpathExpr;
                
-               XNodeSet xNodeSet = (XNodeSet)xPathExprPartResult;
-               DTMIterator sourceNodes = xNodeSet.iter();
+               DTMIterator dtmIter = null;                     
+               try {
+                   dtmIter = locPathIterator.asIterator(xctxt, contextNode);
+               }
+               catch (ClassCastException ex) {
+                   // no op
+               }
                
-               int nextNodeDtmHandle;
+               if (dtmIter != null) {
+                  int nextNode;
+                  while ((nextNode = dtmIter.nextNode()) != DTM.NULL)
+                  {
+                      XNodeSet xNodeSetItem = new XNodeSet(nextNode, xctxt);
+                      resultSeq.add(xNodeSetItem);
+                  }
+               }
+               else if (xpathExprStr.startsWith("$") && xpathExprStr.contains("[") && 
+                                                                           xpathExprStr.endsWith("]")) {
+                   String varRefXPathExprStr = "$" + xpathExprStr.substring(1, xpathExprStr.indexOf('['));
+                   String xpathIndexExprStr = xpathExprStr.substring(xpathExprStr.indexOf('[') + 1, 
+                                                                                       xpathExprStr.indexOf(']'));
+                   
+                   // evaluate the, variable reference XPath expression
+                   if (prefixTable != null) {
+                      varRefXPathExprStr = XslTransformEvaluationHelper.replaceNsUrisWithPrefixesOnXPathStr(
+                                                                                               varRefXPathExprStr, prefixTable);
+                   }
+                   
+                   XPath varXPathObj = new XPath(varRefXPathExprStr, srcLocator, xctxt.getNamespaceContext(), 
+                                                                                                      XPath.SELECT, null);
+                   XObject varEvalResult = varXPathObj.execute(xctxt, xctxt.getCurrentNode(), xctxt.getNamespaceContext());
+                   
+                   // evaluate the, xdm sequence index XPath expression
+                   if (prefixTable != null) {
+                      xpathIndexExprStr = XslTransformEvaluationHelper.replaceNsUrisWithPrefixesOnXPathStr(
+                                                                                                      xpathIndexExprStr, 
+                                                                                                      prefixTable);
+                   }
+                   
+                   XPath xpathIndexObj = new XPath(xpathIndexExprStr, srcLocator, xctxt.getNamespaceContext(), 
+                                                                                                     XPath.SELECT, null);
+                   if (fVars != null) {
+                      xpathIndexObj.fixupVariables(fVars, fGlobalsSize);
+                   }
+                   
+                   XObject seqIndexEvalResult = xpathIndexObj.execute(xctxt, xctxt.getCurrentNode(), 
+                                                                                                xctxt.getNamespaceContext());
+                   
+                   if (varEvalResult instanceof ResultSequence) {
+                       ResultSequence varEvalResultSeq = (ResultSequence)varEvalResult; 
+                       
+                       if (seqIndexEvalResult instanceof XNumber) {
+                          double dValIndex = ((XNumber)seqIndexEvalResult).num();
+                          if (dValIndex == (int)dValIndex) {
+                             XObject evalResult = varEvalResultSeq.item((int)dValIndex - 1);
+                             resultSeq.add(evalResult);
+                          }
+                          else {
+                              throw new javax.xml.transform.TransformerException("XPTY0004 : an index value used with an xdm "
+                                                                                       + "sequence reference, is not an integer.", 
+                                                                                              srcLocator);  
+                          }
+                       }
+                       else if (seqIndexEvalResult instanceof XSNumericType) {
+                          String indexStrVal = ((XSNumericType)seqIndexEvalResult).stringValue();
+                          double dValIndex = (Double.valueOf(indexStrVal)).doubleValue();
+                          if (dValIndex == (int)dValIndex) {
+                             XObject evalResult = varEvalResultSeq.item((int)dValIndex - 1);
+                             resultSeq.add(evalResult);
+                          }
+                          else {
+                              throw new javax.xml.transform.TransformerException("XPTY0004 : an index value used with an xdm "
+                                                                                       + "sequence reference, is not an integer.", 
+                                                                                              srcLocator);  
+                          }
+                       }
+                       else {
+                           throw new javax.xml.transform.TransformerException("XPTY0004 : an index value used with an xdm sequence "
+                                                                                    + "reference, is not numeric.", srcLocator);  
+                       }
+                   }
+               }
+           }
+           else {
+               XObject xPathExprPartResult = xpathObj.execute(xctxt, contextNode, 
+                                                                              xctxt.getNamespaceContext());
                
-               while ((nextNodeDtmHandle = sourceNodes.nextNode()) != DTM.NULL) {
-                  XNodeSet xNodeSetItem = new XNodeSet(nextNodeDtmHandle, dtmMgr);
-                  resultSeq.add(xNodeSetItem);
-               }               
-            }
-            else if (xPathExprPartResult instanceof ResultSequence) {
-               ResultSequence inpResultSeq = (ResultSequence)xPathExprPartResult; 
-               for (int idx1 = 0; idx1 < inpResultSeq.size(); idx1++) {
-                  XObject xObj = inpResultSeq.item(idx1);
-                  resultSeq.add(xObj);                 
+               if (xPathExprPartResult instanceof XNodeSet) {
+                  DTMManager dtmMgr = (DTMManager)xctxt;
+                   
+                  XNodeSet xNodeSet = (XNodeSet)xPathExprPartResult;
+                  DTMIterator sourceNodes = xNodeSet.iter();
+                   
+                  int nextNodeDtmHandle;
+                   
+                  while ((nextNodeDtmHandle = sourceNodes.nextNode()) != DTM.NULL) {
+                     XNodeSet xNodeSetItem = new XNodeSet(nextNodeDtmHandle, dtmMgr);
+                     resultSeq.add(xNodeSetItem);
+                  }               
+               }
+               else if (xPathExprPartResult instanceof ResultSequence) {
+                  ResultSequence inpResultSeq = (ResultSequence)xPathExprPartResult; 
+                  for (int idx1 = 0; idx1 < inpResultSeq.size(); idx1++) {
+                     XObject xObj = inpResultSeq.item(idx1);
+                     resultSeq.add(xObj);                 
+                  }
                }
-            }
-            else {
-               // We're assuming here that, an input value is an xdm singleton 
-               // item.
-               resultSeq.add(xPathExprPartResult);               
-            }
+               else {
+                  // We're assuming here that, an input value is an xdm sequence 
+                  // with cardinality one.
+                  resultSeq.add(xPathExprPartResult);               
+               }
+           }
         }
         
         return resultSeq;
diff --git a/src/org/apache/xpath/operations/Div.java b/src/org/apache/xpath/operations/Div.java
index 79ee7f59..592f5028 100644
--- a/src/org/apache/xpath/operations/Div.java
+++ b/src/org/apache/xpath/operations/Div.java
@@ -20,8 +20,10 @@
  */
 package org.apache.xpath.operations;
 
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathException;
+import org.apache.xpath.objects.ResultSequence;
 import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.objects.XObject;
@@ -207,6 +209,95 @@ public class Div extends Operation
             result = ((XSYearMonthDuration)left).div(new XSDouble(rStrVal));
          }
      }
+     else if ((left instanceof ResultSequence) && (right instanceof XNumber)) {
+         ResultSequence rsLeft = (ResultSequence)left;          
+         if (rsLeft.size() > 1) {
+             throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                  + "than one item is not allowed as the first "
+                                                                                  + "operand of division operator 'div'.");  
+         }
+         else {
+            java.lang.String lStr = XslTransformEvaluationHelper.getStrVal(rsLeft.item(0));
+            double lDouble = (Double.valueOf(lStr)).doubleValue();
+            
+            double rDouble = ((XNumber)right).num();
+            
+            result = new XNumber(lDouble / rDouble);
+         }
+     }
+     else if ((left instanceof XNumber) && (right instanceof ResultSequence)) {
+         ResultSequence rsRight = (ResultSequence)right;          
+         if (rsRight.size() > 1) {
+             throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                  + "than one item is not allowed as the second "
+                                                                                  + "operand of division operator 'div'.");  
+         }
+         else {             
+            double lDouble = ((XNumber)left).num();
+            
+            java.lang.String rStr = XslTransformEvaluationHelper.getStrVal(rsRight.item(0));
+            double rDouble = (Double.valueOf(rStr)).doubleValue();
+            
+            result = new XNumber(lDouble / rDouble);
+         }
+     }
+     else if ((left instanceof ResultSequence) && (right instanceof XSNumericType)) {
+         ResultSequence rsLeft = (ResultSequence)left;          
+         if (rsLeft.size() > 1) {
+             throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                  + "than one item is not allowed as the first "
+                                                                                  + "operand of division operator 'div'.");  
+         }
+         else {
+            java.lang.String lStr = XslTransformEvaluationHelper.getStrVal(rsLeft.item(0));
+            double lDouble = (Double.valueOf(lStr)).doubleValue();
+            
+            java.lang.String rStrVal = ((XSNumericType)right).stringValue();
+            double rDouble = (Double.valueOf(rStrVal)).doubleValue();
+            
+            result = new XNumber(lDouble / rDouble);
+         } 
+     }
+     else if ((left instanceof XSNumericType) && (right instanceof ResultSequence)) {
+         ResultSequence rsRight = (ResultSequence)right;          
+         if (rsRight.size() > 1) {
+             throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                  + "than one item is not allowed as the second "
+                                                                                  + "operand of division operator 'div'.");  
+         }
+         else {                          
+            java.lang.String lStrVal = ((XSNumericType)left).stringValue();
+            double lDouble = (Double.valueOf(lStrVal)).doubleValue();
+            
+            java.lang.String rStr = XslTransformEvaluationHelper.getStrVal(rsRight.item(0));
+            double rDouble = (Double.valueOf(rStr)).doubleValue();
+            
+            result = new XNumber(lDouble / rDouble);
+         }
+     }
+     else if ((left instanceof ResultSequence) && (right instanceof ResultSequence)) {
+         ResultSequence rsLeft = (ResultSequence)left;          
+         if (rsLeft.size() > 1) {
+             throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                  + "than one item is not allowed as the left "
+                                                                                  + "operand of division operator 'div'.");  
+         }
+         
+         ResultSequence rsRight = (ResultSequence)right;          
+         if (rsRight.size() > 1) {
+             throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                  + "than one item is not allowed as the right "
+                                                                                  + "operand of division operator 'div'.");  
+         }
+         
+         java.lang.String lStr = XslTransformEvaluationHelper.getStrVal(rsLeft.item(0));
+         double lDouble = (Double.valueOf(lStr)).doubleValue();
+         
+         java.lang.String rStr = XslTransformEvaluationHelper.getStrVal(rsRight.item(0));
+         double rDouble = (Double.valueOf(rStr)).doubleValue();
+         
+         result = new XNumber(lDouble / rDouble);
+     }
      else {
          try {
             result = new XNumber(left.num() / right.num());
diff --git a/src/org/apache/xpath/operations/Minus.java b/src/org/apache/xpath/operations/Minus.java
index 8b2c273b..febedc9f 100644
--- a/src/org/apache/xpath/operations/Minus.java
+++ b/src/org/apache/xpath/operations/Minus.java
@@ -20,7 +20,9 @@
  */
 package org.apache.xpath.operations;
 
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.ResultSequence;
 import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.objects.XObject;
@@ -180,6 +182,95 @@ public class Minus extends Operation
           
           return result;
       }
+      else if ((left instanceof ResultSequence) && (right instanceof XNumber)) {
+          ResultSequence rsLeft = (ResultSequence)left;          
+          if (rsLeft.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the first "
+                                                                                   + "operand of subtraction operator '-'.");  
+          }
+          else {
+             java.lang.String lStr = XslTransformEvaluationHelper.getStrVal(rsLeft.item(0));
+             double lDouble = (Double.valueOf(lStr)).doubleValue();
+              
+             double rDouble = ((XNumber)right).num();
+             
+             result = new XNumber(lDouble - rDouble);
+          }
+      }
+      else if ((left instanceof XNumber) && (right instanceof ResultSequence)) {
+          ResultSequence rsRight = (ResultSequence)right;          
+          if (rsRight.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the second "
+                                                                                   + "operand of subtraction operator '-'.");  
+          }
+          else {             
+             double lDouble = ((XNumber)left).num();
+             
+             java.lang.String rStr = XslTransformEvaluationHelper.getStrVal(rsRight.item(0));
+             double rDouble = (Double.valueOf(rStr)).doubleValue();
+             
+             result = new XNumber(lDouble - rDouble);
+          }
+      }
+      else if ((left instanceof ResultSequence) && (right instanceof XSNumericType)) {
+          ResultSequence rsLeft = (ResultSequence)left;          
+          if (rsLeft.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the first "
+                                                                                   + "operand of subtraction operator '-'.");  
+          }
+          else {
+             java.lang.String lStr = XslTransformEvaluationHelper.getStrVal(rsLeft.item(0));
+             double lDouble = (Double.valueOf(lStr)).doubleValue();
+             
+             java.lang.String rStrVal = ((XSNumericType)right).stringValue();
+             double rDouble = (Double.valueOf(rStrVal)).doubleValue();
+             
+             result = new XNumber(lDouble - rDouble);
+          } 
+      }
+      else if ((left instanceof XSNumericType) && (right instanceof ResultSequence)) {
+          ResultSequence rsRight = (ResultSequence)right;          
+          if (rsRight.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the second "
+                                                                                   + "operand of subtraction operator '-'.");  
+          }
+          else {                          
+             java.lang.String lStrVal = ((XSNumericType)left).stringValue();
+             double lDouble = (Double.valueOf(lStrVal)).doubleValue();
+             
+             java.lang.String rStr = XslTransformEvaluationHelper.getStrVal(rsRight.item(0));
+             double rDouble = (Double.valueOf(rStr)).doubleValue();
+             
+             result = new XNumber(lDouble - rDouble);
+          }
+      }
+      else if ((left instanceof ResultSequence) && (right instanceof ResultSequence)) {
+          ResultSequence rsLeft = (ResultSequence)left;          
+          if (rsLeft.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the left "
+                                                                                   + "operand of subtraction operator '-'.");  
+          }
+          
+          ResultSequence rsRight = (ResultSequence)right;          
+          if (rsRight.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the right "
+                                                                                   + "operand of subtraction operator '-'.");  
+          }
+          
+          java.lang.String lStr = XslTransformEvaluationHelper.getStrVal(rsLeft.item(0));
+          double lDouble = (Double.valueOf(lStr)).doubleValue();
+          
+          java.lang.String rStr = XslTransformEvaluationHelper.getStrVal(rsRight.item(0));
+          double rDouble = (Double.valueOf(rStr)).doubleValue();
+          
+          result = new XNumber(lDouble - rDouble);
+      }
       else {          
           try {
              result = new XNumber(left.num() - right.num());
diff --git a/src/org/apache/xpath/operations/Mult.java b/src/org/apache/xpath/operations/Mult.java
index dddc5b44..e6c0bbbf 100644
--- a/src/org/apache/xpath/operations/Mult.java
+++ b/src/org/apache/xpath/operations/Mult.java
@@ -20,8 +20,10 @@
  */
 package org.apache.xpath.operations;
 
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathException;
+import org.apache.xpath.objects.ResultSequence;
 import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.objects.XObject;
@@ -209,6 +211,95 @@ public class Mult extends Operation
              result = ((XSYearMonthDuration)left).mult(new XSDouble(rStrVal));
           }
       }
+      else if ((left instanceof ResultSequence) && (right instanceof XNumber)) {
+          ResultSequence rsLeft = (ResultSequence)left;          
+          if (rsLeft.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the first "
+                                                                                   + "operand of multiplication operator '*'.");  
+          }
+          else {
+             java.lang.String lStr = XslTransformEvaluationHelper.getStrVal(rsLeft.item(0));
+             double lDouble = (Double.valueOf(lStr)).doubleValue();
+             
+             double rDouble = ((XNumber)right).num();
+             
+             result = new XNumber(lDouble * rDouble);
+          }
+      }
+      else if ((left instanceof XNumber) && (right instanceof ResultSequence)) {
+          ResultSequence rsRight = (ResultSequence)right;          
+          if (rsRight.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the second "
+                                                                                   + "operand of multiplication operator '*'.");  
+          }
+          else {             
+             double lDouble = ((XNumber)left).num();
+             
+             java.lang.String rStr = XslTransformEvaluationHelper.getStrVal(rsRight.item(0));
+             double rDouble = (Double.valueOf(rStr)).doubleValue();
+             
+             result = new XNumber(lDouble * rDouble);
+          }
+      }
+      else if ((left instanceof ResultSequence) && (right instanceof XSNumericType)) {
+          ResultSequence rsLeft = (ResultSequence)left;          
+          if (rsLeft.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the first "
+                                                                                   + "operand of multiplication operator '*'.");  
+          }
+          else {
+             java.lang.String lStr = XslTransformEvaluationHelper.getStrVal(rsLeft.item(0));
+             double lDouble = (Double.valueOf(lStr)).doubleValue();
+             
+             java.lang.String rStrVal = ((XSNumericType)right).stringValue();
+             double rDouble = (Double.valueOf(rStrVal)).doubleValue();
+             
+             result = new XNumber(lDouble * rDouble);
+          } 
+      }
+      else if ((left instanceof XSNumericType) && (right instanceof ResultSequence)) {
+          ResultSequence rsRight = (ResultSequence)right;          
+          if (rsRight.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the second "
+                                                                                   + "operand of multiplication operator '*'.");  
+          }
+          else {                          
+             java.lang.String lStrVal = ((XSNumericType)left).stringValue();
+             double lDouble = (Double.valueOf(lStrVal)).doubleValue();
+             
+             java.lang.String rStr = XslTransformEvaluationHelper.getStrVal(rsRight.item(0));
+             double rDouble = (Double.valueOf(rStr)).doubleValue();
+             
+             result = new XNumber(lDouble * rDouble);
+          }
+      }
+      else if ((left instanceof ResultSequence) && (right instanceof ResultSequence)) {
+          ResultSequence rsLeft = (ResultSequence)left;          
+          if (rsLeft.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the left "
+                                                                                   + "operand of multiplication operator '*'.");  
+          }
+          
+          ResultSequence rsRight = (ResultSequence)right;          
+          if (rsRight.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the right "
+                                                                                   + "operand of multiplication operator '*'.");  
+          }
+          
+          java.lang.String lStr = XslTransformEvaluationHelper.getStrVal(rsLeft.item(0));
+          double lDouble = (Double.valueOf(lStr)).doubleValue();
+          
+          java.lang.String rStr = XslTransformEvaluationHelper.getStrVal(rsRight.item(0));
+          double rDouble = (Double.valueOf(rStr)).doubleValue();
+          
+          result = new XNumber(lDouble * rDouble);
+      }
       else {
           try {
              result = new XNumber(left.num() * right.num());
diff --git a/src/org/apache/xpath/operations/Plus.java b/src/org/apache/xpath/operations/Plus.java
index 7831238b..431bce64 100644
--- a/src/org/apache/xpath/operations/Plus.java
+++ b/src/org/apache/xpath/operations/Plus.java
@@ -20,7 +20,9 @@
  */
 package org.apache.xpath.operations;
 
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.ResultSequence;
 import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.objects.XObject;
@@ -177,6 +179,93 @@ public class Plus extends Operation
       else if ((left instanceof XSYearMonthDuration) && (right instanceof XSYearMonthDuration)) {
           result = ((XSYearMonthDuration)left).add((XSYearMonthDuration)right);  
       }
+      else if ((left instanceof ResultSequence) && (right instanceof XNumber)) {
+          ResultSequence rsLeft = (ResultSequence)left;          
+          if (rsLeft.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the first "
+                                                                                   + "operand of addition operator '+'.");  
+          }
+          else {
+             java.lang.String lStr = XslTransformEvaluationHelper.getStrVal(rsLeft.item(0));
+             double lDouble = (Double.valueOf(lStr)).doubleValue();
+             double rDouble = ((XNumber)right).num();
+             
+             result = new XNumber(lDouble + rDouble);
+          }
+      }
+      else if ((left instanceof XNumber) && (right instanceof ResultSequence)) {
+          ResultSequence rsRight = (ResultSequence)right;          
+          if (rsRight.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the second "
+                                                                                   + "operand of addition operator '+'.");  
+          }
+          else {             
+             double lDouble = ((XNumber)left).num();
+             java.lang.String rStr = XslTransformEvaluationHelper.getStrVal(rsRight.item(0));
+             double rDouble = (Double.valueOf(rStr)).doubleValue();
+             
+             result = new XNumber(lDouble + rDouble);
+          }
+      }
+      else if ((left instanceof ResultSequence) && (right instanceof XSNumericType)) {
+          ResultSequence rsLeft = (ResultSequence)left;          
+          if (rsLeft.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the first "
+                                                                                   + "operand of addition operator '+'.");  
+          }
+          else {
+             java.lang.String lStr = XslTransformEvaluationHelper.getStrVal(rsLeft.item(0));
+             double lDouble = (Double.valueOf(lStr)).doubleValue();
+             
+             java.lang.String rStrVal = ((XSNumericType)right).stringValue();
+             double rDouble = (Double.valueOf(rStrVal)).doubleValue();
+             
+             result = new XNumber(lDouble + rDouble);
+          } 
+      }
+      else if ((left instanceof XSNumericType) && (right instanceof ResultSequence)) {
+          ResultSequence rsRight = (ResultSequence)right;          
+          if (rsRight.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the second "
+                                                                                   + "operand of addition operator '+'.");  
+          }
+          else {                          
+             java.lang.String lStrVal = ((XSNumericType)left).stringValue();
+             double lDouble = (Double.valueOf(lStrVal)).doubleValue();
+             
+             java.lang.String rStr = XslTransformEvaluationHelper.getStrVal(rsRight.item(0));
+             double rDouble = (Double.valueOf(rStr)).doubleValue();
+             
+             result = new XNumber(lDouble + rDouble);
+          }
+      }
+      else if ((left instanceof ResultSequence) && (right instanceof ResultSequence)) {
+          ResultSequence rsLeft = (ResultSequence)left;          
+          if (rsLeft.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the left "
+                                                                                   + "operand of addition operator '+'.");  
+          }
+          
+          ResultSequence rsRight = (ResultSequence)right;          
+          if (rsRight.size() > 1) {
+              throw new javax.xml.transform.TransformerException("XPTY0004 : a sequence of more "
+                                                                                   + "than one item is not allowed as the right "
+                                                                                   + "operand of addition operator '+'.");  
+          }
+          
+          java.lang.String lStr = XslTransformEvaluationHelper.getStrVal(rsLeft.item(0));
+          double lDouble = (Double.valueOf(lStr)).doubleValue();
+          
+          java.lang.String rStr = XslTransformEvaluationHelper.getStrVal(rsRight.item(0));
+          double rDouble = (Double.valueOf(rStr)).doubleValue();
+          
+          result = new XNumber(lDouble + rDouble);
+      }
       else {
           try {
              result = new XNumber(left.num() + right.num());
diff --git a/tests/grouping/test5.xsl b/tests/grouping/test5.xsl
index cb71436b..57fce4a5 100644
--- a/tests/grouping/test5.xsl
+++ b/tests/grouping/test5.xsl
@@ -22,9 +22,9 @@
         <!-- form the groups again similarly -->
         <result2>
            <xsl:for-each-group select="$aList" group-by=".">
-	      <group grpKey="{current-grouping-key()}">
-	         <xsl:copy-of select="current-group()"/>
-	      </group>
+	         <group grpKey="{current-grouping-key()}">
+	            <xsl:copy-of select="current-group()"/>
+	         </group>
            </xsl:for-each-group>
         </result2>
       </result>
diff --git a/tests/org/apache/xalan/xpath3/SequenceConstructorTests.java b/tests/org/apache/xalan/xpath3/SequenceConstructorTests.java
index fae367e0..b534f0f4 100644
--- a/tests/org/apache/xalan/xpath3/SequenceConstructorTests.java
+++ b/tests/org/apache/xalan/xpath3/SequenceConstructorTests.java
@@ -117,5 +117,35 @@ public class SequenceConstructorTests extends XslTransformTestsUtil {
         
         runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
     }
+    
+    @Test
+    public void xslSequenceConstructorTest8() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test8.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test8.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test8.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xslSequenceConstructorTest9() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_c.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test9.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test8.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xslSequenceConstructorTest10() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_d.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test10.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test8.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
 
 }
diff --git a/tests/sequence_constructor/gold/test8.out b/tests/sequence_constructor/gold/test8.out
new file mode 100644
index 00000000..fbf43cb4
--- /dev/null
+++ b/tests/sequence_constructor/gold/test8.out
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <val>2.1 3.1</val>
+  <val>2.1</val>
+  <val>105.1</val>
+  <val>24.150000000000002</val>
+  <val>105.1</val>
+  <val>100.9</val>
+  <val>216.3</val>
+  <val>49.047619047619044</val>
+</result>
diff --git a/tests/grouping/test5.xsl b/tests/sequence_constructor/test10.xsl
similarity index 50%
copy from tests/grouping/test5.xsl
copy to tests/sequence_constructor/test10.xsl
index cb71436b..fd398a04 100644
--- a/tests/grouping/test5.xsl
+++ b/tests/sequence_constructor/test10.xsl
@@ -1,32 +1,33 @@
 <?xml version="1.0"?>
 <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_a.xml -->
-
-   <xsl:output method="xml" indent="yes"/>
+   <!-- Author: mukulg@apache.org -->
    
-   <xsl:variable name="aList" select="/elem/a"/>
+   <!-- use with test1_d.xml -->
+   
+   <!-- An XSLT stylesheet, to test XPath 3.1 sequences and
+        use of predicate/index operator (i.e, [..]) on them). 
+        This stylesheet example takes as an input, data from
+        an XML external document. -->                
 
-   <xsl:template match="/elem">
+   <xsl:output method="xml" indent="yes"/>
+      
+   <xsl:template match="/temp">
       <result>
-        <result1>
-           <xsl:for-each-group select="$aList" group-by=".">
-              <group grpKey="{current-grouping-key()}">
-                <xsl:copy-of select="current-group()"/>
-              </group>
-           </xsl:for-each-group>
-        </result1>
-        <!-- form the groups again similarly -->
-        <result2>
-           <xsl:for-each-group select="$aList" group-by=".">
-	      <group grpKey="{current-grouping-key()}">
-	         <xsl:copy-of select="current-group()"/>
-	      </group>
-           </xsl:for-each-group>
-        </result2>
+         <xsl:variable name="seq" select="(a[1], a[2]/@val, a[3], a[4]/@val, a[5])"/>         
+	     <xsl:variable name="val1" select="$seq[2]"/>
+	          
+	     <val><xsl:value-of select="($seq[2], $seq[3])"/></val>
+	     <val><xsl:value-of select="$val1"/></val>
+	     <val><xsl:value-of select="xs:double(103) + $val1"/></val>
+	     <val><xsl:value-of select="$val1 * 11.5"/></val>
+	     <val><xsl:value-of select="$val1 + xs:double(103)"/></val>
+	     <val><xsl:value-of select="xs:double(103) - $val1"/></val>
+	     <val><xsl:value-of select="xs:double(103) * $val1"/></val>
+         <val><xsl:value-of select="xs:double(103) div $val1"/></val>
       </result>
    </xsl:template>
    
diff --git a/tests/sequence_constructor/test1_c.xml b/tests/sequence_constructor/test1_c.xml
new file mode 100644
index 00000000..45485cd5
--- /dev/null
+++ b/tests/sequence_constructor/test1_c.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<temp>
+  <a>1.1</a>
+  <a>2.1</a>
+  <a>3.1</a>
+  <a>4.1</a>
+  <a>5.1</a>
+</temp>
\ No newline at end of file
diff --git a/tests/sequence_constructor/test1_d.xml b/tests/sequence_constructor/test1_d.xml
new file mode 100644
index 00000000..c850d15a
--- /dev/null
+++ b/tests/sequence_constructor/test1_d.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<temp>
+  <a>1.1</a>
+  <a val="2.1"/>
+  <a>3.1</a>
+  <a val="4.1"/>
+  <a>5.1</a>
+</temp>
\ No newline at end of file
diff --git a/tests/grouping/test5.xsl b/tests/sequence_constructor/test8.xsl
similarity index 51%
copy from tests/grouping/test5.xsl
copy to tests/sequence_constructor/test8.xsl
index cb71436b..89aa03e5 100644
--- a/tests/grouping/test5.xsl
+++ b/tests/sequence_constructor/test8.xsl
@@ -1,32 +1,30 @@
 <?xml version="1.0"?>
 <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_a.xml -->
-
-   <xsl:output method="xml" indent="yes"/>
+   <!-- Author: mukulg@apache.org -->
    
-   <xsl:variable name="aList" select="/elem/a"/>
+   <!-- An XSLT stylesheet, to test XPath 3.1 sequences and
+        use of predicate/index operator (i.e, [..]) on them). 
+        -->                
 
-   <xsl:template match="/elem">
-      <result>
-        <result1>
-           <xsl:for-each-group select="$aList" group-by=".">
-              <group grpKey="{current-grouping-key()}">
-                <xsl:copy-of select="current-group()"/>
-              </group>
-           </xsl:for-each-group>
-        </result1>
-        <!-- form the groups again similarly -->
-        <result2>
-           <xsl:for-each-group select="$aList" group-by=".">
-	      <group grpKey="{current-grouping-key()}">
-	         <xsl:copy-of select="current-group()"/>
-	      </group>
-           </xsl:for-each-group>
-        </result2>
+   <xsl:output method="xml" indent="yes"/>
+      
+   <xsl:template match="/">
+      <result>         
+         <xsl:variable name="seq" select="(1.1, 2.1, 3.1, 4.1, 5.1)"/>         
+         <xsl:variable name="val1" select="$seq[2]"/>
+         
+         <val><xsl:value-of select="($seq[2], $seq[3])"/></val>
+         <val><xsl:value-of select="$val1"/></val>                  
+         <val><xsl:value-of select="xs:double(103) + $val1"/></val>
+         <val><xsl:value-of select="$val1 * 11.5"/></val>
+         <val><xsl:value-of select="$val1 + xs:double(103)"/></val>
+         <val><xsl:value-of select="xs:double(103) - $val1"/></val>
+         <val><xsl:value-of select="xs:double(103) * $val1"/></val>
+         <val><xsl:value-of select="xs:double(103) div $val1"/></val>         
       </result>
    </xsl:template>
    
diff --git a/tests/grouping/test5.xsl b/tests/sequence_constructor/test9.xsl
similarity index 50%
copy from tests/grouping/test5.xsl
copy to tests/sequence_constructor/test9.xsl
index cb71436b..fd35cc7a 100644
--- a/tests/grouping/test5.xsl
+++ b/tests/sequence_constructor/test9.xsl
@@ -1,32 +1,33 @@
 <?xml version="1.0"?>
 <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_a.xml -->
-
-   <xsl:output method="xml" indent="yes"/>
+   <!-- Author: mukulg@apache.org -->
    
-   <xsl:variable name="aList" select="/elem/a"/>
+   <!-- use with test1_c.xml -->
+   
+   <!-- An XSLT stylesheet, to test XPath 3.1 sequences and
+        use of predicate/index operator (i.e, [..]) on them). 
+        This stylesheet example takes as an input, data from
+        an XML external document. -->                
 
-   <xsl:template match="/elem">
+   <xsl:output method="xml" indent="yes"/>
+      
+   <xsl:template match="/temp">
       <result>
-        <result1>
-           <xsl:for-each-group select="$aList" group-by=".">
-              <group grpKey="{current-grouping-key()}">
-                <xsl:copy-of select="current-group()"/>
-              </group>
-           </xsl:for-each-group>
-        </result1>
-        <!-- form the groups again similarly -->
-        <result2>
-           <xsl:for-each-group select="$aList" group-by=".">
-	      <group grpKey="{current-grouping-key()}">
-	         <xsl:copy-of select="current-group()"/>
-	      </group>
-           </xsl:for-each-group>
-        </result2>
+         <xsl:variable name="seq" select="(a[1], a[2], a[3], a[4], a[5])"/>         
+	     <xsl:variable name="val1" select="$seq[2]"/>
+	          
+	     <val><xsl:value-of select="($seq[2], $seq[3])"/></val>
+	     <val><xsl:value-of select="$val1"/></val>
+	     <val><xsl:value-of select="xs:double(103) + $val1"/></val>
+	     <val><xsl:value-of select="$val1 * 11.5"/></val>
+	     <val><xsl:value-of select="$val1 + xs:double(103)"/></val>
+	     <val><xsl:value-of select="xs:double(103) - $val1"/></val>
+	     <val><xsl:value-of select="xs:double(103) * $val1"/></val>
+         <val><xsl:value-of select="xs:double(103) div $val1"/></val>
       </result>
    </xsl:template>
    


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