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 2024/05/28 09:57:19 UTC

(xalan-java) branch xalan-j_xslt3.0 updated: committing implementation of xpath 3.1 functions array:append and array:subarray, and improvements and refactoring to various other parts of xalanj implementation on this code repos branch

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 0b893a6e committing implementation of xpath 3.1 functions array:append and array:subarray, and improvements and refactoring to various other parts of xalanj implementation on this code repos branch
0b893a6e is described below

commit 0b893a6e9781107d0fe724c2233ef6b44b22bb94
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Tue May 28 15:27:05 2024 +0530

    committing implementation of xpath 3.1 functions array:append and array:subarray, and improvements and refactoring to various other parts of xalanj implementation on this code repos branch
---
 .../apache/xalan/templates/ElemApplyTemplates.java |   2 +-
 src/org/apache/xalan/templates/ElemForEach.java    |  77 ++--
 src/org/apache/xalan/templates/ElemFunction.java   |   2 +-
 src/org/apache/xalan/templates/ElemIterate.java    |  31 +-
 .../xalan/templates/ElemIterateNextIteration.java  |   2 +-
 src/org/apache/xalan/templates/ElemParam.java      |   2 +-
 src/org/apache/xalan/templates/ElemTemplate.java   |   2 +-
 src/org/apache/xalan/templates/ElemVariable.java   |  26 +-
 src/org/apache/xalan/templates/ElemWithParam.java  |   2 +-
 src/org/apache/xpath/compiler/FunctionTable.java   |  40 ++-
 src/org/apache/xpath/compiler/Keywords.java        |  21 ++
 .../xpath/composite/SequenceTypeSupport.java       |  29 +-
 .../xpath/functions/DynamicFunctionCall.java       |   4 +-
 .../{FuncArrayGet.java => FuncArrayAppend.java}    |  67 ++--
 .../apache/xpath/functions/array/FuncArrayGet.java |  92 +++--
 .../apache/xpath/functions/array/FuncArrayPut.java |  87 +++--
 .../apache/xpath/functions/array/FuncSubarray.java | 151 ++++++++
 src/org/apache/xpath/objects/XPathArray.java       |   6 +-
 src/org/apache/xpath/operations/CastAs.java        |   2 +-
 src/org/apache/xpath/operations/CastableAs.java    |   2 +-
 src/org/apache/xpath/operations/InstanceOf.java    | 394 ++++++++++++---------
 tests/org/apache/xalan/xpath3/XPathArrayTests.java |  20 ++
 tests/xpath_array/gold/test3.out                   |   2 +-
 tests/xpath_array/gold/test6.out                   |  14 +
 tests/xpath_array/gold/test7.out                   |   6 +
 tests/xpath_array/test3.xsl                        |  11 +-
 tests/xpath_array/test6.xsl                        |  59 +++
 tests/xpath_array/test7.xsl                        |  55 +++
 28 files changed, 856 insertions(+), 352 deletions(-)

diff --git a/src/org/apache/xalan/templates/ElemApplyTemplates.java b/src/org/apache/xalan/templates/ElemApplyTemplates.java
index f283cc53..0ca4c15e 100644
--- a/src/org/apache/xalan/templates/ElemApplyTemplates.java
+++ b/src/org/apache/xalan/templates/ElemApplyTemplates.java
@@ -405,7 +405,7 @@ public class ElemApplyTemplates extends ElemCallTemplate
                NodeList nodeList = (new XRTreeFrag(dtmNodeHandle, xctxt, template)).convertToNodeset();             
                XObject templateEvalResultForAsAttr = new XNodeSetForDOM(nodeList, xctxt);
                
-               templateEvalResultForAsAttr = SequenceTypeSupport.convertXDMValueToAnotherType(templateEvalResultForAsAttr, templateAsAttrVal, 
+               templateEvalResultForAsAttr = SequenceTypeSupport.convertXdmValueToAnotherType(templateEvalResultForAsAttr, templateAsAttrVal, 
                                                                                                                                           null, xctxt);
                if (templateEvalResultForAsAttr != null) {
                    SerializationHandler handler = transformer.getSerializationHandler();        
diff --git a/src/org/apache/xalan/templates/ElemForEach.java b/src/org/apache/xalan/templates/ElemForEach.java
index 86580782..93fec7fc 100644
--- a/src/org/apache/xalan/templates/ElemForEach.java
+++ b/src/org/apache/xalan/templates/ElemForEach.java
@@ -45,6 +45,7 @@ import org.apache.xpath.functions.Function;
 import org.apache.xpath.objects.ResultSequence;
 import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XPathArray;
 import org.apache.xpath.operations.Operation;
 import org.apache.xpath.operations.Variable;
 
@@ -325,14 +326,30 @@ public class ElemForEach extends ElemTemplateElement implements ExpressionOwner
             XNodeSet nodeSet = XslTransformEvaluationHelper.getXNodeSetFromResultSequence((ResultSequence)evalResult, 
                                                                                                                   (DTMManager)xctxt);             
             if (nodeSet == null) {
-               processResultSequence(transformer, xctxt, evalResult);               
+               processSequenceOrArray(transformer, xctxt, evalResult);               
                return;
             }
             else {
                resultSeqDtmIterator = nodeSet.iter(); 
             }
         }                
-    }    
+    }
+    else if (m_selectExpression instanceof DynamicFunctionCall) {
+        DynamicFunctionCall dfc = (DynamicFunctionCall)m_selectExpression;
+        XObject evalResult = dfc.execute(xctxt);
+        
+        if (evalResult instanceof ResultSequence) {
+            XNodeSet nodeSet = XslTransformEvaluationHelper.getXNodeSetFromResultSequence((ResultSequence)evalResult, 
+                                                                                                                  (DTMManager)xctxt);             
+            if (nodeSet == null) {
+                processSequenceOrArray(transformer, xctxt, evalResult);                
+                return;
+            }
+            else {
+                resultSeqDtmIterator = nodeSet.iter(); 
+            }
+        }
+    }
     else if (m_selectExpression instanceof Variable) {
         XObject evalResult = ((Variable)m_selectExpression).execute(xctxt);                
         
@@ -340,21 +357,24 @@ public class ElemForEach extends ElemTemplateElement implements ExpressionOwner
         	ResultSequence resultSequence = new ResultSequence();
         	resultSequence.add(evalResult);
         	
-        	processResultSequence(transformer, xctxt, resultSequence);
-        	
+        	processSequenceOrArray(transformer, xctxt, resultSequence);        	
             return;
         }        
         else if (evalResult instanceof ResultSequence) {
             XNodeSet nodeSet = XslTransformEvaluationHelper.getXNodeSetFromResultSequence((ResultSequence)evalResult, 
                                                                                                                   (DTMManager)xctxt);             
             if (nodeSet == null) {
-                processResultSequence(transformer, xctxt, evalResult);
+                processSequenceOrArray(transformer, xctxt, evalResult);                
                 return;
             }
             else {
                 resultSeqDtmIterator = nodeSet.iter(); 
             }
         }
