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 2026/01/03 11:54:34 UTC

(xalan-java) branch xalan-j_xslt3.0_mvn updated: committing few xalan-j xslt 3.0 implementation changes

This is an automated email from the ASF dual-hosted git repository.

mukulg pushed a commit to branch xalan-j_xslt3.0_mvn
in repository https://gitbox.apache.org/repos/asf/xalan-java.git


The following commit(s) were added to refs/heads/xalan-j_xslt3.0_mvn by this push:
     new b32997476 committing few xalan-j xslt 3.0 implementation changes
b32997476 is described below

commit b329974769e39e9e2d779d915799f268b357d438
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sat Jan 3 17:23:48 2026 +0530

    committing few xalan-j xslt 3.0 implementation changes
---
 .../apache/xalan/templates/ElemForEachGroup.java   | 110 +++--
 .../org/apache/xalan/templates/ElemFunction.java   |   5 +-
 .../org/apache/xalan/templates/ElemVariable.java   |   5 +-
 .../apache/xalan/templates/FuncCurrentGroup.java   |  56 +--
 .../apache/xalan/transformer/TransformerImpl.java  |  11 +-
 src/main/java/org/apache/xml/dtm/DTMManager.java   |  55 ++-
 .../org/apache/xpath/XPath3DynamicContext.java     | 398 ++++++++++++++++
 .../java/org/apache/xpath/XPath3StaticContext.java | 107 +++++
 src/main/java/org/apache/xpath/XPathContext.java   | 518 +++------------------
 .../org/apache/xpath/compiler/FunctionTable.java   |  33 --
 .../org/apache/xpath/compiler/XPathParser.java     |  63 +--
 .../org/apache/xpath/composite/XPathIfExpr.java    |   9 +-
 .../org/apache/xpath/composite/XPathLetExpr.java   |  11 +-
 .../xpath/composite/XPathQuantifiedExpr.java       |   9 +-
 .../xpath/functions/FuncCurrentDateTime.java       |  14 +-
 .../apache/xpath/functions/FuncFunctionArity.java  |  13 +-
 .../apache/xpath/functions/FuncFunctionName.java   |   9 +-
 .../xpath/functions/XSL3FunctionService.java       |  27 +-
 .../org/apache/xpath/functions/hof/FuncApply.java  |  13 +-
 .../apache/xpath/functions/hof/FuncForEach.java    |  13 +-
 .../xpath/functions/hof/FuncForEachPair.java       |  13 +-
 .../org/apache/xpath/functions/hof/FuncSort.java   |  25 +-
 .../apache/xpath/functions/json/FuncJsonToXml.java |  33 +-
 .../xpath/functions/string/FuncAnalyzeString.java  |  11 +-
 24 files changed, 848 insertions(+), 713 deletions(-)

diff --git a/src/main/java/org/apache/xalan/templates/ElemForEachGroup.java b/src/main/java/org/apache/xalan/templates/ElemForEachGroup.java
index 7b361bc7c..3d69311a8 100644
--- a/src/main/java/org/apache/xalan/templates/ElemForEachGroup.java
+++ b/src/main/java/org/apache/xalan/templates/ElemForEachGroup.java
@@ -791,19 +791,24 @@ public class ElemForEachGroup extends ElemTemplateElement
         			xctxt.setPos(idx + 1);    							// Set value of fn:position() function within xsl:for-each-group
         			xctxt.setLast(m_sortedGroups.size());               // Set value of the number of groups formed
 
-        			for (ElemTemplateElement templateElem = this.m_firstChild; templateElem != null; 
-        					templateElem = templateElem.m_nextSibling) {
+        			try {
         				/**
         				 * Set context item for whole of group contents evaluation, to the initial
         				 * item of the group.
         				 */
         				xctxt.pushCurrentNode((groupNodesDtmHandles.get(0)).intValue());
 
-        				templateElem.setGroupingKey(groupingKey);
-        				templateElem.setGroupNodesDtmHandles(groupNodesDtmHandles);
-        				xctxt.setSAXLocator(templateElem);
-        				transformer.setCurrentElement(templateElem);                   
-        				templateElem.execute(transformer);
+        				for (ElemTemplateElement templateElem = this.m_firstChild; templateElem != null; 
+        						                                                            templateElem = templateElem.m_nextSibling) {        				
+        					templateElem.setGroupingKey(groupingKey);
+        					templateElem.setGroupNodesDtmHandles(groupNodesDtmHandles);
+        					xctxt.setSAXLocator(templateElem);
+        					transformer.setCurrentElement(templateElem);                   
+        					templateElem.execute(transformer);
+        				}
+        			}
+        			finally {
+        				xctxt.popCurrentNode();
         			}
         		}
         	}
@@ -844,28 +849,35 @@ public class ElemForEachGroup extends ElemTemplateElement
         			 * Loop through these groups formed by xsl:for-each-group instruction, and process
         			 * the XSL contents of each group.
         			 */
-        			for (int idx = 0; idx < groupingKeyAndNodeHandlePairList.size(); idx++) {
+        			
+        			int size1 = groupingKeyAndNodeHandlePairList.size();        			
+        			for (int idx = 0; idx < size1; idx++) {
         				GroupingKeyAndNodeHandlePair groupingKeyNodeHandlePair = groupingKeyAndNodeHandlePairList.get(idx);
 
         				Object groupingKey = groupingKeyNodeHandlePair.getGroupingKey();              // current-grouping-key() value, for this group
         				List<Integer> groupNodesDtmHandles = xslForEachGroupMap.get(groupingKey);     // current-group() contents, for this group
 
         				xctxt.setPos(idx + 1);										      // Set value of fn:position() function within xsl:for-each-group
-        				xctxt.setLast(groupingKeyAndNodeHandlePairList.size());		          // Set value of the number of groups formed                        
+        				xctxt.setLast(size1);		                                      // Set value of the number of groups formed                        
 
-        				for (ElemTemplateElement templateElem = this.m_firstChild; templateElem != null; 
-        																						templateElem = templateElem.m_nextSibling) {
+        				try {
         					/**
         					 * Set context item for whole of group contents evaluation, to the
         					 * initial item of the group.
         					 */
         					xctxt.pushCurrentNode((groupNodesDtmHandles.get(0)).intValue());
 
-        					templateElem.setGroupingKey(groupingKey);
-        					templateElem.setGroupNodesDtmHandles(groupNodesDtmHandles);
-        					xctxt.setSAXLocator(templateElem);
-        					transformer.setCurrentElement(templateElem);                   
-        					templateElem.execute(transformer);
+        					for (ElemTemplateElement templateElem = this.m_firstChild; templateElem != null; 
+        							                                                             templateElem = templateElem.m_nextSibling) {        					
+        						templateElem.setGroupingKey(groupingKey);
+        						templateElem.setGroupNodesDtmHandles(groupNodesDtmHandles);
+        						xctxt.setSAXLocator(templateElem);
+        						transformer.setCurrentElement(templateElem);                   
+        						templateElem.execute(transformer);
+        					}
+        				}
+        				finally {
+        					xctxt.popCurrentNode();
         				}
         			}
         		}
@@ -874,28 +886,35 @@ public class ElemForEachGroup extends ElemTemplateElement
         			 * Loop through the groups formed by xsl:for-each-group instruction using 
         			 * 'group-adjacent' attribute, and process the XSL contents of each group.
         			 */
-        			for (int idx = 0; idx < xslForEachGroupAdjacentList.size(); idx++) {
+        			
+        			int size1 = xslForEachGroupAdjacentList.size();
+        			for (int idx = 0; idx < size1; idx++) {
         				GroupingKeyAndGroupPair groupingKeyAndGroupPair = xslForEachGroupAdjacentList.get(idx);
 
         				Object groupingKey = groupingKeyAndGroupPair.getGroupingKey();                             // current-grouping-key() value, for this group
         				List<Integer> groupNodesDtmHandles = groupingKeyAndGroupPair.getGroupNodeDtmHandles();    // current-group() contents, for this group
 
         				xctxt.setPos(idx + 1);										                   // Set value of fn:position() function within xsl:for-each-group
-        				xctxt.setLast(xslForEachGroupAdjacentList.size());		                           // Set value of the number of groups formed                        
+        				xctxt.setLast(size1);		                                                   // Set value of the number of groups formed                        
 
-        				for (ElemTemplateElement templateElem = this.m_firstChild; templateElem != null; 
-        																						templateElem = templateElem.m_nextSibling) {
+        				try {
         					/**
         					 * Set context item for whole of group contents evaluation, to the
         					 * initial item of the group.
         					 */
         					xctxt.pushCurrentNode((groupNodesDtmHandles.get(0)).intValue());
 
-        					templateElem.setGroupingKey(groupingKey);
-        					templateElem.setGroupNodesDtmHandles(groupNodesDtmHandles);
-        					xctxt.setSAXLocator(templateElem);
-        					transformer.setCurrentElement(templateElem);                   
-        					templateElem.execute(transformer);
+        					for (ElemTemplateElement templateElem = this.m_firstChild; templateElem != null; 
+        							                                                            templateElem = templateElem.m_nextSibling) {        					
+        						templateElem.setGroupingKey(groupingKey);
+        						templateElem.setGroupNodesDtmHandles(groupNodesDtmHandles);
+        						xctxt.setSAXLocator(templateElem);
+        						transformer.setCurrentElement(templateElem);                   
+        						templateElem.execute(transformer);
+        					}
+        				}
+        				finally {
+        					xctxt.popCurrentNode();
         				}
         			}
         		}
@@ -906,30 +925,36 @@ public class ElemForEachGroup extends ElemTemplateElement
         			 * instruction, and process the XSL contents of each group.
         			 */
 
-        			for (int idx = 0; idx < xslForEachGroupStartingWithEndingWith.size(); idx++) {
+        			int size1 = xslForEachGroupStartingWithEndingWith.size();
+        			for (int idx = 0; idx < size1; idx++) {
         				List<Integer> groupNodesDtmHandles = xslForEachGroupStartingWithEndingWith.get(idx);
 
         				xctxt.setPos(idx + 1);											// Set value of fn:position() function within xsl:for-each-group
-        				xctxt.setLast(xslForEachGroupStartingWithEndingWith.size());	        // Set value of the number of groups formed                       
+        				xctxt.setLast(size1);	                                        // Set value of the number of groups formed                       
 
-        				for (ElemTemplateElement templateElem = this.m_firstChild; templateElem != null; 
-        																						templateElem = templateElem.m_nextSibling) {                   
+        				try {
         					/**
         					 * Set context item for whole of group contents evaluation, to the initial
         					 * item of the group.
         					 */
         					xctxt.pushCurrentNode((groupNodesDtmHandles.get(0)).intValue());
 
-        					/**
-        					 * The grouping key is absent when, attributes 'group-starting-with' or
-        					 * 'group-ending-with' are used.
-        					 */
-        					templateElem.setGroupingKey(FuncCurrentGroupingKey.XSL_GROUPING_KEY_ABSENT);
-        					
-        					templateElem.setGroupNodesDtmHandles(groupNodesDtmHandles);
-        					xctxt.setSAXLocator(templateElem);
-        					transformer.setCurrentElement(templateElem);                   
-        					templateElem.execute(transformer);
+        					for (ElemTemplateElement templateElem = this.m_firstChild; templateElem != null; 
+        							                                                             templateElem = templateElem.m_nextSibling) {                           					
+        						/**
+        						 * The grouping key is absent when, attributes 'group-starting-with' or
+        						 * 'group-ending-with' are used.
+        						 */
+        						templateElem.setGroupingKey(FuncCurrentGroupingKey.XSL_GROUPING_KEY_ABSENT);
+
+        						templateElem.setGroupNodesDtmHandles(groupNodesDtmHandles);
+        						xctxt.setSAXLocator(templateElem);
+        						transformer.setCurrentElement(templateElem);                   
+        						templateElem.execute(transformer);
+        					}
+        				}
+        				finally {
+        					xctxt.popCurrentNode();
         				}
         			}
         		}
@@ -951,13 +976,6 @@ public class ElemForEachGroup extends ElemTemplateElement
         	xctxt.setLast(0);
         	sourceNodes.detach();
         }
-
-        /**
-         * When a particular xsl:for-each-group's evaluation has completed, set the XPath evaluation 
-         * context node to the node which was the context node before xsl:for-each-group evaluation 
-         * was started.
-         */         
-        xctxt.pushCurrentNode(currentNode);
   }
   
   /**
diff --git a/src/main/java/org/apache/xalan/templates/ElemFunction.java b/src/main/java/org/apache/xalan/templates/ElemFunction.java
index 08be0250d..6cc437fa5 100644
--- a/src/main/java/org/apache/xalan/templates/ElemFunction.java
+++ b/src/main/java/org/apache/xalan/templates/ElemFunction.java
@@ -41,6 +41,7 @@ import org.apache.xml.utils.PrefixResolver;
 import org.apache.xml.utils.QName;
 import org.apache.xpath.VariableStack;
 import org.apache.xpath.XPath;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.compiler.FunctionTable;
 import org.apache.xpath.compiler.Keywords;
@@ -703,8 +704,8 @@ public class ElemFunction extends ElemTemplate
         					   if (xpathNamedFunctionReference.getXslStylesheetFunction() == null) {
         						   String funcNamespace = xpathNamedFunctionReference.getFuncNamespace();
         						   int actualFuncArity = 0;           
-        						   if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
-        								   																(Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
+        						   if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
+        								   																     (Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
         							   actualFuncArity = xpathNamedFunctionReference.getConcatArity();
         						   }
         						   else {
diff --git a/src/main/java/org/apache/xalan/templates/ElemVariable.java b/src/main/java/org/apache/xalan/templates/ElemVariable.java
index ad2634eaf..e9c20c467 100644
--- a/src/main/java/org/apache/xalan/templates/ElemVariable.java
+++ b/src/main/java/org/apache/xalan/templates/ElemVariable.java
@@ -38,6 +38,7 @@ import org.apache.xml.utils.XMLString;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionNode;
 import org.apache.xpath.XPath;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.axes.LocPathIterator;
 import org.apache.xpath.axes.SelfIteratorNoPredicate;
@@ -1562,8 +1563,8 @@ public class ElemVariable extends ElemTemplateElement
 						  String funcLocalName = funcRef1.getFuncName(); 
 						  String funcNamespace = funcRef1.getFuncNamespace();    					  
 						  int xpathNamedFuncRefArity = 0;           
-		            	  if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
-		            			  															(Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
+		            	  if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
+		            			  															        (Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
 		            		  xpathNamedFuncRefArity = funcRef1.getConcatArity();
 		            	  }
 		            	  else {
diff --git a/src/main/java/org/apache/xalan/templates/FuncCurrentGroup.java b/src/main/java/org/apache/xalan/templates/FuncCurrentGroup.java
index ed0d74265..44c3c0260 100644
--- a/src/main/java/org/apache/xalan/templates/FuncCurrentGroup.java
+++ b/src/main/java/org/apache/xalan/templates/FuncCurrentGroup.java
@@ -29,7 +29,7 @@ import org.apache.xpath.objects.XMLNodeCursorImpl;
 import org.apache.xpath.objects.XObject;
 
 /**
- * Implementation of an XSLT 3.0 function current-group().
+ * Implementation of an XSLT 3.0 function fn:current-group.
  * 
  * @author Mukul Gandhi <mu...@apache.org>
  * 
@@ -41,39 +41,39 @@ public class FuncCurrentGroup extends Function
    private static final long serialVersionUID = -9147780878956514961L;
 
    /**
-     * Execute the function. The function must return a valid object.
+     * Implementation of the function. The function must return a valid object.
      * 
-     * @param xctxt The current execution context.
-     * @return a valid XObject.
+     * @param xctxt                          An XPath context object
+     * @return                               a valid XObject
      *
      * @throws javax.xml.transform.TransformerException
    */
    public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
    {
-       XMLNodeCursorImpl result = null;
-       
-       SourceLocator srcLocator = xctxt.getSAXLocator();
-       
-       TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();                            
-       ElemTemplateElement currElemTemplateElement = transformer.getCurrentElement();       
-      
-       List<Integer> groupNodesDtmHandles = currElemTemplateElement.getGroupNodesDtmHandles();
-       while ((groupNodesDtmHandles == null) && (currElemTemplateElement != null)) {
-           currElemTemplateElement = currElemTemplateElement.getParentElem();
-           if (currElemTemplateElement != null) {
-             groupNodesDtmHandles = currElemTemplateElement.getGroupNodesDtmHandles();
-           }
-       }
-       
-       if (groupNodesDtmHandles != null) {
-          result = new XMLNodeCursorImpl(groupNodesDtmHandles, xctxt);
-       }
-       else {
-    	  throw new javax.xml.transform.TransformerException("XTDE1061 : An XPath current-group function call couldn't "
-    	  		                                                                                                       + "determine a group of xdm items.", srcLocator);  
-       }
-              
-       return result;
+	   XMLNodeCursorImpl result = null;
+
+	   SourceLocator srcLocator = xctxt.getSAXLocator();
+
+	   TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();                            
+	   ElemTemplateElement currElemTemplateElement = transformer.getCurrentElement();       
+
+	   List<Integer> groupNodesDtmHandles = currElemTemplateElement.getGroupNodesDtmHandles();
+	   while ((groupNodesDtmHandles == null) && (currElemTemplateElement != null)) {
+		   currElemTemplateElement = currElemTemplateElement.getParentElem();
+		   if (currElemTemplateElement != null) {
+			   groupNodesDtmHandles = currElemTemplateElement.getGroupNodesDtmHandles();
+		   }
+	   }
+
+	   if (groupNodesDtmHandles != null) {
+		   result = new XMLNodeCursorImpl(groupNodesDtmHandles, xctxt);
+	   }
+	   else {
+		   throw new javax.xml.transform.TransformerException("XTDE1061 : An XPath function current-group's call couldn't "
+				                                                                                                       + "determine a group of xdm items.", srcLocator);  
+	   }
+
+	   return result;
    }
 
    @Override
diff --git a/src/main/java/org/apache/xalan/transformer/TransformerImpl.java b/src/main/java/org/apache/xalan/transformer/TransformerImpl.java
index d84a45dbb..70133e784 100644
--- a/src/main/java/org/apache/xalan/transformer/TransformerImpl.java
+++ b/src/main/java/org/apache/xalan/transformer/TransformerImpl.java
@@ -128,6 +128,7 @@ import org.apache.xpath.Expression;
 import org.apache.xpath.ExtensionsProvider;
 import org.apache.xpath.VariableStack;
 import org.apache.xpath.XPath;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.compiler.FunctionTable;
 import org.apache.xpath.compiler.SharedLexerState;
@@ -4615,11 +4616,11 @@ public class TransformerImpl extends Transformer
 			String localName = func1.getFunctionName();
 			String namespaceUri = func1.getNamespace();			
 			
-			if ((namespaceUri != null) && !((Constants.S_EXTENSIONS_JAVA_URL).equals(namespaceUri) || (FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(namespaceUri) ||
-				                                                                  (FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(namespaceUri) || 
-				                                                                  (FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(namespaceUri) ||
-				                                                                  (FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(namespaceUri) ||
-				                                                                  (XMLConstants.W3C_XML_SCHEMA_NS_URI).equals(namespaceUri))) {
+			if ((namespaceUri != null) && !((Constants.S_EXTENSIONS_JAVA_URL).equals(namespaceUri) || (XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(namespaceUri) ||
+				                                                                                      (XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(namespaceUri) || 
+				                                                                                      (XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(namespaceUri) ||
+				                                                                                      (XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(namespaceUri) ||
+				                                                                                      (XMLConstants.W3C_XML_SCHEMA_NS_URI).equals(namespaceUri))) {
 				int funcArity = (func1.getArgVector()).size();
 				QName qName = new QName(namespaceUri, localName);
 				ElemTemplate elemTemplate = templList.getXslFunction(qName, funcArity);
diff --git a/src/main/java/org/apache/xml/dtm/DTMManager.java b/src/main/java/org/apache/xml/dtm/DTMManager.java
index e5b756be2..41c93927e 100644
--- a/src/main/java/org/apache/xml/dtm/DTMManager.java
+++ b/src/main/java/org/apache/xml/dtm/DTMManager.java
@@ -49,27 +49,38 @@ import org.xml.sax.InputSource;
  * <p>The system property that determines which Factory implementation
  * to create is named "org.apache.xml.utils.DTMFactory". This
  * property names a concrete subclass of the DTMFactory abstract
- *  class. If the property is not defined, a platform default is be used.</p>
+ * class. If the property is not defined, a platform default is be used.</p>
  *
  * <p>An instance of this class <emph>must</emph> be safe to use across
  * thread instances.  It is expected that a client will create a single instance
- * of a DTMManager to use across multiple threads.  This will allow sharing
+ * of a DTMManager to use across multiple threads. This will allow sharing
  * of DTMs across multiple processes.</p>
  *
- * <p>Note: this class is incomplete right now.  It will be pretty much
+ * <p>Note: this class is incomplete right now. It will be pretty much
  * modeled after javax.xml.transform.TransformerFactory in terms of its
  * factory support.</p>
+ * 
+ * @author Scott Boag <sc...@us.ibm.com>
+ * @author Gary L Peskin <ga...@apache.org>
+ * @author Myriam Midy <mm...@apache.org>
+ * 
+ * @author Joseph Kesselman <ke...@alum.mit.edu>
+ * @author Morris Kwan <mk...@apache.org>, Ilene Seelemann <il...@apache.org>, Henry Zongaro <zo...@ca.ibm.com>,
+ *         Brian Minchau <mi...@apache.org>, Sarah McNamara <mc...@apache.org>
+ *         
+ * @author Mukul Gandhi <mu...@apache.org>
+ *         (XPath 3.1 specific changes, to this class)
+ *         
+ * @xsl.usage general         
  */
 public abstract class DTMManager
 {
 
-  /** The default property name to load the manager. */
-  private static final String defaultPropName =
-    "org.apache.xml.dtm.DTMManager";
+  /** The default property name to load DTMManager object instance by jvm */
+  private static final String defaultPropName = "org.apache.xml.dtm.DTMManager";
   
-  /** The default class name to use as the manager. */
-  private static String defaultClassName =
-    "org.apache.xml.dtm.ref.DTMManagerDefault";
+  /** The default class name to use as DTMManager object instance */
+  private static String defaultClassName = "org.apache.xml.dtm.ref.DTMManagerDefault";
 
   /**
    * Factory for creating XMLString objects.
@@ -560,39 +571,27 @@ public abstract class DTMManager
    */
   public static final int IDENT_DTM_DEFAULT = ~IDENT_NODE_DEFAULT;
 
-  /** This is the maximum number of DTMs available.  The highest DTM is
-    * one less than this.
+  /** 
+   * This is the maximum number of DTMs available. Maximum DTM 
+   * number is one less than this.
    */
   public static final int IDENT_MAX_DTMS = (IDENT_DTM_DEFAULT >>> IDENT_DTM_NODE_BITS) + 1;
 
 
   /**
-   * %TBD% Doc
-   *
-   * NEEDSDOC @param dtm
-   *
-   * NEEDSDOC ($objectName$) @return
+   * Given a DTM, find the id number in the DTM tables which addresses
+   * the start of the document.
    */
   public abstract int getDTMIdentity(DTM dtm);
 
-  /**
-   * %TBD% Doc
-   *
-   * NEEDSDOC ($objectName$) @return
-   */
   public int getDTMIdentityMask()
   {
-    return IDENT_DTM_DEFAULT;
+	  return IDENT_DTM_DEFAULT;
   }
 
-  /**
-   * %TBD% Doc
-   *
-   * NEEDSDOC ($objectName$) @return
-   */
   public int getNodeIdentityMask()
   {
-    return IDENT_NODE_DEFAULT;
+	  return IDENT_NODE_DEFAULT;
   }
 
 }
diff --git a/src/main/java/org/apache/xpath/XPath3DynamicContext.java b/src/main/java/org/apache/xpath/XPath3DynamicContext.java
new file mode 100644
index 000000000..1b3ce56df
--- /dev/null
+++ b/src/main/java/org/apache/xpath/XPath3DynamicContext.java
@@ -0,0 +1,398 @@
+/*
+ * 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;
+
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.Vector;
+
+import org.apache.xml.dtm.Axis;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMCursorIterator;
+import org.apache.xml.dtm.DTMFilter;
+import org.apache.xml.dtm.DTMManager;
+import org.apache.xml.dtm.DTMWSFilter;
+import org.apache.xml.utils.PrefixResolver;
+import org.apache.xml.utils.QName;
+import org.apache.xpath.objects.XObject;
+
+import xml.xpath31.processor.types.XSDayTimeDuration;
+import xml.xpath31.processor.types.XSDuration;
+
+/**
+ * A class definition, that implements XPath 3.1 expression evaluation's 
+ * dynamic context.
+ * 
+ * Please refer to, XPath 3.1 recommendation section, '2.1.2 Dynamic Context'.
+ * 
+ * @author Scott Boag <sc...@us.ibm.com>
+ * @author Gary L Peskin <ga...@apache.org>
+ * @author Myriam Midy <mm...@apache.org>
+ * 
+ * @author Joseph Kesselman <ke...@alum.mit.edu>
+ * @author Morris Kwan <mk...@apache.org>, Ilene Seelemann <il...@apache.org>, Henry Zongaro <zo...@ca.ibm.com>,
+ *         Brian Minchau <mi...@apache.org>, Sarah McNamara <mc...@apache.org>
+ *         
+ * @author Mukul Gandhi <mu...@apache.org>
+ *         (XPath 3.1 specific changes, to this class)
+ * 
+ * @xsl.usage general
+ */
+public class XPath3DynamicContext extends DTMManager {
+	
+	/** 
+	 * The value of this class field, represents the value returned by fn:position() 
+	 * function when called within XSL instructions 'xsl:for-each-group' or 'xsl:analyze-string'.
+	 */
+	private int m_pos;
+
+	/** 
+	 * The value of this class field, represents the value returned by fn:last() 
+	 * function when called within XSL instructions 'xsl:for-each-group' or 'xsl:analyze-string'.
+	 */
+	private int m_last;
+	
+	/**
+	 *  This data value, represents the XPath 3.1's current evaluation 
+	 *  context item. This is in addition to, XPath context item
+	 *  retrieved in other ways, by Xalan-J implementation.
+	 */
+	private XObject m_xpath3ContextItem = null;
+
+	/**
+	 *  This data value, represents the XPath 3.1's current evaluation 
+	 *  context position.
+	 */
+	private int m_xpath3ContextPosition = -1;
+
+	/**
+	 *  This data value, represents the XPath 3.1's current evaluation 
+	 *  context size.
+	 */
+	private int m_xpath3ContextSize = -1;
+	
+	/**
+	 * This class field, represents XPath dynamic context's 
+	 * implicit timezone. This value is of XML Schema type xs:dayTimeDuration.
+	 */
+	private XSDuration m_timezone;
+	
+	/**
+	 * This represents the value returned by XPath 3.1 function 
+	 * fn:current-dateTime.
+	 */
+	private GregorianCalendar m_currentDateTime;
+	
+	/**
+	 * We use this java.util.Map object, to store variable binding information 
+	 * (i.e, mapping from variable name to its value) for implementations of 
+	 * XPath 3.1 'inline function', 'for', 'let' and 'quantified' expressions.
+	 * 
+	 * We don't use, Xalan-J xpath variable stack for this purpose.
+	 */
+	private Map<QName, XObject> xpathVarMap = new HashMap<QName, XObject>();
+	
+	/**
+	 * This data value, represents certain custom data (represented 
+	 * as a java.util.Map object) within the current XPath 3.1 evaluation 
+	 * context.
+	 */
+	private Map<String, String> m_customDataMap = new HashMap<String, String>();
+	  
+	/**
+	 * Stack of cached "reusable" DTMs for Result Tree Fragments.
+	 * This is a kluge to handle the problem of starting an RTF before
+	 * the old one is complete.
+	 * 
+	 * %REVIEW% I'm using a Vector rather than Stack so we can reuse
+	 * the DTMs if the problem occurs multiple times. I'm not sure that's
+	 * really a net win versus discarding the DTM and starting a new one...
+	 * but the retained RTF DTM will have been tail-pruned so should be small.
+	 */
+	protected Vector m_rtfdtm_stack = null;
+
+	/**
+	 * Though XPathContext context extends 
+	 * the DTMManager, it really is a proxy for this object, which 
+	 * is the real DTMManager.
+	 */
+	protected DTMManager m_dtmManager = DTMManager.newInstance(
+			                                                org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
+
+	/**
+	 * Get an instance of a DTM, loaded with the content from the
+	 * specified source.  If the unique flag is true, a new instance will
+	 * always be returned.  Otherwise it is up to the DTMManager to return a
+	 * new instance or an instance that it already created and may be being used
+	 * by someone else.
+	 * (I think more parameters will need to be added for error handling, and entity
+	 * resolution).
+	 *
+	 * @param source the specification of the source object, which may be null, 
+	 *               in which case it is assumed that node construction will take 
+	 *               by some other means.
+	 * @param unique true if the returned DTM must be unique, probably because it
+	 * is going to be mutated.
+	 * @param wsfilter Enables filtering of whitespace nodes, and may be null.
+	 * @param incremental true if the construction should try and be incremental.
+	 * @param doIndexing true if the caller considers it worth it to use 
+	 *                   indexing schemes.
+	 *
+	 * @return a non-null DTM reference.
+	 */
+	public DTM getDTM(javax.xml.transform.Source source, boolean unique, 
+																		DTMWSFilter wsfilter,
+																		boolean incremental,
+																		boolean doIndexing) {
+		return m_dtmManager.getDTM(source, unique, wsfilter, incremental, doIndexing);
+	}
+
+	/**
+	 * Get an instance of a DTM that "owns" a node handle. 
+	 *
+	 * @param nodeHandle the nodeHandle.
+	 *
+	 * @return a non-null DTM reference.
+	 */
+	public DTM getDTM(int nodeHandle) {
+		return m_dtmManager.getDTM(nodeHandle);
+	}
+
+	/**
+	 * Given a W3C DOM node, try and return a DTM handle.
+	 * Note: calling this may be non-optimal.
+	 * 
+	 * @param node Non-null reference to a DOM node.
+	 * 
+	 * @return a valid DTM handle.
+	 */
+	public int getDTMHandleFromNode(org.w3c.dom.Node node) {
+		return m_dtmManager.getDTMHandleFromNode(node);
+	}
+
+	/**
+	 * Creates an empty <code>DocumentFragment</code> object. 
+	 * @return A new <code>DocumentFragment handle</code>.
+	 */
+	public DTM createDocumentFragment() {
+		return m_dtmManager.createDocumentFragment();
+	}
+
+	/**
+	 * Release a DTM either to a lru pool, or completely remove reference.
+	 * DTMs without system IDs are always hard deleted.
+	 * State: experimental.
+	 * 
+	 * @param dtm The DTM to be released.
+	 * @param shouldHardDelete True if the DTM should be removed no matter what.
+	 * @return true if the DTM was removed, false if it was put back in a lru pool.
+	 */
+	public boolean release(DTM dtm, boolean shouldHardDelete) {
+		// %REVIEW% If it's a DTM which may contain multiple Result Tree
+		// Fragments, we can't discard it unless we know not only that it
+		// is empty, but that the XPathContext itself is going away. So do
+		// _not_ accept the request. (May want to do it as part of
+		// reset(), though.)
+		if(m_rtfdtm_stack!=null && m_rtfdtm_stack.contains(dtm))
+		{
+			return false;
+		}
+
+		return m_dtmManager.release(dtm, shouldHardDelete);
+	}
+
+	/**
+	 * Create a new <code>DTMIterator</code> based on an XPath
+	 * <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or
+	 * a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>.
+	 *
+	 * @param xpathCompiler ??? Somehow we need to pass in a subpart of the
+	 * expression.  I hate to do this with strings, since the larger expression
+	 * has already been parsed.
+	 *
+	 * @param pos The position in the expression.
+	 * @return The newly created <code>DTMIterator</code>.
+	 */
+	public DTMCursorIterator createDTMIterator(Object xpathCompiler, int pos) {
+		return m_dtmManager.createDTMIterator(xpathCompiler, pos);
+	}
+
+	/**
+	 * Create a new <code>DTMIterator</code> based on an XPath
+	 * <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or
+	 * a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>.
+	 *
+	 * @param xpathString Must be a valid string expressing a
+	 * <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or
+	 * a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>.
+	 *
+	 * @param presolver An object that can resolve prefixes to namespace URLs.
+	 *
+	 * @return The newly created <code>DTMIterator</code>.
+	 */
+	public DTMCursorIterator createDTMIterator(String xpathString, PrefixResolver presolver) {
+		return m_dtmManager.createDTMIterator(xpathString, presolver);
+	}
+
+	//
+	/**
+	 * Create a new <code>DTMIterator</code> based only on a whatToShow and
+	 * a DTMFilter.  The traversal semantics are defined as the descendant
+	 * access.
+	 *
+	 * @param whatToShow This flag specifies which node types may appear in
+	 *   the logical view of the tree presented by the iterator. See the
+	 *   description of <code>NodeFilter</code> for the set of possible
+	 *   <code>SHOW_</code> values.These flags can be combined using
+	 *   <code>OR</code>.
+	 * @param filter The <code>NodeFilter</code> to be used with this
+	 *   <code>TreeWalker</code>, or <code>null</code> to indicate no filter.
+	 * @param entityReferenceExpansion The value of this flag determines
+	 *   whether entity reference nodes are expanded.
+	 *
+	 * @return The newly created <code>NodeIterator</code>.
+	 */
+	public DTMCursorIterator createDTMIterator(int whatToShow, DTMFilter filter, 
+			                                                                   boolean entityReferenceExpansion) {
+		return m_dtmManager.createDTMIterator(whatToShow, filter, entityReferenceExpansion);
+	}
+
+	/**
+	 * Create a new <code>DTMIterator</code> that holds exactly one node.
+	 *
+	 * @param node The node handle that the DTMIterator will iterate to.
+	 *
+	 * @return The newly created <code>DTMIterator</code>.
+	 */
+	public DTMCursorIterator createDTMIterator(int node) {
+		DTMCursorIterator iter = new org.apache.xpath.axes.OneStepIteratorForward(Axis.SELF);
+		iter.setRoot(node, this);
+		
+		return iter;
+	}
+
+	/**
+	 * Given a DTM, find the id number in the DTM tables which addresses
+	 * the start of the document.
+	 */
+	public int getDTMIdentity(DTM dtm) {
+		return m_dtmManager.getDTMIdentity(dtm);
+	}
+	
+	/**
+	 * Get the value of implicit timezone.
+	 * 
+	 * @return                             Implicit timezone as xs:dayTimeDuration value. 
+	 */
+	public XSDuration getTimezone() {
+		if (m_timezone == null) {
+			ZonedDateTime zonedDateTime = ZonedDateTime.now();
+			ZoneOffset zoneOffset = zonedDateTime.getOffset();
+			String zoneOffsetStr = zoneOffset.toString();
+			String[] zoneOffsetStrParts = zoneOffsetStr.split("\\+|\\-|:");
+			int zoneHrs = 0;
+			int zoneMinutes = 0;
+			if (zoneOffsetStrParts.length > 1) {
+				zoneHrs = (new Integer(zoneOffsetStrParts[1])).intValue();
+				zoneMinutes = (new Integer(zoneOffsetStrParts[2])).intValue();
+			}
+			boolean isNegativeTimezone = !zoneOffsetStr.startsWith("+");
+			
+			m_timezone = new XSDayTimeDuration(0, zoneHrs, zoneMinutes, 0, isNegativeTimezone);
+		}
+
+		return m_timezone;
+	}
+
+	public void setTimezone(XSDuration timezone) {
+		this.m_timezone = timezone;
+	}
+	
+	public void setPos(int pos) {
+		this.m_pos = pos;
+	}
+
+	public int getPos() {
+		return this.m_pos;
+	}
+
+	public void setLast(int last) {
+		this.m_last = last;	
+	}
+
+	public int getLast() {
+		return this.m_last;
+	}
+	
+	public XObject getXPath3ContextItem() {
+		return m_xpath3ContextItem;
+	}
+
+	public void setXPath3ContextItem(XObject xpath3ContextItem) {
+		this.m_xpath3ContextItem = xpath3ContextItem;
+	}
+
+	public int getXPath3ContextPosition() {
+		return m_xpath3ContextPosition;
+	}
+
+	public void setXPath3ContextPosition(int xpath3ContextPosition) {
+		this.m_xpath3ContextPosition = xpath3ContextPosition;
+	}
+
+	public int getXPath3ContextSize() {
+		return m_xpath3ContextSize;
+	}
+
+	public void setXPath3ContextSize(int xpath3ContextSize) {
+		this.m_xpath3ContextSize = xpath3ContextSize;
+	}
+	
+	public GregorianCalendar getCurrentDateTime() {
+		if (m_currentDateTime == null) {
+			m_currentDateTime = new GregorianCalendar(TimeZone.getDefault());
+		}
+
+		return m_currentDateTime;
+	}
+
+	public void setCurrentDateTime(GregorianCalendar currentDateTime) {
+		this.m_currentDateTime = currentDateTime;
+	}
+
+	public Map<QName, XObject> getXPathVarMap() {
+		return xpathVarMap;
+	}
+
+	public void setXPathVarMap(Map<QName, XObject> xpathVarMap) {
+		this.xpathVarMap = xpathVarMap;
+	}
+	
+	public Map<String, String> getCustomDataMap() {
+		return m_customDataMap;
+	}
+
+	public void setCustomDataMap(Map<String, String> customDataMap) {
+		this.m_customDataMap = customDataMap;
+	}
+
+}
diff --git a/src/main/java/org/apache/xpath/XPath3StaticContext.java b/src/main/java/org/apache/xpath/XPath3StaticContext.java
new file mode 100644
index 000000000..b2c18b4e2
--- /dev/null
+++ b/src/main/java/org/apache/xpath/XPath3StaticContext.java
@@ -0,0 +1,107 @@
+/*
+ * 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;
+
+import org.apache.xpath.compiler.FunctionTable;
+import org.apache.xpath.functions.XSL3FunctionService;
+import org.apache.xpath.functions.XSLFunctionBuilder;
+
+/**
+ * A class definition, that implements XPath 3.1 expression evaluation's 
+ * static context.
+ * 
+ * Please refer to, XPath 3.1 recommendation section, '2.1.1 Static Context'.
+ * 
+ * @author Scott Boag <sc...@us.ibm.com>
+ * @author Gary L Peskin <ga...@apache.org>
+ * @author Myriam Midy <mm...@apache.org>
+ * 
+ * @author Joseph Kesselman <ke...@alum.mit.edu>
+ * @author Morris Kwan <mk...@apache.org>, Ilene Seelemann <il...@apache.org>, Henry Zongaro <zo...@ca.ibm.com>,
+ *         Brian Minchau <mi...@apache.org>, Sarah McNamara <mc...@apache.org>
+ *         
+ * @author Mukul Gandhi <mu...@apache.org>
+ *         (XPath 3.1 specific changes, to this class)
+ * 
+ * @xsl.usage general
+ */
+public class XPath3StaticContext extends XPath3DynamicContext {
+	
+	/**
+	 * XPath 3.1 built-in functions namespace uri, for most of the functions
+	 * available to XPath 3.1 language users. The XPath functions available within
+	 * this namespace, may be used without binding the function name with an XML 
+	 * namespace, or binding with a non-null XML namespace (the commonly used XML 
+	 * namespace prefix for this namespace uri is "fn", as specified by
+	 * XPath 3.1 spec).
+	 */
+	public static final String XPATH_BUILT_IN_FUNCS_NS_URI = "http://www.w3.org/2005/xpath-functions";
+	
+	/**
+	 * XPath 3.1 built-in functions namespace uri, for maths trigonometric and exponential 
+	 * functions. The XPath functions available within this namespace, must be used by 
+	 * qualifying the function name with an XML namespace bound to this uri (the commonly 
+	 * used XML namespace prefix for this namespace uri is "math", as specified by 
+	 * XPath 3.1 spec).
+	 */
+	public static final String XPATH_BUILT_IN_MATH_FUNCS_NS_URI = "http://www.w3.org/2005/xpath-functions/math";
+	
+	/**
+	 * XPath 3.1 built-in functions namespace uri, for map related functions. The XPath functions available 
+	 * within this namespace, must be used by qualifying the function name with an XML namespace bound to this 
+	 * uri (the commonly used XML namespace prefix for this namespace uri is "map", as specified by 
+	 * XPath 3.1 spec).
+	 */
+	public static final String XPATH_BUILT_IN_MAP_FUNCS_NS_URI = "http://www.w3.org/2005/xpath-functions/map";
+	
+	/**
+	 * XPath 3.1 built-in functions namespace uri, for array related functions. The XPath functions available 
+	 * within this namespace, must be used by qualifying the function name with an XML namespace bound to this 
+	 * uri (the commonly used XML namespace prefix for this namespace uri is "array", as specified by 
+	 * XPath 3.1 spec).
+	 */
+	public static final String XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI = "http://www.w3.org/2005/xpath-functions/array";
+	
+	/**
+	 * The default collation uri (the default collation for Xalan-J's XSL 3 support 
+	 * is, "Unicode Codepoint Collation").
+	 */
+	private String m_default_collation = XPathCollationSupport.UNICODE_CODEPOINT_COLLATION_URI;
+
+	/**
+	 * An XPathCollationSupport object instance to support, collations within XPath implementation.
+	 */
+	private XPathCollationSupport m_collationSupport = new XPathCollationSupport(m_default_collation);
+
+	public XPathCollationSupport getXPathCollationSupport() {
+		return m_collationSupport;
+	}
+
+	public String getDefaultCollation() {
+		return m_default_collation;
+	}
+	
+	public FunctionTable getFunctionTable() {
+		return new FunctionTable();
+	}
+
+	public XSL3FunctionService getXSLFunctionService() {
+		return XSLFunctionBuilder.getXSLFunctionService(); 
+	}
+
+}
diff --git a/src/main/java/org/apache/xpath/XPathContext.java b/src/main/java/org/apache/xpath/XPathContext.java
index 04f486681..087c35e28 100644
--- a/src/main/java/org/apache/xpath/XPathContext.java
+++ b/src/main/java/org/apache/xpath/XPathContext.java
@@ -18,14 +18,9 @@
 package org.apache.xpath;
 
 import java.lang.reflect.Method;
-import java.time.ZoneOffset;
-import java.time.ZonedDateTime;
-import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.Stack;
-import java.util.TimeZone;
 import java.util.Vector;
 
 import javax.xml.transform.ErrorListener;
@@ -35,63 +30,53 @@ import javax.xml.transform.URIResolver;
 
 import org.apache.xalan.extensions.ExpressionContext;
 import org.apache.xalan.res.XSLMessages;
-import org.apache.xml.dtm.Axis;
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMCursorIterator;
-import org.apache.xml.dtm.DTMFilter;
 import org.apache.xml.dtm.DTMManager;
-import org.apache.xml.dtm.DTMWSFilter;
 import org.apache.xml.dtm.ref.sax2dtm.SAX2RTFDTM;
 import org.apache.xml.utils.IntStack;
 import org.apache.xml.utils.NodeVector;
 import org.apache.xml.utils.ObjectStack;
 import org.apache.xml.utils.PrefixResolver;
-import org.apache.xml.utils.QName;
 import org.apache.xml.utils.SAXSourceLocator;
 import org.apache.xml.utils.XMLString;
 import org.apache.xpath.axes.SubContextList;
-import org.apache.xpath.compiler.FunctionTable;
-import org.apache.xpath.functions.XSL3FunctionService;
-import org.apache.xpath.functions.XSLFunctionBuilder;
 import org.apache.xpath.objects.DTMXRTreeFrag;
 import org.apache.xpath.objects.XObject;
 import org.apache.xpath.objects.XString;
 import org.apache.xpath.res.XPATHErrorResources;
 import org.xml.sax.XMLReader;
 
-import xml.xpath31.processor.types.XSDayTimeDuration;
-import xml.xpath31.processor.types.XSDuration;
-
 /**
- * Default class for the runtime execution context for XPath.
+ * Class definition, to represent XPath 3.1 expression's evaluation 
+ * context.
+ * 
+ * @author Scott Boag <sc...@us.ibm.com>
+ * @author Gary L Peskin <ga...@apache.org>
+ * @author Myriam Midy <mm...@apache.org>
+ * 
+ * @author Joseph Kesselman <ke...@alum.mit.edu>
+ * @author Morris Kwan <mk...@apache.org>, Ilene Seelemann <il...@apache.org>, Henry Zongaro <zo...@ca.ibm.com>,
+ *         Brian Minchau <mi...@apache.org>, Sarah McNamara <mc...@apache.org>
+ *         
+ * @author Mukul Gandhi <mu...@apache.org>
+ *         (XPath 3.1 specific changes, to this class)         
  * 
- * @xsl.usage advanced
+ * @xsl.usage general
  */
-public class XPathContext extends DTMManager // implements ExpressionContext
+public class XPathContext extends XPath3StaticContext
 {
   
-  IntStack m_last_pushed_rtfdtm=new IntStack();
-  
-  /**
-   * Stack of cached "reusable" DTMs for Result Tree Fragments.
-   * This is a kluge to handle the problem of starting an RTF before
-   * the old one is complete.
-   * 
-   * %REVIEW% I'm using a Vector rather than Stack so we can reuse
-   * the DTMs if the problem occurs multiple times. I'm not sure that's
-   * really a net win versus discarding the DTM and starting a new one...
-   * but the retained RTF DTM will have been tail-pruned so should be small.
-   */
-  private Vector m_rtfdtm_stack=null;
+  private IntStack m_last_pushed_rtfdtm = new IntStack();
   
   /** Index of currently active RTF DTM in m_rtfdtm_stack */
-  private int m_which_rtfdtm=-1;
+  private int m_which_rtfdtm = -1;
   
   /**
    * Most recent "reusable" DTM for Global Result Tree Fragments. No stack is
    * required since we're never going to pop these.
    */
-  private SAX2RTFDTM m_global_rtfdtm=null;
+  private SAX2RTFDTM m_global_rtfdtm = null;
   
   /**
    * HashMap of cached the DTMXRTreeFrag objects, which are identified by DTM IDs.
@@ -102,77 +87,7 @@ public class XPathContext extends DTMManager // implements ExpressionContext
   /**
    * state of the secure processing feature.
    */
-  private boolean m_isSecureProcessing = false;
-  
-  /**
-   *  This data value, represents the XPath 3.1's current evaluation 
-   *  context item. This is in addition to, XPath context item
-   *  retrieved in other ways, by Xalan-J implementation.
-   */
-  private XObject m_xpath3ContextItem = null;
-  
-  /**
-   *  This data value, represents the XPath 3.1's current evaluation 
-   *  context position.
-   */
-  private int m_xpath3ContextPosition = -1;
-  
-  /**
-   *  This data value, represents the XPath 3.1's current evaluation 
-   *  context size.
-   */
-  private int m_xpath3ContextSize = -1; 
-  
-  /**
-   * This data value, represents certain custom data (represented 
-   * as a java.util.Map object) within the current XPath 3.1 evaluation 
-   * context.
-   */
-  private Map<String, String> m_customDataMap = new HashMap<String, String>();
-  
-  private GregorianCalendar m_currentDateTime;
-  
-  private XSDuration m_timezone;
-  
-  /**
-   * We use this java.util.Map object, to store variable binding information 
-   * (i.e, mapping from variable name to its value) for implementations of 
-   * XPath 3.1 'inline function', 'for', 'let' and 'quantified' expressions.
-   * 
-   * We don't use, Xalan-J xpath variable stack for this purpose.
-   */
-  private Map<QName, XObject> xpathVarMap = new HashMap<QName, XObject>();
-  
-  /**
-   * The default collation uri (the default collation for Xalan-J's XSL 3 support 
-   * is, "Unicode Codepoint Collation").
-   */
-  private String m_default_collation = XPathCollationSupport.UNICODE_CODEPOINT_COLLATION_URI;
-  
-  /**
-   * An XPathCollationSupport object instance to support, collations within XPath implementation.
-   */
-  private XPathCollationSupport m_collationSupport = new XPathCollationSupport(m_default_collation);
-	
-  /**
-   * Though XPathContext context extends 
-   * the DTMManager, it really is a proxy for this object, which 
-   * is the real DTMManager.
-   */
-  protected DTMManager m_dtmManager = DTMManager.newInstance(
-                   											org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
-  
-  /** 
-   * The value of this class field, represents the value returned by fn:position() 
-   * function when called within XSL instructions 'xsl:for-each-group' or 'xsl:analyze-string'.
-   */
-  private int m_pos;
-  
-  /** 
-   * The value of this class field, represents the value returned by fn:last() 
-   * function when called within XSL instructions 'xsl:for-each-group' or 'xsl:analyze-string'.
-   */
-  private int m_last;
+  private boolean m_isSecureProcessing = false; 
   
   /**
    * Return the DTMManager object. Though XPathContext context extends 
@@ -200,181 +115,9 @@ public class XPathContext extends DTMManager // implements ExpressionContext
   {
     return m_isSecureProcessing;
   }
-  
-  /**
-   * Get an instance of a DTM, loaded with the content from the
-   * specified source.  If the unique flag is true, a new instance will
-   * always be returned.  Otherwise it is up to the DTMManager to return a
-   * new instance or an instance that it already created and may be being used
-   * by someone else.
-   * (I think more parameters will need to be added for error handling, and entity
-   * resolution).
-   *
-   * @param source the specification of the source object, which may be null, 
-   *               in which case it is assumed that node construction will take 
-   *               by some other means.
-   * @param unique true if the returned DTM must be unique, probably because it
-   * is going to be mutated.
-   * @param wsfilter Enables filtering of whitespace nodes, and may be null.
-   * @param incremental true if the construction should try and be incremental.
-   * @param doIndexing true if the caller considers it worth it to use 
-   *                   indexing schemes.
-   *
-   * @return a non-null DTM reference.
-   */
-  public DTM getDTM(javax.xml.transform.Source source, boolean unique, 
-                    DTMWSFilter wsfilter,
-                    boolean incremental,
-                    boolean doIndexing)
-  {
-    return m_dtmManager.getDTM(source, unique, wsfilter, 
-                               incremental, doIndexing);
-  }
-                             
-  /**
-   * Get an instance of a DTM that "owns" a node handle. 
-   *
-   * @param nodeHandle the nodeHandle.
-   *
-   * @return a non-null DTM reference.
-   */
-  public DTM getDTM(int nodeHandle)
-  {
-    return m_dtmManager.getDTM(nodeHandle);
-  }
-
-  /**
-   * Given a W3C DOM node, try and return a DTM handle.
-   * Note: calling this may be non-optimal.
-   * 
-   * @param node Non-null reference to a DOM node.
-   * 
-   * @return a valid DTM handle.
-   */
-  public int getDTMHandleFromNode(org.w3c.dom.Node node)
-  {
-    return m_dtmManager.getDTMHandleFromNode(node);
-  }
-//
-//  
-  /**
-   * %TBD% Doc
-   */
-  public int getDTMIdentity(DTM dtm)
-  {
-    return m_dtmManager.getDTMIdentity(dtm);
-  }
-//  
-  /**
-   * Creates an empty <code>DocumentFragment</code> object. 
-   * @return A new <code>DocumentFragment handle</code>.
-   */
-  public DTM createDocumentFragment()
-  {
-    return m_dtmManager.createDocumentFragment();
-  }
-//  
-  /**
-   * Release a DTM either to a lru pool, or completely remove reference.
-   * DTMs without system IDs are always hard deleted.
-   * State: experimental.
-   * 
-   * @param dtm The DTM to be released.
-   * @param shouldHardDelete True if the DTM should be removed no matter what.
-   * @return true if the DTM was removed, false if it was put back in a lru pool.
-   */
-  public boolean release(DTM dtm, boolean shouldHardDelete)
-  {
-    // %REVIEW% If it's a DTM which may contain multiple Result Tree
-    // Fragments, we can't discard it unless we know not only that it
-    // is empty, but that the XPathContext itself is going away. So do
-    // _not_ accept the request. (May want to do it as part of
-    // reset(), though.)
-    if(m_rtfdtm_stack!=null && m_rtfdtm_stack.contains(dtm))
-    {
-      return false;
-    }
-  	
-    return m_dtmManager.release(dtm, shouldHardDelete);
-  }
-
-  /**
-   * Create a new <code>DTMIterator</code> based on an XPath
-   * <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or
-   * a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>.
-   *
-   * @param xpathCompiler ??? Somehow we need to pass in a subpart of the
-   * expression.  I hate to do this with strings, since the larger expression
-   * has already been parsed.
-   *
-   * @param pos The position in the expression.
-   * @return The newly created <code>DTMIterator</code>.
-   */
-  public DTMCursorIterator createDTMIterator(Object xpathCompiler, int pos)
-  {
-    return m_dtmManager.createDTMIterator(xpathCompiler, pos);
-  }
-//
-  /**
-   * Create a new <code>DTMIterator</code> based on an XPath
-   * <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or
-   * a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>.
-   *
-   * @param xpathString Must be a valid string expressing a
-   * <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or
-   * a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>.
-   *
-   * @param presolver An object that can resolve prefixes to namespace URLs.
-   *
-   * @return The newly created <code>DTMIterator</code>.
-   */
-  public DTMCursorIterator createDTMIterator(String xpathString,
-          PrefixResolver presolver)
-  {
-    return m_dtmManager.createDTMIterator(xpathString, presolver);
-  }
-//
-  /**
-   * Create a new <code>DTMIterator</code> based only on a whatToShow and
-   * a DTMFilter.  The traversal semantics are defined as the descendant
-   * access.
-   *
-   * @param whatToShow This flag specifies which node types may appear in
-   *   the logical view of the tree presented by the iterator. See the
-   *   description of <code>NodeFilter</code> for the set of possible
-   *   <code>SHOW_</code> values.These flags can be combined using
-   *   <code>OR</code>.
-   * @param filter The <code>NodeFilter</code> to be used with this
-   *   <code>TreeWalker</code>, or <code>null</code> to indicate no filter.
-   * @param entityReferenceExpansion The value of this flag determines
-   *   whether entity reference nodes are expanded.
-   *
-   * @return The newly created <code>NodeIterator</code>.
-   */
-  public DTMCursorIterator createDTMIterator(int whatToShow,
-          DTMFilter filter, boolean entityReferenceExpansion)
-  {
-    return m_dtmManager.createDTMIterator(whatToShow, filter, entityReferenceExpansion);
-  }
-  
-  /**
-   * Create a new <code>DTMIterator</code> that holds exactly one node.
-   *
-   * @param node The node handle that the DTMIterator will iterate to.
-   *
-   * @return The newly created <code>DTMIterator</code>.
-   */
-  public DTMCursorIterator createDTMIterator(int node)
-  {
-    // DescendantIterator iter = new DescendantIterator();
-    DTMCursorIterator iter = new org.apache.xpath.axes.OneStepIteratorForward(Axis.SELF);
-    iter.setRoot(node, this);
-    return iter;
-    // return m_dtmManager.createDTMIterator(node);
-  }
 
   /**
-   * Create an XPathContext instance.  This is equivalent to calling
+   * Create an XPathContext instance. This is equivalent to calling
    * the {@link #XPathContext(boolean)} constructor with the value
    * <code>true</code>.
    */
@@ -384,46 +127,49 @@ public class XPathContext extends DTMManager // implements ExpressionContext
 
   /**
    * Create an XPathContext instance.
-   * @param recursiveVarContext A <code>boolean</code> value indicating whether
-   *             the XPath context needs to support pushing of scopes for
-   *             variable resolution
+   * 
+   * @param recursiveVarContext         A <code>boolean</code> value indicating whether
+   *                                    the XPath context needs to support pushing of scopes for
+   *                                    variable resolution.
    */
   public XPathContext(boolean recursiveVarContext) {
-    m_prefixResolvers.push(null);
-    m_currentNodes.push(DTM.NULL);
-    m_currentExpressionNodes.push(DTM.NULL);
-    m_saxLocations.push(null);
-    m_variableStacks = recursiveVarContext ? new VariableStack()
-                                           : new VariableStack(1);
+	  m_prefixResolvers.push(null);
+	  m_currentNodes.push(DTM.NULL);
+	  m_currentExpressionNodes.push(DTM.NULL);
+	  m_saxLocations.push(null);
+	  m_variableStacks = recursiveVarContext ? new VariableStack() 
+			                                                      : new VariableStack(1);
   }
 
   /**
-   * Create an XPathContext instance.  This is equivalent to calling the
+   * Create an XPathContext instance. This is equivalent to calling the
    * constructor {@link #XPathContext(java.lang.Object,boolean)} with the
    * value of the second parameter set to <code>true</code>.
+   * 
    * @param owner Value that can be retrieved via the getOwnerObject() method.
    * @see #getOwnerObject
    */
   public XPathContext(Object owner)
   {
-    this(owner, true);
+	  this(owner, true);
   }
 
   /**
    * Create an XPathContext instance.
+   * 
    * @param owner Value that can be retrieved via the getOwnerObject() method.
    * @see #getOwnerObject
-   * @param recursiveVarContext A <code>boolean</code> value indicating whether
-   *             the XPath context needs to support pushing of scopes for
-   *             variable resolution
+   * @param recursiveVarContext           A <code>boolean</code> value indicating whether
+   *                                      the XPath context needs to support pushing of scopes for
+   *                                      variable resolution.
    */
   public XPathContext(Object owner, boolean recursiveVarContext) {
-    this(recursiveVarContext);
-    m_owner = owner;
-    try {
-      m_ownerGetErrorListener = m_owner.getClass().getMethod("getErrorListener", new Class[] {});
-    }
-    catch (NoSuchMethodException nsme) {}
+	  this(recursiveVarContext);
+	  m_owner = owner;
+	  try {
+		  m_ownerGetErrorListener = m_owner.getClass().getMethod("getErrorListener", new Class[] {});
+	  }
+	  catch (NoSuchMethodException nsme) {}
   }
 
   /**
@@ -431,37 +177,37 @@ public class XPathContext extends DTMManager // implements ExpressionContext
    */
   public void reset()
   {
-    releaseDTMXRTreeFrags();
-  	// These couldn't be disposed of earlier (see comments in release()); zap them now.
-  	if(m_rtfdtm_stack!=null)
-  		 for (java.util.Enumeration e = m_rtfdtm_stack.elements() ; e.hasMoreElements() ;) 
-  		 	m_dtmManager.release((DTM)e.nextElement(), true);
-
-    m_rtfdtm_stack=null; // drop our references too
-    m_which_rtfdtm=-1;
-    
-    if(m_global_rtfdtm!=null)
-  		 	m_dtmManager.release(m_global_rtfdtm,true);
-    m_global_rtfdtm=null;
-    
-  	
-    m_dtmManager = DTMManager.newInstance(
-                   org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
-                   
-    m_saxLocations.removeAllElements();   
-	m_axesIteratorStack.removeAllElements();
-	m_contextNodeLists.removeAllElements();
-	m_currentExpressionNodes.removeAllElements();
-	m_currentNodes.removeAllElements();
-	m_iteratorRoots.RemoveAllNoClear();
-	m_predicatePos.removeAllElements();
-	m_predicateRoots.RemoveAllNoClear();
-	m_prefixResolvers.removeAllElements();
-	
-	m_prefixResolvers.push(null);
-    m_currentNodes.push(DTM.NULL);
-    m_currentExpressionNodes.push(DTM.NULL);
-    m_saxLocations.push(null);
+	  releaseDTMXRTreeFrags();
+	  // These couldn't be disposed of earlier (see comments in release()); zap them now.
+	  if(m_rtfdtm_stack!=null)
+		  for (java.util.Enumeration e = m_rtfdtm_stack.elements() ; e.hasMoreElements() ;) 
+			  m_dtmManager.release((DTM)e.nextElement(), true);
+
+	  m_rtfdtm_stack=null; // drop our references too
+	  m_which_rtfdtm=-1;
+
+	  if(m_global_rtfdtm!=null)
+		  m_dtmManager.release(m_global_rtfdtm,true);
+	  m_global_rtfdtm=null;
+
+
+	  m_dtmManager = DTMManager.newInstance(
+			                               org.apache.xpath.objects.XMLStringFactoryImpl.getFactory());
+
+	  m_saxLocations.removeAllElements();   
+	  m_axesIteratorStack.removeAllElements();
+	  m_contextNodeLists.removeAllElements();
+	  m_currentExpressionNodes.removeAllElements();
+	  m_currentNodes.removeAllElements();
+	  m_iteratorRoots.RemoveAllNoClear();
+	  m_predicatePos.removeAllElements();
+	  m_predicateRoots.RemoveAllNoClear();
+	  m_prefixResolvers.removeAllElements();
+
+	  m_prefixResolvers.push(null);
+	  m_currentNodes.push(DTM.NULL);
+	  m_currentExpressionNodes.push(DTM.NULL);
+	  m_saxLocations.push(null);
   }
 
   /** The current stylesheet locator. */
@@ -490,14 +236,12 @@ public class XPathContext extends DTMManager // implements ExpressionContext
   /**
    * Push a slot on the locations stack so that setSAXLocator can be 
    * repeatedly called.
-   *
    */
   public void pushSAXLocatorNull()
   {
     m_saxLocations.push(null);
   }
 
-
   /**
    * Pop the current locater.
    */
@@ -857,8 +601,6 @@ public class XPathContext extends DTMManager // implements ExpressionContext
     m_prefixResolvers.pop();
   }
 
-
-
   /**
    * Set the current context node.
    *
@@ -1426,116 +1168,4 @@ public class XPathContext extends DTMManager // implements ExpressionContext
     m_DTMXRTreeFrags = null;
   }
   
-  public FunctionTable getFunctionTable() {
-	  return new FunctionTable();
-  }
-
-  public Map<String, String> getCustomDataMap() {
-	  return m_customDataMap;
-  }
-
-  public void setCustomDataMap(Map<String, String> customDataMap) {
-	  this.m_customDataMap = customDataMap;
-  }
-
-  public XObject getXPath3ContextItem() {
-	  return m_xpath3ContextItem;
-  }
-
-  public void setXPath3ContextItem(XObject xpath3ContextItem) {
-	  this.m_xpath3ContextItem = xpath3ContextItem;
-  }
-
-  public int getXPath3ContextPosition() {
-	  return m_xpath3ContextPosition;
-  }
-
-  public void setXPath3ContextPosition(int xpath3ContextPosition) {
-	  this.m_xpath3ContextPosition = xpath3ContextPosition;
-  }
-
-  public int getXPath3ContextSize() {
-	  return m_xpath3ContextSize;
-  }
-
-  public void setXPath3ContextSize(int xpath3ContextSize) {
-	  this.m_xpath3ContextSize = xpath3ContextSize;
-  }
-
-  public GregorianCalendar getCurrentDateTime() {
-	  if (m_currentDateTime == null) {
-		  m_currentDateTime = new GregorianCalendar(TimeZone.getDefault());
-	  }
-
-	  return m_currentDateTime;
-  }
-
-  public void setCurrentDateTime(GregorianCalendar currentDateTime) {
-	  this.m_currentDateTime = currentDateTime;
-  }
-
-  /**
-   * Get the value of implicit timezone.
-   * 
-   * @return        Implicit timezone as xs:dayTimeDuration value. 
-   */
-  public XSDuration getTimezone() {
-	  if (m_timezone == null) {
-		  ZonedDateTime zonedDateTime = ZonedDateTime.now();
-		  ZoneOffset zoneOffset = zonedDateTime.getOffset();
-		  String zoneOffsetStr = zoneOffset.toString();
-		  String[] zoneOffsetStrParts = zoneOffsetStr.split("\\+|\\-|:");
-		  int zoneHrs = 0;
-		  int zoneMinutes = 0;
-		  if (zoneOffsetStrParts.length > 1) {
-			  zoneHrs = (new Integer(zoneOffsetStrParts[1])).intValue();
-			  zoneMinutes = (new Integer(zoneOffsetStrParts[2])).intValue();
-		  }
-		  boolean isNegativeTimezone = !zoneOffsetStr.startsWith("+");
-		  m_timezone = new XSDayTimeDuration(0, zoneHrs, zoneMinutes, 0, isNegativeTimezone);
-	  }
-
-	  return m_timezone;
-  }
-
-  public void setTimezone(XSDuration timezone) {
-	  this.m_timezone = timezone;
-  }
-
-  public Map<QName, XObject> getXPathVarMap() {
-	  return xpathVarMap;
-  }
-
-  public void setXPathVarMap(Map<QName, XObject> xpathVarMap) {
-	  this.xpathVarMap = xpathVarMap;
-  }
-
-  public XPathCollationSupport getXPathCollationSupport() {
-	  return m_collationSupport;
-  }
-
-  public String getDefaultCollation() {
-	  return m_default_collation;
-  }
-  
-  public XSL3FunctionService getXSLFunctionService() {
-	  return XSLFunctionBuilder.getXSLFunctionService(); 
-  }
-
-  public void setPos(int pos) {
-	 this.m_pos = pos;
-  }
-  
-  public int getPos() {
-	 return this.m_pos;
-  }
-
-  public void setLast(int last) {
-	 this.m_last = last;	
-  }
-  
-  public int getLast() {
-     return this.m_last;
-  }
-  
 }
diff --git a/src/main/java/org/apache/xpath/compiler/FunctionTable.java b/src/main/java/org/apache/xpath/compiler/FunctionTable.java
index d63c80b1b..68800ff79 100644
--- a/src/main/java/org/apache/xpath/compiler/FunctionTable.java
+++ b/src/main/java/org/apache/xpath/compiler/FunctionTable.java
@@ -580,25 +580,6 @@ public class FunctionTable
   /** The 'document-location()' id (Proprietary). */
   public static final int FUNC_DOCLOCATION = 35;
   
-  /**
-   * XPath 3.1 built-in functions namespace uri, for most of the functions
-   * available to XPath 3.1 language users. The XPath functions available within
-   * this namespace, may be used without binding the function name with an XML 
-   * namespace, or binding with a non-null XML namespace (the commonly used XML 
-   * namespace prefix for this namespace uri is "fn", as specified by
-   * XPath 3.1 spec).
-   */
-  public static final String XPATH_BUILT_IN_FUNCS_NS_URI = "http://www.w3.org/2005/xpath-functions";
-  
-  /**
-   * XPath 3.1 built-in functions namespace uri, for maths trigonometric and exponential 
-   * functions. The XPath functions available within this namespace, must be used by 
-   * qualifying the function name with an XML namespace bound to this uri (the commonly 
-   * used XML namespace prefix for this namespace uri is "math", as specified by 
-   * XPath 3.1 spec).
-   */
-  public static final String XPATH_BUILT_IN_MATH_FUNCS_NS_URI = "http://www.w3.org/2005/xpath-functions/math";
-  
   static final Integer[] XPATH_MATH_FUNC_IDS = new Integer[] { new Integer(FUNC_MATH_PI), new Integer(FUNC_MATH_EXP),
                                                                new Integer(FUNC_MATH_EXP10), new Integer(FUNC_MATH_LOG),
                                                                new Integer(FUNC_MATH_LOG10), new Integer(FUNC_MATH_POW),
@@ -609,13 +590,6 @@ public class FunctionTable
   
   static final List<Integer> XPATH_MATH_FUNC_IDS_ARR = Arrays.asList(XPATH_MATH_FUNC_IDS);
   
-  /**
-   * XPath 3.1 built-in functions namespace uri, for map related functions. The XPath functions available 
-   * within this namespace, must be used by qualifying the function name with an XML namespace bound to this 
-   * uri (the commonly used XML namespace prefix for this namespace uri is "map", as specified by 
-   * XPath 3.1 spec).
-   */
-  public static final String XPATH_BUILT_IN_MAP_FUNCS_NS_URI = "http://www.w3.org/2005/xpath-functions/map";
     
   static final Integer[] XPATH_MAP_FUNC_IDS = new Integer[] { new Integer(FUNC_MAP_MERGE), new Integer(FUNC_MAP_SIZE), 
 		                                                      new Integer(FUNC_MAP_KEYS), new Integer(FUNC_MAP_CONTAINS), 
@@ -625,13 +599,6 @@ public class FunctionTable
   
   static final List<Integer> XPATH_MAP_FUNC_IDS_ARR = Arrays.asList(XPATH_MAP_FUNC_IDS);
   
-  /**
-   * XPath 3.1 built-in functions namespace uri, for array related functions. The XPath functions available 
-   * within this namespace, must be used by qualifying the function name with an XML namespace bound to this 
-   * uri (the commonly used XML namespace prefix for this namespace uri is "array", as specified by 
-   * XPath 3.1 spec).
-   */
-  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_APPEND),
diff --git a/src/main/java/org/apache/xpath/compiler/XPathParser.java b/src/main/java/org/apache/xpath/compiler/XPathParser.java
index 07b3675aa..d28a2c916 100644
--- a/src/main/java/org/apache/xpath/compiler/XPathParser.java
+++ b/src/main/java/org/apache/xpath/compiler/XPathParser.java
@@ -81,6 +81,7 @@ import org.apache.xml.utils.ObjectVector;
 import org.apache.xml.utils.PrefixResolver;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionNode;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathProcessorException;
 import org.apache.xpath.composite.ForQuantifiedExprVarBinding;
 import org.apache.xpath.composite.LetExprVarBinding;
@@ -1334,18 +1335,18 @@ public class XPathParser
       // a FilterExpr. 
       id = Keywords.lookupNodeTest(key);
       if (id == null) {
-    	if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(nsUri)) {
+    	if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(nsUri)) {
     	   // This check is there, to avoid XPath parse conflicts with map & array 
     	   // functions with same local name as functions from namespace http://www.w3.org/2005/xpath-functions. 
     	   id = m_functionTable.getFunctionIdForXPathBuiltinFuncs(key);
     	}
-    	else if ((FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(nsUri)) {    	       	   
+    	else if ((XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(nsUri)) {    	       	   
      	   id = m_functionTable.getFunctionIdForXPathBuiltinMathFuncs(key);
      	}
-    	else if ((FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(nsUri)) {    	       	   
+    	else if ((XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(nsUri)) {    	       	   
     	   id = m_functionTable.getFunctionIdForXPathBuiltinMapFuncs(key);
     	}
-    	else if ((FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(nsUri)) {     	   
+    	else if ((XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(nsUri)) {     	   
      	  id = m_functionTable.getFunctionIdForXPathBuiltinArrayFuncs(key);
      	}
     	else {
@@ -5056,10 +5057,10 @@ public class XPathParser
        if (idx != -1) {
     	  String xpathLhsStr = xpathExprStr.substring(0, idx);    	  
     	  String xpathRhsStr = xpathExprStr.substring(idx + 1);
-    	  if (xpathLhsStr.endsWith(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI) || 
-								    			  		xpathLhsStr.endsWith(FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI) ||
-								    			  		xpathLhsStr.endsWith(FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI) ||
-								    			  		xpathLhsStr.endsWith(FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI)) {
+    	  if (xpathLhsStr.endsWith(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI) || 
+													    			  		xpathLhsStr.endsWith(XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI) ||
+													    			  		xpathLhsStr.endsWith(XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI) ||
+													    			  		xpathLhsStr.endsWith(XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI)) {
               restoreTokenQueueScanPosition(prevTokQueueScanPosition);
               
     		  Expr(); 
@@ -5125,17 +5126,17 @@ public class XPathParser
 
 	  if (lookahead(':', 1))
 	  {
-		  if (tokenIs(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI)) 
+		  if (tokenIs(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI)) 
 		  {
 			  nextToken();
 			  consumeExpected(':');
 
-			  int funcTok = getFunctionToken(m_token, FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI);
+			  int funcTok = getFunctionToken(m_token, XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI);
 
 			  if (-1 == funcTok)
 			  {
 				  error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
-						  new Object[] {"{" + FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI + "}" + m_token + "()"});
+						  new Object[] {"{" + XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI + "}" + m_token + "()"});
 			  }         
 
 			  switch (funcTok)
@@ -5154,17 +5155,17 @@ public class XPathParser
 
 			  nextToken();
 		  }
-		  else if (tokenIs(FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI)) 
+		  else if (tokenIs(XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI)) 
 		  {
 			  nextToken();
 			  consumeExpected(':');
 
-			  int funcTok = getFunctionToken(m_token, FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI);
+			  int funcTok = getFunctionToken(m_token, XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI);
 
 			  if (-1 == funcTok)
 			  {
 				  error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
-						  new Object[] {"{" + FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI + "}" + m_token + "()"});
+						  new Object[] {"{" + XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI + "}" + m_token + "()"});
 			  }         
 
 			  switch (funcTok)
@@ -5183,17 +5184,17 @@ public class XPathParser
 
 			  nextToken();
 		  }
-		  else if (tokenIs(FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI)) 
+		  else if (tokenIs(XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI)) 
 		  {
 			  nextToken();
 			  consumeExpected(':');
 
-			  int funcTok = getFunctionToken(m_token, FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI);
+			  int funcTok = getFunctionToken(m_token, XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI);
 
 			  if (-1 == funcTok)
 			  {
 				  error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
-						  new Object[] {"{" + FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI + "}" + m_token + "()"});
+						  new Object[] {"{" + XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI + "}" + m_token + "()"});
 			  }         
 
 			  switch (funcTok)
@@ -5212,17 +5213,17 @@ public class XPathParser
 
 			  nextToken();
 		  }
-		  else if (tokenIs(FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI)) 
+		  else if (tokenIs(XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI)) 
 		  {
 			  nextToken();
 			  consumeExpected(':');
 
-			  int funcTok = getFunctionToken(m_token, FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI);
+			  int funcTok = getFunctionToken(m_token, XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI);
 
 			  if (-1 == funcTok)
 			  {
 				  error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
-						  new Object[] {"{" + FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI + "}" + m_token + "()"});
+						  new Object[] {"{" + XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI + "}" + m_token + "()"});
 			  }         
 
 			  switch (funcTok)
@@ -5256,12 +5257,12 @@ public class XPathParser
 	  }
 	  else
 	  {
-		  int funcTok = getFunctionToken(m_token, FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI);
+		  int funcTok = getFunctionToken(m_token, XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI);
 
 		  if (-1 == funcTok)
 		  {
 			  error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
-					  new Object[]{"{" + FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI + "}" + m_token + "()"});
+					  new Object[]{"{" + XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI + "}" + m_token + "()"});
 		  }      
 
 		  switch (funcTok)
@@ -7878,9 +7879,9 @@ public class XPathParser
     */
 	private void handleXPathParseNamedFuncRefWithNSQual(int opPos) throws TransformerException {				    	  
 
-		if (tokenIs(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI) || tokenIs(FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI) ||
-																  tokenIs(FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI) || 
-				                                                  tokenIs(FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI)) {
+		if (tokenIs(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI) || tokenIs(XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI) ||
+																	    tokenIs(XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI) || 
+					                                                    tokenIs(XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI)) {
 			String funcNamespaceUri = m_token;
 			String nextTokenToAnalyze = getTokenRelative(1);
 			
@@ -8017,7 +8018,7 @@ public class XPathParser
 		TokenQueueScanPosition prevTokQueueScanPosition = new TokenQueueScanPosition(m_queueMark, m_tokenChar, m_token);
 
 		String funcName = m_token.substring(0, m_token.indexOf('#'));
-		int funcTok = getFunctionToken(funcName, FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI);
+		int funcTok = getFunctionToken(funcName, XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI);
 		if (funcTok >= 0) {
 			String namedFuncRef = m_token;
 			nextToken();
@@ -8025,7 +8026,7 @@ public class XPathParser
 
 			m_xpathNamedFunctionReference = new XPathNamedFunctionReference();
 			m_xpathNamedFunctionReference.setFuncName(funcName);
-			m_xpathNamedFunctionReference.setFuncNamespace(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI);			
+			m_xpathNamedFunctionReference.setFuncNamespace(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI);			
 			String funcArityStr = namedFuncRef.substring(namedFuncRef.indexOf('#') + 1);
 			if ((Keywords.FUNC_CONCAT_STRING).equals(funcName)) {
 			   m_xpathNamedFunctionReference.setConcatArity(Integer.valueOf(funcArityStr));
@@ -8532,10 +8533,10 @@ public class XPathParser
   	     char chr2 = str.charAt(strLength - 1);
   	     if (chr2 == ')') {
   	    	String str2 = str.substring(0, idx1); 
-  	    	int funcTok1 = getFunctionToken(str2, FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI);
-  	    	int funcTok2 = getFunctionToken(str2, FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI);
-  	    	int funcTok3 = getFunctionToken(str2, FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI);
-  	    	int funcTok4 = getFunctionToken(str2, FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI);
+  	    	int funcTok1 = getFunctionToken(str2, XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI);
+  	    	int funcTok2 = getFunctionToken(str2, XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI);
+  	    	int funcTok3 = getFunctionToken(str2, XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI);
+  	    	int funcTok4 = getFunctionToken(str2, XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI);
   	    	if ((funcTok1 > -1) || (funcTok2 > -1) || (funcTok3 > -1) || (funcTok4 > -1)) {
   	    		result = true;
   	    	}
diff --git a/src/main/java/org/apache/xpath/composite/XPathIfExpr.java b/src/main/java/org/apache/xpath/composite/XPathIfExpr.java
index 916321023..ff507a8be 100644
--- a/src/main/java/org/apache/xpath/composite/XPathIfExpr.java
+++ b/src/main/java/org/apache/xpath/composite/XPathIfExpr.java
@@ -28,6 +28,7 @@ import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionOwner;
 import org.apache.xpath.XPath;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
 import org.apache.xpath.axes.SelfIteratorNoPredicate;
@@ -174,10 +175,10 @@ public class XPathIfExpr extends Expression {
        if ((evalResult instanceof XPathNamedFunctionReference) && (m_xpathSuffixStr != null)) {
     	   XPathNamedFunctionReference xPathNamedFunctionReference = (XPathNamedFunctionReference)evalResult;
     	   String funcNamespace = xPathNamedFunctionReference.getFuncNamespace();
-    	   if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) || 
-    		   (FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(funcNamespace) ||
-    		   (FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(funcNamespace) ||
-    		   (FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(funcNamespace)) {
+    	   if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) || 
+    		   (XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(funcNamespace) ||
+    		   (XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(funcNamespace) ||
+    		   (XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(funcNamespace)) {
     		   XSL3FunctionService xsl3FunctionService = XSLFunctionBuilder.getXSLFunctionService();
     		   ResultSequence argSeq = new ResultSequence();
     		   if (!m_xpathSuffixStr.equals("()")) {
diff --git a/src/main/java/org/apache/xpath/composite/XPathLetExpr.java b/src/main/java/org/apache/xpath/composite/XPathLetExpr.java
index 52859cc7a..c974a0b65 100644
--- a/src/main/java/org/apache/xpath/composite/XPathLetExpr.java
+++ b/src/main/java/org/apache/xpath/composite/XPathLetExpr.java
@@ -33,6 +33,7 @@ import org.apache.xml.utils.QName;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionOwner;
 import org.apache.xpath.XPath;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
 import org.apache.xpath.compiler.FunctionTable;
@@ -132,7 +133,7 @@ public class XPathLetExpr extends Expression {
     			   String funcLocalName = xpathNamedFuncRef.getFuncName();
     			   int concatArity = 0;
     			   short funcArity = 0;
-    			   if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && (Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
+    			   if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && (Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
     				   concatArity = xpathNamedFuncRef.getConcatArity();
     				   FuncConcat funcConcat = new FuncConcat();
     				   if ((concatArity < funcConcat.getMinArity()) || (concatArity > funcConcat.getMaxArity())) {
@@ -150,16 +151,16 @@ public class XPathLetExpr extends Expression {
     			   FunctionTable funcTable = xctxt.getFunctionTable();
 
     			   Object funcIdObj = null;
-    			   if (FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
+    			   if (XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
     				   funcIdObj = funcTable.getFunctionId(funcLocalName);
     			   }
-    			   else if (FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
+    			   else if (XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
     				   funcIdObj = funcTable.getFunctionIdForXPathBuiltinMathFuncs(funcLocalName);
     			   }
-    			   else if (FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
+    			   else if (XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
     				   funcIdObj = funcTable.getFunctionIdForXPathBuiltinMapFuncs(funcLocalName);
     			   }
-    			   else if (FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
+    			   else if (XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
     				   funcIdObj = funcTable.getFunctionIdForXPathBuiltinArrayFuncs(funcLocalName);
     			   }
 
diff --git a/src/main/java/org/apache/xpath/composite/XPathQuantifiedExpr.java b/src/main/java/org/apache/xpath/composite/XPathQuantifiedExpr.java
index 3bbe7cde4..16774bfbd 100644
--- a/src/main/java/org/apache/xpath/composite/XPathQuantifiedExpr.java
+++ b/src/main/java/org/apache/xpath/composite/XPathQuantifiedExpr.java
@@ -34,6 +34,7 @@ import org.apache.xml.utils.QName;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionOwner;
 import org.apache.xpath.XPath;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
 import org.apache.xpath.compiler.FunctionTable;
@@ -239,10 +240,10 @@ public class XPathQuantifiedExpr extends Expression {
            if (idx2 != -1) {
         	  String xpathLhsStr = varBindingXPathStr.substring(0, idx2);
         	  String xpathRhsStr = varBindingXPathStr.substring(idx2 + 1);
-         	  if (!(xpathLhsStr.endsWith(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI) || 
-															         			 xpathLhsStr.endsWith(FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI) ||
-															         			 xpathLhsStr.endsWith(FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI) ||
-															         			 xpathLhsStr.endsWith(FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI))) {         		 
+         	  if (!(xpathLhsStr.endsWith(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI) || 
+																	         			 xpathLhsStr.endsWith(XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI) ||
+																	         			 xpathLhsStr.endsWith(XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI) ||
+																	         			 xpathLhsStr.endsWith(XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI))) {         		 
        		     if (!XPathParser.isStrHasXPathAxisNamePrefix(xpathRhsStr) && (xpathRhsStr.endsWith("()") || xpathRhsStr.endsWith("(.)"))) {    		  
        		    	XPath xpathLhsObj = new XPath(xpathLhsStr, srcLocator, xctxt.getNamespaceContext(), XPath.SELECT, null);
        		    	
diff --git a/src/main/java/org/apache/xpath/functions/FuncCurrentDateTime.java b/src/main/java/org/apache/xpath/functions/FuncCurrentDateTime.java
index 38d85096e..7837b22ea 100644
--- a/src/main/java/org/apache/xpath/functions/FuncCurrentDateTime.java
+++ b/src/main/java/org/apache/xpath/functions/FuncCurrentDateTime.java
@@ -48,20 +48,20 @@ public class FuncCurrentDateTime extends Function {
    }
 
    /**
-   * Execute the function. The function must return a valid object.
+   * Implementation of the function. The function must return a valid object.
    * 
-   * @param xctxt The current execution context.
+   * @param xctxt                       An XPath context object
    * 
-   * @return A valid XObject.
+   * @return                            A valid XObject
    *
    * @throws javax.xml.transform.TransformerException
    */
   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
     
-    XSDateTime xsDateTime = new XSDateTime(xctxt.getCurrentDateTime(), xctxt.getTimezone());
-    xsDateTime.setPopulatedFromFnCurrentDateTime(true);
-    
-    return xsDateTime;
+	  XSDateTime xsDateTime = new XSDateTime(xctxt.getCurrentDateTime(), xctxt.getTimezone());
+	  xsDateTime.setPopulatedFromFnCurrentDateTime(true);
+
+	  return xsDateTime;
   }
 
   /**
diff --git a/src/main/java/org/apache/xpath/functions/FuncFunctionArity.java b/src/main/java/org/apache/xpath/functions/FuncFunctionArity.java
index 0efee1c54..120ca370b 100644
--- a/src/main/java/org/apache/xpath/functions/FuncFunctionArity.java
+++ b/src/main/java/org/apache/xpath/functions/FuncFunctionArity.java
@@ -33,6 +33,7 @@ import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xml.utils.QName;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionNode;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.compiler.FunctionTable;
 import org.apache.xpath.composite.XPathNamedFunctionReference;
@@ -167,8 +168,8 @@ public class FuncFunctionArity extends FunctionDef1Arg
 				String localName = xpathNamedFunctionReference.getFuncName();
 				String namespace = xpathNamedFunctionReference.getFuncNamespace();
 				Short arity = xpathNamedFunctionReference.getArity(); 
-				if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(namespace) || (FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(namespace) ||
-					(FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(namespace) || (FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(namespace)) {
+				if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(namespace) || (XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(namespace) ||
+					(XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(namespace) || (XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(namespace)) {
 					FunctionTable funcTable = xctxt.getFunctionTable();
 					Object funcId = funcTable.getFunctionId(localName);
 					if (funcId != null) {
@@ -254,10 +255,10 @@ public class FuncFunctionArity extends FunctionDef1Arg
 		
 		ElemFunction elemFunction = xpathNamedFunctionReference.getXslStylesheetFunction();
 		
-		if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) || (FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(funcNamespace) ||
-				                                                                 (FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(funcNamespace) || 
-				                                                                 (FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(funcNamespace) ||
-				                                                                 (XMLConstants.W3C_XML_SCHEMA_NS_URI).equals(funcNamespace)) {				   
+		if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) || (XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(funcNamespace) ||
+						                                                               (XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(funcNamespace) || 
+						                                                               (XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(funcNamespace) ||
+						                                                               (XMLConstants.W3C_XML_SCHEMA_NS_URI).equals(funcNamespace)) {				   
 			XSL3FunctionService xsl3FunctionService = XSLFunctionBuilder.getXSLFunctionService();
 			Function function = xsl3FunctionService.getXPathBuiltInFunction(funcName, funcNamespace, xctxt);
 			
diff --git a/src/main/java/org/apache/xpath/functions/FuncFunctionName.java b/src/main/java/org/apache/xpath/functions/FuncFunctionName.java
index 96a90243b..482275611 100644
--- a/src/main/java/org/apache/xpath/functions/FuncFunctionName.java
+++ b/src/main/java/org/apache/xpath/functions/FuncFunctionName.java
@@ -33,6 +33,7 @@ import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xml.utils.QName;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionNode;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.compiler.FunctionTable;
 import org.apache.xpath.composite.XPathNamedFunctionReference;
@@ -188,7 +189,7 @@ public class FuncFunctionName extends FunctionDef1Arg
 		String namespace = xpathNamedFunctionReference.getFuncNamespace();
 		String prefix = null;
 		Short arity = xpathNamedFunctionReference.getArity();
-		if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(namespace)) {
+		if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(namespace)) {
 			prefix = "fn";
 			Object funcId = funcTable.getFunctionId(localName);
 			if (funcId != null) {
@@ -209,7 +210,7 @@ public class FuncFunctionName extends FunctionDef1Arg
 
 			result = new XSQName(prefix, localName, namespace);
 		}
-		else if ((FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(namespace)) {
+		else if ((XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(namespace)) {
 			prefix = "math";
 			Object funcId = funcTable.getFunctionId(localName);
 			if (funcId != null) {
@@ -230,7 +231,7 @@ public class FuncFunctionName extends FunctionDef1Arg
 
 			result = new XSQName(prefix, localName, namespace);
 		}
-		else if ((FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(namespace)) {
+		else if ((XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(namespace)) {
 			prefix = "map";
 			Object funcId = funcTable.getFunctionId(localName);
 			if (funcId != null) {
@@ -251,7 +252,7 @@ public class FuncFunctionName extends FunctionDef1Arg
 
 			result = new XSQName(prefix, localName, namespace);
 		}
-		else if ((FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(namespace)) {
+		else if ((XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(namespace)) {
 			prefix = "array";
 			Object funcId = funcTable.getFunctionId(localName);
 			if (funcId != null) {
diff --git a/src/main/java/org/apache/xpath/functions/XSL3FunctionService.java b/src/main/java/org/apache/xpath/functions/XSL3FunctionService.java
index 80e881c4c..0fe16be77 100644
--- a/src/main/java/org/apache/xpath/functions/XSL3FunctionService.java
+++ b/src/main/java/org/apache/xpath/functions/XSL3FunctionService.java
@@ -57,6 +57,7 @@ import org.apache.xml.utils.QName;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionNode;
 import org.apache.xpath.XPath;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.axes.SelfIteratorNoPredicate;
 import org.apache.xpath.compiler.FunctionTable;
@@ -233,9 +234,9 @@ public class XSL3FunctionService {
     						String namespace = xpathNamedFunctionReference.getFuncNamespace();
     						Short arity = xpathNamedFunctionReference.getArity();    					   
     						if ((int)arity == funcExtArgStrList.size()) {
-    							if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(namespace) || (FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(namespace) ||
-    									                                                             (FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(namespace) || 
-    									                                                             (FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(namespace)) {
+    							if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(namespace) || (XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(namespace) ||
+    									                                                                   (XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(namespace) || 
+    									                                                                   (XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(namespace)) {
     								FunctionTable funcTable = xctxt.getFunctionTable();
     								Object funcId = funcTable.getFunctionId(localName);
     								if (funcId != null) {
@@ -849,8 +850,8 @@ public class XSL3FunctionService {
     	String funcNamespace = xpathNamedFuncRef.getFuncNamespace();
     	String funcLocalName = xpathNamedFuncRef.getFuncName();
     	int funcArity = 0;           
-    	if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
-    																		(Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
+    	if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
+    																		     (Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
     		funcArity = xpathNamedFuncRef.getConcatArity();
     	}
     	else {
@@ -862,16 +863,16 @@ public class XSL3FunctionService {
     	FunctionTable funcTable = xctxt.getFunctionTable();
 
     	Object funcIdObj = null;
-    	if (FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
+    	if (XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
     		funcIdObj = funcTable.getFunctionId(funcLocalName);
     	}
-    	else if (FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
+    	else if (XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
     		funcIdObj = funcTable.getFunctionIdForXPathBuiltinMathFuncs(funcLocalName);
     	}
-    	else if (FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
+    	else if (XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
     		funcIdObj = funcTable.getFunctionIdForXPathBuiltinMapFuncs(funcLocalName);
     	}
-    	else if (FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
+    	else if (XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
     		funcIdObj = funcTable.getFunctionIdForXPathBuiltinArrayFuncs(funcLocalName);
     	}
 
@@ -1021,22 +1022,22 @@ public class XSL3FunctionService {
         
         FunctionTable funcTable = xctxt.getFunctionTable();
         
-        if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace)) {
+        if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace)) {
            Object funcId = funcTable.getFunctionIdForXPathBuiltinFuncs(funcName);
            int funcIdValue = (int)Integer.valueOf(funcId.toString());
            result = funcTable.getFunction(funcIdValue);
         }
-        else if ((FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(funcNamespace)) {
+        else if ((XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI).equals(funcNamespace)) {
            Object funcId = funcTable.getFunctionIdForXPathBuiltinMathFuncs(funcName);
            int funcIdValue = (int)Integer.valueOf(funcId.toString());
            result = funcTable.getFunction(funcIdValue);
         }
-        else if ((FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(funcNamespace)) {
+        else if ((XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI).equals(funcNamespace)) {
            Object funcId = funcTable.getFunctionIdForXPathBuiltinMapFuncs(funcName);
            int funcIdValue = (int)Integer.valueOf(funcId.toString());
            result = funcTable.getFunction(funcIdValue);
         }
-        else if ((FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(funcNamespace)) {
+        else if ((XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI).equals(funcNamespace)) {
            Object funcId = funcTable.getFunctionIdForXPathBuiltinArrayFuncs(funcName);
            int funcIdValue = (int)Integer.valueOf(funcId.toString());
            result = funcTable.getFunction(funcIdValue);
diff --git a/src/main/java/org/apache/xpath/functions/hof/FuncApply.java b/src/main/java/org/apache/xpath/functions/hof/FuncApply.java
index 3796cf23a..f3c9396ef 100644
--- a/src/main/java/org/apache/xpath/functions/hof/FuncApply.java
+++ b/src/main/java/org/apache/xpath/functions/hof/FuncApply.java
@@ -34,6 +34,7 @@ import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xml.utils.QName;
 import org.apache.xpath.Expression;
 import org.apache.xpath.XPath;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.compiler.FunctionTable;
 import org.apache.xpath.compiler.Keywords;
@@ -169,8 +170,8 @@ public class FuncApply extends Function2Args {
 	  String funcNamespace = namedFuncRef.getFuncNamespace();
 	  String funcLocalName = namedFuncRef.getFuncName();
 	  int funcArity = 0;           
-	  if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
-			  															(Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
+	  if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
+			  															        (Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
 		  funcArity = namedFuncRef.getConcatArity();
 	  }
 	  else {
@@ -180,16 +181,16 @@ public class FuncApply extends Function2Args {
 	  FunctionTable funcTable = xctxt.getFunctionTable();
 
 	  Object funcIdObj = null;
-	  if (FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
+	  if (XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
 		  funcIdObj = funcTable.getFunctionId(funcLocalName);
 	  }
-	  else if (FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
+	  else if (XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
 		  funcIdObj = funcTable.getFunctionIdForXPathBuiltinMathFuncs(funcLocalName);
 	  }
-	  else if (FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
+	  else if (XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
 		  funcIdObj = funcTable.getFunctionIdForXPathBuiltinMapFuncs(funcLocalName);
 	  }
-	  else if (FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
+	  else if (XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
 		  funcIdObj = funcTable.getFunctionIdForXPathBuiltinArrayFuncs(funcLocalName);
 	  }
 
diff --git a/src/main/java/org/apache/xpath/functions/hof/FuncForEach.java b/src/main/java/org/apache/xpath/functions/hof/FuncForEach.java
index 3cc9baee4..228cfc4b9 100644
--- a/src/main/java/org/apache/xpath/functions/hof/FuncForEach.java
+++ b/src/main/java/org/apache/xpath/functions/hof/FuncForEach.java
@@ -32,6 +32,7 @@ import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMCursorIterator;
 import org.apache.xml.utils.QName;
 import org.apache.xpath.XPath;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.axes.LocPathIterator;
 import org.apache.xpath.compiler.FunctionTable;
@@ -325,8 +326,8 @@ public class FuncForEach extends Function2Args {
 	  String funcNamespace = namedFuncRef.getFuncNamespace();
 	  String funcLocalName = namedFuncRef.getFuncName();
 	  int funcArity = 0;           
-	  if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
-			  															(Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
+	  if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
+			  															        (Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
 		  funcArity = namedFuncRef.getConcatArity();
 	  }
 	  else {
@@ -336,16 +337,16 @@ public class FuncForEach extends Function2Args {
 	  FunctionTable funcTable = xctxt.getFunctionTable();
 
 	  Object funcIdObj = null;
-	  if (FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
+	  if (XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
 		  funcIdObj = funcTable.getFunctionId(funcLocalName);
 	  }
-	  else if (FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
+	  else if (XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
 		  funcIdObj = funcTable.getFunctionIdForXPathBuiltinMathFuncs(funcLocalName);
 	  }
-	  else if (FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
+	  else if (XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
 		  funcIdObj = funcTable.getFunctionIdForXPathBuiltinMapFuncs(funcLocalName);
 	  }
-	  else if (FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
+	  else if (XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
 		  funcIdObj = funcTable.getFunctionIdForXPathBuiltinArrayFuncs(funcLocalName);
 	  }
 
diff --git a/src/main/java/org/apache/xpath/functions/hof/FuncForEachPair.java b/src/main/java/org/apache/xpath/functions/hof/FuncForEachPair.java
index 0d0660ad1..0725e2586 100644
--- a/src/main/java/org/apache/xpath/functions/hof/FuncForEachPair.java
+++ b/src/main/java/org/apache/xpath/functions/hof/FuncForEachPair.java
@@ -30,6 +30,7 @@ import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xml.dtm.DTMCursorIterator;
 import org.apache.xml.utils.QName;
 import org.apache.xpath.XPath;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.compiler.FunctionTable;
 import org.apache.xpath.compiler.Keywords;
@@ -135,8 +136,8 @@ public class FuncForEachPair extends XPathHigherOrderBuiltinFunction {
            String funcNamespace = namedFuncRef.getFuncNamespace();
            String funcLocalName = namedFuncRef.getFuncName();
            int funcArity = 0;           
-           if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
-        		                                                              (Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
+           if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
+        		                                                                     (Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
         	   funcArity = namedFuncRef.getConcatArity();
            }
            else {
@@ -146,16 +147,16 @@ public class FuncForEachPair extends XPathHigherOrderBuiltinFunction {
            FunctionTable funcTable = xctxt.getFunctionTable();
            
            Object funcIdObj = null;
-           if (FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
+           if (XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
               funcIdObj = funcTable.getFunctionId(funcLocalName);
            }
-           else if (FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
+           else if (XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
               funcIdObj = funcTable.getFunctionIdForXPathBuiltinMathFuncs(funcLocalName);
            }
-           else if (FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
+           else if (XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
               funcIdObj = funcTable.getFunctionIdForXPathBuiltinMapFuncs(funcLocalName);
            }
-           else if (FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
+           else if (XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
               funcIdObj = funcTable.getFunctionIdForXPathBuiltinArrayFuncs(funcLocalName);
            }
            
diff --git a/src/main/java/org/apache/xpath/functions/hof/FuncSort.java b/src/main/java/org/apache/xpath/functions/hof/FuncSort.java
index 7c089d86a..ff25ad35f 100644
--- a/src/main/java/org/apache/xpath/functions/hof/FuncSort.java
+++ b/src/main/java/org/apache/xpath/functions/hof/FuncSort.java
@@ -35,6 +35,7 @@ import org.apache.xml.dtm.DTMCursorIterator;
 import org.apache.xml.dtm.DTMManager;
 import org.apache.xml.utils.QName;
 import org.apache.xpath.XPath;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.compiler.FunctionTable;
 import org.apache.xpath.compiler.Keywords;
@@ -205,8 +206,8 @@ public class FuncSort extends FunctionMultiArgs
                       String funcNamespace = namedFuncRef.getFuncNamespace();
                       String funcLocalName = namedFuncRef.getFuncName();
                       int funcArity = 0;           
-                	  if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
-                			  															(Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
+                	  if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
+                			  															        (Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
                 		  funcArity = namedFuncRef.getConcatArity();
                 	  }
                 	  else {
@@ -216,16 +217,16 @@ public class FuncSort extends FunctionMultiArgs
                       FunctionTable funcTable = xctxt.getFunctionTable();
                       
                       Object funcIdObj = null;
-                      if (FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
+                      if (XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
                          funcIdObj = funcTable.getFunctionId(funcLocalName);
                       }
-                      else if (FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
+                      else if (XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
                          funcIdObj = funcTable.getFunctionIdForXPathBuiltinMathFuncs(funcLocalName);
                       }
-                      else if (FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
+                      else if (XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
                          funcIdObj = funcTable.getFunctionIdForXPathBuiltinMapFuncs(funcLocalName);
                       }
-                      else if (FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
+                      else if (XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
                          funcIdObj = funcTable.getFunctionIdForXPathBuiltinArrayFuncs(funcLocalName);
                       }
                       
@@ -316,8 +317,8 @@ public class FuncSort extends FunctionMultiArgs
                      String funcNamespace = namedFuncRef.getFuncNamespace();
                      String funcLocalName = namedFuncRef.getFuncName();
                      int funcArity = 0;           
-                     if ((FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
-                    		                                                            (Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
+                     if ((XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI).equals(funcNamespace) && 
+                    		                                                                   (Keywords.FUNC_CONCAT_STRING).equals(funcLocalName)) {
                     	 funcArity = namedFuncRef.getConcatArity();
                      }
                      else {
@@ -327,16 +328,16 @@ public class FuncSort extends FunctionMultiArgs
                      FunctionTable funcTable = xctxt.getFunctionTable();
                      
                      Object funcIdObj = null;
-                     if (FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
+                     if (XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI.equals(funcNamespace)) {
                         funcIdObj = funcTable.getFunctionId(funcLocalName);
                      }
-                     else if (FunctionTable.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
+                     else if (XPath3StaticContext.XPATH_BUILT_IN_MATH_FUNCS_NS_URI.equals(funcNamespace)) {
                         funcIdObj = funcTable.getFunctionIdForXPathBuiltinMathFuncs(funcLocalName);
                      }
-                     else if (FunctionTable.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
+                     else if (XPath3StaticContext.XPATH_BUILT_IN_MAP_FUNCS_NS_URI.equals(funcNamespace)) {
                         funcIdObj = funcTable.getFunctionIdForXPathBuiltinMapFuncs(funcLocalName);
                      }
-                     else if (FunctionTable.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
+                     else if (XPath3StaticContext.XPATH_BUILT_IN_ARRAY_FUNCS_NS_URI.equals(funcNamespace)) {
                         funcIdObj = funcTable.getFunctionIdForXPathBuiltinArrayFuncs(funcLocalName);
                      }
                      
diff --git a/src/main/java/org/apache/xpath/functions/json/FuncJsonToXml.java b/src/main/java/org/apache/xpath/functions/json/FuncJsonToXml.java
index e77d82e3e..7e27e0f1e 100644
--- a/src/main/java/org/apache/xpath/functions/json/FuncJsonToXml.java
+++ b/src/main/java/org/apache/xpath/functions/json/FuncJsonToXml.java
@@ -37,6 +37,7 @@ import org.apache.xalan.xslt.util.XslTransformEvaluationHelper;
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMManager;
 import org.apache.xpath.Expression;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.compiler.FunctionTable;
 import org.apache.xpath.objects.XBoolean;
@@ -427,7 +428,7 @@ public class FuncJsonToXml extends JsonFunction
     private void constructXmlDom(Object jsonObj, Document document, Node parentNode, String keyVal) {
     	
     	if (jsonObj instanceof JSONObject) {
-    		Element mapElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.MAP);
+    		Element mapElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.MAP);
     		parentNode.appendChild(mapElem);    		
     		if (keyVal != null) {
     		   mapElem.setAttribute(XSLJsonConstants.KEY, keyVal);	
@@ -439,28 +440,28 @@ public class FuncJsonToXml extends JsonFunction
 	      	   Object value = ((JSONObject)jsonObj).get(key);
 	      	   
 	      	   if (value instanceof String) {
-	      		 Element strElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.STRING);
+	      		 Element strElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.STRING);
 	      		 strElem.setAttribute(XSLJsonConstants.KEY, key);
 	      		 Text text = document.createTextNode((String)value);
 	      		 strElem.appendChild(text);
 	      		 mapElem.appendChild(strElem);
 	      	   }
 	      	   else if (value instanceof Number) {
-	      		 Element numberElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.NUMBER);
+	      		 Element numberElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.NUMBER);
 	      		 numberElem.setAttribute(XSLJsonConstants.KEY, key);
 	      		 Text text = document.createTextNode(value.toString());
 	      		 numberElem.appendChild(text);
 	      		 mapElem.appendChild(numberElem);
 	      	   }
 	      	   else if (value instanceof Boolean) {
-	      		 Element boolElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.BOOLEAN);
+	      		 Element boolElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.BOOLEAN);
 	      		 boolElem.setAttribute(XSLJsonConstants.KEY, key);
 	      		 Text text = document.createTextNode(value.toString());
 	      		 boolElem.appendChild(text);
 	      		 mapElem.appendChild(boolElem);
 	      	   }	      	   
 	      	   else if (value instanceof JSONArray) {
-	      		  Element arrayElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.ARRAY);
+	      		  Element arrayElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.ARRAY);
 	      		  arrayElem.setAttribute(XSLJsonConstants.KEY, key);
 	      		  mapElem.appendChild(arrayElem);
 	      		  JSONArray jsonArr = (JSONArray)value;
@@ -468,25 +469,25 @@ public class FuncJsonToXml extends JsonFunction
 	    		  for (int idx = 0; idx < arrLen; idx++) {
 	    			  Object arrItem = jsonArr.get(idx);
 	    			  if (arrItem instanceof String) {
-	    				  Element strElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.STRING);
+	    				  Element strElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.STRING);
 	    				  Text text = document.createTextNode((String)arrItem);
 	    				  strElem.appendChild(text);
 	    				  arrayElem.appendChild(strElem);	 
 	    			  }
 	    			  else if (arrItem instanceof Number) {
-	    				  Element numberElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.NUMBER);
+	    				  Element numberElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.NUMBER);
 	    				  Text text = document.createTextNode(arrItem.toString());
 	    				  numberElem.appendChild(text);
 	    				  arrayElem.appendChild(numberElem); 
 	    			  }
 	    			  else if (arrItem instanceof Boolean) {
-	    				  Element boolElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.BOOLEAN);
+	    				  Element boolElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.BOOLEAN);
 	    				  Text text = document.createTextNode(arrItem.toString());
 	    				  boolElem.appendChild(text);
 	    				  arrayElem.appendChild(boolElem);  
 	    			  }
 	    			  else if (JSONObject.NULL.equals(arrItem)) {
-	         			  Element nullElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.NULL);
+	         			  Element nullElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.NULL);
 	         	          arrayElem.appendChild(nullElem);  
 	         		  }
 	    			  else if (arrItem instanceof JSONObject) {
@@ -501,7 +502,7 @@ public class FuncJsonToXml extends JsonFunction
 	      		  constructXmlDom(value, document, mapElem, key); 
 	      	   }
 	      	   else if ((JSONObject.NULL).equals(value)) {
-	      		  Element nullElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, "null");
+	      		  Element nullElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, "null");
 	      		  nullElem.setAttribute(XSLJsonConstants.KEY, key);
 	      		  mapElem.appendChild(nullElem);
 	      	   }
@@ -510,10 +511,10 @@ public class FuncJsonToXml extends JsonFunction
     	else if (jsonObj instanceof JSONArray) {
     		Element arrayElem = null;
     		if (parentNode.getNodeType() == Node.DOCUMENT_NODE) {
-    		   arrayElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.ARRAY);
+    		   arrayElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.ARRAY);
      		}
      		else {
-     		   arrayElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.ARRAY);
+     		   arrayElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.ARRAY);
      		}
     		
      		parentNode.appendChild(arrayElem);
@@ -527,25 +528,25 @@ public class FuncJsonToXml extends JsonFunction
     		for (int idx = 0; idx < arrLen; idx++) {
     		   Object arrItem = jsonArr.get(idx);
     		   if (arrItem instanceof String) {
-    			  Element strElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.STRING);
+    			  Element strElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.STRING);
   	      		  Text text = document.createTextNode((String)arrItem);
   	      		  strElem.appendChild(text);
   	      		  arrayElem.appendChild(strElem);	 
     		   }
     		   else if (arrItem instanceof Number) {
-    			  Element numberElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.NUMBER);
+    			  Element numberElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.NUMBER);
    	      		  Text text = document.createTextNode(arrItem.toString());
    	      		  numberElem.appendChild(text);
    	      		  arrayElem.appendChild(numberElem); 
     		   }
     		   else if (arrItem instanceof Boolean) {
-    			  Element boolElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.BOOLEAN);
+    			  Element boolElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.BOOLEAN);
     	          Text text = document.createTextNode(arrItem.toString());
     	          boolElem.appendChild(text);
     	          arrayElem.appendChild(boolElem);  
     		   }
     		   else if ((JSONObject.NULL).equals(arrItem)) {
-     			  Element nullElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.NULL);
+     			  Element nullElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, XSLJsonConstants.NULL);
      	          arrayElem.appendChild(nullElem);  
      		   }
     		   else if (arrItem instanceof JSONObject) {
diff --git a/src/main/java/org/apache/xpath/functions/string/FuncAnalyzeString.java b/src/main/java/org/apache/xpath/functions/string/FuncAnalyzeString.java
index fbcbd7c7f..6da5305db 100644
--- a/src/main/java/org/apache/xpath/functions/string/FuncAnalyzeString.java
+++ b/src/main/java/org/apache/xpath/functions/string/FuncAnalyzeString.java
@@ -28,6 +28,7 @@ import javax.xml.transform.TransformerException;
 import org.apache.xalan.res.XSLMessages;
 import org.apache.xalan.templates.Constants;
 import org.apache.xml.dtm.DTMManager;
+import org.apache.xpath.XPath3StaticContext;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.compiler.FunctionTable;
 import org.apache.xpath.functions.FunctionMultiArgs;
@@ -126,8 +127,8 @@ public class FuncAnalyzeString extends FunctionMultiArgs {
         
         Document document = createEmptyXmlDom(srcLocator);
         
-        Element analyzeStrResultElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, 
-        		                                                                                        "analyze-string-result");
+        Element analyzeStrResultElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, 
+        		                                                                                               "analyze-string-result");
         document.appendChild(analyzeStrResultElem);
         
         if (strToBeAnalyzed.length() > 0) {
@@ -300,7 +301,7 @@ public class FuncAnalyzeString extends FunctionMultiArgs {
 	 */
 	private void createNonMatchNodeToResult(Document document, Element analyzeStrResultElem, 
 			                                String nonMatchStr) {
-		Element nonMatchElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, "non-match");
+		Element nonMatchElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, "non-match");
 		Text txtNode2 = document.createTextNode(nonMatchStr);
 		nonMatchElem.appendChild(txtNode2);
 		analyzeStrResultElem.appendChild(nonMatchElem);
@@ -317,14 +318,14 @@ public class FuncAnalyzeString extends FunctionMultiArgs {
 	 */
 	private void createMatchNodeToResult(Document document, Element analyzeStrResultElem, 
 			                             String subsequenceStr, String regexStr) {
-		Element matchElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, "match");		
+		Element matchElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, "match");		
 		Pattern regexSubsequencePattern = Pattern.compile(regexStr);
 		Matcher regexSubsequenceMatcher = regexSubsequencePattern.matcher(subsequenceStr);
 		int grpCount = regexSubsequenceMatcher.groupCount();
 		if (grpCount > 0) {
 		   if (regexSubsequenceMatcher.matches()) {
 			   for (int idx = 0; idx < grpCount; idx++) {			  
-				  Element grpElem = document.createElementNS(FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI, "group");
+				  Element grpElem = document.createElementNS(XPath3StaticContext.XPATH_BUILT_IN_FUNCS_NS_URI, "group");
 				  grpElem.setAttribute("nr", String.valueOf(idx+1));
 				  String grpStrValue = regexSubsequenceMatcher.group(idx+1);
 				  Text grpTxtNode = document.createTextNode(grpStrValue);


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