+        else if (evalResult instanceof XPathArray) {
+        	processSequenceOrArray(transformer, xctxt, evalResult);        	
+        	return;
+        }
     }    
     else if (m_selectExpression instanceof Operation) {
         XObject  evalResult = m_selectExpression.execute(xctxt);
@@ -363,7 +383,7 @@ public class ElemForEach extends ElemTemplateElement implements ExpressionOwner
             XNodeSet nodeSet = XslTransformEvaluationHelper.getXNodeSetFromResultSequence((ResultSequence)evalResult, 
                                                                                                                   (DTMManager)xctxt);             
             if (nodeSet == null) {
-                processResultSequence(transformer, xctxt, evalResult);
+                processSequenceOrArray(transformer, xctxt, evalResult);                
                 return;
             }
             else {
@@ -378,7 +398,7 @@ public class ElemForEach extends ElemTemplateElement implements ExpressionOwner
         XNodeSet nodeSet = XslTransformEvaluationHelper.getXNodeSetFromResultSequence((ResultSequence)evalResult, 
                                                                                                               (DTMManager)xctxt);             
         if (nodeSet == null) {
-            processResultSequence(transformer, xctxt, evalResult);
+            processSequenceOrArray(transformer, xctxt, evalResult);            
             return;
         }
         else {
@@ -393,29 +413,13 @@ public class ElemForEach extends ElemTemplateElement implements ExpressionOwner
         XNodeSet nodeSet = XslTransformEvaluationHelper.getXNodeSetFromResultSequence((ResultSequence)evalResult, 
                                                                                                               (DTMManager)xctxt);             
         if (nodeSet == null) {
-            processResultSequence(transformer, xctxt, evalResult);
+            processSequenceOrArray(transformer, xctxt, evalResult);
             return;
         }
         else {
             resultSeqDtmIterator = nodeSet.iter(); 
         }
     }
-    else if (m_selectExpression instanceof DynamicFunctionCall) {
-        DynamicFunctionCall dfc = (DynamicFunctionCall)m_selectExpression;
-        XObject evalResult = dfc.execute(xctxt);
-        
-        if (evalResult instanceof ResultSequence) {
-            XNodeSet nodeSet = XslTransformEvaluationHelper.getXNodeSetFromResultSequence((ResultSequence)evalResult, 
-                                                                                                                  (DTMManager)xctxt);             
-            if (nodeSet == null) {
-                processResultSequence(transformer, xctxt, evalResult);
-                return;
-            }
-            else {
-                resultSeqDtmIterator = nodeSet.iter(); 
-            }
-        }
-    }
     
     DTMIterator sourceNodes = null;
     
@@ -621,24 +625,31 @@ public class ElemForEach extends ElemTemplateElement implements ExpressionOwner
    }
    
    /*
-    * Process each of the XDM items stored within a 'ResultSequence', 
-    * in order, and apply each XDM item to all the XSLT instructions
-    * mentioned within body of current xsl:for-each element.
+    * Process each xdm item stored within a sequence or an array 
+    * in order, and apply xdm item's information to all XSL instructions
+    * mentioned within xsl:for-each's sequence constructor.
     */
-   private void processResultSequence(TransformerImpl transformer,
+   private void processSequenceOrArray(TransformerImpl transformer,
                                                               XPathContext xctxt, XObject evalResult) 
                                                               throws TransformerException {       
-       ResultSequence resultSeq = (ResultSequence)evalResult;
-       List<XObject> resultSeqItems = resultSeq.getResultSequenceItems();
+	   List<XObject> itemsToBeProcessed = null;
+	   if (evalResult instanceof ResultSequence) {
+		   ResultSequence resultSeq = (ResultSequence)evalResult;
+		   itemsToBeProcessed = resultSeq.getResultSequenceItems();   
+	   }
+	   else if (evalResult instanceof XPathArray) {
+		   XPathArray xpathArr = (XPathArray)evalResult;
+		   itemsToBeProcessed = xpathArr.getNativeArray();
+	   }	   
        
-       for (int idx = 0; idx < resultSeqItems.size(); idx++) {
-           XObject resultSeqItem = resultSeqItems.get(idx);
+       for (int idx = 0; idx < itemsToBeProcessed.size(); idx++) {
+           XObject resultSeqItem = itemsToBeProcessed.get(idx);
            
            if (resultSeqItem instanceof XNodeSet) {
               resultSeqItem = ((XNodeSet)resultSeqItem).getFresh(); 
            }
            
-           setXPathContextForXslSequenceProcessing(resultSeqItems.size(), idx, resultSeqItem, xctxt);
+           setXPathContextForXslSequenceProcessing(itemsToBeProcessed.size(), idx, resultSeqItem, xctxt);
            
            for (ElemTemplateElement elemTemplateElem = this.m_firstChild; elemTemplateElem != null; 
                                                           elemTemplateElem = elemTemplateElem.m_nextSibling) {
diff --git a/src/org/apache/xalan/templates/ElemFunction.java b/src/org/apache/xalan/templates/ElemFunction.java
index 8905a6e9..851844d5 100644
--- a/src/org/apache/xalan/templates/ElemFunction.java
+++ b/src/org/apache/xalan/templates/ElemFunction.java
@@ -273,7 +273,7 @@ public class ElemFunction extends ElemTemplate
             funcResultConvertedVal = preprocessXslFunctionOrAVariableResult((XNodeSetForDOM)result, funcAsAttrStrVal, xctxt, null);
             
             if (funcResultConvertedVal == null) {
-                funcResultConvertedVal = SequenceTypeSupport.convertXDMValueToAnotherType(result, funcAsAttrStrVal, null, xctxt);
+                funcResultConvertedVal = SequenceTypeSupport.convertXdmValueToAnotherType(result, funcAsAttrStrVal, null, xctxt);
                 
                 if (funcResultConvertedVal == null) {
                    throw new TransformerException("XPTY0004 : The function call result for function {" + funcNameSpaceUri + "}" + funcLocalName + 
diff --git a/src/org/apache/xalan/templates/ElemIterate.java b/src/org/apache/xalan/templates/ElemIterate.java
index 8e767d36..2ad7fe95 100644
--- a/src/org/apache/xalan/templates/ElemIterate.java
+++ b/src/org/apache/xalan/templates/ElemIterate.java
@@ -34,6 +34,7 @@ import org.apache.xpath.XPathContext;
 import org.apache.xpath.objects.ResultSequence;
 import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XPathArray;
 
 /*
  * Implementation of the XSLT 3.0 xsl:iterate instruction.
@@ -176,26 +177,33 @@ public class ElemIterate extends ElemTemplateElement implements ExpressionOwner
            // instruction's evaluation.
            fXslIterateParamWithparamDataList.clear();
            
-           validateXslElemIterateChildElementsSequence(xctxt); 
+           verifyXslElemIterateChildElementsSequence(xctxt); 
                
-           XObject evalResult = m_selectExpression.execute(xctxt);                              
+           XObject evalResult = m_selectExpression.execute(xctxt);
+           
+           List<XObject> itemsToBeProcessed = null;
                
-           if (evalResult instanceof ResultSequence) {
-               ResultSequence resultSeq = (ResultSequence)evalResult;
-               List<XObject> resultSeqItems = resultSeq.getResultSequenceItems();                                      
+           if ((evalResult instanceof ResultSequence) || (evalResult instanceof XPathArray)) {
+        	   if (evalResult instanceof ResultSequence) {
+        		   itemsToBeProcessed = ((ResultSequence)evalResult).getResultSequenceItems();
+        	   }
+        	   else {
+        		   XPathArray xpathArr = (XPathArray)evalResult;
+        		   itemsToBeProcessed = xpathArr.getNativeArray();
+        	   }
                    
                ElemIterateOnCompletion xslOnCompletionTemplate = null;
                    
                boolean isBreakFromXslContentLoop = false;
                    
-               for (int idx = 0; idx < resultSeqItems.size(); idx++) {
-                  XObject resultSeqItem = resultSeqItems.get(idx);
+               for (int idx = 0; idx < itemsToBeProcessed.size(); idx++) {
+                  XObject resultSeqItem = itemsToBeProcessed.get(idx);
                        
                   if (resultSeqItem instanceof XNodeSet) {
                      resultSeqItem = ((XNodeSet)resultSeqItem).getFresh(); 
                   }
                        
-                  setXPathContextForXslSequenceProcessing(resultSeqItems.size(), idx, resultSeqItem, xctxt);
+                  setXPathContextForXslSequenceProcessing(itemsToBeProcessed.size(), idx, resultSeqItem, xctxt);
                                                                      
                   for (ElemTemplateElement elemTemplate = this.m_firstChild; elemTemplate != null; 
                                                                                        elemTemplate = elemTemplate.m_nextSibling) {                           
@@ -338,9 +346,9 @@ public class ElemIterate extends ElemTemplateElement implements ExpressionOwner
       /**
        * The XSLT 3.0 spec specifies constraints, about what should be the order of XSLT elements 
        * xsl:param and xsl:on-completion within the xsl:iterate element. This method ensures that, 
-       * these XSLT element constraints are validated during an XSLT stylesheet transformation.  
+       * these XSLT element constraints are verified during an XSLT stylesheet transformation.  
        */
-      private void validateXslElemIterateChildElementsSequence(XPathContext xctxt) 
+      private void verifyXslElemIterateChildElementsSequence(XPathContext xctxt) 
                                                                        throws TransformerException {
           
           List<String> xslElemNamesList = new ArrayList<String>();
@@ -399,8 +407,7 @@ public class ElemIterate extends ElemTemplateElement implements ExpressionOwner
                      }
                   }                                    
               }
-          }
-          
+          }          
       }
       
 }
diff --git a/src/org/apache/xalan/templates/ElemIterateNextIteration.java b/src/org/apache/xalan/templates/ElemIterateNextIteration.java
index 4d0f47aa..b9a888fb 100644
--- a/src/org/apache/xalan/templates/ElemIterateNextIteration.java
+++ b/src/org/apache/xalan/templates/ElemIterateNextIteration.java
@@ -257,7 +257,7 @@ public class ElemIterateNextIteration extends ElemTemplateElement implements Exp
                 String withParamAsAttr = elemWithParam.getAs();
                 if (withParamAsAttr != null) {
                    try {
-                      withParamVal = SequenceTypeSupport.convertXDMValueToAnotherType(withParamVal, withParamAsAttr, null, 
+                      withParamVal = SequenceTypeSupport.convertXdmValueToAnotherType(withParamVal, withParamAsAttr, null, 
                                                                                                                  transformer.getXPathContext());
                    }
                    catch (TransformerException ex) {
diff --git a/src/org/apache/xalan/templates/ElemParam.java b/src/org/apache/xalan/templates/ElemParam.java
index 93a01cd2..4082bad2 100644
--- a/src/org/apache/xalan/templates/ElemParam.java
+++ b/src/org/apache/xalan/templates/ElemParam.java
@@ -150,7 +150,7 @@ public class ElemParam extends ElemVariable
             if (asAttrVal != null) {
               try {
                  XObject var = transformer.getXPathContext().getVarStack().getLocalVariable(xctx, m_index);
-                 var = SequenceTypeSupport.convertXDMValueToAnotherType(var, asAttrVal, null, 
+                 var = SequenceTypeSupport.convertXdmValueToAnotherType(var, asAttrVal, null, 
                                                                                    transformer.getXPathContext());
                  if (var == null) {
                     throw new TransformerException("XTTE0590 : The required item type of the value of parameter " + 
diff --git a/src/org/apache/xalan/templates/ElemTemplate.java b/src/org/apache/xalan/templates/ElemTemplate.java
index 06e71b66..d6407fe5 100644
--- a/src/org/apache/xalan/templates/ElemTemplate.java
+++ b/src/org/apache/xalan/templates/ElemTemplate.java
@@ -419,7 +419,7 @@ public class ElemTemplate extends ElemTemplateElement
             
            NodeList nodeList = (new XRTreeFrag(dtmNodeHandle, xctxt, this)).convertToNodeset();             
            templateEvalResultForAsAttr = new XNodeSetForDOM(nodeList, xctxt);
-           templateEvalResultForAsAttr = SequenceTypeSupport.convertXDMValueToAnotherType(templateEvalResultForAsAttr, m_asAttr, 
+           templateEvalResultForAsAttr = SequenceTypeSupport.convertXdmValueToAnotherType(templateEvalResultForAsAttr, m_asAttr, 
                                                                                                                    null, xctxt);
            if (templateEvalResultForAsAttr == null) {
               String errTemplateStr = (m_name != null) ? m_name.toString() : m_matchPattern.getPatternString();
diff --git a/src/org/apache/xalan/templates/ElemVariable.java b/src/org/apache/xalan/templates/ElemVariable.java
index fbefd102..f8dce265 100644
--- a/src/org/apache/xalan/templates/ElemVariable.java
+++ b/src/org/apache/xalan/templates/ElemVariable.java
@@ -353,7 +353,7 @@ public class ElemVariable extends ElemTemplateElement
             	
             	String evalResultStrValue = (evalResult instanceof XSString) ? ((XSString)evalResult).stringValue() : null;            	
             	if (m_asAttr != null && !(XSConstructorFunctionUtil.XS_VALID_TRUE).equals(evalResultStrValue)) {           	     
-                   evalResult = SequenceTypeSupport.convertXDMValueToAnotherType(evalResult, m_asAttr, null, xctxt);
+                   evalResult = SequenceTypeSupport.convertXdmValueToAnotherType(evalResult, m_asAttr, null, xctxt);
                    if (evalResult == null) {
                 	  String xpathPatternStr = m_selectPattern.getPatternString();
                 	  throw new TransformerException("XTTE0570 : The supplied value " + xpathPatternStr + ", doesn't "
@@ -386,10 +386,10 @@ public class ElemVariable extends ElemTemplateElement
         }
         else if (selectExpression instanceof Function) {
             XObject evalResult = ((Function)selectExpression).execute(xctxt);            
-            if ((evalResult instanceof ResultSequence) || 
+            if ((evalResult instanceof ResultSequence) || (evalResult instanceof XPathArray) || 
                                                 (evalResult instanceof XSAnyType)) {
                 if (m_asAttr != null) {
-                   evalResult = SequenceTypeSupport.convertXDMValueToAnotherType(evalResult, m_asAttr, null, xctxt);  
+                   evalResult = SequenceTypeSupport.convertXdmValueToAnotherType(evalResult, m_asAttr, null, xctxt);  
                 }
                 
                 return evalResult; 
@@ -399,7 +399,7 @@ public class ElemVariable extends ElemTemplateElement
             XObject evalResult = selectExpression.execute(xctxt);
             
             if (m_asAttr != null) {
-               evalResult = SequenceTypeSupport.convertXDMValueToAnotherType(evalResult, m_asAttr, null, xctxt);  
+               evalResult = SequenceTypeSupport.convertXdmValueToAnotherType(evalResult, m_asAttr, null, xctxt);  
             }
              
             return evalResult;
@@ -408,7 +408,7 @@ public class ElemVariable extends ElemTemplateElement
             XObject evalResult = ((Range)selectExpression).execute(xctxt);
             
             if (m_asAttr != null) {
-               evalResult = SequenceTypeSupport.convertXDMValueToAnotherType(evalResult, m_asAttr, null, xctxt);  
+               evalResult = SequenceTypeSupport.convertXdmValueToAnotherType(evalResult, m_asAttr, null, xctxt);  
             }
              
             return evalResult; 
@@ -422,7 +422,7 @@ public class ElemVariable extends ElemTemplateElement
             XObject evalResult = opn.operate(leftOperand, rightOperand);
             
             if (m_asAttr != null) {
-               evalResult = SequenceTypeSupport.convertXDMValueToAnotherType(evalResult, m_asAttr, null, xctxt);  
+               evalResult = SequenceTypeSupport.convertXdmValueToAnotherType(evalResult, m_asAttr, null, xctxt);  
             }
              
             return evalResult;
@@ -431,7 +431,7 @@ public class ElemVariable extends ElemTemplateElement
             XObject xpath3ContextItem = xctxt.getXPath3ContextItem();
             if (xpath3ContextItem != null) {               
               if (m_asAttr != null) {
-                 xpath3ContextItem = SequenceTypeSupport.convertXDMValueToAnotherType(xpath3ContextItem, m_asAttr, 
+                 xpath3ContextItem = SequenceTypeSupport.convertXdmValueToAnotherType(xpath3ContextItem, m_asAttr, 
                                                                                                                null, xctxt);  
               }
                 
@@ -455,7 +455,7 @@ public class ElemVariable extends ElemTemplateElement
                var = new XNodeSet(dtmIter);
                
                if (m_asAttr != null) {
-                  var = SequenceTypeSupport.convertXDMValueToAnotherType(var, m_asAttr, null, xctxt);  
+                  var = SequenceTypeSupport.convertXdmValueToAnotherType(var, m_asAttr, null, xctxt);  
                }
                  
                return var; 
@@ -548,7 +548,7 @@ public class ElemVariable extends ElemTemplateElement
                var = resultSeq;
                
                if (m_asAttr != null) {
-                  var = SequenceTypeSupport.convertXDMValueToAnotherType(var, m_asAttr, null, xctxt);  
+                  var = SequenceTypeSupport.convertXdmValueToAnotherType(var, m_asAttr, null, xctxt);  
                }
                   
                return var;
@@ -609,12 +609,12 @@ public class ElemVariable extends ElemTemplateElement
              var = variableConvertedVal;    
           }
           else {
-             var = SequenceTypeSupport.convertXDMValueToAnotherType(var, m_asAttr, null, xctxt); 
+             var = SequenceTypeSupport.convertXdmValueToAnotherType(var, m_asAttr, null, xctxt); 
           }
        }
        else if (var instanceof XPathMap) {
     	  try {
-    	     var = SequenceTypeSupport.convertXDMValueToAnotherType(var, m_asAttr, null, xctxt);
+    	     var = SequenceTypeSupport.convertXdmValueToAnotherType(var, m_asAttr, null, xctxt);
     	  }
     	  catch (TransformerException ex) {
     		 String errMesg = ex.getMessage();
@@ -631,7 +631,7 @@ public class ElemVariable extends ElemTemplateElement
        }
        else if (var instanceof XPathArray) {
     	  try {
-      	     var = SequenceTypeSupport.convertXDMValueToAnotherType(var, m_asAttr, null, xctxt);
+      	     var = SequenceTypeSupport.convertXdmValueToAnotherType(var, m_asAttr, null, xctxt);
       	  }
       	  catch (TransformerException ex) {
       		 String errMesg = ex.getMessage();
@@ -648,7 +648,7 @@ public class ElemVariable extends ElemTemplateElement
        }
        else {
     	  try {
-             var = SequenceTypeSupport.convertXDMValueToAnotherType(var, m_asAttr, null, xctxt);
+             var = SequenceTypeSupport.convertXdmValueToAnotherType(var, m_asAttr, null, xctxt);
     	  }
     	  catch (TransformerException ex) {
     		 throw ex; 
diff --git a/src/org/apache/xalan/templates/ElemWithParam.java b/src/org/apache/xalan/templates/ElemWithParam.java
index 4d65e5c9..fd54bde0 100644
--- a/src/org/apache/xalan/templates/ElemWithParam.java
+++ b/src/org/apache/xalan/templates/ElemWithParam.java
@@ -271,7 +271,7 @@ public class ElemWithParam extends ElemTemplateElement
     }
     
     if (m_asAttr != null) {
-       var = SequenceTypeSupport.convertXDMValueToAnotherType(var, m_asAttr, null, 
+       var = SequenceTypeSupport.convertXdmValueToAnotherType(var, m_asAttr, null, 
                                                                           transformer.getXPathContext());
        if (var == null) {
           throw new TransformerException("XTTE0590 : The required item type of the value of argument used for xsl:with-param " + 
diff --git a/src/org/apache/xpath/compiler/FunctionTable.java b/src/org/apache/xpath/compiler/FunctionTable.java
index bfeb8b53..2ef6f68b 100644
--- a/src/org/apache/xpath/compiler/FunctionTable.java
+++ b/src/org/apache/xpath/compiler/FunctionTable.java
@@ -27,6 +27,7 @@ import java.util.List;
 import javax.xml.transform.TransformerException;
 
 import org.apache.xpath.functions.Function;
+import org.apache.xpath.functions.array.FuncSubarray;
 
 /**
  * The function table for XPath 3.1.
@@ -444,10 +445,30 @@ public class FunctionTable
   
   /** The 'map:entry()' id. */
   public static final int FUNC_MAP_ENTRY = 142;
-  
-  
+    
   /** The 'parse-json' id. */
   public static final int FUNC_PARSE_JSON = 143;
+  
+  /** The 'array:append()' id. */
+  public static final int FUNC_ARRAY_APPEND = 144;
+  
+  /** The 'array:subarray()' id. */
+  public static final int FUNC_ARRAY_SUBARRAY = 145;
+  
+  /** The 'array:remove()' id. */
+  public static final int FUNC_ARRAY_REMOVE = 146;
+  
+  /** The 'array:insert-before()' id. */
+  public static final int FUNC_ARRAY_INSERT_BEFORE = 147;
+  
+  /** The 'array:head()' id. */
+  public static final int FUNC_ARRAY_HEAD = 148;
+  
+  /** The 'array:tail()' id. */
+  public static final int FUNC_ARRAY_TAIL = 149;
+  
+  /** The 'array:reverse()' id. */
+  public static final int FUNC_ARRAY_REVERSE = 150;
 
   // Proprietary
 
@@ -492,7 +513,10 @@ public class FunctionTable
   public static final String XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI = "http://www.w3.org/2005/xpath-functions/array";
     
   static final Integer[] XPATH_ARRAY_FUNC_IDS = new Integer[] { new Integer(FUNC_ARRAY_SIZE), new Integer(FUNC_ARRAY_GET),
-		                                                        new Integer(FUNC_ARRAY_PUT) };
+		                                                        new Integer(FUNC_ARRAY_PUT), new Integer(FUNC_ARRAY_APPEND),
+		                                                        new Integer(FUNC_ARRAY_SUBARRAY), new Integer(FUNC_ARRAY_REMOVE),
+		                                                        new Integer(FUNC_ARRAY_INSERT_BEFORE),new Integer(FUNC_ARRAY_HEAD),
+		                                                        new Integer(FUNC_ARRAY_TAIL),new Integer(FUNC_ARRAY_REVERSE) };
   
   static final List<Integer> XPATH_ARRAY_FUNC_IDS_ARR = Arrays.asList(XPATH_ARRAY_FUNC_IDS);
   
@@ -532,7 +556,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 = 144;
+  private static final int NUM_BUILT_IN_FUNCS = 151;
 
   /**
    * Number of built-in functions that may be added.
@@ -775,6 +799,8 @@ public class FunctionTable
     m_functions[FUNC_ARRAY_SIZE] = org.apache.xpath.functions.array.FuncArraySize.class;
     m_functions[FUNC_ARRAY_GET] = org.apache.xpath.functions.array.FuncArrayGet.class;
     m_functions[FUNC_ARRAY_PUT] = org.apache.xpath.functions.array.FuncArrayPut.class;
+    m_functions[FUNC_ARRAY_APPEND] = org.apache.xpath.functions.array.FuncArrayAppend.class;
+    m_functions[FUNC_ARRAY_SUBARRAY] = org.apache.xpath.functions.array.FuncSubarray.class;
     
     // XPath 3.1 built-in functions configurations for the map 
     // functions namespace http://www.w3.org/2005/xpath-functions/map    
@@ -1054,6 +1080,10 @@ public class FunctionTable
                           new Integer(FunctionTable.FUNC_ARRAY_GET));
          m_functionID.put(Keywords.FUNC_ARRAY_PUT,
                           new Integer(FunctionTable.FUNC_ARRAY_PUT));
+         m_functionID.put(Keywords.FUNC_ARRAY_APPEND,
+                          new Integer(FunctionTable.FUNC_ARRAY_APPEND));
+         m_functionID.put(Keywords.FUNC_ARRAY_SUBARRAY,
+                          new Integer(FunctionTable.FUNC_ARRAY_SUBARRAY));
          
          // XPath 3.1 functions configurations for the map functions 
          // namespace http://www.w3.org/2005/xpath-functions/map
@@ -1089,7 +1119,7 @@ public class FunctionTable
                           new Integer(FunctionTable.FUNC_IN_SCOPE_PREFIXES));
          
          m_functionID.put(Keywords.FUNC_PARSE_JSON,
-                          new Integer(FunctionTable.FUNC_PARSE_JSON));         
+                          new Integer(FunctionTable.FUNC_PARSE_JSON));                  
   }
   
   public FunctionTable(){
diff --git a/src/org/apache/xpath/compiler/Keywords.java b/src/org/apache/xpath/compiler/Keywords.java
index 2e9b2b82..70b38dc6 100644
--- a/src/org/apache/xpath/compiler/Keywords.java
+++ b/src/org/apache/xpath/compiler/Keywords.java
@@ -587,6 +587,27 @@ public class Keywords
   /** parse-json function string. */
   public static final String FUNC_PARSE_JSON = "parse-json";
   
+  /** array:append function string. */
+  public static final String FUNC_ARRAY_APPEND = "append";
+  
+  /** array:subarray function string. */
+  public static final String FUNC_ARRAY_SUBARRAY = "subarray";
+  
+  /** array:remove function string. */
+  public static final String FUNC_ARRAY_REMOVE = "remove";
+  
+  /** array:insert-before function string. */
+  public static final String FUNC_ARRAY_INSERT_BEFORE = "insert-before";
+  
+  /** array:head function string. */
+  public static final String FUNC_ARRAY_HEAD = "head";
+  
+  /** array:tail function string. */
+  public static final String FUNC_ARRAY_TAIL = "tail";
+  
+  /** array:reverse function string. */
+  public static final String FUNC_ARRAY_REVERSE = "reverse";
+  
   // Proprietary, built in functions
 
   /** current function string (Proprietary). */
diff --git a/src/org/apache/xpath/composite/SequenceTypeSupport.java b/src/org/apache/xpath/composite/SequenceTypeSupport.java
index cc5e77dd..6ece7c06 100644
--- a/src/org/apache/xpath/composite/SequenceTypeSupport.java
+++ b/src/org/apache/xpath/composite/SequenceTypeSupport.java
@@ -194,7 +194,7 @@ public class SequenceTypeSupport {
     	XObject result = null;
     	
     	fPrefixTable = prefixTable;    	
-    	result = convertXDMValueToAnotherType(srcValue, sequenceTypeXPathExprStr, null, xctxt);
+    	result = convertXdmValueToAnotherType(srcValue, sequenceTypeXPathExprStr, null, xctxt);
     	
     	return result;
     }
@@ -203,11 +203,11 @@ public class SequenceTypeSupport {
      * This method, supports XPath implementation of "cast as" and 
      * "castable as" expressions.
      */
-    public static XObject castAsAnotherType(XObject srcValue, SequenceTypeData seqExpectedTypeDataInp) 
+    public static XObject castXdmValueToAnotherType(XObject srcValue, SequenceTypeData seqExpectedTypeDataInp) 
     		                                                                                throws TransformerException {
         XObject result = null;
     	
-        result = convertXDMValueToAnotherType(srcValue, null, seqExpectedTypeDataInp, null);
+        result = convertXdmValueToAnotherType(srcValue, null, seqExpectedTypeDataInp, null);
 
         return result;
     }
@@ -234,7 +234,7 @@ public class SequenceTypeSupport {
      *                                
      * @throws TransformerException 
      */
-    public static XObject convertXDMValueToAnotherType(XObject srcValue, String sequenceTypeXPathExprStr, 
+    public static XObject convertXdmValueToAnotherType(XObject srcValue, String sequenceTypeXPathExprStr, 
                                                                                        SequenceTypeData seqExpectedTypeDataInp, 
                                                                                        XPathContext xctxt) throws TransformerException {
         XObject result = null;
@@ -426,13 +426,13 @@ public class SequenceTypeSupport {
             else if (srcValue instanceof XSUntyped) {
                String srcStrVal = ((XSUntyped)srcValue).stringValue();
                // Recursive call to this function
-               result = convertXDMValueToAnotherType(new XSString(srcStrVal), sequenceTypeXPathExprStr, 
+               result = convertXdmValueToAnotherType(new XSString(srcStrVal), sequenceTypeXPathExprStr, 
                                                                                                     seqExpectedTypeDataInp, xctxt);
             }
             else if (srcValue instanceof XSUntypedAtomic) {
                String srcStrVal = ((XSUntypedAtomic)srcValue).stringValue();
                // Recursive call to this function
-               result = convertXDMValueToAnotherType(new XSString(srcStrVal), sequenceTypeXPathExprStr, 
+               result = convertXdmValueToAnotherType(new XSString(srcStrVal), sequenceTypeXPathExprStr, 
                                                                                                     seqExpectedTypeDataInp, xctxt);
             }
             else if (srcValue instanceof XNodeSetForDOM) {               
@@ -449,7 +449,7 @@ public class SequenceTypeSupport {
                ResultSequence srcResultSeq = (ResultSequence)srcValue;
                if (srcResultSeq.size() == 1) {
             	   // Recursive call to this function
-                   result = convertXDMValueToAnotherType(srcResultSeq.item(0), sequenceTypeXPathExprStr, seqExpectedTypeDataInp, xctxt);   
+                   result = convertXdmValueToAnotherType(srcResultSeq.item(0), sequenceTypeXPathExprStr, seqExpectedTypeDataInp, xctxt);   
                }
                else {
                    result = castResultSequenceInstance(srcValue, sequenceTypeXPathExprStr, seqExpectedTypeDataInp, xctxt, srcLocator, 
@@ -534,13 +534,13 @@ public class SequenceTypeSupport {
              			 }
              			 SequenceTypeData keySeqTypeData = sequenceTypeMapTest.getKeySequenceTypeData();
              			 SequenceTypeData valueSeqTypeData = sequenceTypeMapTest.getValueSequenceTypeData();
-             			 XObject mapKeyValTypeCheckResult = SequenceTypeSupport.convertXDMValueToAnotherType(mapKey, null, keySeqTypeData, xctxt);
+             			 XObject mapKeyValTypeCheckResult = SequenceTypeSupport.convertXdmValueToAnotherType(mapKey, null, keySeqTypeData, xctxt);
              			 String mapSequenceTypeStr = (sequenceTypeXPathExprStr != null) ? sequenceTypeXPathExprStr : "";
              			 if (mapKeyValTypeCheckResult == null) {             				
              				throw new TransformerException("XPTY0004 : XPath map entry key's [entry's key name: '" + keyStrVal + "'] value doesn't conform to the key's expected "
              						                                            + "type [map's sequenceType is '" + mapSequenceTypeStr + "']."); 
              			 }
-             			 XObject mapEntryValTypeCheckResult = SequenceTypeSupport.convertXDMValueToAnotherType(mapEntry, null, valueSeqTypeData, xctxt);
+             			 XObject mapEntryValTypeCheckResult = SequenceTypeSupport.convertXdmValueToAnotherType(mapEntry, null, valueSeqTypeData, xctxt);
              			 if (mapEntryValTypeCheckResult == null) {
              				throw new TransformerException("XPTY0004 : XPath map entry's [entry's key name: '" + keyStrVal + "'] value doesn't conform to the map entry value's expected "
              						                                            + "type [map's sequenceType is '" + mapSequenceTypeStr + "'].");  
@@ -567,11 +567,8 @@ public class SequenceTypeSupport {
              			 if (arrItem instanceof ResultSequence) {
              				arrItem = ((ResultSequence)arrItem).item(0);
              			 }
-             			 if (arrItem instanceof ResultSequence) {
-             				arrItem = ((ResultSequence)arrItem).item(0);
-             			 }
              			 SequenceTypeData arrayItemTypeInfo = sequenceTypeArrayTest.getArrayItemTypeInfo();
-             			 XObject arrayItemTypeCheckResult = SequenceTypeSupport.convertXDMValueToAnotherType(arrItem, null, arrayItemTypeInfo, xctxt);
+             			 XObject arrayItemTypeCheckResult = SequenceTypeSupport.convertXdmValueToAnotherType(arrItem, null, arrayItemTypeInfo, xctxt);
              			 String arrayItemSequenceTypeStr = (sequenceTypeXPathExprStr != null) ? sequenceTypeXPathExprStr : "";
              			 if (arrayItemTypeCheckResult == null) {             				
              				throw new TransformerException("XPTY0004 : One or more, of XPath array's item doesn't conform to array item's expected "
@@ -968,7 +965,7 @@ public class SequenceTypeSupport {
                     }
 
                     String nodeStrVal = node.getTextContent();
-                    XObject xObject = convertXDMValueToAnotherType(new XSString(nodeStrVal), sequenceTypeNewXPathExprStr, 
+                    XObject xObject = convertXdmValueToAnotherType(new XSString(nodeStrVal), sequenceTypeNewXPathExprStr, 
                                                                                                                       seqExpectedTypeDataInp, xctxt);                       
                     convertedResultSeq.add(xObject); 
                 }
@@ -1131,7 +1128,7 @@ public class SequenceTypeSupport {
                   if (!((xctxt == null) && ((seqExpectedTypeDataInp != null) && 
                                                                (seqExpectedTypeDataInp.getSequenceTypeKindTest() == null)))) {
                      String nodeStrVal = nodeSetItem.str();
-                     XObject xObject = convertXDMValueToAnotherType(new XSString(nodeStrVal), sequenceTypeNewXPathExprStr, 
+                     XObject xObject = convertXdmValueToAnotherType(new XSString(nodeStrVal), sequenceTypeNewXPathExprStr, 
                                                                                                                     seqExpectedTypeDataInp, xctxt);                       
                      convertedResultSeq.add(xObject);
                   }
@@ -1189,7 +1186,7 @@ public class SequenceTypeSupport {
             
             for (int idx = 0; idx < srcResultSeq.size(); idx++) {
                XObject seqItem = (XObject)(srcResultSeq.item(idx));                       
-               XObject convertedSeqItem = convertXDMValueToAnotherType(seqItem, sequenceTypeNewXPathExprStr, 
+               XObject convertedSeqItem = convertXdmValueToAnotherType(seqItem, sequenceTypeNewXPathExprStr, 
                                                                                                          seqExpectedTypeDataInp, xctxt);
                convertedResultSeq.add(convertedSeqItem);
             }
diff --git a/src/org/apache/xpath/functions/DynamicFunctionCall.java b/src/org/apache/xpath/functions/DynamicFunctionCall.java
index f1c42a52..a9722893 100644
--- a/src/org/apache/xpath/functions/DynamicFunctionCall.java
+++ b/src/org/apache/xpath/functions/DynamicFunctionCall.java
@@ -193,7 +193,7 @@ public class DynamicFunctionCall extends Expression {
 	              
 	              if (paramType != null) {
 	                  try {
-	                     argValue = SequenceTypeSupport.convertXDMValueToAnotherType(argValue, null, paramType, null);                     
+	                     argValue = SequenceTypeSupport.convertXdmValueToAnotherType(argValue, null, paramType, null);                     
 	                     if (argValue == null) {
 	                        throw new TransformerException("XTTE0505 : The item type of argument at position " + (idx + 1) + " of dynamic function call "
 	                                                                                                           + "$" + funcRefVarName + ", doesn't match "
@@ -230,7 +230,7 @@ public class DynamicFunctionCall extends Expression {
 	           SequenceTypeData funcReturnType = inlineFunction.getReturnType();
 	           if (funcReturnType != null) {
 	              try {
-	                 evalResult = SequenceTypeSupport.convertXDMValueToAnotherType(evalResult, null, funcReturnType, null);
+	                 evalResult = SequenceTypeSupport.convertXdmValueToAnotherType(evalResult, null, funcReturnType, null);
 	                 if (evalResult == null) {
 	                    throw new TransformerException("XTTE0505 : The item type of result of dynamic function call $"+ funcRefVarName + ", doesn't match an "
 	                                                                                                                                   + "expected type.", srcLocator);  
diff --git a/src/org/apache/xpath/functions/array/FuncArrayGet.java b/src/org/apache/xpath/functions/array/FuncArrayAppend.java
similarity index 50%
copy from src/org/apache/xpath/functions/array/FuncArrayGet.java
copy to src/org/apache/xpath/functions/array/FuncArrayAppend.java
index 9fe6826e..0f3a4419 100644
--- a/src/org/apache/xpath/functions/array/FuncArrayGet.java
+++ b/src/org/apache/xpath/functions/array/FuncArrayAppend.java
@@ -16,76 +16,67 @@
  */
 package org.apache.xpath.functions.array;
 
-import java.util.List;
-
 import javax.xml.transform.SourceLocator;
 
-import org.apache.xalan.templates.ElemCopyOf;
-import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xpath.Expression;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.functions.Function2Args;
-import org.apache.xpath.objects.ResultSequence;
-import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XObject;
 import org.apache.xpath.objects.XPathArray;
 import org.apache.xpath.operations.Variable;
 
 /**
- * Implementation of the array:get() function.
+ * Implementation of the array:append() function.
  * 
  * @author Mukul Gandhi <mu...@apache.org>
  * 
  * @xsl.usage advanced
  */
-public class FuncArrayGet extends Function2Args {
+public class FuncArrayAppend extends Function2Args {
 	
-	private static final long serialVersionUID = 9085303963460501516L;
+	private static final long serialVersionUID = -4710039738232164809L;
 
-	public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
-	{
+	public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
 	    XObject result = null;
 	       
 	    SourceLocator srcLocator = xctxt.getSAXLocator();
 	       
-	    Expression arg0 = getArg0();
-	    
-	    Expression arg1 = getArg1();
-	    
-	    ResultSequence arg0Seq = null;
-	    
-	    if (arg0 instanceof Variable) {
-	       XObject xObject = ((Variable)arg0).execute(xctxt);
-	       if (xObject instanceof XNodeSet) {
-	    	  // TO DO 
-	       }
-	       else if (xObject instanceof ResultSequence) {
-	    	  arg0Seq = (ResultSequence)xObject; 
-	       }
-	       else if (xObject instanceof XPathArray) {
-	    	  XPathArray xpathArr = (XPathArray)xObject;
-	    	  List<XObject> nativeArr = xpathArr.getNativeArray();
-	    	  arg0Seq = ElemCopyOf.getResultSequenceFromXPathArray(nativeArr);
+	    Expression arg0Expr = getArg0();	    
+	    Expression arg1Expr = getArg1();
+
+	    XPathArray xpathArr = null;
+	    if (arg0Expr instanceof Variable) {
+	       XObject xdmInputArr = ((Variable)arg0Expr).execute(xctxt);
+	       if (xdmInputArr instanceof XPathArray) {
+	    	  xpathArr = (XPathArray)xdmInputArr;
 	       }
 	       else {
-	    	  // TO DO  
+	    	  throw new javax.xml.transform.TransformerException("FORG0006 : The 1st argument of array:append function call, "
+                                                                                              + "needs to be an xdm array", srcLocator); 
 	       }
 	    }
 	    else {
-	       // TO DO
+	       XObject xdmInputArr = arg0Expr.execute(xctxt);
+		   if (xdmInputArr instanceof XPathArray) {
+		      xpathArr = (XPathArray)xdmInputArr;
+		   }
+		   else {
+			  throw new javax.xml.transform.TransformerException("FORG0006 : The 1st argument of array:append function call, "
+                                                                                              + "needs to be an xdm array", srcLocator);	   
+		   }
 	    }
 	    
-	    if (arg1 instanceof Variable) {
-	       XObject arg1XObj = ((Variable)arg1).execute(xctxt);
-	       String arg1Str = XslTransformEvaluationHelper.getStrVal(arg1XObj);
-	       result = arg0Seq.item((Integer.valueOf(arg1Str)).intValue() - 1);
+	    if (arg1Expr instanceof Variable) {
+	       XObject arg1XObj = ((Variable)arg1Expr).execute(xctxt);
+	       xpathArr.add(arg1XObj);
 	    }
 	    else {
-	       XObject arg1XObj = arg1.execute(xctxt);
-		   String arg1Str = XslTransformEvaluationHelper.getStrVal(arg1XObj);
-		   result = arg0Seq.item((Integer.valueOf(arg1Str)).intValue() - 1);
+	       XObject arg1XObj = arg1Expr.execute(xctxt);
+	       xpathArr.add(arg1XObj);
 	    }
 	    
+	    result = xpathArr;
+	    
 	    return result;
 	}
 
diff --git a/src/org/apache/xpath/functions/array/FuncArrayGet.java b/src/org/apache/xpath/functions/array/FuncArrayGet.java
index 9fe6826e..7231ce10 100644
--- a/src/org/apache/xpath/functions/array/FuncArrayGet.java
+++ b/src/org/apache/xpath/functions/array/FuncArrayGet.java
@@ -19,6 +19,7 @@ package org.apache.xpath.functions.array;
 import java.util.List;
 
 import javax.xml.transform.SourceLocator;
+import javax.xml.transform.TransformerException;
 
 import org.apache.xalan.templates.ElemCopyOf;
 import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
@@ -26,11 +27,13 @@ import org.apache.xpath.Expression;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.functions.Function2Args;
 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.XPathArray;
 import org.apache.xpath.operations.Variable;
 
+import xml.xpath31.processor.types.XSNumericType;
+
 /**
  * Implementation of the array:get() function.
  * 
@@ -42,51 +45,84 @@ public class FuncArrayGet extends Function2Args {
 	
 	private static final long serialVersionUID = 9085303963460501516L;
 
-	public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
-	{
+	public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
+		
 	    XObject result = null;
 	       
 	    SourceLocator srcLocator = xctxt.getSAXLocator();
 	       
-	    Expression arg0 = getArg0();
-	    
-	    Expression arg1 = getArg1();
+	    Expression arg0Expr = getArg0();	    
+	    Expression arg1Expr = getArg1();	    	    
 	    
 	    ResultSequence arg0Seq = null;
-	    
-	    if (arg0 instanceof Variable) {
-	       XObject xObject = ((Variable)arg0).execute(xctxt);
-	       if (xObject instanceof XNodeSet) {
-	    	  // TO DO 
-	       }
-	       else if (xObject instanceof ResultSequence) {
-	    	  arg0Seq = (ResultSequence)xObject; 
-	       }
-	       else if (xObject instanceof XPathArray) {
-	    	  XPathArray xpathArr = (XPathArray)xObject;
-	    	  List<XObject> nativeArr = xpathArr.getNativeArray();
-	    	  arg0Seq = ElemCopyOf.getResultSequenceFromXPathArray(nativeArr);
+	    if (arg0Expr instanceof Variable) {
+	       XObject arg0Value = ((Variable)arg0Expr).execute(xctxt);
+	       if (arg0Value instanceof XPathArray) {
+	          arg0Seq = getArg0Seq((XPathArray)arg0Value, srcLocator);
 	       }
 	       else {
-	    	  // TO DO  
+	    	  throw new javax.xml.transform.TransformerException("FORG0006 : The 1st argument of array:get function call, "
+	    	  		                                                                      + "needs to be an xdm array", srcLocator);  
 	       }
 	    }
 	    else {
-	       // TO DO
+	    	XObject arg0Value = arg0Expr.execute(xctxt);
+	    	if (arg0Value instanceof XPathArray) {
+		       arg0Seq = getArg0Seq((XPathArray)arg0Value, srcLocator);
+		    }
+		    else {
+		       throw new javax.xml.transform.TransformerException("FORG0006 : The 1st argument of array:get function call, "
+		       		                                                                      + "needs to be an xdm array", srcLocator);   
+		    }
 	    }
 	    
-	    if (arg1 instanceof Variable) {
-	       XObject arg1XObj = ((Variable)arg1).execute(xctxt);
-	       String arg1Str = XslTransformEvaluationHelper.getStrVal(arg1XObj);
-	       result = arg0Seq.item((Integer.valueOf(arg1Str)).intValue() - 1);
+	    XObject arg1 = null;	    
+	    if (arg1Expr instanceof Variable) {
+	       arg1 = ((Variable)arg1Expr).execute(xctxt);
+	       if ((arg1 instanceof XSNumericType) || (arg1 instanceof XNumber)) {
+	    	  result = getFuncResult(arg0Seq, arg1, srcLocator);   
+	       }
+	       else {
+	    	  throw new javax.xml.transform.TransformerException("FOAY0001 : The 2nd argument of array:get function "
+	    	  		                                                    + "call, needs to be an xs:integer value", srcLocator); 
+	       }
 	    }
 	    else {
-	       XObject arg1XObj = arg1.execute(xctxt);
-		   String arg1Str = XslTransformEvaluationHelper.getStrVal(arg1XObj);
-		   result = arg0Seq.item((Integer.valueOf(arg1Str)).intValue() - 1);
+	       arg1 = arg1Expr.execute(xctxt);
+	       if ((arg1 instanceof XSNumericType) || (arg1 instanceof XNumber)) {
+		      result = getFuncResult(arg0Seq, arg1, srcLocator);   
+		   }
+		   else {
+			  throw new javax.xml.transform.TransformerException("FOAY0001 : The 2nd argument of array:get function "
+                                                                         + "call, needs to be an xs:integer value", srcLocator);	   
+		   }
 	    }
 	    
 	    return result;
 	}
 
+	/**
+	 * Get the value of array:get function's first argument, as ResultSequence object.
+	 */
+	private ResultSequence getArg0Seq(XPathArray arg0Value, SourceLocator srcLocator) {
+		ResultSequence arg0Seq = null;
+
+	    List<XObject> nativeArr = arg0Value.getNativeArray();
+	    arg0Seq = ElemCopyOf.getResultSequenceFromXPathArray(nativeArr);
+		
+		return arg0Seq;
+	}
+	
+	/**
+	 * Get the result of array:get function call. 
+	 */
+	private XObject getFuncResult(ResultSequence arg0Seq, XObject arg1, SourceLocator srcLocator) 			                                                                                   throws TransformerException {
+		XObject result = null;
+		
+	    String secondArgStr = XslTransformEvaluationHelper.getStrVal(arg1);
+		result = arg0Seq.item((Integer.valueOf(secondArgStr)).intValue() - 1);
+		
+		return result;
+	}
+
 }
diff --git a/src/org/apache/xpath/functions/array/FuncArrayPut.java b/src/org/apache/xpath/functions/array/FuncArrayPut.java
index afad259b..826a3aff 100644
--- a/src/org/apache/xpath/functions/array/FuncArrayPut.java
+++ b/src/org/apache/xpath/functions/array/FuncArrayPut.java
@@ -20,17 +20,17 @@ import java.util.List;
 
 import javax.xml.transform.SourceLocator;
 
-import org.apache.xalan.templates.ElemCopyOf;
 import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xpath.Expression;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.functions.Function3Args;
-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.XPathArray;
 import org.apache.xpath.operations.Variable;
 
+import xml.xpath31.processor.types.XSNumericType;
+
 /**
  * Implementation of the array:put() function.
  * 
@@ -48,52 +48,77 @@ public class FuncArrayPut extends Function3Args {
 	       
 	    SourceLocator srcLocator = xctxt.getSAXLocator();
 	       
-	    Expression arg0 = getArg0();	    
-	    Expression arg1 = getArg1();	    
-	    Expression arg2 = getArg2();
+	    Expression arg0Expr = getArg0();	    
+	    Expression arg1Expr = getArg1();	    
+	    Expression arg2Expr = getArg2();
 	    
-	    ResultSequence arg0Seq = null;	    
-	    XObject arg1XObj = null;	    
-	    XObject arg2XObj = null;
+	    XPathArray arg0XPathArr = null;
 	    
-	    if (arg0 instanceof Variable) {
-	       XObject xObject = ((Variable)arg0).execute(xctxt);
-	       if (xObject instanceof XNodeSet) {
-	    	  // TO DO 
-	       }
-	       else if (xObject instanceof ResultSequence) {
-	    	  arg0Seq = (ResultSequence)xObject; 
-	       }
-	       else if (xObject instanceof XPathArray) {
-		      XPathArray xpathArr = (XPathArray)xObject;
-		      List<XObject> nativeArr = xpathArr.getNativeArray();
-		      arg0Seq = ElemCopyOf.getResultSequenceFromXPathArray(nativeArr);
+	    List<XObject> nativeArr = null;	    
+	    if (arg0Expr instanceof Variable) {
+	       XObject xObject = ((Variable)arg0Expr).execute(xctxt);
+	       if (xObject instanceof XPathArray) {
+	    	  arg0XPathArr = (XPathArray)xObject;
+		      nativeArr = arg0XPathArr.getNativeArray();
 		   }
 	       else {
-	    	  // TO DO  
+	    	   throw new javax.xml.transform.TransformerException("FORG0006 : The 1st argument of array:put function call, "
+                                                                         + "needs to be an xdm array", srcLocator);   
 	       }
 	    }
 	    else {
-	       // TO DO
+	    	XObject xObject = arg0Expr.execute(xctxt);
+		    if (xObject instanceof XPathArray) {
+		       arg0XPathArr = (XPathArray)xObject;
+			   nativeArr = arg0XPathArr.getNativeArray();
+			}
+		    else {
+		       throw new javax.xml.transform.TransformerException("FORG0006 : The 1st argument of array:put function call, "
+	                                                                         + "needs to be an xdm array", srcLocator);   
+		    }
 	    }
 	    
-	    if (arg1 instanceof Variable) {
-	       arg1XObj = ((Variable)arg1).execute(xctxt);
+	    XObject arg1XObj = null;
+	    if (arg1Expr instanceof Variable) {
+	       arg1XObj = ((Variable)arg1Expr).execute(xctxt);
+	       if (!((arg1XObj instanceof XSNumericType) || (arg1XObj instanceof XNumber))) {
+	    	  throw new javax.xml.transform.TransformerException("FOAY0001 : The 2nd argument of array:put function "
+                                                                                               + "call, needs to be an xs:integer value", srcLocator); 
+	       }
 	    }
 	    else {
-	       arg1XObj = arg1.execute(xctxt);
+	       arg1XObj = arg1Expr.execute(xctxt);
+	       if (!((arg1XObj instanceof XSNumericType) || (arg1XObj instanceof XNumber))) {
+		      throw new javax.xml.transform.TransformerException("FOAY0001 : The 2nd argument of array:put function "
+	                                                                                           + "call, needs to be an xs:integer value", srcLocator); 
+		   }
 	    }
 	    
-	    if (arg2 instanceof Variable) {
-		   arg2XObj = ((Variable)arg2).execute(xctxt);
+	    XObject arg2XObj = null;
+	    if (arg2Expr instanceof Variable) {
+		   arg2XObj = ((Variable)arg2Expr).execute(xctxt);
 		}
 		else {
-		   arg2XObj = arg2.execute(xctxt);
+		   arg2XObj = arg2Expr.execute(xctxt);
 		}
 	    
-	    arg0Seq.set(Integer.valueOf(XslTransformEvaluationHelper.getStrVal(arg1XObj)) - 1, arg2XObj);
+	    int arg1Int;	    
+	    try {
+	       arg1Int = Integer.valueOf(XslTransformEvaluationHelper.getStrVal(arg1XObj));
+	       int inpArrSize = nativeArr.size();
+	       if ((arg1Int < 1) || (arg1Int > inpArrSize)) {
+	    	   throw new javax.xml.transform.TransformerException("FOAY0001 : The 2nd argument of array:put function all, needs to be "
+	    	   		                                                       + "an xs:integer value in the range 1 to array:size($array) inclusive", srcLocator);  
+	       }	       
+	    }
+	    catch (NumberFormatException ex) {
+	       throw new javax.xml.transform.TransformerException("FOAY0001 : The 2nd argument of array:put function "
+                                                                      + "call, needs to be an xs:integer value", srcLocator); 
+	    }
+	    
+	    nativeArr.set(arg1Int - 1, arg2XObj);
 	    
-	    result = arg0Seq;
+	    result = arg0XPathArr;
 	    
 	    return result;
 	}
diff --git a/src/org/apache/xpath/functions/array/FuncSubarray.java b/src/org/apache/xpath/functions/array/FuncSubarray.java
new file mode 100644
index 00000000..91ffac4e
--- /dev/null
+++ b/src/org/apache/xpath/functions/array/FuncSubarray.java
@@ -0,0 +1,151 @@
+/*
+ * 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.
+ */
+package org.apache.xpath.functions.array;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.functions.FunctionMultiArgs;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XPathArray;
+import org.apache.xpath.operations.Variable;
+
+import xml.xpath31.processor.types.XSNumericType;
+
+/**
+ * Implementation of the array:subarray() function.
+ * 
+ * @author Mukul Gandhi <mu...@apache.org>
+ * 
+ * @xsl.usage advanced
+ */
+public class FuncSubarray extends FunctionMultiArgs {
+
+	private static final long serialVersionUID = 8678849210209571670L;
+
+	public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
+	    
+		XObject result = null;
+	       
+	    SourceLocator srcLocator = xctxt.getSAXLocator();
+	       
+	    Expression arg0Expr = getArg0();	    
+	    Expression arg1Expr = getArg1();
+	    Expression arg2Expr = getArg2();
+	    
+	    if ((arg0Expr == null) || (arg1Expr == null)) {
+	        throw new javax.xml.transform.TransformerException("FORG0006 : An array:subarray function call must have "
+	        		                                                  + "first two arguments.", srcLocator); 
+	    }
+
+	    XPathArray arg0XPathArr = null;	    
+	    if (arg0Expr instanceof Variable) {
+	       XObject xdmInputArr = ((Variable)arg0Expr).execute(xctxt);
+	       if (xdmInputArr instanceof XPathArray) {
+	    	  arg0XPathArr = (XPathArray)xdmInputArr;
+	       }
+	       else {
+	    	  throw new javax.xml.transform.TransformerException("FORG0006 : The 1st argument of array:subarray function call, "
+                                                                                              + "needs to be an xdm array.", srcLocator); 
+	       }
+	    }
+	    else {
+	       XObject xdmInputArr = arg0Expr.execute(xctxt);
+		   if (xdmInputArr instanceof XPathArray) {
+			   arg0XPathArr = (XPathArray)xdmInputArr;
+		   }
+		   else {
+			  throw new javax.xml.transform.TransformerException("FORG0006 : The 1st argument of array:subarray function call, "
+                                                                                              + "needs to be an xdm array.", srcLocator);	   
+		   }
+	    }
+	    
+	    XObject arg1XObj = null;
+	    if (arg1Expr instanceof Variable) {
+	       arg1XObj = ((Variable)arg1Expr).execute(xctxt);	       
+	    }
+	    else {
+	       arg1XObj = arg1Expr.execute(xctxt);	       
+	    }
+	    
+	    int arg1Int = -1;
+	    if ((arg1XObj instanceof XSNumericType) || (arg1XObj instanceof XNumber)) {
+	       String arg1StrVal = XslTransformEvaluationHelper.getStrVal(arg1XObj);
+	       try {
+	          arg1Int = (Integer.valueOf(arg1StrVal)).intValue();
+	       }
+	       catch (NumberFormatException ex) {
+	    	  throw new javax.xml.transform.TransformerException("FORG0006 : The 2nd argument of function call array:subarray is not "
+	    	  		                                                           + "an xs:integer value.", srcLocator); 
+	       }
+	       
+	       if ((arg1Int < 1) || (arg1Int > arg0XPathArr.size())) {
+	    	  throw new javax.xml.transform.TransformerException("FORG0006 : The 2nd argument of function call array:subarray must not "
+	    	  		                                                           + "be less than 1 or greater than size of input array.", srcLocator); 
+	       }
+	    }
+	    else {
+	       throw new javax.xml.transform.TransformerException("FORG0006 : The 2nd argument of function call array:subarray is not "
+	       		                                                                        + "numeric.", srcLocator);
+	    }
+	    
+	    XPathArray resultArray = new XPathArray();
+	    
+	    int arg2Int = -1;
+	    if (arg2Expr != null) {
+	       XObject arg2XObj = arg2Expr.execute(xctxt);
+	       if ((arg2XObj instanceof XSNumericType) || (arg2XObj instanceof XNumber)) {
+		      String arg2StrVal = XslTransformEvaluationHelper.getStrVal(arg2XObj);
+		      try {
+		    	 arg2Int = (Integer.valueOf(arg2StrVal)).intValue();
+		      }
+		      catch (NumberFormatException ex) {
+		    	 throw new javax.xml.transform.TransformerException("FORG0006 : The 3rd argument provided to function call array:subarray is not "
+		    	  		                                                                              + "an xs:integer value.", srcLocator); 
+		      }
+		   }
+	       else {
+		      throw new javax.xml.transform.TransformerException("FORG0006 : The 3rd argument present on function call array:subarray "
+		      		                                                                        + "is not numeric.", srcLocator);
+		   }
+	       
+	       int resultItemCount = 0;
+	       for (int idx = (arg1Int - 1); idx < arg0XPathArr.size(); idx++) {
+	    	  if ((++resultItemCount) <= arg2Int) {
+		         resultArray.add(arg0XPathArr.get(idx));
+	    	  }
+	    	  else {
+	    		 break;  
+	    	  }
+		   }
+	    }
+	    else {	       
+	       for (int idx = (arg1Int - 1); idx < arg0XPathArr.size(); idx++) {
+			  resultArray.add(arg0XPathArr.get(idx)); 
+		   }
+	    }
+	    
+	    result = resultArray;
+	    
+	    
+	    return result;
+	}
+
+}
diff --git a/src/org/apache/xpath/objects/XPathArray.java b/src/org/apache/xpath/objects/XPathArray.java
index c7e8842e..8d34e8aa 100644
--- a/src/org/apache/xpath/objects/XPathArray.java
+++ b/src/org/apache/xpath/objects/XPathArray.java
@@ -52,7 +52,7 @@ public class XPathArray extends XObject {
    }
    
    /**
-    * Appending a value, to an array.
+    * Append an xdm item, to an array.
     */
    public void add(XObject value) {
 	  fList.add(value);  
@@ -89,6 +89,10 @@ public class XPathArray extends XObject {
        return (fList.size() > 0);       
    }
    
+   public void reset() {
+	   fList.clear(); 
+   }
+   
    /**
     * Get the string value of this XPathArray object.
     * 
diff --git a/src/org/apache/xpath/operations/CastAs.java b/src/org/apache/xpath/operations/CastAs.java
index 232560a3..51a31e0b 100644
--- a/src/org/apache/xpath/operations/CastAs.java
+++ b/src/org/apache/xpath/operations/CastAs.java
@@ -53,7 +53,7 @@ public class CastAs extends Operation
       
       SequenceTypeData seqTypedData = (SequenceTypeData)right;
       
-      result = SequenceTypeSupport.castAsAnotherType(left, seqTypedData);
+      result = SequenceTypeSupport.castXdmValueToAnotherType(left, seqTypedData);
       
       return result;
   }
diff --git a/src/org/apache/xpath/operations/CastableAs.java b/src/org/apache/xpath/operations/CastableAs.java
index ae2744e2..cec524c8 100644
--- a/src/org/apache/xpath/operations/CastableAs.java
+++ b/src/org/apache/xpath/operations/CastableAs.java
@@ -56,7 +56,7 @@ public class CastableAs extends Operation
       SequenceTypeData seqTypedData = (SequenceTypeData)right;
       
       try {
-         result = SequenceTypeSupport.castAsAnotherType(left, seqTypedData);
+         result = SequenceTypeSupport.castXdmValueToAnotherType(left, seqTypedData);
          if (result != null) {
         	result = new XSBoolean(true); 
          }
diff --git a/src/org/apache/xpath/operations/InstanceOf.java b/src/org/apache/xpath/operations/InstanceOf.java
index c38a529d..b77078fa 100644
--- a/src/org/apache/xpath/operations/InstanceOf.java
+++ b/src/org/apache/xpath/operations/InstanceOf.java
@@ -21,10 +21,14 @@
 package org.apache.xpath.operations;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
+import javax.xml.transform.TransformerException;
+
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMIterator;
+import org.apache.xpath.composite.SequenceTypeArrayTest;
 import org.apache.xpath.composite.SequenceTypeData;
 import org.apache.xpath.composite.SequenceTypeKindTest;
 import org.apache.xpath.composite.SequenceTypeSupport;
@@ -34,6 +38,7 @@ import org.apache.xpath.objects.XBoolean;
 import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XPathArray;
 import org.apache.xpath.objects.XString;
 
 import xml.xpath31.processor.types.XSAnyURI;
@@ -102,226 +107,295 @@ public class InstanceOf extends Operation
    * This method checks whether, an xdm value is an instance of 
    * a specific type.
    */
-  private boolean isInstanceOf(XObject xdmValue, SequenceTypeData seqTypedData) {
+  private boolean isInstanceOf(XObject xdmValue, SequenceTypeData seqTypeData) {
     
     boolean isInstanceOf = false;
       
     if ((xdmValue instanceof XSUntypedAtomic) && 
-          (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_UNTYPED_ATOMIC)) {
+          (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_UNTYPED_ATOMIC)) {
           isInstanceOf = true;  
       }
       else if ((xdmValue instanceof XSUntyped) && 
-              (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_UNTYPED)) {
+              (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_UNTYPED)) {
           isInstanceOf = true;
       }
       else if ((xdmValue instanceof XString || xdmValue instanceof XSString) && 
-              ((seqTypedData.getSequenceType() == SequenceTypeSupport.STRING) || (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+              ((seqTypeData.getSequenceType() == SequenceTypeSupport.STRING) || (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSNormalizedString) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_NORMALIZED_STRING) || 
-    		                                                (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSNormalizedString) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_NORMALIZED_STRING) || 
+    		                                                (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSToken) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_TOKEN) || 
-    		                                     (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSToken) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_TOKEN) || 
+    		                                     (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSAnyURI) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_URI) || 
-    		                                      (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSAnyURI) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_URI) || 
+    		                                      (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSQName) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_QNAME) || 
-                                                 (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSQName) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_QNAME) || 
+                                                 (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if (((xdmValue instanceof XBoolean) || (xdmValue instanceof XSBoolean)) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.BOOLEAN) || 
-    		                                                                           (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if (((xdmValue instanceof XBoolean) || (xdmValue instanceof XSBoolean)) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.BOOLEAN) || 
+    		                                                                           (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
       else if (xdmValue instanceof XNumber) {          
-          if ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_DOUBLE) || (seqTypedData.getSequenceType() == 
+          if ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_DOUBLE) || (seqTypeData.getSequenceType() == 
         		                                                                    SequenceTypeSupport.XS_DECIMAL) || 
-        		                                                          (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE)) {
+        		                                                          (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE)) {
              isInstanceOf = true; 
           }
           else {
              double doubleVal = ((XNumber)xdmValue).num();
-             if ((doubleVal == (int)doubleVal) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_INTEGER) || 
-                                                   (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_LONG) ||
-                                                   (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_INT) || 
-                                                   (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+             if ((doubleVal == (int)doubleVal) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_INTEGER) || 
+                                                   (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_LONG) ||
+                                                   (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_INT) || 
+                                                   (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
                  isInstanceOf = true; 
              }
           }
       }
-      else if ((xdmValue instanceof XSDouble) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_DOUBLE) || 
-    		                                      (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSDouble) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_DOUBLE) || 
+    		                                      (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
          isInstanceOf = true; 
       }
-      else if ((xdmValue instanceof XSFloat) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_FLOAT) || 
-    		                                     (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSFloat) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_FLOAT) || 
+    		                                     (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSInt) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_INT) || 
-    		                                   (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSInt) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_INT) || 
+    		                                   (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSLong) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_LONG) || 
-    		                                    (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSLong) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_LONG) || 
+    		                                    (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSInteger) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_INTEGER) || 
-    		                                       (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSInteger) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_INTEGER) || 
+    		                                       (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSDecimal) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_DECIMAL) || 
-    		                                       (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSDecimal) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_DECIMAL) || 
+    		                                       (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSDate) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_DATE) || 
-    		                                    (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSDate) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_DATE) || 
+    		                                    (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSDateTime) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_DATETIME) || 
-    		                                        (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSDateTime) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_DATETIME) || 
+    		                                        (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSTime) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_TIME) || 
-    		                                    (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSTime) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_TIME) || 
+    		                                    (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSDuration) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_DURATION) || 
-    		                                        (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSDuration) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_DURATION) || 
+    		                                        (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSDayTimeDuration) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_DAYTIME_DURATION) || 
-    		                                               (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSDayTimeDuration) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_DAYTIME_DURATION) || 
+    		                                               (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
-      else if ((xdmValue instanceof XSYearMonthDuration) && ((seqTypedData.getSequenceType() == SequenceTypeSupport.XS_YEARMONTH_DURATION) || 
-    		                                                 (seqTypedData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
+      else if ((xdmValue instanceof XSYearMonthDuration) && ((seqTypeData.getSequenceType() == SequenceTypeSupport.XS_YEARMONTH_DURATION) || 
+    		                                                 (seqTypeData.getSequenceType() == SequenceTypeSupport.XS_ANY_ATOMIC_TYPE))) {
           isInstanceOf = true;
       }
       else if (xdmValue instanceof XNodeSet) {
-          XNodeSet xdmNodeSet = (XNodeSet)xdmValue;          
-          int nodeSetLen = xdmNodeSet.getLength();          
-          int itemTypeOccurenceIndicator = seqTypedData.getItemTypeOccurrenceIndicator();
-          SequenceTypeKindTest seqTypeKindTest = seqTypedData.getSequenceTypeKindTest();
-          
-          if ((nodeSetLen > 1) && ((itemTypeOccurenceIndicator == 0) || (itemTypeOccurenceIndicator == OccurenceIndicator.ZERO_OR_ONE))) {
-             isInstanceOf = false; 
-          }
-          else {
-             DTMIterator dtmIter = xdmNodeSet.iterRaw();
-                          
-             List<Boolean> nodeSetSequenceTypeKindTestResultList = new ArrayList<Boolean>();
-             
-             int nextNodeDtmHandle;
-             while ((nextNodeDtmHandle = dtmIter.nextNode()) != DTM.NULL) {                 
-                 DTM dtm = dtmIter.getDTM(nextNodeDtmHandle);
-                 java.lang.String nodeName = dtm.getNodeName(nextNodeDtmHandle);
-                 java.lang.String nodeNsUri = dtm.getNamespaceURI(nextNodeDtmHandle);
-                 
-                 if (dtm.getNodeType(nextNodeDtmHandle) == DTM.ELEMENT_NODE) {
-                    if (seqTypeKindTest != null) {
-                       java.lang.String elemNodeKindTestNodeName = seqTypeKindTest.getNodeLocalName();
-                       if (elemNodeKindTestNodeName == null || "".equals(elemNodeKindTestNodeName) || 
-                                                                      SequenceTypeSupport.STAR.equals(elemNodeKindTestNodeName)) {
-                           elemNodeKindTestNodeName = nodeName;  
-                       }
-                       
-                       if ((seqTypeKindTest.getKindVal() == SequenceTypeSupport.ELEMENT_KIND) && (nodeName.equals(elemNodeKindTestNodeName)) 
-                                                    && (SequenceTypeSupport.isTwoXmlNamespacesEqual(nodeNsUri, seqTypeKindTest.getNodeNsUri()))) {
-                           nodeSetSequenceTypeKindTestResultList.add(Boolean.valueOf(true));  
-                       }
-                       else if ((seqTypeKindTest.getKindVal() == SequenceTypeSupport.NODE_KIND) || 
-                                (seqTypeKindTest.getKindVal() == SequenceTypeSupport.ITEM_KIND)) {
-                           nodeSetSequenceTypeKindTestResultList.add(Boolean.valueOf(true)); 
-                       }
-                    }
-                    else {
-                       isInstanceOf = false;
-                       break;
-                    }
-                 }
-                 else if (dtm.getNodeType(nextNodeDtmHandle) == DTM.ATTRIBUTE_NODE) {
-                    if (seqTypeKindTest != null) {
-                       java.lang.String attrNodeKindTestNodeName = seqTypeKindTest.getNodeLocalName();
-                       if (attrNodeKindTestNodeName == null || "".equals(attrNodeKindTestNodeName) || 
-                                                               SequenceTypeSupport.STAR.equals(attrNodeKindTestNodeName)) {
-                           attrNodeKindTestNodeName = nodeName;  
-                       }
-                        
-                       if ((seqTypeKindTest.getKindVal() == SequenceTypeSupport.ATTRIBUTE_KIND) && (nodeName.equals(attrNodeKindTestNodeName)) 
-                                                                                       && (SequenceTypeSupport.isTwoXmlNamespacesEqual(
-                                                                                    		               nodeNsUri, seqTypeKindTest.getNodeNsUri()))) {
-                           nodeSetSequenceTypeKindTestResultList.add(Boolean.valueOf(true));    
-                       }
-                       else if ((seqTypeKindTest.getKindVal() == SequenceTypeSupport.NODE_KIND) || 
-                    		    (seqTypeKindTest.getKindVal() == SequenceTypeSupport.ITEM_KIND)) {
-                           nodeSetSequenceTypeKindTestResultList.add(Boolean.valueOf(true));   
-                       }   
-                    }
-                    else {
-                       isInstanceOf = false;
-                       break;
-                    } 
-                 }
-                 else if (dtm.getNodeType(nextNodeDtmHandle) == DTM.TEXT_NODE) {
-                    if (seqTypeKindTest.getKindVal() == SequenceTypeSupport.TEXT_KIND) {
-                       nodeSetSequenceTypeKindTestResultList.add(Boolean.valueOf(true)); 
-                    }
-                 }
-                 else if (dtm.getNodeType(nextNodeDtmHandle) == DTM.NAMESPACE_NODE) {
-                    if (seqTypeKindTest.getKindVal() == SequenceTypeSupport.NAMESPACE_NODE_KIND) {
-                       nodeSetSequenceTypeKindTestResultList.add(Boolean.valueOf(true)); 
-                    }
-                 }
-             }
-             
-             if (nodeSetSequenceTypeKindTestResultList.size() > 0 && (nodeSetSequenceTypeKindTestResultList.size() == nodeSetLen)) {
-                isInstanceOf = true; 
-             }
-          }
+          isInstanceOf = checkXdmNodesetWithType(xdmValue, seqTypeData);
       }
       else if (xdmValue instanceof ResultSequence) {
-          ResultSequence srcResultSeq = (ResultSequence)xdmValue;
-          
-          int seqLen = srcResultSeq.size();
-          
-          if ((seqLen == 0) && (seqTypedData.getItemTypeOccurrenceIndicator() == OccurenceIndicator.ONE_OR_MANY)) {
-             isInstanceOf = false;  
-          }
-          else if ((seqLen > 0) && (seqTypedData.getSequenceType() == SequenceTypeSupport.EMPTY_SEQUENCE)) {
-             isInstanceOf = false;  
-          }
-          else if ((seqLen > 1) && (seqTypedData.getItemTypeOccurrenceIndicator() == OccurenceIndicator.ZERO_OR_ONE)) {
-             isInstanceOf = false;
-          }
-          
-          SequenceTypeData sequenceTypeDataNew = new SequenceTypeData();          
-          if (seqTypedData.getSequenceTypeKindTest() != null) {
-             sequenceTypeDataNew.setSequenceTypeKindTest(seqTypedData.getSequenceTypeKindTest()); 
-          }
-          else {
-             sequenceTypeDataNew.setSequenceType(seqTypedData.getSequenceType()); 
-          }
-          
-          boolean isInstanceOfOnSeqItem = true;
-          
-          for (int idx = 0; idx < srcResultSeq.size(); idx++) {
-             XObject seqItem = (XObject)(srcResultSeq.item(idx));
-             // Recursive call to this function
-             if (!isInstanceOf(seqItem, sequenceTypeDataNew)) {
-                isInstanceOfOnSeqItem = false;
-                break;
-             }
-          }
-          
-          isInstanceOf = isInstanceOfOnSeqItem; 
-      }
+          isInstanceOf = checkXdmSequenceWithType(xdmValue, seqTypeData); 
+      }    
+      else if (xdmValue instanceof XPathArray) {
+    	  isInstanceOf = isInstanceOfArray(xdmValue, seqTypeData);
+     }
     
-      return isInstanceOf;
+     return isInstanceOf;
+  }
+
+  /**
+   * Check whether, an xdm node set conforms to xpath sequence type information.
+   */
+  private boolean checkXdmNodesetWithType(XObject xdmValue, SequenceTypeData seqTypeData) {
+	
+	  boolean isInstanceOf = false;
+
+	  XNodeSet xdmNodeSet = (XNodeSet)xdmValue;          
+	  int nodeSetLen = xdmNodeSet.getLength();          
+	  int itemTypeOccurenceIndicator = seqTypeData.getItemTypeOccurrenceIndicator();
+	  SequenceTypeKindTest seqTypeKindTest = seqTypeData.getSequenceTypeKindTest();
+
+	  if ((nodeSetLen > 1) && ((itemTypeOccurenceIndicator == 0) || (itemTypeOccurenceIndicator == OccurenceIndicator.ZERO_OR_ONE))) {
+		  isInstanceOf = false; 
+	  }
+	  else {
+		  DTMIterator dtmIter = xdmNodeSet.iterRaw();
+
+		  List<Boolean> nodeSetSequenceTypeKindTestResultList = new ArrayList<Boolean>();
+
+		  int nextNodeDtmHandle;
+		  while ((nextNodeDtmHandle = dtmIter.nextNode()) != DTM.NULL) {                 
+			  DTM dtm = dtmIter.getDTM(nextNodeDtmHandle);
+			  java.lang.String nodeName = dtm.getNodeName(nextNodeDtmHandle);
+			  java.lang.String nodeNsUri = dtm.getNamespaceURI(nextNodeDtmHandle);
+
+			  if (dtm.getNodeType(nextNodeDtmHandle) == DTM.ELEMENT_NODE) {
+				  if (seqTypeKindTest != null) {
+					  java.lang.String elemNodeKindTestNodeName = seqTypeKindTest.getNodeLocalName();
+					  if (elemNodeKindTestNodeName == null || "".equals(elemNodeKindTestNodeName) || 
+							  SequenceTypeSupport.STAR.equals(elemNodeKindTestNodeName)) {
+						  elemNodeKindTestNodeName = nodeName;  
+					  }
+
+					  if ((seqTypeKindTest.getKindVal() == SequenceTypeSupport.ELEMENT_KIND) && (nodeName.equals(elemNodeKindTestNodeName)) 
+							  && (SequenceTypeSupport.isTwoXmlNamespacesEqual(nodeNsUri, seqTypeKindTest.getNodeNsUri()))) {
+						  nodeSetSequenceTypeKindTestResultList.add(Boolean.valueOf(true));  
+					  }
+					  else if ((seqTypeKindTest.getKindVal() == SequenceTypeSupport.NODE_KIND) || 
+							  (seqTypeKindTest.getKindVal() == SequenceTypeSupport.ITEM_KIND)) {
+						  nodeSetSequenceTypeKindTestResultList.add(Boolean.valueOf(true)); 
+					  }
+				  }
+				  else {
+					  isInstanceOf = false;
+					  break;
+				  }
+			  }
+			  else if (dtm.getNodeType(nextNodeDtmHandle) == DTM.ATTRIBUTE_NODE) {
+				  if (seqTypeKindTest != null) {
+					  java.lang.String attrNodeKindTestNodeName = seqTypeKindTest.getNodeLocalName();
+					  if (attrNodeKindTestNodeName == null || "".equals(attrNodeKindTestNodeName) || 
+							  SequenceTypeSupport.STAR.equals(attrNodeKindTestNodeName)) {
+						  attrNodeKindTestNodeName = nodeName;  
+					  }
+
+					  if ((seqTypeKindTest.getKindVal() == SequenceTypeSupport.ATTRIBUTE_KIND) && (nodeName.equals(attrNodeKindTestNodeName)) 
+							  && (SequenceTypeSupport.isTwoXmlNamespacesEqual(
+									  nodeNsUri, seqTypeKindTest.getNodeNsUri()))) {
+						  nodeSetSequenceTypeKindTestResultList.add(Boolean.valueOf(true));    
+					  }
+					  else if ((seqTypeKindTest.getKindVal() == SequenceTypeSupport.NODE_KIND) || 
+							  (seqTypeKindTest.getKindVal() == SequenceTypeSupport.ITEM_KIND)) {
+						  nodeSetSequenceTypeKindTestResultList.add(Boolean.valueOf(true));   
+					  }   
+				  }
+				  else {
+					  isInstanceOf = false;
+					  break;
+				  } 
+			  }
+			  else if (dtm.getNodeType(nextNodeDtmHandle) == DTM.TEXT_NODE) {
+				  if (seqTypeKindTest.getKindVal() == SequenceTypeSupport.TEXT_KIND) {
+					  nodeSetSequenceTypeKindTestResultList.add(Boolean.valueOf(true)); 
+				  }
+			  }
+			  else if (dtm.getNodeType(nextNodeDtmHandle) == DTM.NAMESPACE_NODE) {
+				  if (seqTypeKindTest.getKindVal() == SequenceTypeSupport.NAMESPACE_NODE_KIND) {
+					  nodeSetSequenceTypeKindTestResultList.add(Boolean.valueOf(true)); 
+				  }
+			  }
+		  }
+
+		  if (nodeSetSequenceTypeKindTestResultList.size() > 0 && (nodeSetSequenceTypeKindTestResultList.size() == nodeSetLen)) {
+			  isInstanceOf = true; 
+		  }
+	  }
+	  
+	  return isInstanceOf;
+  }
+
+  /**
+   * Check whether, an xdm sequence conforms to xpath sequence type information.
+   */
+  private boolean checkXdmSequenceWithType(XObject xdmValue, SequenceTypeData seqTypeData) {
+	  
+	  boolean isInstanceOf = false;
+	  
+	  ResultSequence srcResultSeq = (ResultSequence)xdmValue;
+
+	  int seqLen = srcResultSeq.size();
+
+	  if ((seqLen == 0) && (seqTypeData.getItemTypeOccurrenceIndicator() == OccurenceIndicator.ONE_OR_MANY)) {
+		  isInstanceOf = false;  
+	  }
+	  else if ((seqLen > 0) && (seqTypeData.getSequenceType() == SequenceTypeSupport.EMPTY_SEQUENCE)) {
+		  isInstanceOf = false;  
+	  }
+	  else if ((seqLen > 1) && (seqTypeData.getItemTypeOccurrenceIndicator() == OccurenceIndicator.ZERO_OR_ONE)) {
+		  isInstanceOf = false;
+	  }
+
+	  SequenceTypeData sequenceTypeDataNew = new SequenceTypeData();          
+	  if (seqTypeData.getSequenceTypeKindTest() != null) {
+		  sequenceTypeDataNew.setSequenceTypeKindTest(seqTypeData.getSequenceTypeKindTest()); 
+	  }
+	  else {
+		  sequenceTypeDataNew.setSequenceType(seqTypeData.getSequenceType()); 
+	  }
+
+	  boolean isInstanceOfOnSeqItem = true;
+
+	  for (int idx = 0; idx < srcResultSeq.size(); idx++) {
+		  XObject seqItem = (XObject)(srcResultSeq.item(idx));
+		  // Recursive call to this function
+		  if (!isInstanceOf(seqItem, sequenceTypeDataNew)) {
+			  isInstanceOfOnSeqItem = false;
+			  break;
+		  }
+	  }
+
+	  isInstanceOf = isInstanceOfOnSeqItem;
+	  
+	  return isInstanceOf;
+  }
+
+  /**
+   * Check whether, an xdm value is an instance of xpath array.
+   */
+  private boolean isInstanceOfArray(XObject xdmValue, SequenceTypeData seqTypeData) {
+	  
+	  boolean isInstanceOf = false;
+	  
+	  SequenceTypeArrayTest sequenceTypeArrayTest = seqTypeData.getSequenceTypeArrayTest();
+	  if (sequenceTypeArrayTest != null) {
+		  if (sequenceTypeArrayTest.isAnyArrayTest()) {
+			  isInstanceOf = true;
+		  }
+		  else {
+			  XPathArray xpathArr = (XPathArray)xdmValue;
+			  List<XObject> nativeArr = xpathArr.getNativeArray();
+			  Iterator<XObject> arrIter = nativeArr.iterator();
+			  // We check below each of array items, with an expected type
+			  isInstanceOf = true; 
+			  while (arrIter.hasNext()) {
+				  XObject arrItem = arrIter.next();
+				  if (arrItem instanceof ResultSequence) {
+					  arrItem = ((ResultSequence)arrItem).item(0);
+				  }
+				  SequenceTypeData arrayItemTypeInfo = sequenceTypeArrayTest.getArrayItemTypeInfo();
+				  try {
+					  XObject arrayItemTypeCheckResult = SequenceTypeSupport.convertXdmValueToAnotherType(arrItem, null, arrayItemTypeInfo, null);
+					  if (arrayItemTypeCheckResult == null) {             				
+						  isInstanceOf = false;
+						  break;
+					  }
+				  }
+				  catch (TransformerException ex) {
+					  isInstanceOf = false;
+					  break; 
+				  }
+			  } 	
+		  }
+	  }
+	  
+	  return isInstanceOf;
   }
   
 }
diff --git a/tests/org/apache/xalan/xpath3/XPathArrayTests.java b/tests/org/apache/xalan/xpath3/XPathArrayTests.java
index eb86e1d2..896694b0 100644
--- a/tests/org/apache/xalan/xpath3/XPathArrayTests.java
+++ b/tests/org/apache/xalan/xpath3/XPathArrayTests.java
@@ -97,5 +97,25 @@ public class XPathArrayTests extends XSLTransformTestsUtil {
         
         runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
     }
+    
+    @Test
+    public void xslArrayTest6() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test6.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test6.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test6.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xslArrayTest7() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test7.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test7.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test7.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
 
 }
diff --git a/tests/xpath_array/gold/test3.out b/tests/xpath_array/gold/test3.out
index 0a566994..27ab446d 100644
--- a/tests/xpath_array/gold/test3.out
+++ b/tests/xpath_array/gold/test3.out
@@ -1 +1 @@
-<?xml version="1.0" encoding="UTF-8"?><result>a d c</result>
+<?xml version="1.0" encoding="UTF-8"?><result isResultArray="true" isResultStringArray="true">a d c</result>
diff --git a/tests/xpath_array/gold/test6.out b/tests/xpath_array/gold/test6.out
new file mode 100644
index 00000000..af31a3b8
--- /dev/null
+++ b/tests/xpath_array/gold/test6.out
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <arrAfterAppend traversalMethod="xsl:for-each" arrSize="4">
+    <arrItem>a</arrItem>
+    <arrItem>b</arrItem>
+    <arrItem>c</arrItem>
+    <arrItem>d e</arrItem>
+  </arrAfterAppend>
+  <arrAfterAppend traversalMethod="xsl:iterate" arrSize="4">
+    <arrItem>a</arrItem>
+    <arrItem>b</arrItem>
+    <arrItem>c</arrItem>
+    <arrItem>d e</arrItem>
+  </arrAfterAppend>
+</result>
diff --git a/tests/xpath_array/gold/test7.out b/tests/xpath_array/gold/test7.out
new file mode 100644
index 00000000..9706966e
--- /dev/null
+++ b/tests/xpath_array/gold/test7.out
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+  <one arrSize="3">b c d</one>
+  <two arrSize="0"/>
+  <three arrSize="1">b</three>
+  <four arrSize="2">b c</four>
+</result>
diff --git a/tests/xpath_array/test3.xsl b/tests/xpath_array/test3.xsl
index 3c2a6fbb..c59d0c53 100644
--- a/tests/xpath_array/test3.xsl
+++ b/tests/xpath_array/test3.xsl
@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                 xmlns:array="http://www.w3.org/2005/xpath-functions/array"
-                exclude-result-prefixes="array"
+                exclude-result-prefixes="xs array"
                 version="3.0">
                 
     <!-- Author: mukulg@apache.org -->
@@ -14,9 +15,11 @@
     <xsl:output method="xml" indent="yes"/>
 
     <xsl:template match="/">
-       <result>
-         <xsl:variable name="arr1" select="['a', 'b', 'c']"/>
-         <xsl:variable name="resultAfterArrPut" select="array:put($arr1, 2, 'd')"/>
+       <xsl:variable name="arr1" select="['a', 'b', 'c']"/>
+       <xsl:variable name="resultAfterArrPut" select="array:put($arr1, 2, 'd')"/>
+       <result>         
+         <xsl:attribute name="isResultArray" select="$resultAfterArrPut instance of array(*)"/>
+         <xsl:attribute name="isResultStringArray" select="$resultAfterArrPut instance of array(xs:string)"/>          
          <xsl:copy-of select="$resultAfterArrPut"/>
        </result>
     </xsl:template>
diff --git a/tests/xpath_array/test6.xsl b/tests/xpath_array/test6.xsl
new file mode 100644
index 00000000..369a9cac
--- /dev/null
+++ b/tests/xpath_array/test6.xsl
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                xmlns:array="http://www.w3.org/2005/xpath-functions/array"
+				exclude-result-prefixes="xs array"
+                version="3.0">
+                
+    <!-- Author: mukulg@apache.org -->
+    
+    <!-- An XSLT 3.0 test case to test, XPath 3.1 array:append 
+         function, and traversing an array constructed via array:append
+         using both xsl:for-each and xsl:iterate.
+    -->                				
+
+   <xsl:output method="xml" indent="yes"/>      
+
+   <xsl:template match="/">
+      <xsl:variable name="arr1" select="['a', 'b', 'c']" as="array(xs:string)"/>
+      <xsl:variable name="seq1" select="('d', 'e')" as="xs:string*"/>
+      <xsl:variable name="resultArr" select="array:append($arr1, $seq1)" as="array(xs:string)"/>  
+      <result>   	     	     	     
+	     <arrAfterAppend arrSize="{array:size($resultArr)}" traversalMethod="xsl:for-each">
+	       <!-- using xsl:for-each to traverse array -->	        
+	       <xsl:for-each select="$resultArr">
+	          <arrItem>
+	             <xsl:value-of select="."/>
+	          </arrItem>  
+	       </xsl:for-each>
+	     </arrAfterAppend>
+	     <arrAfterAppend arrSize="{array:size($resultArr)}" traversalMethod="xsl:iterate">
+	       <!-- using xsl:iterate to traverse array -->	        
+	       <xsl:iterate select="$resultArr">
+	          <arrItem>
+	             <xsl:value-of select="."/>
+	          </arrItem>  
+	       </xsl:iterate>
+	     </arrAfterAppend>
+	  </result>
+   </xsl:template>
+   
+   <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+   -->
+
+</xsl:stylesheet>
diff --git a/tests/xpath_array/test7.xsl b/tests/xpath_array/test7.xsl
new file mode 100644
index 00000000..4694d856
--- /dev/null
+++ b/tests/xpath_array/test7.xsl
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                xmlns:array="http://www.w3.org/2005/xpath-functions/array"
+				exclude-result-prefixes="xs array"
+                version="3.0">
+                
+    <!-- Author: mukulg@apache.org -->
+    
+    <!-- An XSLT 3.0 test case to test, XPath 3.1 function array:subarray.
+    -->                				
+
+   <xsl:output method="xml" indent="yes"/>      
+
+   <xsl:template match="/">        
+      <result>   	     	     	     
+	     <xsl:variable name="arr1" select="['a', 'b', 'c', 'd']" as="array(xs:string)"/>
+         <xsl:variable name="resultArr1" select="array:subarray($arr1, 2)" as="array(xs:string)"/>
+         <xsl:variable name="resultArr2" select="array:subarray($arr1, 2, 0)" as="array(xs:string)"/>
+         <xsl:variable name="resultArr3" select="array:subarray($arr1, 2, 1)" as="array(xs:string)"/>
+         <xsl:variable name="resultArr4" select="array:subarray($arr1, 2, 2)" as="array(xs:string)"/>
+         <one arrSize="{array:size($resultArr1)}">
+            <xsl:value-of select="$resultArr1"/>
+         </one>
+         <two arrSize="{array:size($resultArr2)}">
+            <xsl:value-of select="$resultArr2"/>
+         </two>
+         <three arrSize="{array:size($resultArr3)}">
+            <xsl:value-of select="$resultArr3"/>
+         </three>
+         <four arrSize="{array:size($resultArr4)}">
+            <xsl:value-of select="$resultArr4"/>
+         </four>
+	  </result>
+   </xsl:template>
+   
+   <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+   -->
+
+</xsl:stylesheet>


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