Xalan3 specific additions and updates


git-svn-id: https://svn.apache.org/repos/asf/xalan/java/branches/xalan3@336638 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/org/apache/xpath/CachedXPathAPI.java b/src/org/apache/xpath/CachedXPathAPI.java
index 7946f50..f477ca5 100644
--- a/src/org/apache/xpath/CachedXPathAPI.java
+++ b/src/org/apache/xpath/CachedXPathAPI.java
@@ -65,7 +65,6 @@
 
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPath;
-import org.apache.xpath.compiler.XPathParser;
 import org.apache.xpath.XPathContext;
 import org.apache.xml.utils.PrefixResolverDefault;
 import org.apache.xml.utils.PrefixResolver;
@@ -319,7 +318,7 @@
       ? ((Document) namespaceNode).getDocumentElement() : namespaceNode);
 
     // Create the XPath object.
-    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
+    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null, 1.0);
 
     // Execute the XPath, and have it return the result
     // return xpath.execute(xpathSupport, contextNode, prefixResolver);
@@ -361,7 +360,7 @@
     //    because XPathContext is weak in a number of areas... perhaps
     //    XPathContext should be done away with.)
     // Create the XPath object.
-    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
+    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null, 1.0);
 
     // Execute the XPath, and have it return the result
     XPathContext xpathSupport = new XPathContext();
diff --git a/src/org/apache/xpath/Expression.java b/src/org/apache/xpath/Expression.java
index 778a3ce..7383881 100644
--- a/src/org/apache/xpath/Expression.java
+++ b/src/org/apache/xpath/Expression.java
@@ -57,25 +57,21 @@
 package org.apache.xpath;
 
 //import org.w3c.dom.Node;
-import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNodeSet;
-import org.apache.xpath.res.XPATHErrorResources;
-import org.apache.xalan.res.XSLMessages;
+import java.io.Serializable;
+import java.util.Vector;
 
-import org.xml.sax.XMLReader;
-import org.xml.sax.ContentHandler;
-
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-
-import org.apache.xml.utils.SAXSourceLocator;
-import org.apache.xml.utils.PrefixResolver;
-import org.apache.xml.utils.XMLString;
-import org.apache.xml.dtm.DTMIterator;
-import org.apache.xml.dtm.DTM;
-
-import javax.xml.transform.SourceLocator;
 import javax.xml.transform.ErrorListener;
+import javax.xml.transform.TransformerException;
+import org.apache.xalan.res.XSLMessages;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMIterator;
+import org.apache.xml.utils.XMLString;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.parser.SimpleNode;
+import org.apache.xpath.res.XPATHErrorResources;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
 
 /**
  * This abstract class serves as the base for all expression objects.  An
@@ -86,8 +82,15 @@
  * and walkers, which must be cloned in order to be used -- the original must
  * still be immutable.
  */
-public abstract class Expression implements java.io.Serializable, ExpressionNode, XPathVisitable
+public abstract class Expression extends SimpleNode 
+	implements java.io.Serializable, ExpressionNode, XPathVisitable
 {
+	
+  public Expression()
+  {
+  	super();
+  }
+  
 
   /**
    * The location where this expression was built from.  Need for diagnostic
@@ -291,7 +294,8 @@
 
     try
     {
-      xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);
+      xctxt.pushCurrentNode(contextNode);
+      xctxt.pushCurrentExpressionNode(contextNode);
 
       return execute(xctxt).iter();
     }
@@ -322,7 +326,8 @@
 
     try
     {
-      xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);
+      xctxt.pushCurrentNode(contextNode);
+      xctxt.pushCurrentExpressionNode(contextNode);
 
       XNodeSet nodeset = (XNodeSet)execute(xctxt);
       return nodeset.iterRaw();
@@ -374,17 +379,10 @@
   }
 
   /**
-   * This function is used to fixup variables from QNames to stack frame
-   * indexes at stylesheet build time.
-   * @param vars List of QNames that correspond to variables.  This list
-   * should be searched backwards for the first qualified name that
-   * corresponds to the variable reference qname.  The position of the
-   * QName in the vector from the start of the vector will be its position
-   * in the stack frame (but variables above the globalsTop value will need
-   * to be offset to the current stack frame).
-   * NEEDSDOC @param globalsSize
+   * Fix up variables from QNames to stack frame
+   * @param vcs Interface to variable stack composition interface.
    */
-  public abstract void fixupVariables(java.util.Vector vars, int globalsSize);
+  public abstract void fixupVariables(VariableComposeState vcs);
   
   /**
    * Compare this object with another object and see 
@@ -464,7 +462,9 @@
         XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
         new Object[]{ msg });
 
-      throw new RuntimeException(fMsg);
+      RuntimeException a = new RuntimeException(fMsg);
+      a.printStackTrace();
+      throw a;
     }
   }
 
@@ -531,6 +531,7 @@
   public void exprAddChild(ExpressionNode n, int i)
   {
   	assertion(false, "exprAddChild method not implemented!");
+  	
   }
 
   /** This method returns a child node.  The children are numbered
@@ -630,4 +631,17 @@
   	  return 0;
   	return m_parent.getColumnNumber();
   }
+  
+  /**
+   * Clone this object, but make certian it is deep.  This is useful 
+   * for derived classes that may want the default clone to be 
+   * light weight, but then want to deep clone in some special cases.
+   * @see java.lang.Object#clone()
+   */
+  public Object cloneDeep() throws CloneNotSupportedException
+  {
+    XNodeSet xns = (XNodeSet)clone();
+    return xns;
+  }
+
 }
diff --git a/src/org/apache/xpath/ExpressionOwner.java b/src/org/apache/xpath/ExpressionOwner.java
index 2b4322a..87b9df3 100644
--- a/src/org/apache/xpath/ExpressionOwner.java
+++ b/src/org/apache/xpath/ExpressionOwner.java
@@ -19,7 +19,6 @@
    * @param exp the raw Expression object, which should not normally be null.
    */
   public void setExpression(Expression exp);
-
-
+  
 }
 
diff --git a/src/org/apache/xpath/NodeSet.java b/src/org/apache/xpath/NodeSet.java
index 1747e1e..ddfdc1a 100644
--- a/src/org/apache/xpath/NodeSet.java
+++ b/src/org/apache/xpath/NodeSet.java
@@ -307,7 +307,7 @@
 
     if (!m_cacheNodes)
       throw new RuntimeException(
-        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_ITERATE, null)); //"This NodeSet can not iterate to a previous node!");
+        "This NodeSet can not iterate to a previous node!");
 
     if ((m_next - 1) > 0)
     {
@@ -362,7 +362,7 @@
 
     if (!m_cacheNodes)
       throw new RuntimeException(
-        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!");
+        "This NodeSet can not do indexing or counting functions!");
 
     if ((index >= 0) && (m_next < m_firstFree))
       m_next = index;
@@ -785,7 +785,7 @@
 
     if (!m_cacheNodes)
       throw new RuntimeException(
-        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!");
+        "This NodeSet can not do indexing or counting functions!");
 
     m_next = i;
   }
@@ -802,7 +802,7 @@
 
     if (!m_cacheNodes)
       throw new RuntimeException(
-        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!");
+        "This NodeSet can not do indexing or counting functions!");
 
     int saved = m_next;
     Node n = (m_next < m_firstFree) ? elementAt(m_next) : null;
@@ -839,12 +839,12 @@
    * request caching after we've already begun stepping through the
    * nodes in this set.
   */
-  public void setShouldCacheNodes(boolean b)
+  public void setShouldCache(boolean b)
   {
 
     if (!isFresh())
       throw new RuntimeException(
-        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_CALL_SETSHOULDCACHENODE, null)); //"Can not call setShouldCacheNodes after nextNode has been called!");
+        "Can not call setShouldCacheNodes after nextNode has been called!");
 
     m_cacheNodes = b;
     m_mutable = true;
diff --git a/src/org/apache/xpath/NodeSetDTM.java b/src/org/apache/xpath/NodeSetDTM.java
index 8d74775..7e25e52 100644
--- a/src/org/apache/xpath/NodeSetDTM.java
+++ b/src/org/apache/xpath/NodeSetDTM.java
@@ -455,7 +455,7 @@
 
     if (!m_cacheNodes)
       throw new RuntimeException(
-        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_ITERATE, null)); //"This NodeSetDTM can not iterate to a previous node!");
+        "This NodeSetDTM can not iterate to a previous node!");
 
     if ((m_next - 1) > 0)
     {
@@ -522,7 +522,7 @@
 
     if (!m_cacheNodes)
       throw new RuntimeException(
-        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null)); //"This NodeSetDTM can not do indexing or counting functions!");
+        "This NodeSetDTM can not do indexing or counting functions!");
 
     if ((index >= 0) && (m_next < m_firstFree))
       m_next = index;
@@ -1174,7 +1174,7 @@
 
     if (!m_cacheNodes)
       throw new RuntimeException(
-        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null)); //"This NodeSetDTM can not do indexing or counting functions!");
+        "This NodeSetDTM can not do indexing or counting functions!");
 
     m_next = i;
   }
@@ -1235,12 +1235,12 @@
    * request caching after we've already begun stepping through the
    * nodes in this set.
   */
-  public void setShouldCacheNodes(boolean b)
+  public void setShouldCache(boolean b)
   {
 
     if (!isFresh())
       throw new RuntimeException(
-        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_CALL_SETSHOULDCACHENODE, null)); //"Can not call setShouldCacheNodes after nextNode has been called!");
+        "Can not call setShouldCacheNodes after nextNode has been called!");
 
     m_cacheNodes = b;
     m_mutable = true;
diff --git a/src/org/apache/xpath/VariableComposeState.java b/src/org/apache/xpath/VariableComposeState.java
new file mode 100644
index 0000000..32693fb
--- /dev/null
+++ b/src/org/apache/xpath/VariableComposeState.java
@@ -0,0 +1,141 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath;
+
+import org.apache.xml.utils.QName;
+
+/**
+ * This is a rather low lever interface that is passed to the 
+ * fixupVariables method on expressions.
+ * 
+ * Created Jul 19, 2002
+ * @author sboag
+ */
+public interface VariableComposeState
+{
+  /**
+   * Given a qualified name, return an integer ID that can be 
+   * quickly compared.
+   *
+   * @param qname a qualified name object, must not be null.
+   *
+   * @return the expanded-name id of the qualified name.
+   */
+  public int getQNameID(QName qname);
+
+  /**
+   * Add the name of a qualified name within the template.  The position in 
+   * the vector is its ID.
+   * @param qname A qualified name of a param or variable, should be non-null.
+   * @return the index where the variable was added.
+   */
+  int addVariableName(final org.apache.xml.utils.QName qname);
+
+  /**
+   * Reset the stack frame size to zero.
+   */
+  void resetStackFrameSize();
+
+  /**
+   * Get the current size of the stack frame.
+   * @return int The size of the stack frame.
+   */
+  int getFrameSize();
+
+  /**
+   * Get the current size of the stack frame.  Use this to record the position 
+   * in a template element at startElement, so that it can be popped 
+   * at endElement.
+   */
+  int getCurrentStackFrameSize();
+
+  /**
+   * Set the current size of the stack frame.
+   */
+  void setCurrentStackFrameSize(int sz);
+
+  /**
+   * Get the size of the globals area.
+   * @return int
+   */
+  int getGlobalsSize();
+
+  /**
+   * Push a "mark" on the stack that will delimit a scope.
+   */
+  void pushStackMark();
+
+  /**
+   * Pop the variable scope to the last mark pushed.
+   */
+  void popStackMark();
+
+  /**
+   * Get the a of QNames that correspond to variables.  This list
+   * should be searched backwards for the first qualified name that
+   * corresponds to the variable reference qname.  The position of the
+   * QName in the vector from the start of the vector will be its position
+   * in the stack frame (but variables above the globalsTop value will need
+   * to be offset to the current stack frame).
+   * 
+   * @return A reference to the vector of variable names.  The reference 
+   * returned is owned by the implementor of this interface, 
+   * and so should not really be mutated, or stored anywhere.
+   */
+  java.util.Vector getVariableNames();
+
+}
diff --git a/src/org/apache/xpath/XPath.java b/src/org/apache/xpath/XPath.java
index 6f2e884..43089cb 100644
--- a/src/org/apache/xpath/XPath.java
+++ b/src/org/apache/xpath/XPath.java
@@ -57,21 +57,24 @@
 package org.apache.xpath;
 
 import java.io.Serializable;
+import java.io.StringReader;
 import java.util.Vector;
 
 import javax.xml.transform.ErrorListener;
 import javax.xml.transform.SourceLocator;
 import javax.xml.transform.TransformerException;
+
+import org.apache.xalan.processor.StylesheetHandler;
 import org.apache.xalan.res.XSLMessages;
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.utils.PrefixResolver;
+import org.apache.xml.utils.QName;
 import org.apache.xml.utils.SAXSourceLocator;
 import org.apache.xml.utils.WrappedRuntimeException;
-import org.apache.xpath.compiler.Compiler;
-import org.apache.xpath.compiler.FunctionTable;
-import org.apache.xpath.compiler.XPathParser;
 import org.apache.xpath.functions.Function;
+import org.apache.xpath.objects.XNodeSequenceSingleton;
 import org.apache.xpath.objects.XObject;
+import org.apache.xpath.parser.ParseException;
 import org.apache.xpath.res.XPATHErrorResources;
 import org.w3c.dom.Node;
 
@@ -108,9 +111,9 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    m_mainExp.fixupVariables(vars, globalsSize);
+    m_mainExp.fixupVariables(vcs);
   }
 
   /**
@@ -171,11 +174,13 @@
   /** Represents a match type expression.  */
   public static final int MATCH = 1;
 
+  public static boolean DEBUG_DUMP_EXPRS = false;
+  public static boolean DEBUG_CHECK_TREE_INTEGRITY = true; // leave as true for a while...
+
   /**
-   * Construct an XPath object.  
-   *
-   * (Needs review -sc) This method initializes an XPathParser/
+   * Construct an XPath object. This method initializes an XPathParser/
    * Compiler and compiles the expression.
+   * 
    * @param exprString The XPath expression.
    * @param locator The location of the expression, may be null.
    * @param prefixResolver A prefix resolver to use to resolve prefixes to 
@@ -183,11 +188,12 @@
    * @param type one of {@link #SELECT} or {@link #MATCH}.
    * @param errorListener The error listener, or null if default should be used.
    *
+   * @param version The version of XPath being used.
    * @throws javax.xml.transform.TransformerException if syntax or other error.
    */
   public XPath(
           String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type,
-          ErrorListener errorListener)
+          ErrorListener errorListener, double version)
             throws javax.xml.transform.TransformerException
   {      
     if(null == errorListener)
@@ -195,18 +201,53 @@
     
     m_patternString = exprString;
 
-    XPathParser parser = new XPathParser(errorListener, locator);
-    Compiler compiler = new Compiler(errorListener, locator);
-
-    if (SELECT == type)
-      parser.initXPath(compiler, exprString, prefixResolver);
-    else if (MATCH == type)
-      parser.initMatchPattern(compiler, exprString, prefixResolver);
-    else
-      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); //"Can not deal with XPath type: " + type);
-
-    // System.out.println("----------------");
-    Expression expr = compiler.compile(0);
+    // TBD: Figure out what to do with errorListener and locator in new world.
+    // errorListener, locator
+    if(DEBUG_DUMP_EXPRS)
+    	System.out.println("expr: "+exprString);
+    	
+    StringReader exprReader = new StringReader(exprString);
+   
+    org.apache.xpath.parser.XPath parser = new org.apache.xpath.parser.XPath(exprReader);
+    
+    if(DEBUG_CHECK_TREE_INTEGRITY)
+    {   
+      assertion(null != prefixResolver, 
+                " prefixResolver can not be null!");
+      assertion(!(prefixResolver instanceof StylesheetHandler), 
+                " prefixResolver can not be a StylesheetHandler!");
+    }
+    parser.setPrefixResolver(prefixResolver);
+    parser.setVersion(version);
+    Expression rootOfRoot;
+	try
+	{
+		if (SELECT == type)
+    		rootOfRoot = (Expression)parser.XPath2();
+    	else if (MATCH == type)
+    		rootOfRoot = (Expression)parser.MatchPattern();
+    	else
+      		throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); //"Can not deal with XPath type: " + type);
+	}
+	catch(org.apache.xpath.parser.ParseException pe)
+	{
+		TransformerException te = new TransformerException(pe);
+		te.setLocator(locator);
+		throw te;
+	}
+	Expression expr = (Expression)rootOfRoot.jjtGetChild(0);
+	
+	if(DEBUG_CHECK_TREE_INTEGRITY)
+	{
+		if(false == expr.checkTreeIntegrity())
+		{
+			System.err.println("Expression is NOT OK: "+m_patternString);
+			expr.dump("| ");
+		}
+	}
+	
+	if(DEBUG_DUMP_EXPRS)
+		expr.dump("| ");
 
     // System.out.println("expr: "+expr);
     this.setExpression(expr);
@@ -218,25 +259,25 @@
 
   }
   
-  /**
-   * Construct an XPath object.  
-   *
-   * (Needs review -sc) This method initializes an XPathParser/
-   * Compiler and compiles the expression.
-   * @param exprString The XPath expression.
-   * @param locator The location of the expression, may be null.
-   * @param prefixResolver A prefix resolver to use to resolve prefixes to 
-   *                       namespace URIs.
-   * @param type one of {@link #SELECT} or {@link #MATCH}.
-   *
-   * @throws javax.xml.transform.TransformerException if syntax or other error.
-   */
-  public XPath(
-          String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type)
-            throws javax.xml.transform.TransformerException
-  {  
-    this(exprString, locator, prefixResolver, type, null);    
-  }
+//  /**
+//   * Construct an XPath object.  
+//   *
+//   * (Needs review -sc) This method initializes an XPathParser/
+//   * Compiler and compiles the expression.
+//   * @param exprString The XPath expression.
+//   * @param locator The location of the expression, may be null.
+//   * @param prefixResolver A prefix resolver to use to resolve prefixes to 
+//   *                       namespace URIs.
+//   * @param type one of {@link #SELECT} or {@link #MATCH}.
+//   *
+//   * @throws javax.xml.transform.TransformerException if syntax or other error.
+//   */
+//  public XPath(
+//          String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type)
+//            throws javax.xml.transform.TransformerException
+//  {  
+//    this(exprString, locator, prefixResolver, type, null);    
+//  }
 
   /**
    * Construct an XPath object.
@@ -276,7 +317,6 @@
           namespaceContext);
   }
   
-
   /**
    * <meta name="usage" content="experimental"/>
    * Given an expression and a context, evaluate the XPath
@@ -296,10 +336,109 @@
           XPathContext xctxt, int contextNode, PrefixResolver namespaceContext)
             throws javax.xml.transform.TransformerException
   {
+    xctxt.pushNamespaceContext(namespaceContext);
+    xctxt.pushCurrentNode(contextNode);
+    xctxt.pushCurrentExpressionNode(contextNode);
+    try
+    {
+      return execute(xctxt, namespaceContext);
+    }
+    finally
+    {
+      xctxt.popNamespaceContext();
+
+      xctxt.popCurrentNodeAndExpression();
+    }
+
+  }
+  
+
+  /**
+   * <meta name="usage" content="experimental"/>
+   * Given an expression, evaluate the XPath
+   * and return the result. The method does not push the current context node!
+   * 
+   * @param xctxt The execution context.
+   * @param namespaceContext The context in which namespaces in the
+   * XPath are supposed to be expanded.
+   * 
+   * @throws TransformerException thrown if the active ProblemListener decides
+   * the error condition is severe enough to halt processing.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(
+          XPathContext xctxt, PrefixResolver namespaceContext)
+            throws javax.xml.transform.TransformerException
+  {
+    XObject xobj = null;
+
+    try
+    {
+      xobj = m_mainExp.execute(xctxt);
+    }
+    catch (TransformerException te)
+    {
+      te.setLocator(this.getLocator());
+      ErrorListener el = xctxt.getErrorListener();
+      if(null != el) // defensive, should never happen.
+      {
+        el.error(te);
+      }
+      else
+        throw te;
+    }
+    catch (Exception e)
+    {
+      while (e instanceof org.apache.xml.utils.WrappedRuntimeException)
+      {
+        e = ((org.apache.xml.utils.WrappedRuntimeException) e).getException();
+      }
+      // e.printStackTrace();
+
+      String msg = e.getMessage();
+      msg = (msg == null || msg.length()== 0)? "Unknown error in XPath" : msg;
+      TransformerException te = new TransformerException(msg,
+              getLocator(), e);
+      ErrorListener el = xctxt.getErrorListener();
+      // te.printStackTrace();
+      if(null != el) // defensive, should never happen.
+      {
+        el.fatalError(te);
+      }
+      else
+        throw te;
+    }
+
+    return xobj;
+  }
+  
+  /**
+   * <meta name="usage" content="experimental"/>
+   * Given an expression and a context, evaluate the XPath
+   * and return the result.
+   * 
+   * @param xctxt The execution context.
+   * @param contextNode The node that "." expresses.
+   * @param namespaceContext The context in which namespaces in the
+   * XPath are supposed to be expanded.
+   * 
+   * @throws TransformerException thrown if the active ProblemListener decides
+   * the error condition is severe enough to halt processing.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(
+          XPathContext xctxt, XObject contextItem, PrefixResolver namespaceContext)
+            throws javax.xml.transform.TransformerException
+  {
 
     xctxt.pushNamespaceContext(namespaceContext);
 
-    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);
+    xctxt.pushCurrentItem(contextItem);
+    int node = contextItem.getNodeHandle();
+    if(DTM.NULL != node)
+      xctxt.pushCurrentExpressionNode(node);
 
     XObject xobj = null;
 
@@ -343,11 +482,14 @@
     {
       xctxt.popNamespaceContext();
 
-      xctxt.popCurrentNodeAndExpression();
+      xctxt.popCurrentItem();
+      if(DTM.NULL != node)
+        xctxt.popCurrentExpressionNode();
     }
 
     return xobj;
   }
+
   
   /**
    * <meta name="usage" content="experimental"/>
@@ -371,8 +513,9 @@
 
     xctxt.pushNamespaceContext(namespaceContext);
 
-    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);
-
+    xctxt.pushCurrentNode(contextNode);
+    xctxt.pushCurrentExpressionNode(contextNode);
+    
     try
     {
       return m_mainExp.bool(xctxt);
@@ -453,6 +596,9 @@
                            + dtm.getNodeName(context) + " for xpath "
                            + this.getPatternString());
       }
+      
+      if(null == score)
+        throw new RuntimeException("What??");
 
       return score.num();
     }
@@ -474,8 +620,25 @@
    */
   public void installFunction(String name, int funcIndex, Function func)
   {
-    FunctionTable.installFunction(func, funcIndex);
+  	// TBD: Figure out proper construction of qname from name.
+  	QName qname = new QName(name);
+  	org.apache.xpath.parser.SimpleNode.m_builtInFunctions.put(name, func);
+    // FunctionTable.installFunction(func, funcIndex);
   }
+  
+  /**
+   * Install a built-in function.
+   * @param name The unqualified name of the function; not currently used.
+   * @param funcIndex The index of the function in the table.
+   * @param func An Implementation of an XPath Function object.
+   * @return the position of the function in the internal index.
+   */
+  public void installFunction(QName qname, Function func)
+  {
+  	org.apache.xpath.parser.SimpleNode.m_builtInFunctions.put(qname, func);
+    // FunctionTable.installFunction(func, funcIndex);
+  }
+
 
   /**
    * Warn the user of an problem.
diff --git a/src/org/apache/xpath/XPathAPI.java b/src/org/apache/xpath/XPathAPI.java
index d6f0bda..be2b57b 100644
--- a/src/org/apache/xpath/XPathAPI.java
+++ b/src/org/apache/xpath/XPathAPI.java
@@ -65,7 +65,6 @@
 
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPath;
-import org.apache.xpath.compiler.XPathParser;
 import org.apache.xpath.XPathContext;
 import org.apache.xml.utils.PrefixResolverDefault;
 import org.apache.xml.utils.PrefixResolver;
@@ -276,7 +275,7 @@
       ? ((Document) namespaceNode).getDocumentElement() : namespaceNode);
 
     // Create the XPath object.
-    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
+    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null, 1.0);
 
     // Execute the XPath, and have it return the result
     // return xpath.execute(xpathSupport, contextNode, prefixResolver);
@@ -318,7 +317,7 @@
     //    because XPathContext is weak in a number of areas... perhaps
     //    XPathContext should be done away with.)
     // Create the XPath object.
-    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
+    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null, 1.0);
 
     // Execute the XPath, and have it return the result
     XPathContext xpathSupport = new XPathContext();
diff --git a/src/org/apache/xpath/XPathContext.java b/src/org/apache/xpath/XPathContext.java
index df47a05..306d4a3 100644
--- a/src/org/apache/xpath/XPathContext.java
+++ b/src/org/apache/xpath/XPathContext.java
@@ -71,17 +71,21 @@
 import org.apache.xml.utils.PrefixResolver;
 import org.apache.xml.utils.QName;
 import org.apache.xml.utils.NodeVector;
+import org.apache.xml.utils.WrappedRuntimeException;
 import org.apache.xalan.res.XSLMessages;
 import org.apache.xpath.res.XPATHErrorResources;
 import org.apache.xpath.axes.ContextNodeList;
 import org.apache.xpath.axes.SubContextList;
+import org.apache.xpath.objects.XNodeSequenceSingleton;
 import org.apache.xpath.objects.XObject;
 import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XSequence;
 import org.apache.xpath.objects.XString;
 
 import org.apache.xalan.extensions.ExpressionContext;
 
 // SAX2 imports
+import org.w3c.dom.traversal.NodeIterator;
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 // import org.xml.sax.Locator;
@@ -112,13 +116,19 @@
 import org.apache.xpath.axes.DescendantIterator;
 
 // For  handling.
-import org.apache.xml.dtm.ref.sax2dtm.SAX2RTFDTM;
+import org.apache.xml.dtm.ref.sax2dtm.SAX2DTM;
 
 /**
  * <meta name="usage" content="advanced"/>
  * Default class for the runtime execution context for XPath.
  * 
- * <p>This class extends DTMManager but does not directly implement it.</p>
+ * <p>XPathContext has been enhanced to carry the proposed "static context"
+ * information for XPath 2.0. This sketch was initially based on
+ * http://www.w3.org/TR/2002/WD-xpath20-2002043
+ * </p> 
+ * 
+ * <p>This class extends DTMManager but does not directly implement it;
+ * instead, it operates as proxy for an actual DTMManager.</p>
  */
 public class XPathContext extends DTMManager // implements ExpressionContext
 {
@@ -141,7 +151,7 @@
    * 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 SAX2DTM m_global_rtfdtm=null;
   
 	
   /**
@@ -342,8 +352,8 @@
   public XPathContext()
   {
     m_prefixResolvers[m_prefixResolversTop++] = null;
-    m_currentNodes[m_currentNodesFirstFree++] = DTM.NULL;
-    m_currentNodes[m_currentExpressionNodesFirstFree++] = DTM.NULL;
+    m_currentItems[m_currentNodesFirstFree++] = XSequence.EMPTY;
+    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = DTM.NULL;
     m_saxLocations[m_saxLocationsTop++] = null;
   }
 
@@ -360,8 +370,8 @@
     }
     catch (NoSuchMethodException nsme) {}
     m_prefixResolvers[m_prefixResolversTop++] = null;
-    m_currentNodes[m_currentNodesFirstFree++] = DTM.NULL;
-    m_currentNodes[m_currentExpressionNodesFirstFree++] = DTM.NULL;
+    m_currentItems[m_currentNodesFirstFree++] = XSequence.EMPTY;
+    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = DTM.NULL;
     m_saxLocations[m_saxLocationsTop++] = null;
   }
 
@@ -392,7 +402,7 @@
 	m_contextNodeLists = new Stack();
 	m_currentExpressionNodes = new int[RECURSIONLIMIT];
 	m_currentExpressionNodesFirstFree = 0;
-	m_currentNodes = new int[RECURSIONLIMIT];
+	m_currentItems = new XObject[RECURSIONLIMIT];
 	m_currentNodesFirstFree = 0;
 	m_iteratorRoots = new NodeVector();
 	m_predicatePos = new IntStack();
@@ -401,8 +411,8 @@
 	int m_prefixResolversTop = 0;
 	
 	m_prefixResolvers[m_prefixResolversTop++] = null;
-    m_currentNodes[m_currentNodesFirstFree++] = DTM.NULL;
-    m_currentNodes[m_currentExpressionNodesFirstFree++] = DTM.NULL;
+    m_currentItems[m_currentNodesFirstFree++] = XSequence.EMPTY;
+    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = DTM.NULL;
     m_saxLocations[m_saxLocationsTop++] = null;
   }
 
@@ -690,14 +700,51 @@
    * @return  the <a href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a>,
    * also refered to here as a <term>context node list</term>.
    */
-  public final DTMIterator getContextNodeList()
+  public final XSequence getContextSequence()
   {
 
     if (m_contextNodeLists.size() > 0)
-      return (DTMIterator) m_contextNodeLists.peek();
+      return (XSequence) m_contextNodeLists.peek();
     else
       return null;
   }
+  
+  /**
+   * Get the current context node list.
+   *
+   * @return  the <a href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a>,
+   * also refered to here as a <term>context node list</term>.
+   */
+  public final DTMIterator getContextNodeList()
+  {
+
+    try
+    {
+      if (m_contextNodeLists.size() > 0)
+      {
+        Object contextSequence = m_contextNodeLists.peek();
+        if (contextSequence instanceof DTMIterator)
+        {
+          return (DTMIterator) contextSequence;
+        }
+        else
+          if (contextSequence instanceof XObject)
+          {
+            return ((XObject) contextSequence).iter();
+          }
+          else
+          {
+            return null; // or error
+          }
+      }
+      else
+        return null;
+    }
+    catch (TransformerException e)
+    {
+      throw new WrappedRuntimeException(e);
+    }
+  }
 
   /**
    * <meta name="usage" content="internal"/>
@@ -706,9 +753,40 @@
    * @param nl the <a href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a>,
    * also refered to here as a <term>context node list</term>.
    */
-  public final void pushContextNodeList(DTMIterator nl)
+  public final void pushContextSequence(XSequence xseq)
   {
-    m_contextNodeLists.push(nl);
+    m_contextNodeLists.push(xseq);
+  }
+
+  /**
+   * <meta name="usage" content="internal"/>
+   * Pop the current context node list.
+   */
+  public final void popContextSequence()
+  {
+  	if(m_contextNodeLists.isEmpty())
+  	  System.err.println("Warning: popContextNodeList when stack is empty!");
+  	else
+      m_contextNodeLists.pop();
+  }
+  
+/**
+   * <meta name="usage" content="internal"/>
+   * Set the current context node list.
+   *
+   * @param nl the <a href="http://www.w3.org/TR/xslt#dt-current-node-list">current node list</a>,
+   * also refered to here as a <term>context node list</term>.
+   */
+  public final void pushContextNodeList(DTMIterator iterator)
+  {
+    if(iterator instanceof XSequence)
+      m_contextNodeLists.push((XSequence)iterator);
+    else
+    {
+      XNodeSet nodeset = new XNodeSet(iterator);
+      nodeset.setCurrentPos(iterator.getCurrentPos());
+      m_contextNodeLists.push(nodeset);
+    }
   }
 
   /**
@@ -717,12 +795,13 @@
    */
   public final void popContextNodeList()
   {
-  	if(m_contextNodeLists.isEmpty())
-  	  System.err.println("Warning: popContextNodeList when stack is empty!");
-  	else
+    if(m_contextNodeLists.isEmpty())
+      System.err.println("Warning: popContextNodeList when stack is empty!");
+    else
       m_contextNodeLists.pop();
   }
 
+
   /**
    * The ammount to use for stacks that record information during the 
    * recursive execution.
@@ -733,13 +812,14 @@
    *  Not to be confused with the current node list.  %REVIEW% Note that there 
    *  are no bounds check and resize for this stack, so if it is blown, it's all 
    *  over.  */
-  private int m_currentNodes[] = new int[RECURSIONLIMIT];
+  private XObject m_currentItems[] = new XObject[RECURSIONLIMIT];
+  
   protected int m_currentNodesFirstFree = 0;
    
 //  private NodeVector m_currentNodes = new NodeVector();
   
-  public int[] getCurrentNodeStack() {return m_currentNodes; }
-  public void setCurrentNodeStack(int[] nv) { m_currentNodes = nv; }
+//  public XObject[] getCurrentItemStack() {return m_currentItems; }
+  public void setCurrentNodeStack(XObject[] nv) { m_currentItems = nv; }
 
   /**
    * Get the current context node.
@@ -748,21 +828,88 @@
    */
   public final int getCurrentNode()
   {
-    return m_currentNodes[m_currentNodesFirstFree-1];
+    XObject current = m_currentItems[m_currentNodesFirstFree - 1];
+    if (current instanceof XNodeSequenceSingleton)
+      return ((XNodeSequenceSingleton) current).getNodeHandle();
+//    else if (current instanceof DTMIterator)
+//      return ((DTMIterator) current).getCurrentNode();
+    else
+      return DTM.NULL;
   }
   
   /**
+   * Get the current context node.
+   *
+   * @return the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
+   */
+  public final XObject getCurrentItem()
+  {
+    return m_currentItems[m_currentNodesFirstFree - 1];
+  }
+  
+  /**
+   * Set the current context node.
+   *
+   * @param cn the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
+   */
+  public final void setCurrentItem(XObject cn)
+  {
+    m_currentItems[m_currentNodesFirstFree - 1] = cn;
+  }
+
+  
+  /**
+   * Set the current context node.
+   *
+   * @param cn the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
+   */
+  public final void setCurrentNode(int cn)
+  {
+    DTM dtm = m_dtmManager.getDTM(cn);
+    m_currentItems[m_currentNodesFirstFree - 1] = new XNodeSequenceSingleton(cn, dtm);
+  }
+
+  
+  /**
    * Set the current context node and expression node.
    *
    * @param cn the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
    * @param en the sub-expression context node.
    */
+  public final void pushCurrentItemAndExpression(XObject cn, int en)
+  {
+    m_currentItems[m_currentNodesFirstFree++] = cn;
+    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = en;
+  }
+  
+  /**
+   * Set the current context node and expression node.
+   *
+   * @param cn the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
+   * @param en the sub-expression context node.
+   * @deprecated
+   */
+  public final void pushCurrentItemAndExpression(int cn, int en)
+  {
+    pushCurrentNode(cn);
+    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = en;
+  }
+  
+  /**
+   * Set the current context node and expression node.
+   *
+   * @param cn the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
+   * @param en the sub-expression context node.
+   * @deprecated
+   */
   public final void pushCurrentNodeAndExpression(int cn, int en)
   {
-    m_currentNodes[m_currentNodesFirstFree++] = cn;
-    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = cn;
+    pushCurrentNode(cn);
+    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = en;
   }
 
+
+
   /**
    * Set the current context node.
    */
@@ -779,14 +926,30 @@
    * @param en the sub-expression context node.
    * @param nc the namespace context (prefix resolver.
    */
-  public final void pushExpressionState(int cn, int en, PrefixResolver nc)
+  public final void pushExpressionState(XObject cn, int en, PrefixResolver nc)
   {
-    m_currentNodes[m_currentNodesFirstFree++] = cn;
-    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = cn;
+    m_currentItems[m_currentNodesFirstFree++] = cn;
+    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = en;
     m_prefixResolvers[m_prefixResolversTop++] = nc;
   }
   
   /**
+   * Push the current context node, expression node, and prefix resolver.
+   *
+   * @param cn the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
+   * @param en the sub-expression context node.
+   * @param nc the namespace context (prefix resolver.
+   * @deprecated
+   */
+  public final void pushExpressionState(int cn, int en, PrefixResolver nc)
+  {
+    pushCurrentNode(cn);
+    m_currentExpressionNodes[m_currentExpressionNodesFirstFree++] = en;
+    m_prefixResolvers[m_prefixResolversTop++] = nc;
+  }
+
+  
+  /**
    * Pop the current context node, expression node, and prefix resolver.
    */
   public final void popExpressionState()
@@ -796,29 +959,77 @@
     m_prefixResolversTop--;
   }
 
-
+  /**
+   * Set the current context node.
+   *
+   * @param n the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
+   * @deprecated
+   */
+  public final void pushCurrentNode(int nodeHandle)
+  {
+    DTM dtm = getDTM(nodeHandle);
+    XNodeSequenceSingleton xseq = new XNodeSequenceSingleton(nodeHandle, dtm);
+    // xseq.next(); // so get current will work.  Is this right? -sb
+    m_currentItems[m_currentNodesFirstFree++] = xseq;
+  }
+  
+  /**
+   * Pop the current context node.
+   * @deprecated
+   */
+  public final void popCurrentNode()
+  {
+    m_currentNodesFirstFree--;
+  }
 
   /**
    * Set the current context node.
    *
    * @param n the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
    */
-  public final void pushCurrentNode(int n)
+  public final void pushCurrentItem(XObject xobj)
   {
-    m_currentNodes[m_currentNodesFirstFree++] = n;
+    m_currentItems[m_currentNodesFirstFree++] = xobj;
+  }
+  
+  /**
+   * Pop the current context node.
+   */
+  public final void popCurrentItem()
+  {
+    m_currentNodesFirstFree--;
   }
   
   public int getCurrentNodeFirstFree()
   {
     return m_currentNodesFirstFree;
-  }
-
-  /**
-   * Pop the current context node.
+  }	
+	 /**
+   * The current group. 
+   * The current group will only be non-empty when an
+   * xsl-for-each-group instruction is being evaluated. 
    */
-  public final void popCurrentNode()
+  private XSequence m_currentGroup ; 
+  
+  /**
+   * Return the current group or and empty NodeSet
+   * if one is not found. 
+   */
+  public XSequence getCurrentGroup()
   {
-    m_currentNodesFirstFree--;
+  	if (m_currentGroup == null)
+  	  m_currentGroup = XSequence.EMPTY;
+  	return m_currentGroup;
+  }
+  
+  /**
+   * Set the current group.
+   * The current group will only be non-empty when an
+   * xsl-for-each-group instruction is being evaluated.
+   */
+  public void setCurrentGroup(XSequence currentGroup)
+  {
+  	m_currentGroup = currentGroup;
   }
   
   /**
@@ -1071,15 +1282,19 @@
    * @return An iterator for the current context list, as
    * defined in XSLT.
    */
-  public final DTMIterator getContextNodes()
+  public final XSequence getContextNodes()
   {
 
     try
     {
-      DTMIterator cnl = getContextNodeList();
+      XSequence cnl = getContextSequence();
 
       if (null != cnl)
-        return cnl.cloneWithReset();
+      {
+        cnl = (XSequence)cnl.clone();
+        cnl.reset();
+        return cnl;
+      }
       else
         return null;  // for now... this might ought to be an empty iterator.
     }
@@ -1144,6 +1359,7 @@
      */
     public org.w3c.dom.traversal.NodeIterator getContextNodes()
     {
+      DTMIterator iterator = getContextNodeList();
       return new org.apache.xml.dtm.ref.DTMNodeIterator(getContextNodeList());
     }
   
@@ -1223,7 +1439,7 @@
 	// the latter will ever arise, but I'd rather be just a bit paranoid..
 	if( m_global_rtfdtm==null || m_global_rtfdtm.isTreeIncomplete() )
 	{
-  		m_global_rtfdtm=(SAX2RTFDTM)m_dtmManager.getDTM(null,true,null,false,false);
+  		m_global_rtfdtm=(SAX2DTM)m_dtmManager.getDTM(null,true,null,false,false);
 	}
     return m_global_rtfdtm;
   }
@@ -1242,7 +1458,7 @@
    */
   public DTM getRTFDTM()
   {
-  	SAX2RTFDTM rtfdtm;
+  	SAX2DTM rtfdtm;
 
   	// We probably should _NOT_ be applying whitespace filtering at this stage!
   	//
@@ -1257,17 +1473,17 @@
 	if(m_rtfdtm_stack==null)
 	{
 		m_rtfdtm_stack=new Vector();
-  		rtfdtm=(SAX2RTFDTM)m_dtmManager.getDTM(null,true,null,false,false);
+  		rtfdtm=(SAX2DTM)m_dtmManager.getDTM(null,true,null,false,false);
     m_rtfdtm_stack.addElement(rtfdtm);
 		++m_which_rtfdtm;
 	}
 	else if(m_which_rtfdtm<0)
 	{
-		rtfdtm=(SAX2RTFDTM)m_rtfdtm_stack.elementAt(++m_which_rtfdtm);
+		rtfdtm=(SAX2DTM)m_rtfdtm_stack.elementAt(++m_which_rtfdtm);
 	}
 	else
 	{
-		rtfdtm=(SAX2RTFDTM)m_rtfdtm_stack.elementAt(m_which_rtfdtm);
+		rtfdtm=(SAX2DTM)m_rtfdtm_stack.elementAt(m_which_rtfdtm);
   		
 	  	// It might already be under construction -- the classic example would be
  	 	// an xsl:variable which uses xsl:call-template as part of its value. To
@@ -1278,10 +1494,10 @@
   		if(rtfdtm.isTreeIncomplete())
 	  	{
 	  		if(++m_which_rtfdtm < m_rtfdtm_stack.size())
-				rtfdtm=(SAX2RTFDTM)m_rtfdtm_stack.elementAt(m_which_rtfdtm);
+				rtfdtm=(SAX2DTM)m_rtfdtm_stack.elementAt(m_which_rtfdtm);
 	  		else
 	  		{
-		  		rtfdtm=(SAX2RTFDTM)m_dtmManager.getDTM(null,true,null,false,false);
+		  		rtfdtm=(SAX2DTM)m_dtmManager.getDTM(null,true,null,false,false);
           m_rtfdtm_stack.addElement(rtfdtm); 	
 	  		}
  	 	}
@@ -1298,7 +1514,7 @@
   {
   	m_last_pushed_rtfdtm.push(m_which_rtfdtm);
   	if(null!=m_rtfdtm_stack)
-	  	((SAX2RTFDTM)(getRTFDTM())).pushRewindMark();
+	  	((SAX2DTM)(getRTFDTM())).pushRewindMark();
   }
   
   /** Pop the RTFDTM's context mark. This discards any RTFs added after the last
@@ -1325,7 +1541,7 @@
   	{
   		if(previous>=0) // guard against none-active
   		{
-	  		boolean isEmpty=((SAX2RTFDTM)(m_rtfdtm_stack.elementAt(previous))).popRewindMark();
+	  		boolean isEmpty=((SAX2DTM)(m_rtfdtm_stack.elementAt(previous))).popRewindMark();
   		}
   	}
   	else while(m_which_rtfdtm!=previous)
@@ -1333,8 +1549,181 @@
   		// Empty each DTM before popping, so it's ready for reuse
   		// _DON'T_ pop the previous, since it's still open (which is why we
   		// stacked up more of these) and did not receive a mark.
-  		boolean isEmpty=((SAX2RTFDTM)(m_rtfdtm_stack.elementAt(m_which_rtfdtm))).popRewindMark();
+  		boolean isEmpty=((SAX2DTM)(m_rtfdtm_stack.elementAt(m_which_rtfdtm))).popRewindMark();
   		--m_which_rtfdtm; 
   	}
   }
+ 
+ 
+   //================================================================
+   // XPath 2.0 PRELIMINARY: Static Context
+   
+   /** XPATH2: Type Exception Policy: If "strict", type compatability errors
+    * should be reported as such. If "flexible", "fallback conversions" will
+    * be invoked and only if they fail will an error be reported.
+    * */
+   private boolean m2_typeExceptionPolicyStrict=true;
+ 
+   /** XPATH2: Type Exception Policy: If _strict_, type compatability errors
+    * should be reported as such. If _flexible_, "fallback conversions" will
+    * be invoked and only if they fail will an error be reported.
+    *
+    * @param strict True for strict type checking, false for flexible
+    * interpretation (attempt fallback).
+    * */
+   public void setTypeExceptionPolicyStrict(boolean strict)
+   {
+     m2_typeExceptionPolicyStrict=strict;
+   }
+ 
+   /** XPATH2: Type Exception Policy: If _strict_, type compatability errors
+    * should be reported as such. If _flexible_, "fallback conversions" will
+    * be invoked and only if they fail will an error be reported.
+    *
+    * @returns True for strict type checking, false for flexible
+    * interpretation (attempt fallback).
+    * */
+   public boolean isTypeExceptionPolicyStrict()
+   {
+     return m2_typeExceptionPolicyStrict;
+   }
+ 
+   /* XPATH2: In-Scope Namespaces: See setNamespaceContext. */
+ 
+   /** XPATH2: Default Namespace: Namespace URI to be presumed for
+    * any unprefixed QName appearing where an element or type name is
+    * expected. If null, the default is "no namespace".
+    *  
+    *  %REVIEW% What about attr names?
+    * */
+   private String m2_defaultNamespaceURI=null;
+   
+   /** XPATH2: Default Namespace: Namespace URI to be presumed for
+    * any unprefixed QName appearing where an element or type name is
+    * expected.
+    *  
+    *  %REVIEW% What about attr names?
+    *
+    * @param uri URI to be use. If null, the default is "no namespace".
+    * Empty string is currently treated as a real but poorly formed URI;
+    * we can quibble about that...
+    * */
+   public void setDefaultNamespaceURI(String uri)
+   {
+     m2_defaultNamespaceURI=uri;
+   }
+   
+   /** XPATH2: Default Namespace: Namespace URI to be presumed for
+    * any unprefixed QName appearing where an element or type name is
+    * expected.
+    *  
+    *  %REVIEW% What about attr names?
+    *
+    * @returns uri URI to be use. If null, the default is "no namespace".
+    * Empty string is currently treated as a real but poorly formed URI;
+    * we can quibble about that...
+    * */
+   public String getDefaultNamespaceURI()
+   {
+     return m2_defaultNamespaceURI;
+   }
+   
+   /** XPATH2: Default Function Namespace: Namespace URI to be presumed for
+    * any unprefixed QName appearing where a function name is
+    * expected. If null, the default is "no namespace".
+    * */
+   private String m2_defaultFunctionNamespaceURI=null;
+   
+   /** XPATH2: Default Function Namespace: Namespace URI to be presumed for
+    * any unprefixed QName appearing where a function name is
+    * expected. If null, the default is "no namespace".
+    *
+    * @param uri URI to be use. If null, the default is "no namespace".
+    * Empty string is currently treated as a real but poorly formed URI;
+    * we can quibble about that...
+    * */
+   public void setDefaultFunctionNamespaceURI(String uri)
+   {
+     m2_defaultFunctionNamespaceURI=uri;
+   }
+   
+   /** XPATH2: Default Function Namespace: Namespace URI to be presumed for
+    * any unprefixed QName appearing where a function name is
+    * expected. If null, the default is "no namespace".
+    *
+    * @returns uri URI to be use. If null, the default is "no namespace".
+    * Empty string is currently treated as a real but poorly formed URI;
+    * we can quibble about that...
+    * */
+   public String getDefaultFunctionNamespaceURI()
+   {
+     return m2_defaultFunctionNamespaceURI;
+   }
+   
+   /* XPATH2: In-Scope Variables: See getVarStack, getVariableOrParam....
+      %REVIEW% In XPath2 variables have type, and static variables have
+      static type; make sure it's retrievable.
+    */
+   
+   /** XPATH2: In-Scope Schema Definitions: Set of (QName,type definition)
+       pairs, defining the types available for reference in the expression.
+       Includes the built-in schema types, all globally-declared types in
+       explicitly imported schemas -- but, significantly, does NOT necessarily
+       include the types referenced by any given instance document!
+ 
+ 	%ISSUE% Xerces dependencies are very roughly encapsulated, but
+ 	this is EXTREMELY ugly architecturally.
+   */
+   private org.apache.xml.dtm.ref.xni2dtm.AbstractSchema m2_issd=null;
+   
+   public void addInScopeSchemaDefinitions(String publicID, String systemID)
+   {
+   	if(m2_issd == null)
+   		m2_issd=new org.apache.xml.dtm.ref.xni2dtm.AbstractSchema();
+   		
+   	m2_issd.appendSchema(publicID, systemID, getBaseURI());
+   }
+   
+   public org.apache.xml.dtm.ref.xni2dtm.AbstractSchema getInScopeSchemaDefinitions()
+   {
+   	return m2_issd;
+   }
+   
+   /** XPATH2: Base URI. Should be used by the document() function. Seems
+    * to be needed by other operations as well, though XPath doesn't make this
+    * clear -- eg, resolving import-schema URI references.
+    * 
+    * The definition here is swiped from FuncDocument, and _should_ yield the
+    * base URI of the stylesheet node currently being executed. I'm not 110%
+    * sure it works in all cases. %REVIEW%
+    * */
+   public String getBaseURI()
+   {
+   	return getNamespaceContext().getBaseIdentifier();
+   }
+
+	/** XPATH2 support: We need a central place to ask which version we're
+	 * currently trying to support, since some behaviors may change.
+	 * 
+	 * We know where to look if called from a stylesheet. 
+	 * 
+	 * I'm not sure where to look if we're using the XPath API; we
+	 * may need to define an API for that purpose.
+	 * 
+	 * @return String containing "1.0", "2.0", etc. If someone wants to
+	 * compare sub-fields of this string... we don't currently help them.
+	 * */   
+   public String getXPathVersion()
+   {
+   	try
+   	{
+   		return ((org.apache.xalan.transformer.TransformerImpl)m_owner).getStylesheet().getVersion();
+   	}
+   	catch(Exception e)
+   	{
+   		// %REVIEW% %TODO% Where does a bare XPath get this info?
+   		return "1.0";
+   	}
+   	
+   }
 }
diff --git a/src/org/apache/xpath/XPathVisitor.java b/src/org/apache/xpath/XPathVisitor.java
index db73d51..4d8cc6d 100644
--- a/src/org/apache/xpath/XPathVisitor.java
+++ b/src/org/apache/xpath/XPathVisitor.java
@@ -57,6 +57,7 @@
 package org.apache.xpath;
 
 import org.apache.xpath.patterns.NodeTest;
+import org.apache.xpath.types.InstanceofExpr;
 import org.apache.xpath.axes.LocPathIterator;
 import org.apache.xpath.axes.UnionPathIterator;
 import org.apache.xpath.functions.Function;
@@ -233,6 +234,19 @@
 	{
 		return true;
 	}
+  
+  /**
+   * Visit a number literal.
+   * @param owner The owner of the expression, to which the expression can 
+   *              be reset if rewriting takes place.
+   * @param num The number literal object.
+   * @return true if the sub expressions should be traversed.
+   */
+  public boolean visitInstanceOf(ExpressionOwner owner, InstanceofExpr num)
+  {
+    return true;
+  }
+
 
 
 }
diff --git a/src/org/apache/xpath/axes/AttributeIterator.java b/src/org/apache/xpath/axes/AttributeIterator.java
index f31fb6e..311e999 100644
--- a/src/org/apache/xpath/axes/AttributeIterator.java
+++ b/src/org/apache/xpath/axes/AttributeIterator.java
@@ -57,15 +57,9 @@
 package org.apache.xpath.axes;
 
 import javax.xml.transform.TransformerException;
-
-import org.apache.xpath.XPathContext;
-import org.apache.xpath.compiler.Compiler;
-import org.apache.xpath.patterns.NodeTest;
-import org.apache.xpath.objects.XObject;
-
+import org.apache.xml.dtm.Axis;
 import org.apache.xml.dtm.DTM;
-import org.apache.xml.dtm.DTMIterator;
-import org.apache.xml.dtm.DTMFilter;
+import org.apache.xpath.parser.StepExpr;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -79,16 +73,15 @@
   /**
    * Create a AttributeIterator object.
    *
-   * @param compiler A reference to the Compiler that contains the op map.
-   * @param opPos The position within the op map, which contains the
-   * location path expression for this itterator.
+   * @param stepExpr The step expression from the parser.
+   * @param analysis The analysis bits for the total path expression.
    *
    * @throws javax.xml.transform.TransformerException
    */
-  AttributeIterator(Compiler compiler, int opPos, int analysis)
+  AttributeIterator(StepExpr stepExpr, int analysis)
           throws javax.xml.transform.TransformerException
   {
-    super(compiler, opPos, analysis);
+    super(stepExpr, analysis);    
   }
     
   /**
diff --git a/src/org/apache/xpath/axes/AxesWalker.java b/src/org/apache/xpath/axes/AxesWalker.java
index e2da9dd..02dc2b2 100644
--- a/src/org/apache/xpath/axes/AxesWalker.java
+++ b/src/org/apache/xpath/axes/AxesWalker.java
@@ -66,11 +66,8 @@
 import org.apache.xpath.ExpressionOwner;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
-import org.apache.xpath.compiler.Compiler;
-import org.apache.xpath.patterns.NodeTest;
-
-import org.apache.xpath.res.XPATHErrorResources;
-import org.apache.xalan.res.XSLMessages;
+import org.apache.xpath.parser.Node;
+import org.apache.xpath.parser.StepExpr;
 
 /**
  * Serves as common interface for axes Walkers, and stores common
@@ -106,13 +103,11 @@
    *
    * @throws javax.xml.transform.TransformerException
    */
-  public void init(Compiler compiler, int opPos, int stepType)
+  public void init(org.apache.xpath.parser.StepExpr stepExpr)
           throws javax.xml.transform.TransformerException
   {
 
-    initPredicateInfo(compiler, opPos);
-
-    // int testType = compiler.getOp(nodeTestOpPos);
+    initPredicateInfo(stepExpr);
   }
 
   /**
@@ -264,7 +259,7 @@
     if (DTM.NULL == root)
     {
       throw new RuntimeException(
-        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_SETTING_WALKER_ROOT_TO_NULL, null)); //"\n !!!! Error! Setting the root of a walker to null!!!");
+        "\n !!!! Error! Setting the root of a walker to null!!!");
     }
 
     resetProximityPositions();
@@ -624,4 +619,61 @@
 
   /** The DTM inner traversal class, that corresponds to the super axis. */
   protected DTMAxisTraverser m_traverser; 
+  
+  public Node jjtGetChild(int i) 
+  {
+    if((null != m_nextWalker) && i == 0)
+    	return m_nextWalker;
+    else
+    	return null;
+  }
+
+  public int jjtGetNumChildren() 
+  {
+  	
+    return ((null == m_nextWalker) ? 0 : 1);
+  }
+
+  public String toString()
+  {
+  	String namespace = getNamespace();
+  	String localname = getLocalName();
+  	return org.apache.xml.dtm.Axis.names[m_axis]+"::"+
+  		((null != namespace) ? (namespace+":") : "")+
+  		((null != localname) ? localname : "node()")+
+  		" "+super.toString();
+  }
+  
 }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/org/apache/xpath/axes/BasicTestIterator.java b/src/org/apache/xpath/axes/BasicTestIterator.java
index 7f822b7..ed047cb 100644
--- a/src/org/apache/xpath/axes/BasicTestIterator.java
+++ b/src/org/apache/xpath/axes/BasicTestIterator.java
@@ -6,7 +6,7 @@
 import org.apache.xml.dtm.DTMIterator;
 import org.apache.xml.utils.PrefixResolver;
 import org.apache.xpath.VariableStack;
-import org.apache.xpath.compiler.Compiler;
+import org.apache.xpath.parser.StepExpr;
 
 /**
  * Base for iterators that handle predicates.  Does the basic next 
@@ -50,13 +50,12 @@
    *
    * @throws javax.xml.transform.TransformerException
    */
-  protected BasicTestIterator(Compiler compiler, int opPos, int analysis)
+  protected BasicTestIterator(StepExpr stepExpr, int analysis)
           throws javax.xml.transform.TransformerException
   {
-    super(compiler, opPos, analysis, false);
+    super(stepExpr.getParser().getPrefixResolver());
     
-    int firstStepPos = compiler.getFirstChildPos(opPos);
-    int whatToShow = compiler.getWhatToShow(firstStepPos);
+    int whatToShow = stepExpr.getWhatToShow();
 
     if ((0 == (whatToShow
                & (DTMFilter.SHOW_ATTRIBUTE 
@@ -67,34 +66,11 @@
       initNodeTest(whatToShow);
     else
     {
-      initNodeTest(whatToShow, compiler.getStepNS(firstStepPos),
-                              compiler.getStepLocalName(firstStepPos));
+      initNodeTest(whatToShow, stepExpr.getNamespaceURI(),
+                              stepExpr.getLocalName());
     }
-    initPredicateInfo(compiler, firstStepPos);
+    initPredicateInfo(stepExpr);
   }
-
-  /**
-   * Create a LocPathIterator object, including creation
-   * of step walkers from the opcode list, and call back
-   * into the Compiler to create predicate expressions.
-   *
-   * @param compiler The Compiler which is creating
-   * this expression.
-   * @param opPos The position of this iterator in the
-   * opcode list from the compiler.
-   * @param shouldLoadWalkers True if walkers should be
-   * loaded, or false if this is a derived iterator and
-   * it doesn't wish to load child walkers.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  protected BasicTestIterator(
-          Compiler compiler, int opPos, int analysis, boolean shouldLoadWalkers)
-            throws javax.xml.transform.TransformerException
-  {
-    super(compiler, opPos, analysis, shouldLoadWalkers);
-  }
-
 	
   /**
    * Get the next node via getNextXXX.  Bottlenecked for derived class override.
@@ -197,6 +173,7 @@
 
     return clone;
   }
+  
 
 
 }
diff --git a/src/org/apache/xpath/axes/ChildIterator.java b/src/org/apache/xpath/axes/ChildIterator.java
index e5e39e2..41a2d1b 100644
--- a/src/org/apache/xpath/axes/ChildIterator.java
+++ b/src/org/apache/xpath/axes/ChildIterator.java
@@ -57,16 +57,10 @@
 package org.apache.xpath.axes;
 
 import javax.xml.transform.TransformerException;
-
-import org.apache.xpath.compiler.Compiler;
-import org.apache.xpath.patterns.NodeTest;
-import org.apache.xpath.XPathContext;
-import org.apache.xml.utils.PrefixResolver;
-
-//import org.w3c.dom.Node;
-//import org.w3c.dom.DOMException;
+import org.apache.xml.dtm.Axis;
 import org.apache.xml.dtm.DTM;
-import org.apache.xml.dtm.DTMIterator;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.parser.StepExpr;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -77,22 +71,35 @@
  */
 public class ChildIterator extends LocPathIterator
 {
-
   /**
    * Create a ChildIterator object.
    *
-   * @param compiler A reference to the Compiler that contains the op map.
-   * @param opPos The position within the op map, which contains the
-   * location path expression for this itterator.
-   * @param analysis Analysis bits of the entire pattern.
+   * @param stepExpr The step expression from the parser.
+   * @param analysis The analysis bits for the total path expression.
    *
    * @throws javax.xml.transform.TransformerException
    */
-  ChildIterator(Compiler compiler, int opPos, int analysis)
+  ChildIterator(StepExpr stepExpr, int analysis)
           throws javax.xml.transform.TransformerException
   {
-    super(compiler, opPos, analysis, false);
   }
+
+
+//  /**
+//   * Create a ChildIterator object.
+//   *
+//   * @param compiler A reference to the Compiler that contains the op map.
+//   * @param opPos The position within the op map, which contains the
+//   * location path expression for this itterator.
+//   * @param analysis Analysis bits of the entire pattern.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  ChildIterator(Compiler compiler, int opPos, int analysis)
+//          throws javax.xml.transform.TransformerException
+//  {
+//    super(compiler, opPos, analysis, false);
+//  }
   
   /**
    * Return the first node out of the nodeset, if this expression is 
diff --git a/src/org/apache/xpath/axes/ChildTestIterator.java b/src/org/apache/xpath/axes/ChildTestIterator.java
index 9515a1f..695af5e 100644
--- a/src/org/apache/xpath/axes/ChildTestIterator.java
+++ b/src/org/apache/xpath/axes/ChildTestIterator.java
@@ -57,16 +57,11 @@
 package org.apache.xpath.axes;
 
 import javax.xml.transform.TransformerException;
-
-import org.apache.xpath.compiler.Compiler;
-import org.apache.xpath.patterns.NodeTest;
-import org.apache.xpath.objects.XObject;
-
-import org.apache.xml.dtm.DTM;
-import org.apache.xml.dtm.DTMIterator;
-import org.apache.xml.dtm.DTMFilter;
-import org.apache.xml.dtm.DTMAxisTraverser;
 import org.apache.xml.dtm.Axis;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMAxisTraverser;
+import org.apache.xml.dtm.DTMIterator;
+import org.apache.xpath.parser.StepExpr;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -86,17 +81,30 @@
   /**
    * Create a ChildTestIterator object.
    *
-   * @param compiler A reference to the Compiler that contains the op map.
-   * @param opPos The position within the op map, which contains the
-   * location path expression for this itterator.
+   * @param stepExpr The step expression from the parser.
+   * @param analysis The analysis bits for the total path expression.
    *
    * @throws javax.xml.transform.TransformerException
    */
-  ChildTestIterator(Compiler compiler, int opPos, int analysis)
+  ChildTestIterator(StepExpr stepExpr, int analysis)
           throws javax.xml.transform.TransformerException
   {
-    super(compiler, opPos, analysis);
+    super(stepExpr, analysis);    
   }
+
+  /**
+   * Create a ChildTestIterator object.
+   *
+   * @param traverser Traverser that tells how the KeyIterator is to be handled.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public ChildTestIterator()
+  {
+
+    super();
+  }
+  
   
   /**
    * Create a ChildTestIterator object.
diff --git a/src/org/apache/xpath/axes/ContextNodeList.java b/src/org/apache/xpath/axes/ContextNodeList.java
index 00e94a3..1e97ae6 100644
--- a/src/org/apache/xpath/axes/ContextNodeList.java
+++ b/src/org/apache/xpath/axes/ContextNodeList.java
@@ -99,7 +99,7 @@
    *
    * @param b true if the nodes should be cached.
    */
-  public void setShouldCacheNodes(boolean b);
+  public void setShouldCache(boolean b);
 
   /**
    * If an index is requested, NodeSetDTM will call this method
diff --git a/src/org/apache/xpath/axes/DescendantIterator.java b/src/org/apache/xpath/axes/DescendantIterator.java
index b336033..d678788 100644
--- a/src/org/apache/xpath/axes/DescendantIterator.java
+++ b/src/org/apache/xpath/axes/DescendantIterator.java
@@ -65,8 +65,7 @@
 import org.apache.xpath.Expression;
 import org.apache.xpath.VariableStack;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.compiler.Compiler;
-import org.apache.xpath.compiler.OpCodes;
+import org.apache.xpath.parser.StepExpr;
 import org.apache.xpath.patterns.NodeTest;
 
 /**
@@ -86,68 +85,14 @@
    *
    * @throws javax.xml.transform.TransformerException
    */
-  DescendantIterator(Compiler compiler, int opPos, int analysis)
+  DescendantIterator(StepExpr stepExpr)
           throws javax.xml.transform.TransformerException
   {
 
-    super(compiler, opPos, analysis, false);
-
-    int ops[] = compiler.getOpMap();
-    int firstStepPos = compiler.getFirstChildPos(opPos);
-    int stepType = ops[firstStepPos];
-
-    boolean orSelf = (OpCodes.FROM_DESCENDANTS_OR_SELF == stepType);
-    boolean fromRoot = false;
-    if (OpCodes.FROM_SELF == stepType)
-    {
-      orSelf = true;
-      // firstStepPos += 8;
-    }
-    else if(OpCodes.FROM_ROOT == stepType)
-    {
-      fromRoot = true;
-      // Ugly code... will go away when AST work is done.
-      int nextStepPos = compiler.getNextStepPos(firstStepPos);
-      if(ops[nextStepPos] == OpCodes.FROM_DESCENDANTS_OR_SELF)
-        orSelf = true;
-      // firstStepPos += 8;
-    }
-    
-    // Find the position of the last step.
-    int nextStepPos = firstStepPos;
-    while(true)
-    {
-      nextStepPos = compiler.getNextStepPos(nextStepPos);
-      if(nextStepPos > 0)
-      {
-        int stepOp = compiler.getOp(nextStepPos);
-        if(OpCodes.ENDOP != stepOp)
-          firstStepPos = nextStepPos;
-        else
-          break;
-      }
-      else
-        break;
+    super();
+    m_axis = stepExpr.getAxis();
       
-    }
-    
-    // Fix for http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1336
-    if((analysis & WalkerFactory.BIT_CHILD) != 0)
-      orSelf = false;
-      
-    if(fromRoot)
-    {
-      if(orSelf)
-        m_axis = Axis.DESCENDANTSORSELFFROMROOT;
-      else
-        m_axis = Axis.DESCENDANTSFROMROOT;
-    }
-    else if(orSelf)
-      m_axis = Axis.DESCENDANTORSELF;
-    else
-      m_axis = Axis.DESCENDANT;
-
-    int whatToShow = compiler.getWhatToShow(firstStepPos);
+    int whatToShow = stepExpr.getWhatToShow();
 
     if ((0 == (whatToShow
                & (DTMFilter.SHOW_ATTRIBUTE | DTMFilter.SHOW_ELEMENT
@@ -156,10 +101,9 @@
       initNodeTest(whatToShow);
     else
     {
-      initNodeTest(whatToShow, compiler.getStepNS(firstStepPos),
-                              compiler.getStepLocalName(firstStepPos));
+      initNodeTest(whatToShow, stepExpr.getNamespaceURI(), stepExpr.getLocalName());
     }
-    initPredicateInfo(compiler, firstStepPos);
+    initPredicateInfo(stepExpr);
   }
   
   /**
diff --git a/src/org/apache/xpath/axes/FilterExprIterator.java b/src/org/apache/xpath/axes/FilterExprIterator.java
index eaca9e4..aaa92b9 100644
--- a/src/org/apache/xpath/axes/FilterExprIterator.java
+++ b/src/org/apache/xpath/axes/FilterExprIterator.java
@@ -1,12 +1,18 @@
 package org.apache.xpath.axes;
 
+import java.io.PrintStream;
 import java.util.Vector;
 
 import org.apache.xml.dtm.DTM;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathVisitor;
 import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XSequence;
+import org.apache.xpath.objects.XSequenceSingleton;
+import org.apache.xpath.parser.Node;
 
 public class FilterExprIterator extends BasicTestIterator
 {
@@ -15,7 +21,7 @@
   private Expression m_expr;
 
   /** The result of executing m_expr.  Needs to be deep cloned on clone op.  */
-  transient private XNodeSet m_exprObj;
+  transient private XSequence m_exprObj;
 
   private boolean m_mustHardReset = false;
   private boolean m_canDetachNodeset = true;
@@ -70,7 +76,11 @@
   {
     if (null != m_exprObj)
     {
-      m_lastFetched = m_exprObj.nextNode();
+      XObject item = m_exprObj.next();
+      if(item != null && item != XSequence.EMPTY)
+        m_lastFetched = item.getNodeHandle();
+      else
+        m_lastFetched = DTM.NULL;
     }
     else
       m_lastFetched = DTM.NULL;
@@ -100,10 +110,10 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    super.fixupVariables(vars, globalsSize);
-    m_expr.fixupVariables(vars, globalsSize);
+    super.fixupVariables(vcs);
+    m_expr.fixupVariables(vcs);
   }
 
   /**
@@ -145,7 +155,12 @@
    */
   public boolean isDocOrdered()
   {
-    return m_exprObj.isDocOrdered();
+    if(m_exprObj instanceof XNodeSet)
+      return ((XNodeSet)m_exprObj).isDocOrdered();
+    else if(m_exprObj instanceof XSequenceSingleton)
+      return true;
+    else
+      return false;
   }
 
   class filterExprOwner implements ExpressionOwner
@@ -199,5 +214,29 @@
 
     return true;
   }
+  
+//  /**
+//   * @see org.apache.xpath.parser.Node#jjtGetChild(int)
+//   */
+//  public Node jjtGetChild(int i)
+//  {
+//    return (0 == i) ? m_expr : null;
+//  }
+//
+//  /**
+//   * @see org.apache.xpath.parser.Node#jjtGetNumChildren()
+//   */
+//  public int jjtGetNumChildren()
+//  {
+//    return (null != m_expr) ? 1 : 0;
+//  }
+//
+//  /**
+//   * @see org.apache.xpath.parser.SimpleNode#dump(String, PrintStream)
+//   */
+//  public void dump(String prefix, PrintStream ps)
+//  {
+//    super.dump(prefix, ps);
+//  }
 
 }
\ No newline at end of file
diff --git a/src/org/apache/xpath/axes/FilterExprIteratorSimple.java b/src/org/apache/xpath/axes/FilterExprIteratorSimple.java
index 55c7b87..e4ccfe4 100644
--- a/src/org/apache/xpath/axes/FilterExprIteratorSimple.java
+++ b/src/org/apache/xpath/axes/FilterExprIteratorSimple.java
@@ -1,17 +1,21 @@
 package org.apache.xpath.axes;
 
-import java.util.Vector;
-
 import javax.xml.transform.TransformerException;
+
 import org.apache.xml.dtm.Axis;
 import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMIterator;
 import org.apache.xml.utils.PrefixResolver;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.VariableStack;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
 import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XSequence;
+import org.apache.xpath.objects.XSequenceSingleton;
 
 /**
  * Class to use for one-step iteration that doesn't have a predicate, and 
@@ -24,7 +28,7 @@
   private Expression m_expr;
 
   /** The result of executing m_expr.  Needs to be deep cloned on clone op.  */
-  transient private XNodeSet m_exprObj;
+  transient private XSequence m_exprObj;
 
   private boolean m_mustHardReset = false;
   private boolean m_canDetachNodeset = true;
@@ -72,7 +76,7 @@
    * Execute the expression.  Meant for reuse by other FilterExpr iterators 
    * that are not derived from this object.
    */
-  public static XNodeSet executeFilterExpr(int context, XPathContext xctxt, 
+  public static XSequence executeFilterExpr(int context, XPathContext xctxt, 
   												PrefixResolver prefixResolver,
   												boolean isTopLevel,
   												int stackFrame,
@@ -80,7 +84,7 @@
     throws org.apache.xml.utils.WrappedRuntimeException
   {
     PrefixResolver savedResolver = xctxt.getNamespaceContext();
-    XNodeSet result = null;
+    XSequence result = null;
 
     try
     {
@@ -101,14 +105,26 @@
         int savedStart = vars.getStackFrame();
         vars.setStackFrame(stackFrame);
 
-        result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
-        result.setShouldCacheNodes(true);
+        result = (XSequence) expr.execute(xctxt);
+        result.setShouldCache(true);
 
         // These two statements need to be combined into one operation.
         vars.setStackFrame(savedStart);
       }
       else
-          result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
+          result = (XNodeSet) expr.execute(xctxt);
+         
+      /* %REVIEW% %OPT%
+      	Unfortunately, not all variables can be statically resolved into either
+      	definitely RTF or definitely not RTF. 
+      	
+      	%REVIEW% FIX: Should be using standardized error strings.
+      */ 
+      if(result instanceof org.apache.xpath.objects.XRTreeFrag
+      		&& "1.0".equals(xctxt.getXPathVersion())
+      		)
+      		xctxt.getErrorListener().error(new TransformerException(
+      			"Result Tree Fragments/Temporary Trees are not Nodesets in XSLT 1.0. Switch version to 2.0 or use the nodeset() extension"));
 
     }
     catch (javax.xml.transform.TransformerException se)
@@ -142,7 +158,11 @@
 
     if (null != m_exprObj)
     {
-      m_lastFetched = next = m_exprObj.nextNode();
+      XObject item = m_exprObj.next();
+      if(item != null && item != XSequence.EMPTY)
+        m_lastFetched = next = item.getNodeHandle();
+      else
+        m_lastFetched = next = DTM.NULL;
     }
     else
       m_lastFetched = next = DTM.NULL;
@@ -186,10 +206,10 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    super.fixupVariables(vars, globalsSize);
-    m_expr.fixupVariables(vars, globalsSize);
+    super.fixupVariables(vcs);
+    m_expr.fixupVariables(vcs);
   }
 
   /**
@@ -231,7 +251,12 @@
    */
   public boolean isDocOrdered()
   {
-    return m_exprObj.isDocOrdered();
+    if(m_exprObj instanceof XNodeSet)
+      return ((XNodeSet)m_exprObj).isDocOrdered();
+    else if(m_exprObj instanceof XSequenceSingleton)
+      return true;
+    else
+      return false;
   }
 
   class filterExprOwner implements ExpressionOwner
@@ -294,8 +319,8 @@
    */
   public int getAxis()
   {
-  	if(null != m_exprObj)
-    	return m_exprObj.getAxis();
+  	if(null != m_exprObj && m_exprObj instanceof XNodeSet)
+    	return ((XNodeSet)m_exprObj).getAxis();
     else
     	return Axis.FILTEREDLIST;
   }
diff --git a/src/org/apache/xpath/axes/FilterExprWalker.java b/src/org/apache/xpath/axes/FilterExprWalker.java
index 3af0a17..b18c3aa 100644
--- a/src/org/apache/xpath/axes/FilterExprWalker.java
+++ b/src/org/apache/xpath/axes/FilterExprWalker.java
@@ -56,22 +56,21 @@
  */
 package org.apache.xpath.axes;
 
-import java.util.Vector;
-
-import javax.xml.transform.TransformerException;
-import org.apache.xalan.templates.FuncKey;
 import org.apache.xml.dtm.Axis;
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMIterator;
-import org.apache.xml.utils.PrefixResolver;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionOwner;
-import org.apache.xpath.VariableStack;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
-import org.apache.xpath.compiler.Compiler;
-import org.apache.xpath.compiler.OpCodes;
+import org.apache.xpath.functions.Function;
 import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XSequence;
+import org.apache.xpath.objects.XSequenceSingleton;
+import org.apache.xpath.parser.Node;
+import org.apache.xpath.parser.PathExpr;
 
 /**
  * Walker for the OP_VARIABLE, or OP_EXTFUNCTION, or OP_FUNCTION, or OP_GROUP,
@@ -94,64 +93,93 @@
   /**
    * Init a FilterExprWalker.
    *
-   * @param compiler non-null reference to the Compiler that is constructing.
-   * @param opPos positive opcode position for this step.
-   * @param stepType The type of step.
+   * @param stepExpr The FilterExpr's expression.
    *
    * @throws javax.xml.transform.TransformerException
    */
-  public void init(Compiler compiler, int opPos, int stepType)
-          throws javax.xml.transform.TransformerException
+  public void init(org.apache.xpath.parser.StepExpr stepExpr)
+    throws javax.xml.transform.TransformerException
   {
+    int childCount = stepExpr.jjtGetNumChildren();
+    if (childCount > 0)
+    {
+      Node child = stepExpr.jjtGetChild(0);
+      m_expr = (Expression) child;
+      // Not sure if this is still needed.  Probably not. -sb
+      if (m_expr instanceof WalkingIterator)
+      {
+        WalkingIterator wi = (WalkingIterator) m_expr;
+        if (wi.getFirstWalker() instanceof FilterExprWalker)
+        {
+          FilterExprWalker fw = (FilterExprWalker) wi.getFirstWalker();
+          if (null == fw.getNextWalker())
+          {
+            m_expr = fw.m_expr;
+            m_expr.exprSetParent(this);
+          }
+        }
 
-    super.init(compiler, opPos, stepType);
+      }
+      if (m_expr instanceof Function)
+      {
+        m_mustHardReset = true;
+      }
+      if (m_expr instanceof org.apache.xalan.templates.FuncKey)
+      {
+        // hack/temp workaround
+        m_canDetachNodeset = false;
+      }
+      m_expr.exprSetParent(this);
+
+    }
+    super.init(stepExpr);
 
     // Smooth over an anomily in the opcode map...
-    switch (stepType)
-    {
-    case OpCodes.OP_FUNCTION :
-    case OpCodes.OP_EXTFUNCTION :
-    	m_mustHardReset = true;
-    case OpCodes.OP_GROUP :
-    case OpCodes.OP_VARIABLE :
-      m_expr = compiler.compile(opPos);
-      m_expr.exprSetParent(this);
-      if((OpCodes.OP_FUNCTION == stepType) && (m_expr instanceof org.apache.xalan.templates.FuncKey))
-      {
-      	// hack/temp workaround
-      	m_canDetachNodeset = false;
-      }
-      break;
-    default :
-      m_expr = compiler.compile(opPos + 2);
-      m_expr.exprSetParent(this);
-    }
-//    if(m_expr instanceof WalkingIterator)
-//    {
-//      WalkingIterator wi = (WalkingIterator)m_expr;
-//      if(wi.getFirstWalker() instanceof FilterExprWalker)
-//      {
-//      	FilterExprWalker fw = (FilterExprWalker)wi.getFirstWalker();
-//      	if(null == fw.getNextWalker())
-//      	{
-//      		m_expr = fw.m_expr;
-//      		m_expr.exprSetParent(this);
-//      	}
-//      }
-//      		
-//    }
+    //    switch (stepType)
+    //    {
+    //    case OpCodes.OP_FUNCTION :
+    //    case OpCodes.OP_EXTFUNCTION :
+    //    	m_mustHardReset = true;
+    //    case OpCodes.OP_GROUP :
+    //    case OpCodes.OP_VARIABLE :
+    //      m_expr = compiler.compile(opPos);
+    //      m_expr.exprSetParent(this);
+    //      if((OpCodes.OP_FUNCTION == stepType) && (m_expr instanceof org.apache.xalan.templates.FuncKey))
+    //      {
+    //      	// hack/temp workaround
+    //      	m_canDetachNodeset = false;
+    //      }
+    //      break;
+    //    default :
+    //      m_expr = compiler.compile(opPos + 2);
+    //      m_expr.exprSetParent(this);
+    //    }
+    //    if(m_expr instanceof WalkingIterator)
+    //    {
+    //      WalkingIterator wi = (WalkingIterator)m_expr;
+    //      if(wi.getFirstWalker() instanceof FilterExprWalker)
+    //      {
+    //      	FilterExprWalker fw = (FilterExprWalker)wi.getFirstWalker();
+    //      	if(null == fw.getNextWalker())
+    //      	{
+    //      		m_expr = fw.m_expr;
+    //      		m_expr.exprSetParent(this);
+    //      	}
+    //      }
+    //      		
+    //    }
   }
-  
+
   /**
    * Detaches the walker from the set which it iterated over, releasing
    * any computational resources and placing the iterator in the INVALID
    * state.
    */
   public void detach()
-  {  
-  	super.detach();
-  	m_exprObj.detach();
-  	m_exprObj = null;
+  {
+    super.detach();
+    m_exprObj.detach();
+    m_exprObj = null;
   }
 
   /**
@@ -165,9 +193,14 @@
 
     super.setRoot(root);
 
-  	m_exprObj = FilterExprIteratorSimple.executeFilterExpr(root, 
-  	                  m_lpi.getXPathContext(), m_lpi.getPrefixResolver(), 
-  	                  m_lpi.getIsTopLevel(), m_lpi.m_stackFrame, m_expr);
+    m_exprObj =
+      FilterExprIteratorSimple.executeFilterExpr(
+        root,
+        m_lpi.getXPathContext(),
+        m_lpi.getPrefixResolver(),
+        m_lpi.getIsTopLevel(),
+        m_lpi.m_stackFrame,
+        m_expr);
 
   }
 
@@ -189,7 +222,7 @@
 
     return clone;
   }
-  
+
   /**
    * This method needs to override AxesWalker.acceptNode because FilterExprWalkers
    * don't need to, and shouldn't, do a node test.
@@ -232,13 +265,21 @@
 
     if (null != m_exprObj)
     {
-       int next = m_exprObj.nextNode();
-       return next;
+      int next;
+      XObject item = m_exprObj.next();
+      if(item != null && item != XSequence.EMPTY)
+        next = item.getNodeHandle();
+      else
+      {
+        m_exprObj.reset();
+        next = DTM.NULL;
+      }
+      return next;
     }
     else
       return DTM.NULL;
   }
-  
+
   /**
    * Get the index of the last node that can be itterated to.
    *
@@ -251,14 +292,14 @@
   {
     return m_exprObj.getLength();
   }
-  
+
   /** The contained expression. Should be non-null.
    *  @serial   */
   private Expression m_expr;
 
   /** The result of executing m_expr.  Needs to be deep cloned on clone op.  */
-  transient private XNodeSet m_exprObj;
-  
+  transient private XSequence m_exprObj;
+
   private boolean m_mustHardReset = false;
   private boolean m_canDetachNodeset = true;
 
@@ -272,43 +313,42 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    super.fixupVariables(vars, globalsSize);
-    m_expr.fixupVariables(vars, globalsSize);
+    super.fixupVariables(vcs);
+    m_expr.fixupVariables(vcs);
   }
-  
+
   /**
    * Get the inner contained expression of this filter.
    */
   public Expression getInnerExpression()
   {
-  	return m_expr;
+    return m_expr;
   }
-  
+
   /**
    * Set the inner contained expression of this filter.
    */
   public void setInnerExpression(Expression expr)
   {
-  	expr.exprSetParent(this);
-  	m_expr = expr;
+    expr.exprSetParent(this);
+    m_expr = expr;
   }
 
-  
   /** 
    * Get the analysis bits for this walker, as defined in the WalkerFactory.
    * @return One of WalkerFactory#BIT_DESCENDANT, etc.
    */
   public int getAnalysisBits()
   {
-      if (null != m_expr && m_expr instanceof PathComponent)
-      {
-        return ((PathComponent) m_expr).getAnalysisBits();
-      }
-      return WalkerFactory.BIT_FILTER;
+    if (null != m_expr && m_expr instanceof PathComponent)
+    {
+      return ((PathComponent) m_expr).getAnalysisBits();
+    }
+    return WalkerFactory.BIT_FILTER;
   }
-  
+
   /**
    * Returns true if all the nodes in the iteration well be returned in document 
    * order.
@@ -318,9 +358,14 @@
    */
   public boolean isDocOrdered()
   {
-    return m_exprObj.isDocOrdered();
+    if(m_exprObj instanceof XNodeSet)
+      return ((XNodeSet)m_exprObj).isDocOrdered();
+    else if(m_exprObj instanceof XSequenceSingleton)
+      return true;
+    else
+      return false;
   }
-  
+
   /**
    * Returns the axis being iterated, if it is known.
    * 
@@ -329,14 +374,17 @@
    */
   public int getAxis()
   {
-    return m_exprObj.getAxis();
+    if(null != m_exprObj && m_exprObj instanceof XNodeSet)
+      return ((XNodeSet)m_exprObj).getAxis();
+    else
+      return Axis.FILTEREDLIST;
   }
-  
+
   class filterExprOwner implements ExpressionOwner
   {
-      /**
-     * @see ExpressionOwner#getExpression()
-     */
+    /**
+    * @see ExpressionOwner#getExpression()
+    */
     public Expression getExpression()
     {
       return m_expr;
@@ -347,43 +395,99 @@
      */
     public void setExpression(Expression exp)
     {
-    	exp.exprSetParent(FilterExprWalker.this);
-    	m_expr = exp;
+      exp.exprSetParent(FilterExprWalker.this);
+      m_expr = exp;
     }
+
+  }
+
+  /**
+   * This will traverse the heararchy, calling the visitor for 
+   * each member.  If the called visitor method returns 
+   * false, the subtree should not be called.
+   * 
+   * @param owner The owner of the visitor, where that path may be 
+   *              rewritten if needed.
+   * @param visitor The visitor whose appropriate method will be called.
+   */
+  public void callPredicateVisitors(XPathVisitor visitor)
+  {
+    m_expr.callVisitors(new filterExprOwner(), visitor);
+
+    super.callPredicateVisitors(visitor);
+  }
+
+  /**
+   * @see Expression#deepEquals(Expression)
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    if (!super.deepEquals(expr))
+      return false;
+
+    FilterExprWalker walker = (FilterExprWalker) expr;
+    if (!m_expr.deepEquals(walker.m_expr))
+      return false;
+
+    return true;
+  }
+
+  public void jjtAddChild(Node n, int i)
+  {
+    if (n instanceof AxesWalker)
+    {
+      super.jjtAddChild(n, i);
+    }
+    else // Do we care about i?
+      {
+      n = fixupPrimarys(n);
+      m_expr = (Expression) n;
+    }
+
+  }
+
+  public Node jjtGetChild(int i)
+  {
+    if (i == 0)
+      return m_expr;
+    else
+      if ((null != m_nextWalker) && i == 1)
+        return m_nextWalker;
+      else
+        return null;
+  }
+
+  public int jjtGetNumChildren()
+  {
+    return ((null == m_nextWalker) ? 0 : 1) + ((null == m_expr) ? 0 : 1);
+  }
+
+  /**
+   * This function checks the integrity of the tree, after it has been fully built and 
+   * is ready for execution.  Derived classes can overload this function to check 
+   * their own assumptions.
+   */
+  public boolean checkTreeIntegrity(
+    int levelCount,
+    int childNumber,
+    boolean isOK)
+  {
+    if (null == m_expr)
+      isOK =
+        flagProblem(
+          toString()
+            + " the expression for FilterExpr can not be null at this point!");
+    return super.checkTreeIntegrity(levelCount, childNumber, isOK);
   }
   
-	/**
-	 * This will traverse the heararchy, calling the visitor for 
-	 * each member.  If the called visitor method returns 
-	 * false, the subtree should not be called.
-	 * 
-	 * @param owner The owner of the visitor, where that path may be 
-	 *              rewritten if needed.
-	 * @param visitor The visitor whose appropriate method will be called.
-	 */
-	public void callPredicateVisitors(XPathVisitor visitor)
-	{
-	  m_expr.callVisitors(new filterExprOwner(), visitor);
-	  
-	  super.callPredicateVisitors(visitor);
-	} 
-
-
-    /**
-     * @see Expression#deepEquals(Expression)
-     */
-    public boolean deepEquals(Expression expr)
-    {
-      if (!super.deepEquals(expr))
-                return false;
-
-      FilterExprWalker walker = (FilterExprWalker)expr;
-      if(!m_expr.deepEquals(walker.m_expr))
-      	return false;
-
-      return true;
-    }
-
-	
+  /**
+   * @see org.apache.xpath.parser.SimpleNode#isPathExpr()
+   */
+  public boolean isPathExpr()
+  {
+    // keep it from reducing if not a nodeset expression.
+    return (m_expr instanceof DTMIterator) ? true : 
+      (m_expr instanceof PathExpr) ? true : false; 
+  }
 
 }
diff --git a/src/org/apache/xpath/axes/HasPositionalPredChecker.java b/src/org/apache/xpath/axes/HasPositionalPredChecker.java
index 37570d6..32887a4 100644
--- a/src/org/apache/xpath/axes/HasPositionalPredChecker.java
+++ b/src/org/apache/xpath/axes/HasPositionalPredChecker.java
@@ -8,10 +8,10 @@
 import org.apache.xpath.functions.Function;
 import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.operations.Div;
-import org.apache.xpath.operations.Minus;
+import org.apache.xpath.operations.Subtract;
 import org.apache.xpath.operations.Mod;
 import org.apache.xpath.operations.Mult;
-import org.apache.xpath.operations.Plus;
+import org.apache.xpath.operations.Add;
 import org.apache.xpath.operations.Quo;
 import org.apache.xpath.operations.Variable;
 
@@ -81,8 +81,8 @@
       if((pred instanceof Variable) || 
          (pred instanceof XNumber) ||
          (pred instanceof Div) ||
-         (pred instanceof Plus) ||
-         (pred instanceof Minus) ||
+         (pred instanceof Add) ||
+         (pred instanceof Subtract) ||
          (pred instanceof Mod) ||
          (pred instanceof Quo) ||
          (pred instanceof Mult) ||
diff --git a/src/org/apache/xpath/axes/LocPathIterator.java b/src/org/apache/xpath/axes/LocPathIterator.java
index 5205e3b..c12ae86 100644
--- a/src/org/apache/xpath/axes/LocPathIterator.java
+++ b/src/org/apache/xpath/axes/LocPathIterator.java
@@ -70,11 +70,9 @@
 import org.apache.xpath.ExpressionOwner;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
-import org.apache.xpath.compiler.Compiler;
 import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XObject;
-import org.apache.xpath.res.XPATHErrorResources;
-import org.apache.xalan.res.XSLMessages;
+import org.apache.xpath.parser.Node;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
@@ -102,6 +100,7 @@
    */
   protected LocPathIterator()
   {
+    setLocPathIterator(this);
   }
 
 
@@ -115,48 +114,10 @@
   {
 
     setLocPathIterator(this);
+
     m_prefixResolver = nscontext;
   }
 
-  /**
-   * Create a LocPathIterator object, including creation
-   * of step walkers from the opcode list, and call back
-   * into the Compiler to create predicate expressions.
-   *
-   * @param compiler The Compiler which is creating
-   * this expression.
-   * @param opPos The position of this iterator in the
-   * opcode list from the compiler.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  protected LocPathIterator(Compiler compiler, int opPos, int analysis)
-          throws javax.xml.transform.TransformerException
-  {
-    this(compiler, opPos, analysis, true);
-  }
-
-  /**
-   * Create a LocPathIterator object, including creation
-   * of step walkers from the opcode list, and call back
-   * into the Compiler to create predicate expressions.
-   *
-   * @param compiler The Compiler which is creating
-   * this expression.
-   * @param opPos The position of this iterator in the
-   * opcode list from the compiler.
-   * @param shouldLoadWalkers True if walkers should be
-   * loaded, or false if this is a derived iterator and
-   * it doesn't wish to load child walkers.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  protected LocPathIterator(
-          Compiler compiler, int opPos, int analysis, boolean shouldLoadWalkers)
-            throws javax.xml.transform.TransformerException
-  {
-    setLocPathIterator(this);
-  }
   
   /** 
    * Get the analysis bits for this walker, as defined in the WalkerFactory.
@@ -233,7 +194,10 @@
    */
   public DTMManager getDTMManager()
   {
-    return m_execContext.getDTMManager();
+    if(null != m_execContext)
+      return m_execContext.getDTMManager();
+    else
+      return null;
   }
   
   /**
@@ -253,8 +217,12 @@
   {
 
     XNodeSet iter = new XNodeSet((LocPathIterator)m_clones.getInstance());
-
-    iter.setRoot(xctxt.getCurrentNode(), xctxt);
+    int nodeHandle = xctxt.getCurrentNode();
+    if(nodeHandle == DTM.NULL)
+    {
+      throw new RuntimeException("Can not execute path expression without a current node being active!");
+    }
+    iter.setRoot(nodeHandle, xctxt);
 
     return iter;
   }
@@ -460,10 +428,10 @@
    *
    * @param b True if this iterator should cache nodes.
    */
-  public void setShouldCacheNodes(boolean b)
+  public void setShouldCache(boolean b)
   {
 
-    assertion(false, "setShouldCacheNodes not supported by this iterater!");
+    assertion(false, "setShouldCache not supported by this iterater!");
   }
   
   /**
@@ -619,7 +587,7 @@
   public int previousNode()
   {
     throw new RuntimeException(
-      XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_ITERATE, null)); //"This NodeSetDTM can not iterate to a previous node!");
+      "This NodeSetDTM can not iterate to a previous node!");
   }
 
   /**
@@ -1064,4 +1032,25 @@
     return getLength();
   }
 
+  /**
+   * @see java.lang.Object#toString()
+   */
+  public String toString()
+  {
+  	String namespace = getNamespace();
+  	String localname = getLocalName();
+  	if(getAxis() >= 0)
+  	{
+	  	return org.apache.xml.dtm.Axis.names[getAxis()]+"::"+
+	  		((null != namespace) ? (namespace+":") : "")+
+	  		((null != localname) ? localname : "node()")+
+	  		" "+super.toString();
+  	}
+  	else
+  	{
+  		return super.toString();
+  	}
+  }
+
+  
 }
diff --git a/src/org/apache/xpath/axes/MatchPatternIterator.java b/src/org/apache/xpath/axes/MatchPatternIterator.java
index c577131..7bba77c 100644
--- a/src/org/apache/xpath/axes/MatchPatternIterator.java
+++ b/src/org/apache/xpath/axes/MatchPatternIterator.java
@@ -63,8 +63,6 @@
 import org.apache.xpath.XPathContext;
 import org.apache.xml.utils.PrefixResolver;
 import org.apache.xpath.axes.SubContextList;
-import org.apache.xpath.compiler.PsuedoNames;
-import org.apache.xpath.compiler.Compiler;
 import org.apache.xpath.patterns.StepPattern;
 import org.apache.xpath.VariableStack;
 import org.apache.xpath.patterns.NodeTest;
@@ -100,97 +98,97 @@
   
 //  protected int m_nsElemBase = DTM.NULL;
 
-  /**
-   * Create a LocPathIterator object, including creation
-   * of step walkers from the opcode list, and call back
-   * into the Compiler to create predicate expressions.
-   *
-   * @param compiler The Compiler which is creating
-   * this expression.
-   * @param opPos The position of this iterator in the
-   * opcode list from the compiler.
-   * @param analysis Analysis bits that give general information about the 
-   * LocationPath.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  MatchPatternIterator(Compiler compiler, int opPos, int analysis)
-          throws javax.xml.transform.TransformerException
-  {
-
-    super(compiler, opPos, analysis, false);
-
-    int firstStepPos = compiler.getFirstChildPos(opPos);
-
-    m_pattern = WalkerFactory.loadSteps(this, compiler, firstStepPos, 0); 
-
-    boolean fromRoot = false;
-    boolean walkBack = false;
-    boolean walkDescendants = false;
-    boolean walkAttributes = false;
-
-    if (0 != (analysis & (WalkerFactory.BIT_ROOT | 
-                          WalkerFactory.BIT_ANY_DESCENDANT_FROM_ROOT)))
-      fromRoot = true;
-      
-    if (0 != (analysis
-              & (WalkerFactory.BIT_ANCESTOR
-                 | WalkerFactory.BIT_ANCESTOR_OR_SELF
-                 | WalkerFactory.BIT_PRECEDING
-                 | WalkerFactory.BIT_PRECEDING_SIBLING 
-                 | WalkerFactory.BIT_FOLLOWING
-                 | WalkerFactory.BIT_FOLLOWING_SIBLING
-                 | WalkerFactory.BIT_PARENT | WalkerFactory.BIT_FILTER)))
-      walkBack = true;
-
-    if (0 != (analysis
-              & (WalkerFactory.BIT_DESCENDANT_OR_SELF
-                 | WalkerFactory.BIT_DESCENDANT
-                 | WalkerFactory.BIT_CHILD)))
-      walkDescendants = true;
-
-    if (0 != (analysis
-              & (WalkerFactory.BIT_ATTRIBUTE | WalkerFactory.BIT_NAMESPACE)))
-      walkAttributes = true;
-      
-    if(false || DEBUG)
-    {
-      System.out.print("analysis: "+Integer.toBinaryString(analysis));
-      System.out.println(", "+WalkerFactory.getAnalysisString(analysis));
-    }
-      
-    if(fromRoot || walkBack)
-    {
-      if(walkAttributes)
-      {
-        m_superAxis = Axis.ALL;
-      }
-      else
-      {
-        m_superAxis = Axis.DESCENDANTSFROMROOT;
-      }
-    }
-    else if(walkDescendants)
-    {
-      if(walkAttributes)
-      {
-        m_superAxis = Axis.ALLFROMNODE;
-      }
-      else
-      {
-        m_superAxis = Axis.DESCENDANTORSELF;
-      }
-    }
-    else
-    {
-      m_superAxis = Axis.ALL;
-    }
-    if(false || DEBUG)
-    {
-      System.out.println("axis: "+Axis.names[m_superAxis]);
-    }
-    
-  }
+//  /**
+//   * Create a LocPathIterator object, including creation
+//   * of step walkers from the opcode list, and call back
+//   * into the Compiler to create predicate expressions.
+//   *
+//   * @param compiler The Compiler which is creating
+//   * this expression.
+//   * @param opPos The position of this iterator in the
+//   * opcode list from the compiler.
+//   * @param analysis Analysis bits that give general information about the 
+//   * LocationPath.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  MatchPatternIterator(Compiler compiler, int opPos, int analysis)
+//          throws javax.xml.transform.TransformerException
+//  {
+//
+//    super(compiler, opPos, analysis, false);
+//
+//    int firstStepPos = compiler.getFirstChildPos(opPos);
+//
+//    m_pattern = WalkerFactory.loadSteps(this, compiler, firstStepPos, 0); 
+//
+//    boolean fromRoot = false;
+//    boolean walkBack = false;
+//    boolean walkDescendants = false;
+//    boolean walkAttributes = false;
+//
+//    if (0 != (analysis & (WalkerFactory.BIT_ROOT | 
+//                          WalkerFactory.BIT_ANY_DESCENDANT_FROM_ROOT)))
+//      fromRoot = true;
+//      
+//    if (0 != (analysis
+//              & (WalkerFactory.BIT_ANCESTOR
+//                 | WalkerFactory.BIT_ANCESTOR_OR_SELF
+//                 | WalkerFactory.BIT_PRECEDING
+//                 | WalkerFactory.BIT_PRECEDING_SIBLING 
+//                 | WalkerFactory.BIT_FOLLOWING
+//                 | WalkerFactory.BIT_FOLLOWING_SIBLING
+//                 | WalkerFactory.BIT_PARENT | WalkerFactory.BIT_FILTER)))
+//      walkBack = true;
+//
+//    if (0 != (analysis
+//              & (WalkerFactory.BIT_DESCENDANT_OR_SELF
+//                 | WalkerFactory.BIT_DESCENDANT
+//                 | WalkerFactory.BIT_CHILD)))
+//      walkDescendants = true;
+//
+//    if (0 != (analysis
+//              & (WalkerFactory.BIT_ATTRIBUTE | WalkerFactory.BIT_NAMESPACE)))
+//      walkAttributes = true;
+//      
+//    if(false || DEBUG)
+//    {
+//      System.out.print("analysis: "+Integer.toBinaryString(analysis));
+//      System.out.println(", "+WalkerFactory.getAnalysisString(analysis));
+//    }
+//      
+//    if(fromRoot || walkBack)
+//    {
+//      if(walkAttributes)
+//      {
+//        m_superAxis = Axis.ALL;
+//      }
+//      else
+//      {
+//        m_superAxis = Axis.DESCENDANTSFROMROOT;
+//      }
+//    }
+//    else if(walkDescendants)
+//    {
+//      if(walkAttributes)
+//      {
+//        m_superAxis = Axis.ALLFROMNODE;
+//      }
+//      else
+//      {
+//        m_superAxis = Axis.DESCENDANTORSELF;
+//      }
+//    }
+//    else
+//    {
+//      m_superAxis = Axis.ALL;
+//    }
+//    if(false || DEBUG)
+//    {
+//      System.out.println("axis: "+Axis.names[m_superAxis]);
+//    }
+//    
+//  }
   
   
   /**
diff --git a/src/org/apache/xpath/axes/OneStepIterator.java b/src/org/apache/xpath/axes/OneStepIterator.java
index fb9d4ce..eb91e70 100644
--- a/src/org/apache/xpath/axes/OneStepIterator.java
+++ b/src/org/apache/xpath/axes/OneStepIterator.java
@@ -7,7 +7,7 @@
 import org.apache.xml.dtm.DTMIterator;
 import org.apache.xpath.Expression;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.compiler.Compiler;
+import org.apache.xpath.parser.StepExpr;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -26,19 +26,17 @@
   /**
    * Create a OneStepIterator object.
    *
-   * @param compiler A reference to the Compiler that contains the op map.
-   * @param opPos The position within the op map, which contains the
-   * location path expression for this itterator.
+   * @param stepExpr The step expression from the parser.
+   * @param analysis The analysis bits for the total path expression.
    *
    * @throws javax.xml.transform.TransformerException
    */
-  OneStepIterator(Compiler compiler, int opPos, int analysis)
+  OneStepIterator(StepExpr stepExpr, int analysis)
           throws javax.xml.transform.TransformerException
   {
-    super(compiler, opPos, analysis);
-    int firstStepPos = compiler.getFirstChildPos(opPos);
+    super(stepExpr, analysis);
     
-    m_axis = WalkerFactory.getAxisFromStep(compiler, firstStepPos);
+    m_axis = stepExpr.getAxis();
     
   }
   
diff --git a/src/org/apache/xpath/axes/OneStepIteratorForward.java b/src/org/apache/xpath/axes/OneStepIteratorForward.java
index fea0ecf..2116379 100644
--- a/src/org/apache/xpath/axes/OneStepIteratorForward.java
+++ b/src/org/apache/xpath/axes/OneStepIteratorForward.java
@@ -4,7 +4,7 @@
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMFilter;
 import org.apache.xpath.Expression;
-import org.apache.xpath.compiler.Compiler;
+import org.apache.xpath.parser.StepExpr;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -20,21 +20,19 @@
   protected int m_axis = -1;
 
   /**
-   * Create a OneStepIterator object.
+   * Create a OneStepIteratorForward object.
    *
-   * @param compiler A reference to the Compiler that contains the op map.
-   * @param opPos The position within the op map, which contains the
-   * location path expression for this itterator.
+   * @param stepExpr The step expression from the parser.
+   * @param analysis The analysis bits for the total path expression.
    *
    * @throws javax.xml.transform.TransformerException
    */
-  OneStepIteratorForward(Compiler compiler, int opPos, int analysis)
+  OneStepIteratorForward(StepExpr stepExpr, int analysis)
           throws javax.xml.transform.TransformerException
   {
-    super(compiler, opPos, analysis);
-    int firstStepPos = compiler.getFirstChildPos(opPos);
+    super(stepExpr, analysis);
     
-    m_axis = WalkerFactory.getAxisFromStep(compiler, firstStepPos);
+    m_axis = stepExpr.getAxis();
     
   }
     
diff --git a/src/org/apache/xpath/axes/PredicatedNodeTest.java b/src/org/apache/xpath/axes/PredicatedNodeTest.java
index 8655855..c67cbd2 100644
--- a/src/org/apache/xpath/axes/PredicatedNodeTest.java
+++ b/src/org/apache/xpath/axes/PredicatedNodeTest.java
@@ -10,10 +10,13 @@
 import org.apache.xml.utils.PrefixResolver;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
-import org.apache.xpath.compiler.Compiler;
 import org.apache.xpath.objects.XObject;
+import org.apache.xpath.parser.Node;
+import org.apache.xpath.parser.Predicates;
+import org.apache.xpath.parser.StepExpr;
 import org.apache.xpath.patterns.NodeTest;
 
 public abstract class PredicatedNodeTest extends NodeTest implements SubContextList
@@ -140,22 +143,24 @@
    *
    * @throws javax.xml.transform.TransformerException
    */
-  protected void initPredicateInfo(Compiler compiler, int opPos)
+  protected void initPredicateInfo(StepExpr stepExpr)
           throws javax.xml.transform.TransformerException
   {
-
-    int pos = compiler.getFirstPredicateOpPos(opPos);
-
-    if(pos > 0)
+    Expression lastChild = (Expression)stepExpr.jjtGetChild(stepExpr.jjtGetNumChildren()-1);
+    if(lastChild instanceof Predicates)
     {
-      m_predicates = compiler.getCompiledPredicates(pos);
-      if(null != m_predicates)
-      {
-      	for(int i = 0; i < m_predicates.length; i++)
-      	{
-      		m_predicates[i].exprSetParent(this);
-      	}
-      }
+    	Predicates preds = (Predicates)lastChild;
+    	int numPreds = preds.jjtGetNumChildren();
+    	if(numPreds > 0)
+    	{
+    		m_predicates = new Expression[numPreds];
+	      	for(int i = 0; i < m_predicates.length; i++)
+	      	{
+	      		Expression pred = (Expression)preds.jjtGetChild(i);
+	      		m_predicates[i] = pred;
+	      		pred.exprSetParent(this);
+	      	}
+    	}
     }
   }
 
@@ -393,15 +398,15 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    super.fixupVariables(vars, globalsSize);
+    super.fixupVariables(vcs);
 
     int nPredicates = getPredicateCount();
 
     for (int i = 0; i < nPredicates; i++)
     {
-      m_predicates[i].fixupVariables(vars, globalsSize);
+      m_predicates[i].fixupVariables(vcs);
     }
   }
 
@@ -624,5 +629,63 @@
     	m_predicates[m_index] = exp;
     }
   }
-    
+  
+  public String toString()
+  {
+  	int myCount = (null == m_predicates) ? 0 : m_predicates.length;
+  	String str = "";
+  	
+  	for(int i = 0; i < myCount; i++)
+  	{
+  		// java.io.StringWriter sw = new java.io.StringWriter();
+  		char buf[] = new char[1024*32];
+  		java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
+  		java.io.PrintStream ps = new java.io.PrintStream(baos);
+  		
+  		m_predicates[i].dump("", ps);
+  		ps.flush();
+  		String predString = baos.toString().trim();
+  		
+  		str += "["+predString+"]";
+  	}
+  	str += " "+super.toString();
+  	return str;
+  }
+
+  
+//  public Node jjtGetChild(int i) 
+//  {
+//    int superclassChildCount = super.jjtGetNumChildren();
+//  	int myCount = (null == m_predicates) ? 0 : m_predicates.length;
+//    if(i < myCount)
+//    	return m_predicates[i];
+//    else
+//    	return super.jjtGetChild(i-myCount);
+//  }
+//
+//  public int jjtGetNumChildren() 
+//  {
+//  	int myCount = (null == m_predicates) ? 0 : m_predicates.length;
+//    return super.jjtGetNumChildren()+myCount;
+//  }
+
+  /**
+   * Tell if this node is part of a PathExpr chain.  For instance:
+   * <pre>
+   * 	|UnaryExpr
+   * 	|   PathExpr
+   * 	|      StepExpr
+   * 	|         AxisChild child::
+   * 	|         NodeTest
+   * 	|            NameTest
+   * 	|               QName foo
+   * 	|         Predicates   * 
+   * </pre><br/>
+   * In this example, UnaryExpr, PathExpr, and StepExpr should all return true.
+   */
+  public boolean isPathExpr()
+  {
+  	return true;
+  }
+
 }
diff --git a/src/org/apache/xpath/axes/RTFIterator.java b/src/org/apache/xpath/axes/RTFIterator.java
index be1ca70..a53cd69 100644
--- a/src/org/apache/xpath/axes/RTFIterator.java
+++ b/src/org/apache/xpath/axes/RTFIterator.java
@@ -7,17 +7,16 @@
 package org.apache.xpath.axes;
 
 import javax.xml.transform.TransformerException;
-import org.apache.xpath.compiler.Compiler;
 
 public class RTFIterator extends OneStepIteratorForward {
 
-	/**
-	 * Constructor for RTFIterator
-	 */
-	RTFIterator(Compiler compiler, int opPos, int analysis)
-		throws TransformerException {
-		super(compiler, opPos, analysis);
-	}
+//	/**
+//	 * Constructor for RTFIterator
+//	 */
+//	RTFIterator(Compiler compiler, int opPos, int analysis)
+//		throws TransformerException {
+//		super(compiler, opPos, analysis);
+//	}
 
 	/**
 	 * Constructor for RTFIterator
diff --git a/src/org/apache/xpath/axes/ReverseAxesWalker.java b/src/org/apache/xpath/axes/ReverseAxesWalker.java
index 9b18536..2a34456 100644
--- a/src/org/apache/xpath/axes/ReverseAxesWalker.java
+++ b/src/org/apache/xpath/axes/ReverseAxesWalker.java
@@ -61,7 +61,6 @@
 import org.apache.xpath.axes.LocPathIterator;
 import org.apache.xpath.XPath;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.compiler.OpCodes;
 import org.apache.xpath.objects.XObject;
 
 import javax.xml.transform.TransformerException;
diff --git a/src/org/apache/xpath/axes/SelfIteratorNoPredicate.java b/src/org/apache/xpath/axes/SelfIteratorNoPredicate.java
index 0f3630c..09a5fcf 100644
--- a/src/org/apache/xpath/axes/SelfIteratorNoPredicate.java
+++ b/src/org/apache/xpath/axes/SelfIteratorNoPredicate.java
@@ -2,7 +2,8 @@
 
 import javax.xml.transform.TransformerException;
 
-import org.apache.xpath.compiler.Compiler;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XSequence;
 import org.apache.xpath.patterns.NodeTest;
 import org.apache.xpath.XPathContext;
 import org.apache.xml.utils.PrefixResolver;
@@ -20,21 +21,21 @@
 public class SelfIteratorNoPredicate extends LocPathIterator
 {
 
-  /**
-   * Create a SelfIteratorNoPredicate object.
-   *
-   * @param compiler A reference to the Compiler that contains the op map.
-   * @param opPos The position within the op map, which contains the
-   * location path expression for this itterator.
-   * @param analysis Analysis bits.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  SelfIteratorNoPredicate(Compiler compiler, int opPos, int analysis)
-          throws javax.xml.transform.TransformerException
-  {
-    super(compiler, opPos, analysis, false);
-  }
+//  /**
+//   * Create a SelfIteratorNoPredicate object.
+//   *
+//   * @param compiler A reference to the Compiler that contains the op map.
+//   * @param opPos The position within the op map, which contains the
+//   * location path expression for this itterator.
+//   * @param analysis Analysis bits.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  SelfIteratorNoPredicate(Compiler compiler, int opPos, int analysis)
+//          throws javax.xml.transform.TransformerException
+//  {
+//    super(compiler, opPos, analysis, false);
+//  }
   
   /**
    * Create a SelfIteratorNoPredicate object.
@@ -51,6 +52,26 @@
   {
     super(null);
   }
+  
+  /**
+   * Execute this iterator, meaning create a clone that can
+   * store state, and initialize it for fast execution from
+   * the current runtime state.  When this is called, no actual
+   * query from the current context node is performed.
+   *
+   * @param xctxt The XPath execution context.
+   *
+   * @return An XNodeSet reference that holds this iterator.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt)
+          throws javax.xml.transform.TransformerException
+  {
+    XObject item = xctxt.getCurrentItem();
+    return item;
+  }
+
 
 
   /**
diff --git a/src/org/apache/xpath/axes/UnionPathIterator.java b/src/org/apache/xpath/axes/UnionPathIterator.java
index f0d1876..d8fa524 100644
--- a/src/org/apache/xpath/axes/UnionPathIterator.java
+++ b/src/org/apache/xpath/axes/UnionPathIterator.java
@@ -56,20 +56,15 @@
  */
 package org.apache.xpath.axes;
 
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.Serializable;
-import java.util.Vector;
-
-import javax.xml.transform.TransformerException;
-import org.apache.xml.dtm.Axis;
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMIterator;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathVisitor;
-import org.apache.xpath.compiler.Compiler;
-import org.apache.xpath.compiler.OpCodes;
+import org.apache.xpath.functions.Function;
+import org.apache.xpath.operations.Variable;
+import org.apache.xpath.parser.Node;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -79,8 +74,9 @@
  * As each node is iterated via nextNode(), the node is also stored
  * in the NodeVector, so that previousNode() can easily be done.
  */
-public class UnionPathIterator extends LocPathIterator
-        implements Cloneable, DTMIterator, java.io.Serializable, PathComponent
+public class UnionPathIterator
+  extends LocPathIterator
+  implements Cloneable, DTMIterator, java.io.Serializable, PathComponent
 {
 
   /**
@@ -114,7 +110,7 @@
       {
         int n = m_exprs.length;
         DTMIterator newIters[] = new DTMIterator[n];
-  
+
         for (int i = 0; i < n; i++)
         {
           DTMIterator iter = m_exprs[i].asIterator(m_execContext, context);
@@ -124,12 +120,12 @@
         m_iterators = newIters;
       }
     }
-    catch(Exception e)
+    catch (Exception e)
     {
       throw new org.apache.xml.utils.WrappedRuntimeException(e);
     }
   }
-  
+
   /**
    * Add an iterator to the union list.
    *
@@ -157,10 +153,10 @@
       m_iterators[len] = expr;
     }
     expr.nextNode();
-    if(expr instanceof Expression)
-    	((Expression)expr).exprSetParent(this);
+    if (expr instanceof Expression)
+       ((Expression) expr).exprSetParent(this);
   }
-  
+
   /**
    *  Detaches the iterator from the set which it iterated over, releasing
    * any computational resources and placing the iterator in the INVALID
@@ -169,102 +165,85 @@
    * exception INVALID_STATE_ERR.
    */
   public void detach()
-  {    
-    if(null != m_iterators)
+  {
+    if (null != m_iterators)
     {
-    	int n = m_iterators.length;
-    	for(int i = 0; i < n; i++)
-    	{
-    		m_iterators[i].detach();
-    	}
-    	m_iterators = null;
+      int n = m_iterators.length;
+      for (int i = 0; i < n; i++)
+      {
+        m_iterators[i].detach();
+      }
+      m_iterators = null;
     }
   }
 
+  /**
+   * @see org.apache.xpath.parser.Node#jjtAddChild(Node, int)
+   */
+  public void jjtAddChild(Node n, int i)
+  {
+    if (n instanceof UnionPathIterator)
+    {
+      int nChildren = n.jjtGetNumChildren();
+      for (int j = 0; j < nChildren; j++)
+      {
+        Node child = n.jjtGetChild(j);
+        child.jjtSetParent(this);
+        if (j == 0)
+          jjtAddChild(child, i);
+        else
+          jjtAddChild(child, m_exprs.length); // order doesn't matter!
+      }
+      return;
+    }
+    if (null == m_exprs)
+    {
+      m_exprs = new LocPathIterator[i + 1];
+    }
+    else
+      if (i >= m_exprs.length)
+      {
+
+        // Slow but space conservative.
+        LocPathIterator[] exprs = new LocPathIterator[m_exprs.length + 1];
+
+        System.arraycopy(m_exprs, 0, exprs, 0, m_exprs.length);
+
+        m_exprs = exprs;
+      }
+    n = fixupPrimarys(n);
+
+    // If a function or variable has been reduced from a path 
+    // expression, essentially 
+    // we need to turn it back into a path expression here!  There 
+    // might be a way to do this a bit earlier.  -sb
+    // if(!(((SimpleNode)n).isPathExpr()))
+    if(n instanceof Variable || n instanceof Function)
+    {
+      FilterExprIteratorSimple feis =
+        new FilterExprIteratorSimple((Expression) n);
+      feis.jjtSetParent(this);
+      n = feis;
+    }
+    m_exprs[i] = (LocPathIterator) n;
+  }
 
   /**
-   * Create a UnionPathIterator object, including creation 
-   * of location path iterators from the opcode list, and call back 
-   * into the Compiler to create predicate expressions.
-   *
-   * @param compiler The Compiler which is creating 
-   * this expression.
-   * @param opPos The position of this iterator in the 
-   * opcode list from the compiler.
-   *
-   * @throws javax.xml.transform.TransformerException
+   * @see org.apache.xpath.parser.Node#jjtGetChild(int)
    */
-  public UnionPathIterator(Compiler compiler, int opPos)
-          throws javax.xml.transform.TransformerException
+  public Node jjtGetChild(int i)
   {
-
-    super();
-
-    opPos = compiler.getFirstChildPos(opPos);
-
-    loadLocationPaths(compiler, opPos, 0);
+    return m_exprs[i];
   }
-  
+
   /**
-   * This will return an iterator capable of handling the union of paths given.
-   * 
-   * @param compiler The Compiler which is creating 
-   * this expression.
-   * @param opPos The position of this iterator in the 
-   * opcode list from the compiler.
-   * 
-   * @return Object that is derived from LocPathIterator.
-   *
-   * @throws javax.xml.transform.TransformerException
+   * @see org.apache.xpath.parser.Node#jjtGetNumChildren()
    */
-  public static LocPathIterator createUnionIterator(Compiler compiler, int opPos)
-          throws javax.xml.transform.TransformerException
+  public int jjtGetNumChildren()
   {
-  	// For the moment, I'm going to first create a full UnionPathIterator, and 
-  	// then see if I can reduce it to a UnionChildIterator.  It would obviously 
-  	// be more effecient to just test for the conditions for a UnionChildIterator, 
-  	// and then create that directly.
-  	UnionPathIterator upi = new UnionPathIterator(compiler, opPos);
-  	int nPaths = upi.m_exprs.length;
-  	boolean isAllChildIterators = true;
-  	for(int i = 0; i < nPaths; i++)
-  	{
-  		LocPathIterator lpi = upi.m_exprs[i];
-  		
-  		if(lpi.getAxis() != Axis.CHILD)
-  		{
-  			isAllChildIterators = false;
-  			break;
-  		}
-  		else
-  		{
-  			// check for positional predicates or position function, which won't work.
-  			if(HasPositionalPredChecker.check(lpi))
-  			{
-  				isAllChildIterators = false;
-  				break;
-  			}
-  		}
-  	}
-  	if(isAllChildIterators)
-  	{
-  		UnionChildIterator uci = new UnionChildIterator();
-  		
-	  	for(int i = 0; i < nPaths; i++)
-	  	{
-	  		PredicatedNodeTest lpi = upi.m_exprs[i];
-	  		// I could strip the lpi down to a pure PredicatedNodeTest, but 
-	  		// I don't think it's worth it.  Note that the test can be used 
-	  		// as a static object... so it doesn't have to be cloned.
-	  		uci.addNodeTest(lpi);
-	  	}
-	  	return uci;
-  		
-  	}
-  	else
-  		return upi;
+    return m_exprs.length;
   }
-  
+
   /** 
    * Get the analysis bits for this walker, as defined in the WalkerFactory.
    * @return One of WalkerFactory#BIT_DESCENDANT, etc.
@@ -272,21 +251,21 @@
   public int getAnalysisBits()
   {
     int bits = 0;
-    
+
     if (m_exprs != null)
     {
       int n = m_exprs.length;
 
       for (int i = 0; i < n; i++)
       {
-      	int bit = m_exprs[i].getAnalysisBits();
+        int bit = m_exprs[i].getAnalysisBits();
         bits |= bit;
       }
     }
 
     return bits;
   }
-  
+
   /**
    * Read the object from a serialization stream.
    *
@@ -296,12 +275,12 @@
    * @throws javax.xml.transform.TransformerException
    */
   private void readObject(java.io.ObjectInputStream stream)
-          throws java.io.IOException, javax.xml.transform.TransformerException
+    throws java.io.IOException, javax.xml.transform.TransformerException
   {
     try
     {
       stream.defaultReadObject();
-      m_clones =  new IteratorPool(this);
+      m_clones = new IteratorPool(this);
     }
     catch (ClassNotFoundException cnfe)
     {
@@ -321,109 +300,56 @@
   {
 
     UnionPathIterator clone = (UnionPathIterator) super.clone();
-//    if (m_iterators != null)
-//    {
-//      int n = m_iterators.length;
-//
-//      clone.m_iterators = new LocPathIterator[n];
-//
-//      for (int i = 0; i < n; i++)
-//      {
-//        clone.m_iterators[i] = (LocPathIterator)m_iterators[i].clone();
-//      }
-//    }
 
+    // %REVIEW% Not 100% sure this clone should be done here! -sb
+    if(clone.m_iterators == m_iterators && null != m_iterators)
+    {
+      DTMIterator[] clonedIters = new DTMIterator[m_iterators.length];
+      clone.m_iterators = clonedIters;
+      for (int i = 0; i < m_iterators.length; i++)
+      {
+        clonedIters[i] = (DTMIterator)((Expression)m_iterators[i]).cloneDeep();
+      }
+    }  
+    
     return clone;
   }
-  
-  
-  /**
-   * Create a new location path iterator.
-   *
-   * @param compiler The Compiler which is creating 
-   * this expression.
-   * @param opPos The position of this iterator in the 
-   *
-   * @return New location path iterator.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  protected LocPathIterator createDTMIterator(
-          Compiler compiler, int opPos) throws javax.xml.transform.TransformerException
-  {
-    LocPathIterator lpi = (LocPathIterator)WalkerFactory.newDTMIterator(compiler, opPos, 
-                                      (compiler.getLocationPathDepth() <= 0));
-    return lpi;
-  }
 
   /**
-   * Initialize the location path iterators.  Recursive.
-   *
-   * @param compiler The Compiler which is creating 
-   * this expression.
-   * @param opPos The position of this iterator in the 
-   * opcode list from the compiler.
-   * @param count The insert position of the iterator.
-   *
-   * @throws javax.xml.transform.TransformerException
+   *  Get a cloned Iterator that is reset to the beginning
+   *  of the query.
+   * 
+   *  @return A cloned NodeIterator set of the start of the query.
+   * 
+   *  @throws CloneNotSupportedException
    */
-  protected void loadLocationPaths(Compiler compiler, int opPos, int count)
-          throws javax.xml.transform.TransformerException
+  public DTMIterator cloneWithReset() throws CloneNotSupportedException
   {
 
-    // TODO: Handle unwrapped FilterExpr
-    int steptype = compiler.getOpMap()[opPos];
+    UnionPathIterator clone = (UnionPathIterator) super.cloneWithReset();
 
-    if (steptype == OpCodes.OP_LOCATIONPATH)
-    {
-      loadLocationPaths(compiler, compiler.getNextOpPos(opPos), count + 1);
+    clone.resetProximityPositions();
 
-      m_exprs[count] = createDTMIterator(compiler, opPos);
-      m_exprs[count].exprSetParent(this);
-    }
-    else
-    {
-
-      // Have to check for unwrapped functions, which the LocPathIterator
-      // doesn't handle. 
-      switch (steptype)
-      {
-      case OpCodes.OP_VARIABLE :
-      case OpCodes.OP_EXTFUNCTION :
-      case OpCodes.OP_FUNCTION :
-      case OpCodes.OP_GROUP :
-        loadLocationPaths(compiler, compiler.getNextOpPos(opPos), count + 1);
-
-        WalkingIterator iter =
-          new WalkingIterator(compiler.getNamespaceContext());
-        iter.exprSetParent(this);
-          
-        if(compiler.getLocationPathDepth() <= 0)
-          iter.setIsTopLevel(true);
-
-        iter.m_firstWalker = new org.apache.xpath.axes.FilterExprWalker(iter);
-
-        iter.m_firstWalker.init(compiler, opPos, steptype);
-
-        m_exprs[count] = iter;
-        break;
-      default :
-        m_exprs = new LocPathIterator[count];
-      }
-    }
+    return clone;
   }
 
   /**
    *  Returns the next node in the set and advances the position of the
    * iterator in the set. After a DTMIterator is created, the first call
    * to nextNode() returns the first node in the set.
+   * 
    * @return  The next <code>Node</code> in the set being iterated over, or
    *   <code>null</code> if there are no more members in that set.
    */
   public int nextNode()
   {
-  	if(m_foundLast)
-  		return DTM.NULL;
+    if (m_foundLast)
+      return DTM.NULL;
+
+    if (DTM.NULL == m_lastFetched)
+    {
+      resetProximityPositions();
+    }
 
     // Loop through the iterators getting the current fetched 
     // node, and get the earliest occuring in document order
@@ -433,42 +359,70 @@
     {
       int n = m_iterators.length;
       int iteratorUsed = -1;
+      int savedIteratorUsed = -1;
+      int savedEarliestNode = DTM.NULL;
 
-      for (int i = 0; i < n; i++)
+      while (true)
       {
-        int node = m_iterators[i].getCurrentNode();
-
-        if (DTM.NULL == node)
-          continue;
-        else if (DTM.NULL == earliestNode)
+        for (int i = 0; i < n; i++)
         {
-          iteratorUsed = i;
-          earliestNode = node;
-        }
-        else
-        {
-          if (node == earliestNode)
-          {
+          int node = m_iterators[i].getCurrentNode();
 
-            // Found a duplicate, so skip past it.
-            m_iterators[i].nextNode();
-          }
+          if (DTM.NULL == node)
+            continue;
           else
-          {
-            DTM dtm = getDTM(node);
-
-            if (dtm.isNodeAfter(node, earliestNode))
+            if (DTM.NULL == earliestNode)
             {
               iteratorUsed = i;
               earliestNode = node;
             }
-          }
+            else
+            {
+              if (node == earliestNode)
+              {
+
+                // Found a duplicate, so skip past it.
+                // %REVIEW% Make sure this is really what we 
+                // want to do for XPath 2.0.
+                m_iterators[i].nextNode();
+              }
+              else
+              {
+                DTM dtm = getDTM(node);
+
+                if (dtm.isNodeAfter(node, earliestNode))
+                {
+                  iteratorUsed = i;
+                  earliestNode = node;
+                }
+              }
+            }
         }
+
+        if (DTM.NULL == earliestNode)
+          break;
+
+        else
+          if (getPredicateCount() == 0)
+          {
+            m_iterators[iteratorUsed].nextNode();
+            break;
+          }
+          else
+          {
+            m_iterators[iteratorUsed].nextNode();
+            int acceptence = acceptNode(earliestNode);
+
+            if (DTMIterator.FILTER_ACCEPT == acceptence)
+              break;
+              
+            earliestNode = DTM.NULL;
+          }
       }
 
       if (DTM.NULL != earliestNode)
       {
-        m_iterators[iteratorUsed].nextNode();
+        // m_iterators[iteratorUsed].nextNode();
 
         incrementCurrentPos();
       }
@@ -480,10 +434,11 @@
 
     return earliestNode;
   }
-            
+
   /**
    * This function is used to fixup variables from QNames to stack frame 
    * indexes at stylesheet build time.
+   * 
    * @param vars List of QNames that correspond to variables.  This list 
    * should be searched backwards for the first qualified name that 
    * corresponds to the variable reference qname.  The position of the 
@@ -491,15 +446,15 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    for (int i = 0; i < m_exprs.length; i++) 
+    for (int i = 0; i < m_exprs.length; i++)
     {
-      m_exprs[i].fixupVariables(vars, globalsSize);
+      m_exprs[i].fixupVariables(vcs);
     }
-    
+
   }
-  
+
   /**
    * The location path iterators, one for each
    * <a href="http://www.w3.org/TR/xpath#NT-LocationPath">location
@@ -508,7 +463,6 @@
    */
   protected LocPathIterator[] m_exprs;
 
-    
   /**
    * The location path iterators, one for each
    * <a href="http://www.w3.org/TR/xpath#NT-LocationPath">location
@@ -516,7 +470,7 @@
    * @serial
    */
   protected DTMIterator[] m_iterators;
-      
+
   /**
    * Returns the axis being iterated, if it is known.
    * 
@@ -528,16 +482,16 @@
     // Could be smarter.
     return -1;
   }
-  
+
   class iterOwner implements ExpressionOwner
   {
-  	int m_index;
-  	
-  	iterOwner(int index)
-  	{
-  		m_index = index;
-  	}
-  	
+    int m_index;
+
+    iterOwner(int index)
+    {
+      m_index = index;
+    }
+
     /**
      * @see ExpressionOwner#getExpression()
      */
@@ -551,23 +505,23 @@
      */
     public void setExpression(Expression exp)
     {
-    	
-    	if(!(exp instanceof LocPathIterator))
-    	{
-    		// Yuck.  Need FilterExprIter.  Or make it so m_exprs can be just 
-    		// plain expressions?
-    		WalkingIterator wi = new WalkingIterator(getPrefixResolver());
-    		FilterExprWalker few = new FilterExprWalker(wi);
-    		wi.setFirstWalker(few);
-    		few.setInnerExpression(exp);
-    		wi.exprSetParent(UnionPathIterator.this);
-    		few.exprSetParent(wi);
-    		exp.exprSetParent(few);
-    		exp = wi;
-    	}
-    	else
-    		exp.exprSetParent(UnionPathIterator.this);
-    	m_exprs[m_index] = (LocPathIterator)exp;
+
+      if (!(exp instanceof LocPathIterator))
+      {
+        // Yuck.  Need FilterExprIter.  Or make it so m_exprs can be just 
+        // plain expressions?
+        WalkingIterator wi = new WalkingIterator(getPrefixResolver());
+        FilterExprWalker few = new FilterExprWalker(wi);
+        wi.setFirstWalker(few);
+        few.setInnerExpression(exp);
+        wi.exprSetParent(UnionPathIterator.this);
+        few.exprSetParent(wi);
+        exp.exprSetParent(few);
+        exp = wi;
+      }
+      else
+        exp.exprSetParent(UnionPathIterator.this);
+      m_exprs[m_index] = (LocPathIterator) exp;
     }
 
   }
@@ -577,49 +531,49 @@
    */
   public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
   {
-  	 	if(visitor.visitUnionPath(owner, this))
-  	 	{
-  	 		if(null != m_exprs)
-  	 		{
-  	 			int n = m_exprs.length;
-  	 			for(int i = 0; i < n; i++)
-  	 			{
-  	 				m_exprs[i].callVisitors(new iterOwner(i), visitor);
-  	 			}
-  	 		}
-  	 	}
-  }
-  
-    /**
-     * @see Expression#deepEquals(Expression)
-     */
-    public boolean deepEquals(Expression expr)
+    if (visitor.visitUnionPath(owner, this))
     {
-      if (!super.deepEquals(expr))
-            return false;
-
-      UnionPathIterator upi = (UnionPathIterator) expr;
-
       if (null != m_exprs)
       {
         int n = m_exprs.length;
-        
-        if((null == upi.m_exprs) || (upi.m_exprs.length != n))
-        	return false;
-        
         for (int i = 0; i < n; i++)
         {
-          if(!m_exprs[i].deepEquals(upi.m_exprs[i]))
-          	return false;
+          m_exprs[i].callVisitors(new iterOwner(i), visitor);
         }
       }
-      else if (null != upi.m_exprs)
+    }
+  }
+
+  /**
+   * @see Expression#deepEquals(Expression)
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    if (!super.deepEquals(expr))
+      return false;
+
+    UnionPathIterator upi = (UnionPathIterator) expr;
+
+    if (null != m_exprs)
+    {
+      int n = m_exprs.length;
+
+      if ((null == upi.m_exprs) || (upi.m_exprs.length != n))
+        return false;
+
+      for (int i = 0; i < n; i++)
       {
+        if (!m_exprs[i].deepEquals(upi.m_exprs[i]))
           return false;
       }
-
-      return true;
     }
+    else
+      if (null != upi.m_exprs)
+      {
+        return false;
+      }
 
+    return true;
+  }
 
 }
diff --git a/src/org/apache/xpath/axes/WalkerFactory.java b/src/org/apache/xpath/axes/WalkerFactory.java
index 8db21c1..c884745 100644
--- a/src/org/apache/xpath/axes/WalkerFactory.java
+++ b/src/org/apache/xpath/axes/WalkerFactory.java
@@ -56,769 +56,85 @@
  */
 package org.apache.xpath.axes;
 
-import org.apache.xpath.compiler.OpCodes;
-import org.apache.xpath.compiler.Compiler;
-import org.apache.xpath.compiler.FunctionTable;
-import org.apache.xpath.patterns.NodeTest;
-import org.apache.xpath.patterns.StepPattern;
-import org.apache.xpath.patterns.ContextMatchStepPattern;
-import org.apache.xpath.patterns.FunctionPattern;
-import org.apache.xpath.Expression;
-import org.apache.xpath.objects.XNumber;
+import javax.xml.transform.TransformerException;
 import org.apache.xalan.res.XSLMessages;
-import org.apache.xpath.res.XPATHErrorResources;
-
+import org.apache.xml.dtm.Axis;
 import org.apache.xml.dtm.DTMFilter;
 import org.apache.xml.dtm.DTMIterator;
-import org.apache.xml.dtm.Axis;
+import org.apache.xpath.Expression;
+import org.apache.xpath.functions.FuncLast;
+import org.apache.xpath.functions.FuncPosition;
+import org.apache.xpath.functions.Function;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.operations.Variable;
+import org.apache.xpath.parser.Node;
+import org.apache.xpath.parser.NodeTest;
+import org.apache.xpath.parser.PathExpr;
+import org.apache.xpath.parser.PatternAxis;
+import org.apache.xpath.parser.Predicates;
+import org.apache.xpath.parser.StepExpr;
+import org.apache.xpath.res.XPATHErrorResources;
 
-/**
- * This class is both a factory for XPath location path expressions,
- * which are built from the opcode map output, and an analysis engine
- * for the location path expressions in order to provide optimization hints.
- */
 public class WalkerFactory
 {
-
-  /**
-   * <meta name="usage" content="advanced"/>
-   * This method is for building an array of possible levels
-   * where the target element(s) could be found for a match.
-   * @param xpath The xpath that is executing.
-   * @param context The current source tree context node.
-   *
-   * @param lpi The owning location path iterator.
-   * @param compiler non-null reference to compiler object that has processed
-   *                 the XPath operations into an opcode map.
-   * @param stepOpCodePos The opcode position for the step.
-   *
-   * @return non-null AxesWalker derivative.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  static AxesWalker loadOneWalker(
-          WalkingIterator lpi, Compiler compiler, int stepOpCodePos)
-            throws javax.xml.transform.TransformerException
-  {
-
-    AxesWalker firstWalker = null;
-    int stepType = compiler.getOpMap()[stepOpCodePos];
-
-    if (stepType != OpCodes.ENDOP)
-    {
-
-      // m_axesWalkers = new AxesWalker[1];
-      // As we unwind from the recursion, create the iterators.
-      firstWalker = createDefaultWalker(compiler, stepType, lpi, 0);
-
-      firstWalker.init(compiler, stepOpCodePos, stepType);
-    }
-
-    return firstWalker;
-  }
-
-  /**
-   * <meta name="usage" content="advanced"/>
-   * This method is for building an array of possible levels
-   * where the target element(s) could be found for a match.
-   * @param xpath The xpath that is executing.
-   * @param context The current source tree context node.
-   *
-   * @param lpi The owning location path iterator object.
-   * @param compiler non-null reference to compiler object that has processed
-   *                 the XPath operations into an opcode map.
-   * @param stepOpCodePos The opcode position for the step.
-   * @param stepIndex The top-level step index withing the iterator.
-   *
-   * @return non-null AxesWalker derivative.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  static AxesWalker loadWalkers(
-          WalkingIterator lpi, Compiler compiler, int stepOpCodePos, int stepIndex)
-            throws javax.xml.transform.TransformerException
-  {
-
-    int stepType;
-    AxesWalker firstWalker = null;
-    AxesWalker walker, prevWalker = null;
-    int ops[] = compiler.getOpMap();
-    int analysis = analyze(compiler, stepOpCodePos, stepIndex);
-
-    while (OpCodes.ENDOP != (stepType = ops[stepOpCodePos]))
-    {
-      walker = createDefaultWalker(compiler, stepOpCodePos, lpi, analysis);
-
-      walker.init(compiler, stepOpCodePos, stepType);
-      walker.exprSetParent(lpi);
-
-      // walker.setAnalysis(analysis);
-      if (null == firstWalker)
-      {
-        firstWalker = walker;
-      }
-      else
-      {
-        prevWalker.setNextWalker(walker);
-        walker.setPrevWalker(prevWalker);
-      }
-
-      prevWalker = walker;
-      stepOpCodePos = compiler.getNextStepPos(stepOpCodePos);
-
-      if (stepOpCodePos < 0)
-        break;
-    }
-
-    return firstWalker;
-  }
-  
   public static boolean isSet(int analysis, int bits)
   {
     return (0 != (analysis & bits));
   }
-  
-  public static void diagnoseIterator(String name, int analysis, Compiler compiler)
-  {
-    System.out.println(compiler.toString()+", "+name+", "
-                             + Integer.toBinaryString(analysis) + ", "
-                             + getAnalysisString(analysis));
-  }
 
   /**
-   * Create a new LocPathIterator iterator.  The exact type of iterator
-   * returned is based on an analysis of the XPath operations.
-   *
-   * @param compiler non-null reference to compiler object that has processed
-   *                 the XPath operations into an opcode map.
-   * @param opPos The position of the operation code for this itterator.
-   *
-   * @return non-null reference to a LocPathIterator or derivative.
-   *
-   * @throws javax.xml.transform.TransformerException
+   * Get a corresponding BIT_XXX from an axis.
+   * @param axis One of Axis.ANCESTOR, etc.
+   * @return One of BIT_ANCESTOR, etc.
    */
-  public static DTMIterator newDTMIterator(
-          Compiler compiler, int opPos,
-          boolean isTopLevel)
-            throws javax.xml.transform.TransformerException
+  static public int getAnalysisBitFromAxes(int axis)
   {
-
-    int firstStepPos = compiler.getFirstChildPos(opPos);
-    int analysis = analyze(compiler, firstStepPos, 0);
-    boolean isOneStep = isOneStep(analysis);
-    DTMIterator iter;
-
-    // Is the iteration a one-step attribute pattern (i.e. select="@foo")?
-    if (isOneStep && walksSelfOnly(analysis) && 
-        isWild(analysis) && !hasPredicate(analysis))
+    switch (axis) // Generate new traverser
     {
-      if (DEBUG_ITERATOR_CREATION)
-        diagnoseIterator("SelfIteratorNoPredicate", analysis, compiler);
-
-      // Then use a simple iteration of the attributes, with node test 
-      // and predicate testing.
-      iter = new SelfIteratorNoPredicate(compiler, opPos, analysis);
-    }
-    // Is the iteration exactly one child step?
-    else if (walksChildrenOnly(analysis) && isOneStep)
-    {
-
-      // Does the pattern specify *any* child with no predicate? (i.e. select="child::node()".
-      if (isWild(analysis) && !hasPredicate(analysis))
-      {
-        if (DEBUG_ITERATOR_CREATION)
-          diagnoseIterator("ChildIterator", analysis, compiler);
-
-        // Use simple child iteration without any test.
-        iter = new ChildIterator(compiler, opPos, analysis);
-      }
-      else
-      {
-        if (DEBUG_ITERATOR_CREATION)
-          diagnoseIterator("ChildTestIterator", analysis, compiler);
-
-        // Else use simple node test iteration with predicate test.
-        iter = new ChildTestIterator(compiler, opPos, analysis);
-      }
-    }
-    // Is the iteration a one-step attribute pattern (i.e. select="@foo")?
-    else if (isOneStep && walksAttributes(analysis))
-    {
-      if (DEBUG_ITERATOR_CREATION)
-        diagnoseIterator("AttributeIterator", analysis, compiler);
-
-      // Then use a simple iteration of the attributes, with node test 
-      // and predicate testing.
-      iter = new AttributeIterator(compiler, opPos, analysis);
-    }
-    else if(isOneStep && !walksFilteredList(analysis))
-    {
-      if( !walksNamespaces(analysis) 
-      && (walksInDocOrder(analysis) || isSet(analysis, BIT_PARENT)))
-      {
-        if (false || DEBUG_ITERATOR_CREATION)
-          diagnoseIterator("OneStepIteratorForward", analysis, compiler);
-  
-        // Then use a simple iteration of the attributes, with node test 
-        // and predicate testing.
-        iter = new OneStepIteratorForward(compiler, opPos, analysis);
-      }
-      else
-      {
-        if (false || DEBUG_ITERATOR_CREATION)
-          diagnoseIterator("OneStepIterator", analysis, compiler);
-  
-        // Then use a simple iteration of the attributes, with node test 
-        // and predicate testing.
-        iter = new OneStepIterator(compiler, opPos, analysis);
-      }
-    }
-
-    // Analysis of "//center":
-    // bits: 1001000000001010000000000000011
-    // count: 3
-    // root
-    // child:node()
-    // BIT_DESCENDANT_OR_SELF
-    // It's highly possible that we should have a seperate bit set for 
-    // "//foo" patterns.
-    // For at least the time being, we can't optimize patterns like 
-    // "//table[3]", because this has to be analyzed as 
-    // "/descendant-or-self::node()/table[3]" in order for the indexes 
-    // to work right.
-    else if (isOptimizableForDescendantIterator(compiler, firstStepPos, 0)
-              // && getStepCount(analysis) <= 3 
-              // && walksDescendants(analysis) 
-              // && walksSubtreeOnlyFromRootOrContext(analysis)
-             )
-    {
-      if (DEBUG_ITERATOR_CREATION)
-        diagnoseIterator("DescendantIterator", analysis, compiler);
-
-      iter = new DescendantIterator(compiler, opPos, analysis);
-    }
-    else
-    { 
-      if(isNaturalDocOrder(compiler, firstStepPos, 0, analysis))
-      {
-        if (false || DEBUG_ITERATOR_CREATION)
-        {
-          diagnoseIterator("WalkingIterator", analysis, compiler);
-        }
-  
-        iter = new WalkingIterator(compiler, opPos, analysis, true);
-      }
-      else
-      {
-//        if (DEBUG_ITERATOR_CREATION)
-//          diagnoseIterator("MatchPatternIterator", analysis, compiler);
-//
-//        return new MatchPatternIterator(compiler, opPos, analysis);
-        if (DEBUG_ITERATOR_CREATION)
-          diagnoseIterator("WalkingIteratorSorted", analysis, compiler);
-
-        iter = new WalkingIteratorSorted(compiler, opPos, analysis, true);
-      }
-    }
-    if(iter instanceof LocPathIterator)
-      ((LocPathIterator)iter).setIsTopLevel(isTopLevel);
-      
-    return iter;
-  }
-  
-  /**
-   * Special purpose function to see if we can optimize the pattern for 
-   * a DescendantIterator.
-   *
-   * @param compiler non-null reference to compiler object that has processed
-   *                 the XPath operations into an opcode map.
-   * @param stepOpCodePos The opcode position for the step.
-   * @param stepIndex The top-level step index withing the iterator.
-   *
-   * @return 32 bits as an integer that give information about the location
-   * path as a whole.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  public static int getAxisFromStep(
-          Compiler compiler, int stepOpCodePos)
-            throws javax.xml.transform.TransformerException
-  {
-
-    int ops[] = compiler.getOpMap();
-    int stepType = ops[stepOpCodePos];
-
-    switch (stepType)
-    {
-    case OpCodes.FROM_FOLLOWING :
-      return Axis.FOLLOWING;
-    case OpCodes.FROM_FOLLOWING_SIBLINGS :
-      return Axis.FOLLOWINGSIBLING;
-    case OpCodes.FROM_PRECEDING :
-      return Axis.PRECEDING;
-    case OpCodes.FROM_PRECEDING_SIBLINGS :
-      return Axis.PRECEDINGSIBLING;
-    case OpCodes.FROM_PARENT :
-      return Axis.PARENT;
-    case OpCodes.FROM_NAMESPACE :
-      return Axis.NAMESPACE;
-    case OpCodes.FROM_ANCESTORS :
-      return Axis.ANCESTOR;
-    case OpCodes.FROM_ANCESTORS_OR_SELF :
-      return Axis.ANCESTORORSELF;
-    case OpCodes.FROM_ATTRIBUTES :
-      return Axis.ATTRIBUTE;
-    case OpCodes.FROM_ROOT :
-      return Axis.ROOT;
-    case OpCodes.FROM_CHILDREN :
-      return Axis.CHILD;
-    case OpCodes.FROM_DESCENDANTS_OR_SELF :
-      return Axis.DESCENDANTORSELF;
-    case OpCodes.FROM_DESCENDANTS :
-      return Axis.DESCENDANT;
-    case OpCodes.FROM_SELF :
-      return Axis.SELF;
-    case OpCodes.OP_EXTFUNCTION :
-    case OpCodes.OP_FUNCTION :
-    case OpCodes.OP_GROUP :
-    case OpCodes.OP_VARIABLE :
-      return Axis.FILTEREDLIST;
-    }
-
-    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
-                               //+ stepType);
-   }
-    
-    /**
-     * Get a corresponding BIT_XXX from an axis.
-     * @param axis One of Axis.ANCESTOR, etc.
-     * @return One of BIT_ANCESTOR, etc.
-     */
-    static public int getAnalysisBitFromAxes(int axis)
-    {
-      switch (axis) // Generate new traverser
-        {
-        case Axis.ANCESTOR :
-          return BIT_ANCESTOR;
-        case Axis.ANCESTORORSELF :
-          return BIT_ANCESTOR_OR_SELF;
-        case Axis.ATTRIBUTE :
-          return BIT_ATTRIBUTE;
-        case Axis.CHILD :
-          return BIT_CHILD;
-        case Axis.DESCENDANT :
-          return BIT_DESCENDANT;
-        case Axis.DESCENDANTORSELF :
-          return BIT_DESCENDANT_OR_SELF;
-        case Axis.FOLLOWING :
-          return BIT_FOLLOWING;
-        case Axis.FOLLOWINGSIBLING :
-          return BIT_FOLLOWING_SIBLING;
-        case Axis.NAMESPACE :
-        case Axis.NAMESPACEDECLS :
-          return BIT_NAMESPACE;
-        case Axis.PARENT :
-          return BIT_PARENT;
-        case Axis.PRECEDING :
-          return BIT_PRECEDING;
-        case Axis.PRECEDINGSIBLING :
-          return BIT_PRECEDING_SIBLING;
-        case Axis.SELF :
-          return BIT_SELF;
-        case Axis.ALLFROMNODE :
-          return BIT_DESCENDANT_OR_SELF;
-          // case Axis.PRECEDINGANDANCESTOR :
-        case Axis.DESCENDANTSFROMROOT :
-        case Axis.ALL :
-        case Axis.DESCENDANTSORSELFFROMROOT :
-          return BIT_ANY_DESCENDANT_FROM_ROOT;
-        case Axis.ROOT :
-          return BIT_ROOT;
-        case Axis.FILTEREDLIST :
-          return BIT_FILTER;
-        default :
-          return BIT_FILTER;
-      }
-    }
-  
-  static boolean functionProximateOrContainsProximate(Compiler compiler, 
-                                                      int opPos)
-  {
-    int endFunc = opPos + compiler.getOp(opPos + 1) - 1;
-    opPos = compiler.getFirstChildPos(opPos);
-    int funcID = compiler.getOp(opPos);
-    //  System.out.println("funcID: "+funcID);
-    //  System.out.println("opPos: "+opPos);
-    //  System.out.println("endFunc: "+endFunc);
-    switch(funcID)
-    {
-      case FunctionTable.FUNC_LAST:
-      case FunctionTable.FUNC_POSITION:
-        return true;
-      default:
-        opPos++;
-        int i = 0;
-        for (int p = opPos; p < endFunc; p = compiler.getNextOpPos(p), i++)
-        {
-          int innerExprOpPos = p+2;
-          int argOp = compiler.getOp(innerExprOpPos);
-          boolean prox = isProximateInnerExpr(compiler, innerExprOpPos);
-          if(prox)
-            return true;
-        }
-
-    }
-    return false;
-  }
-  
-  static boolean isProximateInnerExpr(Compiler compiler, int opPos)
-  {
-    int op = compiler.getOp(opPos);
-    int innerExprOpPos = opPos+2;
-    switch(op)
-    {
-      case OpCodes.OP_ARGUMENT:
-        if(isProximateInnerExpr(compiler, innerExprOpPos))
-          return true;
-        break;
-      case OpCodes.OP_VARIABLE:
-      case OpCodes.OP_NUMBERLIT:
-      case OpCodes.OP_LITERAL:
-      case OpCodes.OP_LOCATIONPATH:
-        break; // OK
-      case OpCodes.OP_FUNCTION:
-        boolean isProx = functionProximateOrContainsProximate(compiler, opPos);
-        if(isProx)
-          return true;
-        break;
-      case OpCodes.OP_GT:
-      case OpCodes.OP_GTE:
-      case OpCodes.OP_LT:
-      case OpCodes.OP_LTE:
-      case OpCodes.OP_EQUALS:
-        int leftPos = compiler.getFirstChildPos(op);
-        int rightPos = compiler.getNextOpPos(leftPos);
-        isProx = isProximateInnerExpr(compiler, leftPos);
-        if(isProx)
-          return true;
-        isProx = isProximateInnerExpr(compiler, rightPos);
-        if(isProx)
-          return true;
-        break;
-      default:
-        return true; // be conservative...
-    }
-    return false;
-  }
-    
-  /**
-   * Tell if the predicates need to have proximity knowledge.
-   */
-  public static boolean mightBeProximate(Compiler compiler, int opPos, int stepType)
-          throws javax.xml.transform.TransformerException
-  {
-
-    boolean mightBeProximate = false;
-    int argLen;
-
-    switch (stepType)
-    {
-    case OpCodes.OP_VARIABLE :
-    case OpCodes.OP_EXTFUNCTION :
-    case OpCodes.OP_FUNCTION :
-    case OpCodes.OP_GROUP :
-      argLen = compiler.getArgLength(opPos);
-      break;
-    default :
-      argLen = compiler.getArgLengthOfStep(opPos);
-    }
-
-    int predPos = compiler.getFirstPredicateOpPos(opPos);
-    int count = 0;
-
-    while (OpCodes.OP_PREDICATE == compiler.getOp(predPos))
-    {
-      count++;
-      
-      int innerExprOpPos = predPos+2;
-      int predOp = compiler.getOp(innerExprOpPos);
-
-      switch(predOp)
-      {
-        case OpCodes.OP_VARIABLE:
-        	return true; // Would need more smarts to tell if this could be a number or not!
-        case OpCodes.OP_LOCATIONPATH:
-          // OK.
-          break;
-        case OpCodes.OP_NUMBER:
-        case OpCodes.OP_NUMBERLIT:
-          return true; // that's all she wrote!
-        case OpCodes.OP_FUNCTION:
-          boolean isProx 
-            = functionProximateOrContainsProximate(compiler, innerExprOpPos);
-          if(isProx)
-            return true;
-          break;
-        case OpCodes.OP_GT:
-        case OpCodes.OP_GTE:
-        case OpCodes.OP_LT:
-        case OpCodes.OP_LTE:
-        case OpCodes.OP_EQUALS:
-          int leftPos = compiler.getFirstChildPos(innerExprOpPos);
-          int rightPos = compiler.getNextOpPos(leftPos);
-          isProx = isProximateInnerExpr(compiler, leftPos);
-          if(isProx)
-            return true;
-          isProx = isProximateInnerExpr(compiler, rightPos);
-          if(isProx)
-            return true;
-          break;
-        default:
-          return true; // be conservative...
-      }
-
-      predPos = compiler.getNextOpPos(predPos);
-    }
-
-    return mightBeProximate;
-  }
-  
-  /**
-   * Special purpose function to see if we can optimize the pattern for 
-   * a DescendantIterator.
-   *
-   * @param compiler non-null reference to compiler object that has processed
-   *                 the XPath operations into an opcode map.
-   * @param stepOpCodePos The opcode position for the step.
-   * @param stepIndex The top-level step index withing the iterator.
-   *
-   * @return 32 bits as an integer that give information about the location
-   * path as a whole.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  private static boolean isOptimizableForDescendantIterator(
-          Compiler compiler, int stepOpCodePos, int stepIndex)
-            throws javax.xml.transform.TransformerException
-  {
-
-    int stepType;
-    int ops[] = compiler.getOpMap();
-    int stepCount = 0;
-    boolean foundDorDS = false;
-    boolean foundSelf = false;
-    boolean foundDS = false;
-    
-    int nodeTestType = OpCodes.NODETYPE_NODE;
-    
-    while (OpCodes.ENDOP != (stepType = ops[stepOpCodePos]))
-    {
-      // The DescendantIterator can only do one node test.  If there's more 
-      // than one, use another iterator.
-      if(nodeTestType != OpCodes.NODETYPE_NODE && nodeTestType != OpCodes.NODETYPE_ROOT)
-        return false;
-        
-      stepCount++;
-      if(stepCount > 3)
-        return false;
-        
-      boolean mightBeProximate = mightBeProximate(compiler, stepOpCodePos, stepType);
-      if(mightBeProximate)
-        return false;
-
-      switch (stepType)
-      {
-      case OpCodes.FROM_FOLLOWING :
-      case OpCodes.FROM_FOLLOWING_SIBLINGS :
-      case OpCodes.FROM_PRECEDING :
-      case OpCodes.FROM_PRECEDING_SIBLINGS :
-      case OpCodes.FROM_PARENT :
-      case OpCodes.OP_VARIABLE :
-      case OpCodes.OP_EXTFUNCTION :
-      case OpCodes.OP_FUNCTION :
-      case OpCodes.OP_GROUP :
-      case OpCodes.FROM_NAMESPACE :
-      case OpCodes.FROM_ANCESTORS :
-      case OpCodes.FROM_ANCESTORS_OR_SELF :
-      case OpCodes.FROM_ATTRIBUTES :
-      case OpCodes.MATCH_ATTRIBUTE :
-      case OpCodes.MATCH_ANY_ANCESTOR :
-      case OpCodes.MATCH_IMMEDIATE_ANCESTOR :
-        return false;
-      case OpCodes.FROM_ROOT :
-        if(1 != stepCount)
-          return false;
-        break;
-      case OpCodes.FROM_CHILDREN :
-        if(!foundDS && !(foundDorDS && foundSelf))
-          return false;
-        break;
-      case OpCodes.FROM_DESCENDANTS_OR_SELF :
-        foundDS = true;
-      case OpCodes.FROM_DESCENDANTS :
-        if(3 == stepCount)
-          return false;
-        foundDorDS = true;
-        break;
-      case OpCodes.FROM_SELF :
-        if(1 != stepCount)
-          return false;
-        foundSelf = true;
-        break;
+      case Axis.ANCESTOR :
+        return BIT_ANCESTOR;
+      case Axis.ANCESTORORSELF :
+        return BIT_ANCESTOR_OR_SELF;
+      case Axis.ATTRIBUTE :
+        return BIT_ATTRIBUTE;
+      case Axis.CHILD :
+        return BIT_CHILD;
+      case Axis.DESCENDANT :
+        return BIT_DESCENDANT;
+      case Axis.DESCENDANTORSELF :
+        return BIT_DESCENDANT_OR_SELF;
+      case Axis.FOLLOWING :
+        return BIT_FOLLOWING;
+      case Axis.FOLLOWINGSIBLING :
+        return BIT_FOLLOWING_SIBLING;
+      case Axis.NAMESPACE :
+      case Axis.NAMESPACEDECLS :
+        return BIT_NAMESPACE;
+      case Axis.PARENT :
+        return BIT_PARENT;
+      case Axis.PRECEDING :
+        return BIT_PRECEDING;
+      case Axis.PRECEDINGSIBLING :
+        return BIT_PRECEDING_SIBLING;
+      case Axis.SELF :
+        return BIT_SELF;
+      case Axis.ALLFROMNODE :
+        return BIT_DESCENDANT_OR_SELF;
+        // case Axis.PRECEDINGANDANCESTOR :
+      case Axis.DESCENDANTSFROMROOT :
+      case Axis.ALL :
+      case Axis.DESCENDANTSORSELFFROMROOT :
+        return BIT_DESCENDANT | BIT_DESCENDANT_OR_SELF | BIT_ANY_DESCENDANT_FROM_ROOT;
+      case Axis.ROOT :
+        return BIT_ROOT;
+      case Axis.FILTEREDLIST :
+        return BIT_FILTER;
       default :
-        throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
-                                  // + stepType);
-      }
-      
-      nodeTestType = compiler.getStepTestType(stepOpCodePos);
-
-      int nextStepOpCodePos = compiler.getNextStepPos(stepOpCodePos);
-
-      if (nextStepOpCodePos < 0)
-        break;
-        
-      if(OpCodes.ENDOP != ops[nextStepOpCodePos])
-      {
-        if(compiler.countPredicates(stepOpCodePos) > 0)
-        {
-          return false;
-        }
-      }
-      
-      stepOpCodePos = nextStepOpCodePos;
+        return BIT_FILTER;
     }
-
-    return true;
   }
 
   /**
-   * Analyze the location path and return 32 bits that give information about
-   * the location path as a whole.  See the BIT_XXX constants for meaning about
-   * each of the bits.
-   *
-   * @param compiler non-null reference to compiler object that has processed
-   *                 the XPath operations into an opcode map.
-   * @param stepOpCodePos The opcode position for the step.
-   * @param stepIndex The top-level step index withing the iterator.
-   *
-   * @return 32 bits as an integer that give information about the location
-   * path as a whole.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  private static int analyze(
-          Compiler compiler, int stepOpCodePos, int stepIndex)
-            throws javax.xml.transform.TransformerException
-  {
-
-    int stepType;
-    int ops[] = compiler.getOpMap();
-    int stepCount = 0;
-    int analysisResult = 0x00000000;  // 32 bits of analysis
-
-    while (OpCodes.ENDOP != (stepType = ops[stepOpCodePos]))
-    {
-      stepCount++;
-
-      // String namespace = compiler.getStepNS(stepOpCodePos);
-      // boolean isNSWild = (null != namespace) 
-      //                   ? namespace.equals(NodeTest.WILD) : false;
-      // String localname = compiler.getStepLocalName(stepOpCodePos);
-      // boolean isWild = (null != localname) ? localname.equals(NodeTest.WILD) : false;
-      boolean predAnalysis = analyzePredicate(compiler, stepOpCodePos,
-                                              stepType);
-
-      if (predAnalysis)
-        analysisResult |= BIT_PREDICATE;
-
-      switch (stepType)
-      {
-      case OpCodes.OP_VARIABLE :
-      case OpCodes.OP_EXTFUNCTION :
-      case OpCodes.OP_FUNCTION :
-      case OpCodes.OP_GROUP :
-        analysisResult |= BIT_FILTER;
-        break;
-      case OpCodes.FROM_ROOT :
-        analysisResult |= BIT_ROOT;
-        break;
-      case OpCodes.FROM_ANCESTORS :
-        analysisResult |= BIT_ANCESTOR;
-        break;
-      case OpCodes.FROM_ANCESTORS_OR_SELF :
-        analysisResult |= BIT_ANCESTOR_OR_SELF;
-        break;
-      case OpCodes.FROM_ATTRIBUTES :
-        analysisResult |= BIT_ATTRIBUTE;
-        break;
-      case OpCodes.FROM_NAMESPACE :
-        analysisResult |= BIT_NAMESPACE;
-        break;
-      case OpCodes.FROM_CHILDREN :
-        analysisResult |= BIT_CHILD;
-        break;
-      case OpCodes.FROM_DESCENDANTS :
-        analysisResult |= BIT_DESCENDANT;
-        break;
-      case OpCodes.FROM_DESCENDANTS_OR_SELF :
-
-        // Use a special bit to to make sure we get the right analysis of "//foo".
-        if (2 == stepCount && BIT_ROOT == analysisResult)
-        {
-          analysisResult |= BIT_ANY_DESCENDANT_FROM_ROOT;
-        }
-
-        analysisResult |= BIT_DESCENDANT_OR_SELF;
-        break;
-      case OpCodes.FROM_FOLLOWING :
-        analysisResult |= BIT_FOLLOWING;
-        break;
-      case OpCodes.FROM_FOLLOWING_SIBLINGS :
-        analysisResult |= BIT_FOLLOWING_SIBLING;
-        break;
-      case OpCodes.FROM_PRECEDING :
-        analysisResult |= BIT_PRECEDING;
-        break;
-      case OpCodes.FROM_PRECEDING_SIBLINGS :
-        analysisResult |= BIT_PRECEDING_SIBLING;
-        break;
-      case OpCodes.FROM_PARENT :
-        analysisResult |= BIT_PARENT;
-        break;
-      case OpCodes.FROM_SELF :
-        analysisResult |= BIT_SELF;
-        break;
-      case OpCodes.MATCH_ATTRIBUTE :
-        analysisResult |= (BIT_MATCH_PATTERN | BIT_ATTRIBUTE);
-        break;
-      case OpCodes.MATCH_ANY_ANCESTOR :
-        analysisResult |= (BIT_MATCH_PATTERN | BIT_ANCESTOR);
-        break;
-      case OpCodes.MATCH_IMMEDIATE_ANCESTOR :
-        analysisResult |= (BIT_MATCH_PATTERN | BIT_PARENT);
-        break;
-      default :
-        throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
-                                   //+ stepType);
-      }
-
-      if (OpCodes.NODETYPE_NODE == ops[stepOpCodePos + 3])  // child::node()
-      {
-        analysisResult |= BIT_NODETEST_ANY;
-      }
-
-      stepOpCodePos = compiler.getNextStepPos(stepOpCodePos);
-
-      if (stepOpCodePos < 0)
-        break;
-    }
-
-    analysisResult |= (stepCount & BITS_COUNT);
-
-    return analysisResult;
-  }
-  
-  /**
    * Tell if the given axis goes downword.  Bogus name, if you can think of 
    * a better one, please do tell.  This really has to do with inverting 
    * attribute axis.
@@ -828,954 +144,14 @@
    */
   public static boolean isDownwardAxisOfMany(int axis)
   {
-    return ((Axis.DESCENDANTORSELF == axis) ||
-          (Axis.DESCENDANT == axis) 
-          || (Axis.FOLLOWING == axis) 
-//          || (Axis.FOLLOWINGSIBLING == axis) 
-          || (Axis.PRECEDING == axis) 
-//          || (Axis.PRECEDINGSIBLING == axis)
-          );
-  }
-
-  /**
-   * Read a <a href="http://www.w3.org/TR/xpath#location-paths">LocationPath</a>
-   * as a generalized match pattern.  What this means is that the LocationPath
-   * is read backwards, as a test on a given node, to see if it matches the
-   * criteria of the selection, and ends up at the context node.  Essentially,
-   * this is a backwards query from a given node, to find the context node.
-   * <p>So, the selection "foo/daz[2]" is, in non-abreviated expanded syntax,
-   * "self::node()/following-sibling::foo/child::daz[position()=2]".
-   * Taking this as a match pattern for a probable node, it works out to
-   * "self::daz/parent::foo[child::daz[position()=2 and isPrevStepNode()]
-   * precedingSibling::node()[isContextNodeOfLocationPath()]", adding magic
-   * isPrevStepNode and isContextNodeOfLocationPath operations.  Predicates in
-   * the location path have to be executed by the following step,
-   * because they have to know the context of their execution.
-   *
-   * @param mpi The MatchPatternIterator to which the steps will be attached.
-   * @param compiler The compiler that holds the syntax tree/op map to
-   * construct from.
-   * @param stepOpCodePos The current op code position within the opmap.
-   * @param stepIndex The top-level step index withing the iterator.
-   *
-   * @return A StepPattern object, which may contain relative StepPatterns.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  static StepPattern loadSteps(
-          MatchPatternIterator mpi, Compiler compiler, int stepOpCodePos, 
-                                                       int stepIndex)
-            throws javax.xml.transform.TransformerException
-  {
-    if (DEBUG_PATTERN_CREATION)
-    {
-      System.out.println("================");
-      System.out.println("loadSteps for: "+compiler.getPatternString());
-    }
-    int stepType;
-    StepPattern step = null;
-    StepPattern firstStep = null, prevStep = null;
-    int ops[] = compiler.getOpMap();
-    int analysis = analyze(compiler, stepOpCodePos, stepIndex);
-
-    while (OpCodes.ENDOP != (stepType = ops[stepOpCodePos]))
-    {
-      step = createDefaultStepPattern(compiler, stepOpCodePos, mpi, analysis,
-                                      firstStep, prevStep);
-
-      if (null == firstStep)
-      {
-        firstStep = step;
-      }
-      else
-      {
-
-        //prevStep.setNextWalker(step);
-        step.setRelativePathPattern(prevStep);
-      }
-
-      prevStep = step;
-      stepOpCodePos = compiler.getNextStepPos(stepOpCodePos);
-
-      if (stepOpCodePos < 0)
-        break;
-    }
-    
-    int axis = Axis.SELF;
-    int paxis = Axis.SELF;
-    StepPattern tail = step;
-    for (StepPattern pat = step; null != pat; 
-         pat = pat.getRelativePathPattern()) 
-    {
-      int nextAxis = pat.getAxis();
-      //int nextPaxis = pat.getPredicateAxis();
-      pat.setAxis(axis);
-      
-      // The predicate axis can't be moved!!!  Test Axes103
-      // pat.setPredicateAxis(paxis);
-      
-      // If we have an attribute or namespace axis that went up, then 
-      // it won't find the attribute in the inverse, since the select-to-match
-      // axes are not invertable (an element is a parent of an attribute, but 
-      // and attribute is not a child of an element).
-      // If we don't do the magic below, then "@*/ancestor-or-self::*" gets
-      // inverted for match to "self::*/descendant-or-self::@*/parent::node()",
-      // which obviously won't work.
-      // So we will rewrite this as:
-      // "self::*/descendant-or-self::*/attribute::*/parent::node()"
-      // Child has to be rewritten a little differently:
-      // select: "@*/parent::*"
-      // inverted match: "self::*/child::@*/parent::node()"
-      // rewrite: "self::*/attribute::*/parent::node()"
-      // Axes that go down in the select, do not have to have special treatment 
-      // in the rewrite. The following inverted match will still not select 
-      // anything.
-      // select: "@*/child::*"
-      // inverted match: "self::*/parent::@*/parent::node()"
-      // Lovely business, this.
-      // -sb
-      int whatToShow = pat.getWhatToShow();
-      if(whatToShow == DTMFilter.SHOW_ATTRIBUTE || 
-         whatToShow == DTMFilter.SHOW_NAMESPACE)
-      {
-        int newAxis = (whatToShow == DTMFilter.SHOW_ATTRIBUTE) ? 
-                       Axis.ATTRIBUTE : Axis.NAMESPACE;
-        if(isDownwardAxisOfMany(axis))
-        {
-          StepPattern attrPat = new StepPattern(whatToShow, 
-                                    pat.getNamespace(),
-                                    pat.getLocalName(),
-                                //newAxis, pat.getPredicateAxis);
-                                                newAxis, 0); // don't care about the predicate axis
-          XNumber score = pat.getStaticScore();
-          pat.setNamespace(null);
-          pat.setLocalName(NodeTest.WILD);
-          attrPat.setPredicates(pat.getPredicates());
-          pat.setPredicates(null);
-          pat.setWhatToShow(DTMFilter.SHOW_ELEMENT);
-          StepPattern rel = pat.getRelativePathPattern();
-          pat.setRelativePathPattern(attrPat);
-          attrPat.setRelativePathPattern(rel);
-          attrPat.setStaticScore(score);
-          
-          // This is needed to inverse a following pattern, because of the 
-          // wacky Xalan rules for following from an attribute.  See axes108.
-          // By these rules, following from an attribute is not strictly 
-          // inverseable.
-          if(Axis.PRECEDING == pat.getAxis())
-            pat.setAxis(Axis.PRECEDINGANDANCESTOR);
-            
-          else if(Axis.DESCENDANT == pat.getAxis())
-            pat.setAxis(Axis.DESCENDANTORSELF);
-          
-          pat = attrPat;
-        }
-        else if(Axis.CHILD == pat.getAxis())
-        {
-          // In this case just change the axis.
-          // pat.setWhatToShow(whatToShow);
-          pat.setAxis(Axis.ATTRIBUTE);
-        }
-      }
-      axis = nextAxis;
-      //paxis = nextPaxis;
-      tail = pat;
-    }
-    
-    if(axis < Axis.ALL)
-    {
-      StepPattern selfPattern = new ContextMatchStepPattern(axis, paxis);
-      // We need to keep the new nodetest from affecting the score...
-      XNumber score = tail.getStaticScore();
-      tail.setRelativePathPattern(selfPattern);
-      tail.setStaticScore(score);
-      selfPattern.setStaticScore(score);
-    }        
-
-    if (DEBUG_PATTERN_CREATION)
-    {
-      System.out.println("Done loading steps: "+step.toString());
-            
-      System.out.println("");
-    }
-    return step;  // start from last pattern?? //firstStep;
-  }
-
-  /**
-   * Create a StepPattern that is contained within a LocationPath.
-   *
-   *
-   * @param compiler The compiler that holds the syntax tree/op map to
-   * construct from.
-   * @param stepOpCodePos The current op code position within the opmap.
-   * @param mpi The MatchPatternIterator to which the steps will be attached.
-   * @param analysis 32 bits of analysis, from which the type of AxesWalker
-   *                 may be influenced.
-   * @param tail The step that is the first step analyzed, but the last 
-   *                  step in the relative match linked list, i.e. the tail.
-   *                  May be null.
-   * @param head The step that is the current head of the relative 
-   *                 match step linked list.
-   *                 May be null.
-   *
-   * @return the head of the list.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  private static StepPattern createDefaultStepPattern(
-          Compiler compiler, int opPos, MatchPatternIterator mpi, 
-          int analysis, StepPattern tail, StepPattern head)
-            throws javax.xml.transform.TransformerException
-  {
-
-    int stepType = compiler.getOp(opPos);
-    boolean simpleInit = false;
-    int totalNumberWalkers = (analysis & BITS_COUNT);
-    boolean prevIsOneStepDown = true;
-    int firstStepPos = compiler.getFirstChildPos(opPos);
-    
-    int whatToShow = compiler.getWhatToShow(opPos);
-    StepPattern ai = null;
-    int axis, predicateAxis;
-    
-    switch (stepType)
-    {
-    case OpCodes.OP_VARIABLE :
-    case OpCodes.OP_EXTFUNCTION :
-    case OpCodes.OP_FUNCTION :
-    case OpCodes.OP_GROUP :
-      prevIsOneStepDown = false;
-
-      Expression expr;
-
-      switch (stepType)
-      {
-      case OpCodes.OP_VARIABLE :
-      case OpCodes.OP_EXTFUNCTION :
-      case OpCodes.OP_FUNCTION :
-      case OpCodes.OP_GROUP :
-        expr = compiler.compile(opPos);
-        break;
-      default :
-        expr = compiler.compile(opPos + 2);
-      }
-
-      axis = Axis.FILTEREDLIST;
-      predicateAxis = Axis.FILTEREDLIST;
-      ai = new FunctionPattern(expr, axis, predicateAxis);
-      simpleInit = true;
-      break;
-    case OpCodes.FROM_ROOT :
-      whatToShow = DTMFilter.SHOW_DOCUMENT
-                   | DTMFilter.SHOW_DOCUMENT_FRAGMENT;
-
-      axis = Axis.ROOT;
-      predicateAxis = Axis.ROOT;
-      ai = new StepPattern(DTMFilter.SHOW_DOCUMENT | 
-                                DTMFilter.SHOW_DOCUMENT_FRAGMENT,
-                                axis, predicateAxis);
-      break;
-    case OpCodes.FROM_ATTRIBUTES :
-      whatToShow = DTMFilter.SHOW_ATTRIBUTE;
-      axis = Axis.PARENT;
-      predicateAxis = Axis.ATTRIBUTE;
-      // ai = new StepPattern(whatToShow, Axis.SELF, Axis.SELF);
-      break;
-    case OpCodes.FROM_NAMESPACE :
-      whatToShow = DTMFilter.SHOW_NAMESPACE;
-      axis = Axis.PARENT;
-      predicateAxis = Axis.NAMESPACE;
-      // ai = new StepPattern(whatToShow, axis, predicateAxis);
-      break;
-    case OpCodes.FROM_ANCESTORS :
-      axis = Axis.DESCENDANT;
-      predicateAxis = Axis.ANCESTOR;
-      break;
-    case OpCodes.FROM_CHILDREN :
-      axis = Axis.PARENT;
-      predicateAxis = Axis.CHILD;
-      break;
-    case OpCodes.FROM_ANCESTORS_OR_SELF :
-      axis = Axis.DESCENDANTORSELF;
-      predicateAxis = Axis.ANCESTORORSELF;
-      break;
-    case OpCodes.FROM_SELF :
-      axis = Axis.SELF;
-      predicateAxis = Axis.SELF;
-      break;
-    case OpCodes.FROM_PARENT :
-      axis = Axis.CHILD;
-      predicateAxis = Axis.PARENT;
-      break;
-    case OpCodes.FROM_PRECEDING_SIBLINGS :
-      axis = Axis.FOLLOWINGSIBLING;
-      predicateAxis = Axis.PRECEDINGSIBLING;
-      break;
-    case OpCodes.FROM_PRECEDING :
-      axis = Axis.FOLLOWING;
-      predicateAxis = Axis.PRECEDING;
-      break;
-    case OpCodes.FROM_FOLLOWING_SIBLINGS :
-      axis = Axis.PRECEDINGSIBLING;
-      predicateAxis = Axis.FOLLOWINGSIBLING;
-      break;
-    case OpCodes.FROM_FOLLOWING :
-      axis = Axis.PRECEDING;
-      predicateAxis = Axis.FOLLOWING;
-      break;
-    case OpCodes.FROM_DESCENDANTS_OR_SELF :
-      axis = Axis.ANCESTORORSELF;
-      predicateAxis = Axis.DESCENDANTORSELF;
-      break;
-    case OpCodes.FROM_DESCENDANTS :
-      axis = Axis.ANCESTOR;
-      predicateAxis = Axis.DESCENDANT;
-      break;
-    default :
-      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
-                                 //+ stepType);
-    }
-    if(null == ai)
-    {
-      whatToShow = compiler.getWhatToShow(opPos); // %REVIEW%
-      ai = new StepPattern(whatToShow, compiler.getStepNS(opPos),
-                                compiler.getStepLocalName(opPos),
-                                axis, predicateAxis);
-    }
-   
-    if (false || DEBUG_PATTERN_CREATION)
-    {
-      System.out.print("new step: "+ ai);
-      System.out.print(", axis: " + Axis.names[ai.getAxis()]);
-      System.out.print(", predAxis: " + Axis.names[ai.getAxis()]);
-      System.out.print(", what: ");
-      System.out.print("    ");
-      ai.debugWhatToShow(ai.getWhatToShow());
-    }
-
-    int argLen = compiler.getFirstPredicateOpPos(opPos);
-
-    ai.setPredicates(compiler.getCompiledPredicates(argLen));
-
-    return ai;
-  }
-
-  /**
-   * Analyze a step and give information about it's predicates.  Right now this
-   * just returns true or false if the step has a predicate.
-   *
-   * @param compiler non-null reference to compiler object that has processed
-   *                 the XPath operations into an opcode map.
-   * @param opPos The opcode position for the step.
-   * @param stepType The type of step, one of OP_GROUP, etc.
-   *
-   * @return true if step has a predicate.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  static boolean analyzePredicate(Compiler compiler, int opPos, int stepType)
-          throws javax.xml.transform.TransformerException
-  {
-
-    int argLen;
-
-    switch (stepType)
-    {
-    case OpCodes.OP_VARIABLE :
-    case OpCodes.OP_EXTFUNCTION :
-    case OpCodes.OP_FUNCTION :
-    case OpCodes.OP_GROUP :
-      argLen = compiler.getArgLength(opPos);
-      break;
-    default :
-      argLen = compiler.getArgLengthOfStep(opPos);
-    }
-
-    int pos = compiler.getFirstPredicateOpPos(opPos);
-    int nPredicates = compiler.countPredicates(pos);
-
-    return (nPredicates > 0) ? true : false;
-  }
-
-  /**
-   * Create the proper Walker from the axes type.
-   *
-   * @param compiler non-null reference to compiler object that has processed
-   *                 the XPath operations into an opcode map.
-   * @param opPos The opcode position for the step.
-   * @param lpi The owning location path iterator.
-   * @param analysis 32 bits of analysis, from which the type of AxesWalker
-   *                 may be influenced.
-   *
-   * @return non-null reference to AxesWalker derivative.
-   * @throws RuntimeException if the input is bad.
-   */
-  private static AxesWalker createDefaultWalker(Compiler compiler, int opPos,
-          WalkingIterator lpi, int analysis)
-  {
-
-    AxesWalker ai = null;
-    int stepType = compiler.getOp(opPos);
-
-    /*
-    System.out.println("0: "+compiler.getOp(opPos));
-    System.out.println("1: "+compiler.getOp(opPos+1));
-    System.out.println("2: "+compiler.getOp(opPos+2));
-    System.out.println("3: "+compiler.getOp(opPos+3));
-    System.out.println("4: "+compiler.getOp(opPos+4));
-    System.out.println("5: "+compiler.getOp(opPos+5));
-    */
-    boolean simpleInit = false;
-    int totalNumberWalkers = (analysis & BITS_COUNT);
-    boolean prevIsOneStepDown = true;
-
-    switch (stepType)
-    {
-    case OpCodes.OP_VARIABLE :
-    case OpCodes.OP_EXTFUNCTION :
-    case OpCodes.OP_FUNCTION :
-    case OpCodes.OP_GROUP :
-      prevIsOneStepDown = false;
-
-      if (DEBUG_WALKER_CREATION)
-        System.out.println("new walker:  FilterExprWalker: " + analysis
-                           + ", " + compiler.toString());
-
-      ai = new FilterExprWalker(lpi);
-      simpleInit = true;
-      break;
-    case OpCodes.FROM_ROOT :
-      ai = new AxesWalker(lpi, Axis.ROOT);
-      break;
-    case OpCodes.FROM_ANCESTORS :
-      prevIsOneStepDown = false;
-      ai = new ReverseAxesWalker(lpi, Axis.ANCESTOR);
-      break;
-    case OpCodes.FROM_ANCESTORS_OR_SELF :
-      prevIsOneStepDown = false;
-      ai = new ReverseAxesWalker(lpi, Axis.ANCESTORORSELF);
-      break;
-    case OpCodes.FROM_ATTRIBUTES :
-      ai = new AxesWalker(lpi, Axis.ATTRIBUTE);
-      break;
-    case OpCodes.FROM_NAMESPACE :
-      ai = new AxesWalker(lpi, Axis.NAMESPACE);
-      break;
-    case OpCodes.FROM_CHILDREN :
-      ai = new AxesWalker(lpi, Axis.CHILD);
-      break;
-    case OpCodes.FROM_DESCENDANTS :
-      prevIsOneStepDown = false;
-      ai = new AxesWalker(lpi, Axis.DESCENDANT);
-      break;
-    case OpCodes.FROM_DESCENDANTS_OR_SELF :
-      prevIsOneStepDown = false;
-      ai = new AxesWalker(lpi, Axis.DESCENDANTORSELF);
-      break;
-    case OpCodes.FROM_FOLLOWING :
-      prevIsOneStepDown = false;
-      ai = new AxesWalker(lpi, Axis.FOLLOWING);
-      break;
-    case OpCodes.FROM_FOLLOWING_SIBLINGS :
-      prevIsOneStepDown = false;
-      ai = new AxesWalker(lpi, Axis.FOLLOWINGSIBLING);
-      break;
-    case OpCodes.FROM_PRECEDING :
-      prevIsOneStepDown = false;
-      ai = new ReverseAxesWalker(lpi, Axis.PRECEDING);
-      break;
-    case OpCodes.FROM_PRECEDING_SIBLINGS :
-      prevIsOneStepDown = false;
-      ai = new ReverseAxesWalker(lpi, Axis.PRECEDINGSIBLING);
-      break;
-    case OpCodes.FROM_PARENT :
-      prevIsOneStepDown = false;
-      ai = new ReverseAxesWalker(lpi, Axis.PARENT);
-      break;
-    case OpCodes.FROM_SELF :
-      ai = new AxesWalker(lpi, Axis.SELF);
-      break;
-    default :
-      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
-                                 //+ stepType);
-    }
-
-    if (simpleInit)
-    {
-      ai.initNodeTest(DTMFilter.SHOW_ALL);
-    }
-    else
-    {
-      int whatToShow = compiler.getWhatToShow(opPos);
-
-      /*
-      System.out.print("construct: ");
-      NodeTest.debugWhatToShow(whatToShow);
-      System.out.println("or stuff: "+(whatToShow & (DTMFilter.SHOW_ATTRIBUTE
-                             | DTMFilter.SHOW_ELEMENT
-                             | DTMFilter.SHOW_PROCESSING_INSTRUCTION)));
-      */
-      if ((0 == (whatToShow
-                 & (DTMFilter.SHOW_ATTRIBUTE | DTMFilter.SHOW_NAMESPACE | DTMFilter.SHOW_ELEMENT
-                    | DTMFilter.SHOW_PROCESSING_INSTRUCTION))) || (whatToShow == DTMFilter.SHOW_ALL))
-        ai.initNodeTest(whatToShow);
-      else
-      {
-        ai.initNodeTest(whatToShow, compiler.getStepNS(opPos),
-                        compiler.getStepLocalName(opPos));
-      }
-    }
-
-    return ai;
-  }
-  
-  public static String getAnalysisString(int analysis)
-  {
-    StringBuffer buf = new StringBuffer();
-    buf.append("count: "+getStepCount(analysis)+" ");
-    if((analysis & BIT_NODETEST_ANY) != 0)
-    {
-      buf.append("NTANY|");
-    }
-    if((analysis & BIT_PREDICATE) != 0)
-    {
-      buf.append("PRED|");
-    }
-    if((analysis & BIT_ANCESTOR) != 0)
-    {
-      buf.append("ANC|");
-    }
-    if((analysis & BIT_ANCESTOR_OR_SELF) != 0)
-    {
-      buf.append("ANCOS|");
-    }
-    if((analysis & BIT_ATTRIBUTE) != 0)
-    {
-      buf.append("ATTR|");
-    }
-    if((analysis & BIT_CHILD) != 0)
-    {
-      buf.append("CH|");
-    }
-    if((analysis & BIT_DESCENDANT) != 0)
-    {
-      buf.append("DESC|");
-    }
-    if((analysis & BIT_DESCENDANT_OR_SELF) != 0)
-    {
-      buf.append("DESCOS|");
-    }
-    if((analysis & BIT_FOLLOWING) != 0)
-    {
-      buf.append("FOL|");
-    }
-    if((analysis & BIT_FOLLOWING_SIBLING) != 0)
-    {
-      buf.append("FOLS|");
-    }
-    if((analysis & BIT_NAMESPACE) != 0)
-    {
-      buf.append("NS|");
-    }
-    if((analysis & BIT_PARENT) != 0)
-    {
-      buf.append("P|");
-    }
-    if((analysis & BIT_PRECEDING) != 0)
-    {
-      buf.append("PREC|");
-    }
-    if((analysis & BIT_PRECEDING_SIBLING) != 0)
-    {
-      buf.append("PRECS|");
-    }
-    if((analysis & BIT_SELF) != 0)
-    {
-      buf.append(".|");
-    }
-    if((analysis & BIT_FILTER) != 0)
-    {
-      buf.append("FLT|");
-    }
-    if((analysis & BIT_ROOT) != 0)
-    {
-      buf.append("R|");
-    }
-    return buf.toString();
-  }
-
-  /** Set to true for diagnostics about walker creation */
-  static final boolean DEBUG_PATTERN_CREATION = false;
-
-  /** Set to true for diagnostics about walker creation */
-  static final boolean DEBUG_WALKER_CREATION = false;
-
-  /** Set to true for diagnostics about iterator creation */
-  static final boolean DEBUG_ITERATOR_CREATION = false;
-  
-  public static boolean hasPredicate(int analysis)
-  {
-    return (0 != (analysis & BIT_PREDICATE));
-  }
-
-  public static boolean isWild(int analysis)
-  {
-    return (0 != (analysis & BIT_NODETEST_ANY));
-  }
-
-  public static boolean walksAncestors(int analysis)
-  {
-    return isSet(analysis, BIT_ANCESTOR | BIT_ANCESTOR_OR_SELF);
-  }
-  
-  public static boolean walksAttributes(int analysis)
-  {
-    return (0 != (analysis & BIT_ATTRIBUTE));
-  }
-
-  public static boolean walksNamespaces(int analysis)
-  {
-    return (0 != (analysis & BIT_NAMESPACE));
-  }  
-
-  public static boolean walksChildren(int analysis)
-  {
-    return (0 != (analysis & BIT_CHILD));
-  }
-
-  public static boolean walksDescendants(int analysis)
-  {
-    return isSet(analysis, BIT_DESCENDANT | BIT_DESCENDANT_OR_SELF);
-  }
-
-  public static boolean walksSubtree(int analysis)
-  {
-    return isSet(analysis, BIT_DESCENDANT | BIT_DESCENDANT_OR_SELF | BIT_CHILD);
-  }
-  
-  public static boolean walksSubtreeOnlyMaybeAbsolute(int analysis)
-  {
-    return walksSubtree(analysis)
-           && !walksExtraNodes(analysis) 
-           && !walksUp(analysis) 
-           && !walksSideways(analysis) 
-           ;
-  }
-  
-  public static boolean walksSubtreeOnly(int analysis)
-  {
-    return walksSubtreeOnlyMaybeAbsolute(analysis) 
-           && !isAbsolute(analysis) 
-           ;
-  }
-
-  public static boolean walksFilteredList(int analysis)
-  {
-    return isSet(analysis, BIT_FILTER);
-  }
-  
-  public static boolean walksSubtreeOnlyFromRootOrContext(int analysis)
-  {
-    return walksSubtree(analysis)
-           && !walksExtraNodes(analysis) 
-           && !walksUp(analysis) 
-           && !walksSideways(analysis) 
-           && !isSet(analysis, BIT_FILTER) 
-           ;
-  }
-
-  public static boolean walksInDocOrder(int analysis)
-  {
-    return (walksSubtreeOnlyMaybeAbsolute(analysis)
-           || walksExtraNodesOnly(analysis)
-           || walksFollowingOnlyMaybeAbsolute(analysis)) 
-           && !isSet(analysis, BIT_FILTER) 
-           ;
-  }
-  
-  public static boolean walksFollowingOnlyMaybeAbsolute(int analysis)
-  {
-    return isSet(analysis, BIT_SELF | BIT_FOLLOWING_SIBLING | BIT_FOLLOWING)
-           && !walksSubtree(analysis) 
-           && !walksUp(analysis) 
-           && !walksSideways(analysis) 
-           ;
-  }
-  
-  public static boolean walksUp(int analysis)
-  {
-    return isSet(analysis, BIT_PARENT | BIT_ANCESTOR | BIT_ANCESTOR_OR_SELF);
-  }
-  
-  public static boolean walksSideways(int analysis)
-  {
-    return isSet(analysis, BIT_FOLLOWING | BIT_FOLLOWING_SIBLING | 
-                           BIT_PRECEDING | BIT_PRECEDING_SIBLING);
-  }
-  
-  public static boolean walksExtraNodes(int analysis)
-  {
-    return isSet(analysis, BIT_NAMESPACE | BIT_ATTRIBUTE);
-  }
-
-  public static boolean walksExtraNodesOnly(int analysis)
-  {
-    return walksExtraNodes(analysis)
-           && !isSet(analysis, BIT_SELF) 
-           && !walksSubtree(analysis) 
-           && !walksUp(analysis) 
-           && !walksSideways(analysis) 
-           && !isAbsolute(analysis) 
-           ;
-  }
-
-  public static boolean isAbsolute(int analysis)
-  {
-    return isSet(analysis, BIT_ROOT | BIT_FILTER);
-  }
-  
-  public static boolean walksChildrenOnly(int analysis)
-  {
-    return walksChildren(analysis)
-           && !isSet(analysis, BIT_SELF)
-           && !walksExtraNodes(analysis)
-           && !walksDescendants(analysis) 
-           && !walksUp(analysis) 
-           && !walksSideways(analysis) 
-           && (!isAbsolute(analysis) || isSet(analysis, BIT_ROOT))
-           ;
-  }
-  
-  public static boolean walksChildrenAndExtraAndSelfOnly(int analysis)
-  {
-    return walksChildren(analysis)
-           && !walksDescendants(analysis) 
-           && !walksUp(analysis) 
-           && !walksSideways(analysis) 
-           && (!isAbsolute(analysis) || isSet(analysis, BIT_ROOT))
-           ;
-  }
-  
-  public static boolean walksDescendantsAndExtraAndSelfOnly(int analysis)
-  {
-    return !walksChildren(analysis)
-           && walksDescendants(analysis) 
-           && !walksUp(analysis) 
-           && !walksSideways(analysis) 
-           && (!isAbsolute(analysis) || isSet(analysis, BIT_ROOT))
-           ;
-  }
-  
-  public static boolean walksSelfOnly(int analysis)
-  {
-    return isSet(analysis, BIT_SELF) 
-           && !walksSubtree(analysis) 
-           && !walksUp(analysis) 
-           && !walksSideways(analysis) 
-           && !isAbsolute(analysis) 
-           ;
-  }
-
-  
-  public static boolean walksUpOnly(int analysis)
-  {
-    return !walksSubtree(analysis) 
-           && walksUp(analysis) 
-           && !walksSideways(analysis) 
-           && !isAbsolute(analysis) 
-           ;
-  }
-  
-  public static boolean walksDownOnly(int analysis)
-  {
-    return walksSubtree(analysis) 
-           && !walksUp(analysis) 
-           && !walksSideways(analysis) 
-           && !isAbsolute(analysis) 
-           ;
-  }
-
-  public static boolean walksDownExtraOnly(int analysis)
-  {
-    return walksSubtree(analysis) &&  walksExtraNodes(analysis)
-           && !walksUp(analysis) 
-           && !walksSideways(analysis) 
-           && !isAbsolute(analysis) 
-           ;
-  }
-  
-  public static boolean canSkipSubtrees(int analysis)
-  {
-    return isSet(analysis, BIT_CHILD) | walksSideways(analysis);
-  }
-  
-  public static boolean canCrissCross(int analysis)
-  {
-    // This could be done faster.  Coded for clarity.
-    if(walksSelfOnly(analysis))
-      return false;
-    else if(walksDownOnly(analysis) && !canSkipSubtrees(analysis))
-      return false;
-    else if(walksChildrenAndExtraAndSelfOnly(analysis))
-      return false;
-    else if(walksDescendantsAndExtraAndSelfOnly(analysis))
-      return false;
-    else if(walksUpOnly(analysis))
-      return false;
-    else if(walksExtraNodesOnly(analysis))
-      return false;
-    else if(walksSubtree(analysis) 
-           && (walksSideways(analysis) 
-            || walksUp(analysis) 
-            || canSkipSubtrees(analysis)))
-      return true;
-    else
-      return false;
-  }
-  
-  /**
-   * Tell if the pattern can be 'walked' with the iteration steps in natural 
-   * document order, without duplicates.
-   *
-   * @param analysis The general analysis of the pattern.
-   *
-   * @return true if the walk can be done in natural order.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  static public boolean isNaturalDocOrder(int analysis)
-  {
-    if(canCrissCross(analysis) || isSet(analysis, BIT_NAMESPACE) ||
-       walksFilteredList(analysis))
-      return false;
-      
-    if(walksInDocOrder(analysis))
-      return true;
-      
-    return false;
-  }
-  
-  /**
-   * Tell if the pattern can be 'walked' with the iteration steps in natural 
-   * document order, without duplicates.
-   *
-   * @param compiler non-null reference to compiler object that has processed
-   *                 the XPath operations into an opcode map.
-   * @param stepOpCodePos The opcode position for the step.
-   * @param stepIndex The top-level step index withing the iterator.
-   * @param analysis The general analysis of the pattern.
-   *
-   * @return true if the walk can be done in natural order.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  private static boolean isNaturalDocOrder(
-          Compiler compiler, int stepOpCodePos, int stepIndex, int analysis)
-            throws javax.xml.transform.TransformerException
-  {
-    if(canCrissCross(analysis))
-      return false;
-      
-    // Namespaces can present some problems, so just punt if we're looking for 
-    // these.
-    if(isSet(analysis, BIT_NAMESPACE))
-      return false;
-      
-    // The following, preceding, following-sibling, and preceding sibling can 
-    // be found in doc order if we get to this point, but if they occur 
-    // together, they produce 
-    // duplicates, so it's better for us to eliminate this case so we don't 
-    // have to check for duplicates during runtime if we're using a 
-    // WalkingIterator.
-    if(isSet(analysis, BIT_FOLLOWING | BIT_FOLLOWING_SIBLING) && 
-       isSet(analysis, BIT_PRECEDING | BIT_PRECEDING_SIBLING))
-      return  false;
-      
-    // OK, now we have to check for select="@*/axis::*" patterns, which 
-    // can also cause duplicates to happen.  But select="axis*/@::*" patterns 
-    // are OK, as are select="@foo/axis::*" patterns.
-    // Unfortunately, we can't do this just via the analysis bits.
-    
-    int stepType;
-    int ops[] = compiler.getOpMap();
-    int stepCount = 0;
-    boolean foundWildAttribute = false;
-    
-    // Steps that can traverse anything other than down a 
-    // subtree or that can produce duplicates when used in 
-    // combonation are counted with this variable.
-    int potentialDuplicateMakingStepCount = 0;
-    
-    while (OpCodes.ENDOP != (stepType = ops[stepOpCodePos]))
-    {        
-      stepCount++;
-        
-      switch (stepType)
-      {
-      case OpCodes.FROM_ATTRIBUTES :
-      case OpCodes.MATCH_ATTRIBUTE :
-        if(foundWildAttribute) // Maybe not needed, but be safe.
-          return false;
-        
-        // This doesn't seem to work as a test for wild card.  Hmph.
-        // int nodeTestType = compiler.getStepTestType(stepOpCodePos);  
-        
-        String localName = compiler.getStepLocalName(stepOpCodePos);
-        // System.err.println("localName: "+localName);
-        if(localName.equals("*"))
-        {
-          foundWildAttribute = true;
-        }
-        break;
-      case OpCodes.FROM_FOLLOWING :
-      case OpCodes.FROM_FOLLOWING_SIBLINGS :
-      case OpCodes.FROM_PRECEDING :
-      case OpCodes.FROM_PRECEDING_SIBLINGS :
-      case OpCodes.FROM_PARENT :
-      case OpCodes.OP_VARIABLE :
-      case OpCodes.OP_EXTFUNCTION :
-      case OpCodes.OP_FUNCTION :
-      case OpCodes.OP_GROUP :
-      case OpCodes.FROM_NAMESPACE :
-      case OpCodes.FROM_ANCESTORS :
-      case OpCodes.FROM_ANCESTORS_OR_SELF :      
-      case OpCodes.MATCH_ANY_ANCESTOR :
-      case OpCodes.MATCH_IMMEDIATE_ANCESTOR :
-      case OpCodes.FROM_DESCENDANTS_OR_SELF :
-      case OpCodes.FROM_DESCENDANTS :
-        if(potentialDuplicateMakingStepCount > 0)
-            return false;
-        potentialDuplicateMakingStepCount++;
-      case OpCodes.FROM_ROOT :
-      case OpCodes.FROM_CHILDREN :
-      case OpCodes.FROM_SELF :
-        if(foundWildAttribute)
-          return false;
-        break;
-      default :
-        throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
-                                  // + stepType);
-      }
-
-      int nextStepOpCodePos = compiler.getNextStepPos(stepOpCodePos);
-
-      if (nextStepOpCodePos < 0)
-        break;
-              
-      stepOpCodePos = nextStepOpCodePos;
-    }
-
-    return true;
-  }
-  
-  public static boolean isOneStep(int analysis)
-  {
-    return (analysis & BITS_COUNT) == 0x00000001;
-  }
-
-  public static int getStepCount(int analysis)
-  {
-    return (analysis & BITS_COUNT);
+    return (
+      (Axis.DESCENDANTORSELF == axis)
+      || (Axis.DESCENDANT == axis)
+      || (Axis.FOLLOWING == axis)
+    //          || (Axis.FOLLOWINGSIBLING == axis) 
+    || (Axis.PRECEDING == axis)
+    //          || (Axis.PRECEDINGSIBLING == axis)
+    );
   }
 
   /**
@@ -1842,16 +218,14 @@
    * If any of these bits are on, the expression may likely traverse outside
    *  the given subtree.
    */
-  public static final int BITMASK_TRAVERSES_OUTSIDE_SUBTREE = (BIT_NAMESPACE  // ??
-                                                                | BIT_PRECEDING_SIBLING
-                                                                | BIT_PRECEDING
-                                                                | BIT_FOLLOWING_SIBLING
-                                                                | BIT_FOLLOWING
-                                                                | BIT_PARENT  // except parent of attrs.
-                                                                | BIT_ANCESTOR_OR_SELF
-                                                                | BIT_ANCESTOR
-                                                                | BIT_FILTER
-                                                                | BIT_ROOT);
+    public static final int BITMASK_TRAVERSES_OUTSIDE_SUBTREE =
+      (BIT_NAMESPACE // ??
+    | BIT_PRECEDING_SIBLING
+    | BIT_PRECEDING
+    | BIT_FOLLOWING_SIBLING
+    | BIT_FOLLOWING
+    | BIT_PARENT // except parent of attrs.
+  | BIT_ANCESTOR_OR_SELF | BIT_ANCESTOR | BIT_FILTER | BIT_ROOT);
 
   /**
    * Bit is on if any of the walkers can go backwards in document
@@ -1872,4 +246,3042 @@
 
   /** Bit is on if the expression is a match pattern. */
   public static final int BIT_MATCH_PATTERN = (0x00001000 << 19);
+
+  /**
+   * Analyze a step and give information about it's predicates.  Right now this
+   * just returns true or false if the step has a predicate.
+   *
+   * @param compiler non-null reference to compiler object that has processed
+   *                 the XPath operations into an opcode map.
+   * @param opPos The opcode position for the step.
+   * @param stepType The type of step, one of OP_GROUP, etc.
+   *
+   * @return true if step has a predicate.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  static boolean analyzePredicate(StepExpr stepExpr)
+    throws javax.xml.transform.TransformerException
+  {
+
+    int childCount = stepExpr.jjtGetNumChildren();
+    Node lastChild = stepExpr.jjtGetChild(childCount - 1);
+    if (lastChild instanceof Predicates)
+    {
+      if (lastChild.jjtGetNumChildren() > 0)
+      {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  /**
+   * Analyze the location path and return 32 bits that give information about
+   * the location path as a whole.  See the BIT_XXX constants for meaning about
+   * each of the bits.
+   *
+   * @param compiler non-null reference to compiler object that has processed
+   *                 the XPath operations into an opcode map.
+   * @param stepOpCodePos The opcode position for the step.
+   * @param stepIndex The top-level step index withing the iterator.
+   *
+   * @return 32 bits as an integer that give information about the location
+   * path as a whole.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  private static int analyze(PathExpr pathExpr, int stepIndex)
+    throws javax.xml.transform.TransformerException
+  {
+    int numSteps = pathExpr.jjtGetNumChildren();
+    int analysisResult = 0x00000000; // 32 bits of analysis
+
+    for (int i = stepIndex; i < numSteps; i++)
+    {
+      StepExpr stepExpr = (StepExpr) pathExpr.jjtGetChild(i);
+
+      boolean predAnalysis = analyzePredicate(stepExpr);
+
+      if (predAnalysis)
+        analysisResult |= BIT_PREDICATE;
+
+      Node firstChild = stepExpr.jjtGetChild(0);
+      if (firstChild instanceof PatternAxis)
+      {
+        int axis = ((PatternAxis) firstChild).getAxis();
+        switch (axis)
+        {
+          case Axis.ROOT :
+            analysisResult |= BIT_ROOT;
+            break;
+          case Axis.DESCENDANTSORSELFFROMROOT :
+          case Axis.DESCENDANTSFROMROOT :
+            analysisResult |= (BIT_ROOT | BIT_ANY_DESCENDANT_FROM_ROOT);
+            break;
+          case Axis.ANCESTOR :
+            analysisResult |= BIT_ANCESTOR;
+            break;
+          case Axis.ANCESTORORSELF :
+            analysisResult |= BIT_ANCESTOR_OR_SELF;
+            break;
+          case Axis.ATTRIBUTE :
+            analysisResult |= BIT_ATTRIBUTE;
+            break;
+          case Axis.NAMESPACE :
+            analysisResult |= BIT_NAMESPACE;
+            break;
+          case Axis.CHILD :
+            analysisResult |= BIT_CHILD;
+            break;
+          case Axis.DESCENDANT :
+            analysisResult |= BIT_DESCENDANT;
+            break;
+          case Axis.DESCENDANTORSELF :
+            analysisResult |= BIT_DESCENDANT_OR_SELF;
+            break;
+          case Axis.FOLLOWING :
+            analysisResult |= BIT_FOLLOWING;
+            break;
+          case Axis.FOLLOWINGSIBLING :
+            analysisResult |= BIT_FOLLOWING_SIBLING;
+            break;
+          case Axis.PRECEDING :
+            analysisResult |= BIT_PRECEDING;
+            break;
+          case Axis.PRECEDINGSIBLING :
+            analysisResult |= BIT_PRECEDING_SIBLING;
+            break;
+          case Axis.PARENT :
+            analysisResult |= BIT_PARENT;
+            break;
+          case Axis.SELF :
+            analysisResult |= BIT_SELF;
+            break;
+          default :
+            // TBD: Change the wording of this expression.
+            throw new RuntimeException(
+              XSLMessages.createXPATHMessage(
+                XPATHErrorResources.ER_NULL_ERROR_HANDLER,
+                new Object[] { firstChild.getClass().getName()}));
+            //"Programmer's assertion: unknown opcode: "
+            //+ stepType);
+        }
+        Node secondChild = stepExpr.jjtGetChild(1);
+        if (secondChild instanceof org.apache.xpath.parser.NodeTest)
+        {
+          org.apache.xpath.parser.NodeTest nt =
+            (org.apache.xpath.parser.NodeTest) secondChild;
+          if (nt.getWhatToShow() == org.apache.xml.dtm.DTMFilter.SHOW_ALL)
+          {
+            analysisResult |= BIT_NODETEST_ANY;
+          }
+        }
+
+      }
+      else
+      {
+        analysisResult |= BIT_FILTER;
+      }
+
+    }
+
+    analysisResult |= (numSteps & BITS_COUNT);
+
+    return analysisResult;
+  }
+
+  /**
+   * Create a new LocPathIterator iterator.  The exact type of iterator
+   * returned is based on an analysis of the XPath operations.
+   *
+   * @param compiler non-null reference to compiler object that has processed
+   *                 the XPath operations into an opcode map.
+   * @param opPos The position of the operation code for this itterator.
+   *
+   * @return non-null reference to a LocPathIterator or derivative.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public static DTMIterator newDTMIterator(
+    PathExpr pathExpr,
+    boolean isTopLevel)
+    throws javax.xml.transform.TransformerException
+  {
+
+    int analysis = analyze(pathExpr, 0);
+    boolean isOneStep = isOneStep(analysis);
+    DTMIterator iter = getPossibleUnion(pathExpr, isTopLevel, isOneStep);
+    
+    if(null != iter)
+      return iter;
+    
+    // Is the iteration a one-step attribute pattern (i.e. select="@foo")?
+    if (isOneStep
+      && walksSelfOnly(analysis)
+      && isWild(analysis)
+      && !hasPredicate(analysis))
+    {
+      if (DEBUG_ITERATOR_CREATION)
+        diagnoseIterator("SelfIteratorNoPredicate", analysis, pathExpr);
+
+      // Then use a simple iteration of the attributes, with node test 
+      // and predicate testing.
+      iter = new SelfIteratorNoPredicate();
+    }
+    // Is the iteration exactly one child step?
+    else
+      if (walksChildrenOnly(analysis) && isOneStep)
+      {
+
+        // Does the pattern specify *any* child with no predicate? (i.e. select="child::node()".
+        if (isWild(analysis) && !hasPredicate(analysis))
+        {
+          if (DEBUG_ITERATOR_CREATION)
+            diagnoseIterator("ChildIterator", analysis, pathExpr);
+
+          // Use simple child iteration without any test.
+          StepExpr stepExpr = (StepExpr) pathExpr.jjtGetChild(0);
+          iter = new ChildIterator(stepExpr, analysis);
+        }
+        else
+        {
+          if (DEBUG_ITERATOR_CREATION)
+            diagnoseIterator("ChildTestIterator", analysis, pathExpr);
+
+          // Else use simple node test iteration with predicate test.
+          StepExpr stepExpr = (StepExpr) pathExpr.jjtGetChild(0);
+          iter = new ChildTestIterator(stepExpr, analysis);
+        }
+      }
+    // Is the iteration a one-step attribute pattern (i.e. select="@foo")?
+    else
+      if (isOneStep && walksAttributes(analysis))
+      {
+        if (DEBUG_ITERATOR_CREATION)
+          diagnoseIterator("AttributeIterator", analysis, pathExpr);
+
+        // Then use a simple iteration of the attributes, with node test 
+        // and predicate testing.
+        StepExpr stepExpr = (StepExpr) pathExpr.jjtGetChild(0);
+        iter = new AttributeIterator(stepExpr, analysis);
+      }
+      else
+        if (isOneStep && !walksFilteredList(analysis))
+        {
+          StepExpr stepExpr = (StepExpr) pathExpr.jjtGetChild(0);
+          if (!walksNamespaces(analysis)
+            && (walksInDocOrder(analysis) || isSet(analysis, BIT_PARENT)))
+          {
+            if (false || DEBUG_ITERATOR_CREATION)
+              diagnoseIterator("OneStepIteratorForward", analysis, pathExpr);
+
+            // Then use a simple iteration of the attributes, with node test 
+            // and predicate testing.
+            iter = new OneStepIteratorForward(stepExpr, analysis);
+          }
+          else
+          {
+            if (false || DEBUG_ITERATOR_CREATION)
+              diagnoseIterator("OneStepIterator", analysis, pathExpr);
+
+            // Then use a simple iteration of the attributes, with node test 
+            // and predicate testing.
+            iter = new OneStepIterator(stepExpr, analysis);
+          }
+        }
+
+    // Analysis of "//center":
+    // bits: 1001000000001010000000000000011
+    // count: 3
+    // root
+    // child:node()
+    // BIT_DESCENDANT_OR_SELF
+    // It's highly possible that we should have a seperate bit set for 
+    // "//foo" patterns.
+    // For at least the time being, we can't optimize patterns like 
+    // "//table[3]", because this has to be analyzed as 
+    // "/descendant-or-self::node()/table[3]" in order for the indexes 
+    // to work right.
+    else
+      if (isOptimizableForDescendantIterator(pathExpr,
+        0) // && getStepCount(analysis) <= 3 
+      // && walksDescendants(analysis) 
+      // && walksSubtreeOnlyFromRootOrContext(analysis)
+      )
+      {
+        if (DEBUG_ITERATOR_CREATION)
+          diagnoseIterator("DescendantIterator", analysis, pathExpr);
+        StepExpr stepExpr;
+        if (pathExpr.jjtGetNumChildren() == 2)
+        {
+          stepExpr = (StepExpr) pathExpr.jjtGetChild(1);
+          PatternAxis axisExpr = stepExpr.getAxisExpr();
+          axisExpr.setAxis(org.apache.xml.dtm.Axis.DESCENDANTSFROMROOT);
+        }
+        else
+          stepExpr = (StepExpr) pathExpr.jjtGetChild(0);
+        iter = new DescendantIterator(stepExpr);
+      }
+      else
+      {
+        if (isNaturalDocOrder(pathExpr, 0, analysis))
+        {
+          if (false || DEBUG_ITERATOR_CREATION)
+          {
+            diagnoseIterator("WalkingIterator", analysis, pathExpr);
+          }
+
+          iter =
+            new WalkingIterator(
+              pathExpr.getParser().getPrefixResolver(),
+              pathExpr);
+        }
+        else
+        {
+          //        if (DEBUG_ITERATOR_CREATION)
+          //          diagnoseIterator("MatchPatternIterator", analysis, compiler);
+          //
+          //        return new MatchPatternIterator(compiler, opPos, analysis);
+          if (DEBUG_ITERATOR_CREATION)
+            diagnoseIterator("WalkingIteratorSorted", analysis, pathExpr);
+
+          iter =
+            new WalkingIteratorSorted(
+              pathExpr.getParser().getPrefixResolver(),
+              pathExpr);
+        }
+      }
+    if (iter instanceof LocPathIterator)
+       ((LocPathIterator) iter).setIsTopLevel(isTopLevel);
+
+    return iter;
+  }
+
+  /**
+   * Check to see if we have a UnionPathIterator contained by a 
+   * StepExpr and possibly a predicate, contained in a PathExpr.
+   * If this is the case, we just want the UnionPathIterator and 
+   * any predicates it may have.
+   * It's likely that this reduction should be done somewhere else.
+   * 
+   * @param pathExpr The path construction node that holds the subtree.
+   * @param isTopLevel True if this expression is at the top-level.
+   * @param isOneStep True if this expression only has one step.
+   * @return DTMIterator The reduced union iterator, or null if not a union.
+   * @throws TransformerException
+   */
+  private static DTMIterator getPossibleUnion(
+    PathExpr pathExpr,
+    boolean isTopLevel,
+    boolean isOneStep)
+    throws TransformerException
+  {
+    Node n;
+    if(isOneStep && 
+      (n = pathExpr.jjtGetChild(0).jjtGetChild(0)) instanceof UnionPathIterator)
+    {
+      UnionPathIterator upi = (UnionPathIterator)n;
+      StepExpr se = (StepExpr)pathExpr.jjtGetChild(0);
+      
+      upi.initPredicateInfo(se);
+      upi.setWhatToShow(DTMFilter.SHOW_ALL);
+        
+      upi.setIsTopLevel(isTopLevel);
+      return upi;
+    }
+    else
+      return null;
+  }
+
+  public static void diagnoseIterator(
+    String name,
+    int analysis,
+    PathExpr pathExpr)
+  {
+    System.out.println(
+      pathExpr.toString()
+        + ", "
+        + name
+        + ", "
+        + Integer.toBinaryString(analysis)
+        + ", "
+        + getAnalysisString(analysis));
+  }
+
+  public static String getAnalysisString(int analysis)
+  {
+    StringBuffer buf = new StringBuffer();
+    buf.append("count: " + getStepCount(analysis) + " ");
+    if ((analysis & BIT_NODETEST_ANY) != 0)
+    {
+      buf.append("NTANY|");
+    }
+    if ((analysis & BIT_PREDICATE) != 0)
+    {
+      buf.append("PRED|");
+    }
+    if ((analysis & BIT_ANCESTOR) != 0)
+    {
+      buf.append("ANC|");
+    }
+    if ((analysis & BIT_ANCESTOR_OR_SELF) != 0)
+    {
+      buf.append("ANCOS|");
+    }
+    if ((analysis & BIT_ATTRIBUTE) != 0)
+    {
+      buf.append("ATTR|");
+    }
+    if ((analysis & BIT_CHILD) != 0)
+    {
+      buf.append("CH|");
+    }
+    if ((analysis & BIT_DESCENDANT) != 0)
+    {
+      buf.append("DESC|");
+    }
+    if ((analysis & BIT_DESCENDANT_OR_SELF) != 0)
+    {
+      buf.append("DESCOS|");
+    }
+    if ((analysis & BIT_FOLLOWING) != 0)
+    {
+      buf.append("FOL|");
+    }
+    if ((analysis & BIT_FOLLOWING_SIBLING) != 0)
+    {
+      buf.append("FOLS|");
+    }
+    if ((analysis & BIT_NAMESPACE) != 0)
+    {
+      buf.append("NS|");
+    }
+    if ((analysis & BIT_PARENT) != 0)
+    {
+      buf.append("P|");
+    }
+    if ((analysis & BIT_PRECEDING) != 0)
+    {
+      buf.append("PREC|");
+    }
+    if ((analysis & BIT_PRECEDING_SIBLING) != 0)
+    {
+      buf.append("PRECS|");
+    }
+    if ((analysis & BIT_SELF) != 0)
+    {
+      buf.append(".|");
+    }
+    if ((analysis & BIT_FILTER) != 0)
+    {
+      buf.append("FLT|");
+    }
+    if ((analysis & BIT_ROOT) != 0)
+    {
+      buf.append("R|");
+    }
+    return buf.toString();
+  }
+
+  /** Set to true for diagnostics about walker creation */
+  static final boolean DEBUG_PATTERN_CREATION = false;
+
+  /** Set to true for diagnostics about walker creation */
+  static final boolean DEBUG_WALKER_CREATION = false;
+
+  /** Set to true for diagnostics about iterator creation */
+  static final boolean DEBUG_ITERATOR_CREATION = false;
+
+  public static boolean hasPredicate(int analysis)
+  {
+    return (0 != (analysis & BIT_PREDICATE));
+  }
+
+  public static boolean isWild(int analysis)
+  {
+    return (0 != (analysis & BIT_NODETEST_ANY));
+  }
+
+  public static boolean walksAncestors(int analysis)
+  {
+    return isSet(analysis, BIT_ANCESTOR | BIT_ANCESTOR_OR_SELF);
+  }
+
+  public static boolean walksAttributes(int analysis)
+  {
+    return (0 != (analysis & BIT_ATTRIBUTE));
+  }
+
+  public static boolean walksNamespaces(int analysis)
+  {
+    return (0 != (analysis & BIT_NAMESPACE));
+  }
+
+  public static boolean walksChildren(int analysis)
+  {
+    return (0 != (analysis & BIT_CHILD));
+  }
+
+  public static boolean walksDescendants(int analysis)
+  {
+    return isSet(analysis, BIT_DESCENDANT | BIT_DESCENDANT_OR_SELF | BIT_ANY_DESCENDANT_FROM_ROOT);
+  }
+
+  public static boolean walksSubtree(int analysis)
+  {
+    return isSet(analysis, BIT_DESCENDANT | BIT_DESCENDANT_OR_SELF | BIT_CHILD);
+  }
+
+  public static boolean walksSubtreeOnlyMaybeAbsolute(int analysis)
+  {
+    return walksSubtree(analysis)
+      && !walksExtraNodes(analysis)
+      && !walksUp(analysis)
+      && !walksSideways(analysis);
+  }
+
+  public static boolean walksSubtreeOnly(int analysis)
+  {
+    return walksSubtreeOnlyMaybeAbsolute(analysis) && !isAbsolute(analysis);
+  }
+
+  public static boolean walksFilteredList(int analysis)
+  {
+    return isSet(analysis, BIT_FILTER);
+  }
+
+  public static boolean walksSubtreeOnlyFromRootOrContext(int analysis)
+  {
+    return walksSubtree(analysis)
+      && !walksExtraNodes(analysis)
+      && !walksUp(analysis)
+      && !walksSideways(analysis)
+      && !isSet(analysis, BIT_FILTER);
+  }
+
+  public static boolean walksInDocOrder(int analysis)
+  {
+    return (
+      walksSubtreeOnlyMaybeAbsolute(analysis)
+        || walksExtraNodesOnly(analysis)
+        || walksFollowingOnlyMaybeAbsolute(analysis))
+      && !isSet(analysis, BIT_FILTER);
+  }
+
+  public static boolean walksFollowingOnlyMaybeAbsolute(int analysis)
+  {
+    return isSet(analysis, BIT_SELF | BIT_FOLLOWING_SIBLING | BIT_FOLLOWING)
+      && !walksSubtree(analysis)
+      && !walksUp(analysis)
+      && !walksSideways(analysis);
+  }
+
+  public static boolean walksUp(int analysis)
+  {
+    return isSet(analysis, BIT_PARENT | BIT_ANCESTOR | BIT_ANCESTOR_OR_SELF);
+  }
+
+  public static boolean walksSideways(int analysis)
+  {
+    return isSet(
+      analysis,
+      BIT_FOLLOWING
+        | BIT_FOLLOWING_SIBLING
+        | BIT_PRECEDING
+        | BIT_PRECEDING_SIBLING);
+  }
+
+  public static boolean walksExtraNodes(int analysis)
+  {
+    return isSet(analysis, BIT_NAMESPACE | BIT_ATTRIBUTE);
+  }
+
+  public static boolean walksExtraNodesOnly(int analysis)
+  {
+    return walksExtraNodes(analysis)
+      && !isSet(analysis, BIT_SELF)
+      && !walksSubtree(analysis)
+      && !walksUp(analysis)
+      && !walksSideways(analysis)
+      && !isAbsolute(analysis);
+  }
+
+  public static boolean isAbsolute(int analysis)
+  {
+    return isSet(analysis, BIT_ROOT | BIT_FILTER);
+  }
+
+  public static boolean walksChildrenOnly(int analysis)
+  {
+    return walksChildren(analysis)
+      && !isSet(analysis, BIT_SELF)
+      && !walksExtraNodes(analysis)
+      && !walksDescendants(analysis)
+      && !walksUp(analysis)
+      && !walksSideways(analysis)
+      && (!isAbsolute(analysis) || isSet(analysis, BIT_ROOT));
+  }
+
+  public static boolean walksChildrenAndExtraAndSelfOnly(int analysis)
+  {
+    return walksChildren(analysis)
+      && !walksDescendants(analysis)
+      && !walksUp(analysis)
+      && !walksSideways(analysis)
+      && (!isAbsolute(analysis) || isSet(analysis, BIT_ROOT));
+  }
+
+  public static boolean walksDescendantsAndExtraAndSelfOnly(int analysis)
+  {
+    return !walksChildren(analysis)
+      && walksDescendants(analysis)
+      && !walksUp(analysis)
+      && !walksSideways(analysis)
+      && (!isAbsolute(analysis) || isSet(analysis, BIT_ROOT));
+  }
+
+  public static boolean walksSelfOnly(int analysis)
+  {
+    return isSet(analysis, BIT_SELF)
+      && !walksSubtree(analysis)
+      && !walksUp(analysis)
+      && !walksSideways(analysis)
+      && !isAbsolute(analysis);
+  }
+
+  public static boolean walksUpOnly(int analysis)
+  {
+    return !walksSubtree(analysis)
+      && walksUp(analysis)
+      && !walksSideways(analysis)
+      && !isAbsolute(analysis);
+  }
+
+  public static boolean walksDownOnly(int analysis)
+  {
+    return walksSubtree(analysis)
+      && !walksUp(analysis)
+      && !walksSideways(analysis)
+      && !isAbsolute(analysis);
+  }
+
+  public static boolean walksDownExtraOnly(int analysis)
+  {
+    return walksSubtree(analysis)
+      && walksExtraNodes(analysis)
+      && !walksUp(analysis)
+      && !walksSideways(analysis)
+      && !isAbsolute(analysis);
+  }
+
+  public static boolean canSkipSubtrees(int analysis)
+  {
+    return isSet(analysis, BIT_CHILD) | walksSideways(analysis);
+  }
+
+  public static boolean canCrissCross(int analysis)
+  {
+    // This could be done faster.  Coded for clarity.
+    if (walksSelfOnly(analysis))
+      return false;
+    else
+      if (walksDownOnly(analysis) && !canSkipSubtrees(analysis))
+        return false;
+      else
+        if (walksChildrenAndExtraAndSelfOnly(analysis))
+          return false;
+        else
+          if (walksDescendantsAndExtraAndSelfOnly(analysis))
+            return false;
+          else
+            if (walksUpOnly(analysis))
+              return false;
+            else
+              if (walksExtraNodesOnly(analysis))
+                return false;
+              else
+                if (walksSubtree(analysis)
+                  && (walksSideways(analysis)
+                    || walksUp(analysis)
+                    || canSkipSubtrees(analysis)))
+                  return true;
+                else
+                  return false;
+  }
+
+  /**
+   * Tell if the pattern can be 'walked' with the iteration steps in natural 
+   * document order, without duplicates.
+   *
+   * @param analysis The general analysis of the pattern.
+   *
+   * @return true if the walk can be done in natural order.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  static public boolean isNaturalDocOrder(int analysis)
+  {
+    if (canCrissCross(analysis)
+      || isSet(analysis, BIT_NAMESPACE)
+      || walksFilteredList(analysis))
+      return false;
+
+    if (walksInDocOrder(analysis))
+      return true;
+
+    return false;
+  }
+
+  public static boolean isOneStep(int analysis)
+  {
+    return (analysis & BITS_COUNT) == 0x00000001;
+  }
+
+  public static int getStepCount(int analysis)
+  {
+    return (analysis & BITS_COUNT);
+  }
+
+  /**
+   * Tell if the pattern can be 'walked' with the iteration steps in natural 
+   * document order, without duplicates.
+   *
+   * @param pathExpr Root of the path expression being analyzed.
+   * @param stepIndex The top-level step index withing the iterator.
+   * @param analysis The general analysis of the pattern.
+   *
+   * @return true if the walk can be done in natural order.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  private static boolean isNaturalDocOrder(
+    PathExpr pathExpr,
+    int stepIndex,
+    int analysis)
+    throws javax.xml.transform.TransformerException
+  {
+    if (canCrissCross(analysis))
+      return false;
+
+    // Namespaces can present some problems, so just punt if we're looking for 
+    // these.
+    if (isSet(analysis, BIT_NAMESPACE))
+      return false;
+
+    // The following, preceding, following-sibling, and preceding sibling can 
+    // be found in doc order if we get to this point, but if they occur 
+    // together, they produce 
+    // duplicates, so it's better for us to eliminate this case so we don't 
+    // have to check for duplicates during runtime if we're using a 
+    // WalkingIterator.
+    if (isSet(analysis, BIT_FOLLOWING | BIT_FOLLOWING_SIBLING)
+      && isSet(analysis, BIT_PRECEDING | BIT_PRECEDING_SIBLING))
+      return false;
+
+    // OK, now we have to check for select="@*/axis::*" patterns, which 
+    // can also cause duplicates to happen.  But select="axis*/@::*" patterns 
+    // are OK, as are select="@foo/axis::*" patterns.
+    // Unfortunately, we can't do this just via the analysis bits.
+
+    int stepType;
+    boolean foundWildAttribute = false;
+
+    // Steps that can traverse anything other than down a 
+    // subtree or that can produce duplicates when used in 
+    // combonation are counted with this variable.
+    int potentialDuplicateMakingStepCount = 0;
+
+    int numSteps = pathExpr.jjtGetNumChildren();
+
+    for (int i = 0; i < numSteps; i++)
+    {
+      StepExpr stepExpr = (StepExpr) pathExpr.jjtGetChild(stepIndex);
+
+      Node firstChild = stepExpr.jjtGetChild(0);
+      if (firstChild instanceof PatternAxis)
+      {
+        Node secondChild = stepExpr.jjtGetChild(1);
+        org.apache.xpath.parser.NodeTest nt;
+        boolean isTotallyWild;
+
+        if (secondChild instanceof org.apache.xpath.parser.NodeTest)
+        {
+          nt = (org.apache.xpath.parser.NodeTest) secondChild;
+          isTotallyWild = nt.isTotallyWild();
+          // Double check.
+          if (0
+            != (nt.getWhatToShow() | org.apache.xml.dtm.DTMFilter.SHOW_ALL))
+          {
+            isTotallyWild = true;
+          }
+        }
+        else
+        {
+          isTotallyWild = false;
+          nt = null;
+        }
+
+        int axis = ((PatternAxis) firstChild).getAxis();
+        switch (axis)
+        {
+          case Axis.NAMESPACE :
+          case Axis.ATTRIBUTE :
+            if (foundWildAttribute) // Maybe not needed, but be safe.
+              return false;
+            if (isTotallyWild)
+              foundWildAttribute = true;
+            break;
+          case Axis.DESCENDANTSFROMROOT :
+          case Axis.DESCENDANTSORSELFFROMROOT :
+          case Axis.ANCESTOR :
+          case Axis.ANCESTORORSELF :
+          case Axis.DESCENDANT :
+          case Axis.DESCENDANTORSELF :
+          case Axis.FOLLOWING :
+          case Axis.FOLLOWINGSIBLING :
+          case Axis.PRECEDING :
+          case Axis.PRECEDINGSIBLING :
+          case Axis.PARENT :
+            if (potentialDuplicateMakingStepCount > 0)
+              return false;
+            potentialDuplicateMakingStepCount++;
+          case Axis.ROOT :
+          case Axis.CHILD :
+          case Axis.SELF :
+            if (foundWildAttribute)
+              return false;
+            break;
+          default :
+            // TBD: Change the wording of this expression.
+            throw new RuntimeException(
+              XSLMessages.createXPATHMessage(
+                XPATHErrorResources.ER_NULL_ERROR_HANDLER,
+                new Object[] { firstChild.getClass().getName()}));
+            //"Programmer's assertion: unknown opcode: "
+            //+ stepType);
+        }
+      }
+      else
+      {
+        // For the moment return false if it is a filter expression.  
+        // Ideally, we'd like to follow the analysis into a variable or function.
+        return false;
+      }
+    }
+
+    return true;
+  }
+
+  /**
+   * Special purpose function to see if we can optimize the pattern for 
+   * a DescendantIterator.
+   *
+   * @param pathExpr Root of the path expression being analyzed.
+   * @param stepIndex The top-level step index withing the iterator.
+   *
+   * @return 32 bits as an integer that give information about the location
+   * path as a whole.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  private static boolean isOptimizableForDescendantIterator(
+    PathExpr pathExpr,
+    int stepIndex)
+    throws javax.xml.transform.TransformerException
+  {
+
+    int stepType;
+    boolean foundDESCENDANTSFROMROOT = false;
+
+    int nodeTestType = DTMFilter.SHOW_ALL;
+
+    int numSteps = pathExpr.jjtGetNumChildren();
+
+    if (numSteps > 2)
+      return false;
+
+    for (int i = 0; i < numSteps; i++)
+    {
+      StepExpr stepExpr = (StepExpr) pathExpr.jjtGetChild(i);
+
+      int axis = stepExpr.getAxis();
+      switch (axis)
+      {
+        case Axis.SELF :
+        case Axis.ATTRIBUTE :
+        case Axis.ROOT :
+        case Axis.ANCESTOR :
+        case Axis.ANCESTORORSELF :
+        case Axis.NAMESPACE :
+        case Axis.DESCENDANT :
+        case Axis.DESCENDANTORSELF :
+        case Axis.FOLLOWING :
+        case Axis.FOLLOWINGSIBLING :
+        case Axis.PRECEDING :
+        case Axis.PRECEDINGSIBLING :
+        case Axis.PARENT :
+          return false;
+        case Axis.DESCENDANTSORSELFFROMROOT :
+        case Axis.DESCENDANTSFROMROOT :
+          if (0 != i)
+            return false;
+          foundDESCENDANTSFROMROOT = true;
+          if (analyzePredicate(stepExpr))
+          {
+            return false;
+          }
+          break;
+        case Axis.CHILD :
+          if (!foundDESCENDANTSFROMROOT || 1 != i)
+            return false;
+          if(mightBeProximate(stepExpr))
+            return false;
+          break;
+        default :
+          return false;
+          // TBD: Change the wording of this expression.
+          // throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{firstChild.getClass().getName()})); //"Programmer's assertion: unknown opcode: "
+      }
+
+      // TBD: I don't think the code will function properly without this.      
+      //      boolean mightBeProximate = mightBeProximate(compiler, stepOpCodePos, stepType);
+      //      if(mightBeProximate)
+      //        return false;
+
+    }
+
+    return true;
+  }
+
+  // TBD: Needs to use methods on the expressions instead of instanceof!
+  /**
+   * Tell if the predicates need to have proximity knowledge.
+   */
+  public static boolean mightBeProximate(Expression stepExpr)
+    throws javax.xml.transform.TransformerException
+  {
+
+    boolean mightBeProximate = false;
+    int argLen;
+
+    Node lastChild = stepExpr.jjtGetChild(stepExpr.jjtGetNumChildren() - 1);
+    if (lastChild instanceof Predicates)
+    {
+      Predicates preds = (Predicates) lastChild;
+      int numChildren = preds.jjtGetNumChildren();
+      for (int i = 0; i < numChildren; i++)
+      {
+        Expression expr = (Expression) preds.jjtGetChild(i);
+
+        if (expr instanceof org.apache.xpath.operations.Variable)
+        {
+          return true;
+          // Would need more smarts to tell if this could be a number or not!
+        }
+        else
+          if (expr instanceof org.apache.xpath.objects.XNumber)
+          {
+            return true;
+          }
+          else
+            if (expr instanceof org.apache.xpath.parser.PathExpr
+              || expr instanceof LocPathIterator)
+            {
+              // OK, keep going, we don't want to recurse.
+            }
+            else
+              if (expr instanceof org.apache.xpath.functions.Function)
+              {
+                boolean isProx =
+                  functionProximateOrContainsProximate(
+                    (org.apache.xpath.functions.Function) expr);
+                if (isProx)
+                  return true;
+                break;
+
+              }
+              else
+              {
+                int numChildrenOfExpr = expr.jjtGetNumChildren();
+                for (int j = 0; j < numChildrenOfExpr; j++)
+                {
+                  Expression exprChild = (Expression) expr.jjtGetChild(j);
+                  boolean prox = isProximateInnerExpr(exprChild);
+                  if (prox)
+                    return true;
+                }
+              }
+
+      }
+    }
+
+    return mightBeProximate;
+  }
+
+  // TBD: Needs to use methods on the expressions instead of instanceof!
+  static boolean functionProximateOrContainsProximate(
+    org.apache.xpath.functions.Function func)
+  {
+    if (func instanceof org.apache.xpath.functions.FuncLast
+      || func instanceof org.apache.xpath.functions.FuncPosition)
+    {
+      return true;
+    }
+    else
+    {
+      int numChildren = func.jjtGetNumChildren();
+      for (int i = 0; i < numChildren; i++)
+      {
+        Expression expr = (Expression) func.jjtGetChild(i);
+        boolean prox = isProximateInnerExpr(expr);
+        if (prox)
+          return true;
+      }
+    }
+    return false;
+  }
+
+  // TBD: Needs to use methods on the expressions instead of instanceof!
+  static boolean isProximateInnerExpr(Expression expr)
+  {
+    boolean mightBeProximate = false;
+    int argLen;
+
+    if (expr instanceof org.apache.xpath.parser.PathExpr
+      || expr instanceof LocPathIterator)
+    {
+      // OK, we don't want to recurse!
+    }
+    else
+      if (expr instanceof org.apache.xpath.functions.Function)
+      {
+        boolean isProx =
+          functionProximateOrContainsProximate(
+            (org.apache.xpath.functions.Function) expr);
+        if (isProx)
+          return true;
+      }
+      else
+      {
+        int numChildrenOfExpr = expr.jjtGetNumChildren();
+        for (int j = 0; j < numChildrenOfExpr; j++)
+        {
+          Expression exprChild = (Expression) expr.jjtGetChild(j);
+          boolean prox = isProximateInnerExpr(exprChild);
+          if (prox)
+            return true;
+        }
+      }
+    return mightBeProximate;
+  }
+
+  /**
+   * Create the proper Walker from the axes type.
+   *
+   * @param compiler non-null reference to compiler object that has processed
+   *                 the XPath operations into an opcode map.
+   * @param opPos The opcode position for the step.
+   * @param lpi The owning location path iterator.
+   * @param analysis 32 bits of analysis, from which the type of AxesWalker
+   *                 may be influenced.
+   *
+   * @return non-null reference to AxesWalker derivative.
+   * @throws RuntimeException if the input is bad.
+   */
+  private static AxesWalker createDefaultWalker(
+    StepExpr stepExpr,
+    WalkingIterator lpi,
+    int analysis)
+  {
+
+    AxesWalker ai = null;
+
+    PatternAxis patternAxis = stepExpr.getAxisExpr();
+    if (null != patternAxis)
+    {
+      boolean isTotallyWild = stepExpr.isTotallyWild();
+
+      int axis = stepExpr.getAxis();
+      switch (axis)
+      {
+        case Axis.ROOT :
+          ai = new AxesWalker(lpi, Axis.ROOT);
+          break;
+        case Axis.DESCENDANTSFROMROOT :
+          ai = new AxesWalker(lpi, Axis.DESCENDANTSFROMROOT);
+          break;
+        case Axis.DESCENDANTSORSELFFROMROOT :
+          ai = new AxesWalker(lpi, Axis.DESCENDANTSORSELFFROMROOT);
+          break;
+        case Axis.ANCESTOR :
+          ai = new ReverseAxesWalker(lpi, Axis.ANCESTOR);
+          break;
+        case Axis.ANCESTORORSELF :
+          ai = new ReverseAxesWalker(lpi, Axis.ANCESTORORSELF);
+          break;
+        case Axis.ATTRIBUTE :
+          ai = new AxesWalker(lpi, Axis.ATTRIBUTE);
+          break;
+        case Axis.NAMESPACE :
+          ai = new AxesWalker(lpi, Axis.NAMESPACE);
+          break;
+        case Axis.CHILD :
+          ai = new AxesWalker(lpi, Axis.CHILD);
+          break;
+        case Axis.DESCENDANT :
+          ai = new AxesWalker(lpi, Axis.DESCENDANT);
+          break;
+        case Axis.DESCENDANTORSELF :
+          ai = new AxesWalker(lpi, Axis.DESCENDANTORSELF);
+          break;
+        case Axis.FOLLOWING :
+          ai = new AxesWalker(lpi, Axis.FOLLOWING);
+          break;
+        case Axis.FOLLOWINGSIBLING :
+          ai = new AxesWalker(lpi, Axis.FOLLOWINGSIBLING);
+          break;
+        case Axis.PRECEDING :
+          ai = new ReverseAxesWalker(lpi, Axis.PRECEDING);
+          break;
+        case Axis.PRECEDINGSIBLING :
+          ai = new ReverseAxesWalker(lpi, Axis.PRECEDINGSIBLING);
+          break;
+        case Axis.PARENT :
+          ai = new ReverseAxesWalker(lpi, Axis.PARENT);
+          break;
+        case Axis.SELF :
+          ai = new AxesWalker(lpi, Axis.SELF);
+          break;
+        default :
+          throw new RuntimeException(
+            XSLMessages.createXPATHMessage(
+              XPATHErrorResources.ER_NULL_ERROR_HANDLER,
+              new Object[] { StepExpr.class.getName()}));
+          //"Programmer's assertion: unknown opcode: "
+          //+ stepType);
+      }
+      int whatToShow = stepExpr.getWhatToShow();
+
+      /*
+      System.out.print("construct: ");
+      NodeTest.debugWhatToShow(whatToShow);
+      System.out.println("or stuff: "+(whatToShow & (DTMFilter.SHOW_ATTRIBUTE
+                             | DTMFilter.SHOW_ELEMENT
+                             | DTMFilter.SHOW_PROCESSING_INSTRUCTION)));
+      */
+      if ((0
+        == (whatToShow
+          & (DTMFilter.SHOW_ATTRIBUTE
+            | DTMFilter.SHOW_NAMESPACE
+            | DTMFilter.SHOW_ELEMENT
+            | DTMFilter.SHOW_PROCESSING_INSTRUCTION)))
+        || (whatToShow == DTMFilter.SHOW_ALL))
+        ai.initNodeTest(whatToShow);
+      else
+      {
+        ai.initNodeTest(
+          whatToShow,
+          stepExpr.getNamespaceURI(),
+          stepExpr.getLocalName());
+      }
+    }
+    else
+    {
+      // FilterWalker
+      if (DEBUG_WALKER_CREATION)
+        System.out.println(
+          "new walker:  FilterExprWalker: "
+            + analysis
+            + ", "
+            + stepExpr.toString());
+
+      ai = new FilterExprWalker(lpi);
+      try
+      {
+        ai.init(stepExpr);
+      }
+      catch (TransformerException te)
+      {
+        throw new org.apache.xml.utils.WrappedRuntimeException(te);
+      }
+      ai.initNodeTest(DTMFilter.SHOW_ALL);
+    }
+
+    return ai;
+  }
+
+  /**
+   * <meta name="usage" content="advanced"/>
+   * This method is for building an array of possible levels
+   * where the target element(s) could be found for a match.
+   * @param xpath The xpath that is executing.
+   * @param context The current source tree context node.
+   *
+   * @param lpi The owning location path iterator object.
+   * @param compiler non-null reference to compiler object that has processed
+   *                 the XPath operations into an opcode map.
+   * @param stepOpCodePos The opcode position for the step.
+   * @param stepIndex The top-level step index withing the iterator.
+   *
+   * @return non-null AxesWalker derivative.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  static AxesWalker loadWalkers(
+    org.apache.xpath.parser.PathExpr pathExpr,
+    WalkingIterator lpi)
+    throws javax.xml.transform.TransformerException
+  {
+
+    int stepType;
+    AxesWalker firstWalker = null;
+    AxesWalker walker, prevWalker = null;
+    int analysis = analyze(pathExpr, 0);
+    int numSteps = pathExpr.jjtGetNumChildren();
+
+    for (int i = 0; i < numSteps; i++)
+    {
+      StepExpr stepExpr = (StepExpr) pathExpr.jjtGetChild(i);
+
+      walker = createDefaultWalker(stepExpr, lpi, analysis);
+      walker.init(stepExpr);
+
+      // walker.setAnalysis(analysis);
+      if (null == firstWalker)
+      {
+        firstWalker = walker;
+        walker.exprSetParent(lpi);
+      }
+      else
+      {
+        prevWalker.setNextWalker(walker);
+        walker.setPrevWalker(prevWalker);
+        walker.exprSetParent(prevWalker);
+      }
+
+      prevWalker = walker;
+    }
+
+    return firstWalker;
+  }
+
 }
+
+//import org.apache.xpath.compiler.OpCodes;
+//import org.apache.xpath.compiler.Compiler;
+//import org.apache.xpath.compiler.FunctionTable;
+//import org.apache.xpath.patterns.NodeTest;
+//import org.apache.xpath.patterns.StepPattern;
+//import org.apache.xpath.patterns.ContextMatchStepPattern;
+//import org.apache.xpath.patterns.FunctionPattern;
+//import org.apache.xpath.Expression;
+//import org.apache.xpath.objects.XNumber;
+//import org.apache.xalan.res.XSLMessages;
+//import org.apache.xpath.res.XPATHErrorResources;
+//
+//import org.apache.xml.dtm.DTMFilter;
+//import org.apache.xml.dtm.DTMIterator;
+//import org.apache.xml.dtm.Axis;
+//
+///**
+// * This class is both a factory for XPath location path expressions,
+// * which are built from the opcode map output, and an analysis engine
+// * for the location path expressions in order to provide optimization hints.
+// */
+//public class WalkerFactory
+//{
+//
+//  /**
+//   * <meta name="usage" content="advanced"/>
+//   * This method is for building an array of possible levels
+//   * where the target element(s) could be found for a match.
+//   * @param xpath The xpath that is executing.
+//   * @param context The current source tree context node.
+//   *
+//   * @param lpi The owning location path iterator.
+//   * @param compiler non-null reference to compiler object that has processed
+//   *                 the XPath operations into an opcode map.
+//   * @param stepOpCodePos The opcode position for the step.
+//   *
+//   * @return non-null AxesWalker derivative.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  static AxesWalker loadOneWalker(
+//          WalkingIterator lpi, Compiler compiler, int stepOpCodePos)
+//            throws javax.xml.transform.TransformerException
+//  {
+//
+//    AxesWalker firstWalker = null;
+//    int stepType = compiler.getOpMap()[stepOpCodePos];
+//
+//    if (stepType != OpCodes.ENDOP)
+//    {
+//
+//      // m_axesWalkers = new AxesWalker[1];
+//      // As we unwind from the recursion, create the iterators.
+//      firstWalker = createDefaultWalker(compiler, stepType, lpi, 0);
+//
+//      firstWalker.init(compiler, stepOpCodePos, stepType);
+//    }
+//
+//    return firstWalker;
+//  }
+//
+//  /**
+//   * <meta name="usage" content="advanced"/>
+//   * This method is for building an array of possible levels
+//   * where the target element(s) could be found for a match.
+//   * @param xpath The xpath that is executing.
+//   * @param context The current source tree context node.
+//   *
+//   * @param lpi The owning location path iterator object.
+//   * @param compiler non-null reference to compiler object that has processed
+//   *                 the XPath operations into an opcode map.
+//   * @param stepOpCodePos The opcode position for the step.
+//   * @param stepIndex The top-level step index withing the iterator.
+//   *
+//   * @return non-null AxesWalker derivative.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  static AxesWalker loadWalkers(
+//          WalkingIterator lpi, Compiler compiler, int stepOpCodePos, int stepIndex)
+//            throws javax.xml.transform.TransformerException
+//  {
+//
+//    int stepType;
+//    AxesWalker firstWalker = null;
+//    AxesWalker walker, prevWalker = null;
+//    int ops[] = compiler.getOpMap();
+//    int analysis = analyze(compiler, stepOpCodePos, stepIndex);
+//
+//    while (OpCodes.ENDOP != (stepType = ops[stepOpCodePos]))
+//    {
+//      walker = createDefaultWalker(compiler, stepOpCodePos, lpi, analysis);
+//
+//      walker.init(compiler, stepOpCodePos, stepType);
+//      walker.exprSetParent(lpi);
+//
+//      // walker.setAnalysis(analysis);
+//      if (null == firstWalker)
+//      {
+//        firstWalker = walker;
+//      }
+//      else
+//      {
+//        prevWalker.setNextWalker(walker);
+//        walker.setPrevWalker(prevWalker);
+//      }
+//
+//      prevWalker = walker;
+//      stepOpCodePos = compiler.getNextStepPos(stepOpCodePos);
+//
+//      if (stepOpCodePos < 0)
+//        break;
+//    }
+//
+//    return firstWalker;
+//  }
+//  
+//  public static boolean isSet(int analysis, int bits)
+//  {
+//    return (0 != (analysis & bits));
+//  }
+//  
+//  public static void diagnoseIterator(String name, int analysis, Compiler compiler)
+//  {
+//    System.out.println(compiler.toString()+", "+name+", "
+//                             + Integer.toBinaryString(analysis) + ", "
+//                             + getAnalysisString(analysis));
+//  }
+//
+//  /**
+//   * Create a new LocPathIterator iterator.  The exact type of iterator
+//   * returned is based on an analysis of the XPath operations.
+//   *
+//   * @param compiler non-null reference to compiler object that has processed
+//   *                 the XPath operations into an opcode map.
+//   * @param opPos The position of the operation code for this itterator.
+//   *
+//   * @return non-null reference to a LocPathIterator or derivative.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  public static DTMIterator newDTMIterator(
+//          Compiler compiler, int opPos,
+//          boolean isTopLevel)
+//            throws javax.xml.transform.TransformerException
+//  {
+//
+//    int firstStepPos = compiler.getFirstChildPos(opPos);
+//    int analysis = analyze(compiler, firstStepPos, 0);
+//    boolean isOneStep = isOneStep(analysis);
+//    DTMIterator iter;
+//
+//    // Is the iteration a one-step attribute pattern (i.e. select="@foo")?
+//    if (isOneStep && walksSelfOnly(analysis) && 
+//        isWild(analysis) && !hasPredicate(analysis))
+//    {
+//      if (DEBUG_ITERATOR_CREATION)
+//        diagnoseIterator("SelfIteratorNoPredicate", analysis, compiler);
+//
+//      // Then use a simple iteration of the attributes, with node test 
+//      // and predicate testing.
+//      iter = new SelfIteratorNoPredicate(compiler, opPos, analysis);
+//    }
+//    // Is the iteration exactly one child step?
+//    else if (walksChildrenOnly(analysis) && isOneStep)
+//    {
+//
+//      // Does the pattern specify *any* child with no predicate? (i.e. select="child::node()".
+//      if (isWild(analysis) && !hasPredicate(analysis))
+//      {
+//        if (DEBUG_ITERATOR_CREATION)
+//          diagnoseIterator("ChildIterator", analysis, compiler);
+//
+//        // Use simple child iteration without any test.
+//        iter = new ChildIterator(compiler, opPos, analysis);
+//      }
+//      else
+//      {
+//        if (DEBUG_ITERATOR_CREATION)
+//          diagnoseIterator("ChildTestIterator", analysis, compiler);
+//
+//        // Else use simple node test iteration with predicate test.
+//        iter = new ChildTestIterator(compiler, opPos, analysis);
+//      }
+//    }
+//    // Is the iteration a one-step attribute pattern (i.e. select="@foo")?
+//    else if (isOneStep && walksAttributes(analysis))
+//    {
+//      if (DEBUG_ITERATOR_CREATION)
+//        diagnoseIterator("AttributeIterator", analysis, compiler);
+//
+//      // Then use a simple iteration of the attributes, with node test 
+//      // and predicate testing.
+//      iter = new AttributeIterator(compiler, opPos, analysis);
+//    }
+//    else if(isOneStep && !walksFilteredList(analysis))
+//    {
+//      if( !walksNamespaces(analysis) 
+//      && (walksInDocOrder(analysis) || isSet(analysis, BIT_PARENT)))
+//      {
+//        if (false || DEBUG_ITERATOR_CREATION)
+//          diagnoseIterator("OneStepIteratorForward", analysis, compiler);
+//  
+//        // Then use a simple iteration of the attributes, with node test 
+//        // and predicate testing.
+//        iter = new OneStepIteratorForward(compiler, opPos, analysis);
+//      }
+//      else
+//      {
+//        if (false || DEBUG_ITERATOR_CREATION)
+//          diagnoseIterator("OneStepIterator", analysis, compiler);
+//  
+//        // Then use a simple iteration of the attributes, with node test 
+//        // and predicate testing.
+//        iter = new OneStepIterator(compiler, opPos, analysis);
+//      }
+//    }
+//
+//    // Analysis of "//center":
+//    // bits: 1001000000001010000000000000011
+//    // count: 3
+//    // root
+//    // child:node()
+//    // BIT_DESCENDANT_OR_SELF
+//    // It's highly possible that we should have a seperate bit set for 
+//    // "//foo" patterns.
+//    // For at least the time being, we can't optimize patterns like 
+//    // "//table[3]", because this has to be analyzed as 
+//    // "/descendant-or-self::node()/table[3]" in order for the indexes 
+//    // to work right.
+//    else if (isOptimizableForDescendantIterator(compiler, firstStepPos, 0)
+//              // && getStepCount(analysis) <= 3 
+//              // && walksDescendants(analysis) 
+//              // && walksSubtreeOnlyFromRootOrContext(analysis)
+//             )
+//    {
+//      if (DEBUG_ITERATOR_CREATION)
+//        diagnoseIterator("DescendantIterator", analysis, compiler);
+//
+//      iter = new DescendantIterator(compiler, opPos, analysis);
+//    }
+//    else
+//    { 
+//      if(isNaturalDocOrder(compiler, firstStepPos, 0, analysis))
+//      {
+//        if (false || DEBUG_ITERATOR_CREATION)
+//        {
+//          diagnoseIterator("WalkingIterator", analysis, compiler);
+//        }
+//  
+//        iter = new WalkingIterator(compiler, opPos, analysis, true);
+//      }
+//      else
+//      {
+////        if (DEBUG_ITERATOR_CREATION)
+////          diagnoseIterator("MatchPatternIterator", analysis, compiler);
+////
+////        return new MatchPatternIterator(compiler, opPos, analysis);
+//        if (DEBUG_ITERATOR_CREATION)
+//          diagnoseIterator("WalkingIteratorSorted", analysis, compiler);
+//
+//        iter = new WalkingIteratorSorted(compiler, opPos, analysis, true);
+//      }
+//    }
+//    if(iter instanceof LocPathIterator)
+//      ((LocPathIterator)iter).setIsTopLevel(isTopLevel);
+//      
+//    return iter;
+//  }
+//  
+//  /**
+//   * Special purpose function to see if we can optimize the pattern for 
+//   * a DescendantIterator.
+//   *
+//   * @param compiler non-null reference to compiler object that has processed
+//   *                 the XPath operations into an opcode map.
+//   * @param stepOpCodePos The opcode position for the step.
+//   * @param stepIndex The top-level step index withing the iterator.
+//   *
+//   * @return 32 bits as an integer that give information about the location
+//   * path as a whole.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  public static int getAxisFromStep(
+//          Compiler compiler, int stepOpCodePos)
+//            throws javax.xml.transform.TransformerException
+//  {
+//
+//    int ops[] = compiler.getOpMap();
+//    int stepType = ops[stepOpCodePos];
+//
+//    switch (stepType)
+//    {
+//    case OpCodes.FROM_FOLLOWING :
+//      return Axis.FOLLOWING;
+//    case OpCodes.FROM_FOLLOWING_SIBLINGS :
+//      return Axis.FOLLOWINGSIBLING;
+//    case OpCodes.FROM_PRECEDING :
+//      return Axis.PRECEDING;
+//    case OpCodes.FROM_PRECEDING_SIBLINGS :
+//      return Axis.PRECEDINGSIBLING;
+//    case OpCodes.FROM_PARENT :
+//      return Axis.PARENT;
+//    case OpCodes.FROM_NAMESPACE :
+//      return Axis.NAMESPACE;
+//    case OpCodes.FROM_ANCESTORS :
+//      return Axis.ANCESTOR;
+//    case OpCodes.FROM_ANCESTORS_OR_SELF :
+//      return Axis.ANCESTORORSELF;
+//    case OpCodes.FROM_ATTRIBUTES :
+//      return Axis.ATTRIBUTE;
+//    case OpCodes.FROM_ROOT :
+//      return Axis.ROOT;
+//    case OpCodes.FROM_CHILDREN :
+//      return Axis.CHILD;
+//    case OpCodes.FROM_DESCENDANTS_OR_SELF :
+//      return Axis.DESCENDANTORSELF;
+//    case OpCodes.FROM_DESCENDANTS :
+//      return Axis.DESCENDANT;
+//    case OpCodes.FROM_SELF :
+//      return Axis.SELF;
+//    case OpCodes.OP_EXTFUNCTION :
+//    case OpCodes.OP_FUNCTION :
+//    case OpCodes.OP_GROUP :
+//    case OpCodes.OP_VARIABLE :
+//      return Axis.FILTEREDLIST;
+//    }
+//
+//    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
+//                               //+ stepType);
+//   }
+//    
+//    /**
+//     * Get a corresponding BIT_XXX from an axis.
+//     * @param axis One of Axis.ANCESTOR, etc.
+//     * @return One of BIT_ANCESTOR, etc.
+//     */
+//    static public int getAnalysisBitFromAxes(int axis)
+//    {
+//      switch (axis) // Generate new traverser
+//        {
+//        case Axis.ANCESTOR :
+//          return BIT_ANCESTOR;
+//        case Axis.ANCESTORORSELF :
+//          return BIT_ANCESTOR_OR_SELF;
+//        case Axis.ATTRIBUTE :
+//          return BIT_ATTRIBUTE;
+//        case Axis.CHILD :
+//          return BIT_CHILD;
+//        case Axis.DESCENDANT :
+//          return BIT_DESCENDANT;
+//        case Axis.DESCENDANTORSELF :
+//          return BIT_DESCENDANT_OR_SELF;
+//        case Axis.FOLLOWING :
+//          return BIT_FOLLOWING;
+//        case Axis.FOLLOWINGSIBLING :
+//          return BIT_FOLLOWING_SIBLING;
+//        case Axis.NAMESPACE :
+//        case Axis.NAMESPACEDECLS :
+//          return BIT_NAMESPACE;
+//        case Axis.PARENT :
+//          return BIT_PARENT;
+//        case Axis.PRECEDING :
+//          return BIT_PRECEDING;
+//        case Axis.PRECEDINGSIBLING :
+//          return BIT_PRECEDING_SIBLING;
+//        case Axis.SELF :
+//          return BIT_SELF;
+//        case Axis.ALLFROMNODE :
+//          return BIT_DESCENDANT_OR_SELF;
+//          // case Axis.PRECEDINGANDANCESTOR :
+//        case Axis.DESCENDANTSFROMROOT :
+//        case Axis.ALL :
+//        case Axis.DESCENDANTSORSELFFROMROOT :
+//          return BIT_ANY_DESCENDANT_FROM_ROOT;
+//        case Axis.ROOT :
+//          return BIT_ROOT;
+//        case Axis.FILTEREDLIST :
+//          return BIT_FILTER;
+//        default :
+//          return BIT_FILTER;
+//      }
+//    }
+//  
+//  static boolean functionProximateOrContainsProximate(Compiler compiler, 
+//                                                      int opPos)
+//  {
+//    int endFunc = opPos + compiler.getOp(opPos + 1) - 1;
+//    opPos = compiler.getFirstChildPos(opPos);
+//    int funcID = compiler.getOp(opPos);
+//    //  System.out.println("funcID: "+funcID);
+//    //  System.out.println("opPos: "+opPos);
+//    //  System.out.println("endFunc: "+endFunc);
+//    switch(funcID)
+//    {
+//      case FunctionTable.FUNC_LAST:
+//      case FunctionTable.FUNC_POSITION:
+//        return true;
+//      default:
+//        opPos++;
+//        int i = 0;
+//        for (int p = opPos; p < endFunc; p = compiler.getNextOpPos(p), i++)
+//        {
+//          int innerExprOpPos = p+2;
+//          int argOp = compiler.getOp(innerExprOpPos);
+//          boolean prox = isProximateInnerExpr(compiler, innerExprOpPos);
+//          if(prox)
+//            return true;
+//        }
+//
+//    }
+//    return false;
+//  }
+//  
+//  static boolean isProximateInnerExpr(Compiler compiler, int opPos)
+//  {
+//    int op = compiler.getOp(opPos);
+//    int innerExprOpPos = opPos+2;
+//    switch(op)
+//    {
+//      case OpCodes.OP_ARGUMENT:
+//        if(isProximateInnerExpr(compiler, innerExprOpPos))
+//          return true;
+//        break;
+//      case OpCodes.OP_VARIABLE:
+//      case OpCodes.OP_NUMBERLIT:
+//      case OpCodes.OP_LITERAL:
+//      case OpCodes.OP_LOCATIONPATH:
+//        break; // OK
+//      case OpCodes.OP_FUNCTION:
+//        boolean isProx = functionProximateOrContainsProximate(compiler, opPos);
+//        if(isProx)
+//          return true;
+//        break;
+//      case OpCodes.OP_GT:
+//      case OpCodes.OP_GTE:
+//      case OpCodes.OP_LT:
+//      case OpCodes.OP_LTE:
+//      case OpCodes.OP_EQUALS:
+//        int leftPos = compiler.getFirstChildPos(op);
+//        int rightPos = compiler.getNextOpPos(leftPos);
+//        isProx = isProximateInnerExpr(compiler, leftPos);
+//        if(isProx)
+//          return true;
+//        isProx = isProximateInnerExpr(compiler, rightPos);
+//        if(isProx)
+//          return true;
+//        break;
+//      default:
+//        return true; // be conservative...
+//    }
+//    return false;
+//  }
+//    
+//  /**
+//   * Tell if the predicates need to have proximity knowledge.
+//   */
+//  public static boolean mightBeProximate(Compiler compiler, int opPos, int stepType)
+//          throws javax.xml.transform.TransformerException
+//  {
+//
+//    boolean mightBeProximate = false;
+//    int argLen;
+//
+//    switch (stepType)
+//    {
+//    case OpCodes.OP_VARIABLE :
+//    case OpCodes.OP_EXTFUNCTION :
+//    case OpCodes.OP_FUNCTION :
+//    case OpCodes.OP_GROUP :
+//      argLen = compiler.getArgLength(opPos);
+//      break;
+//    default :
+//      argLen = compiler.getArgLengthOfStep(opPos);
+//    }
+//
+//    int predPos = compiler.getFirstPredicateOpPos(opPos);
+//    int count = 0;
+//
+//    while (OpCodes.OP_PREDICATE == compiler.getOp(predPos))
+//    {
+//      count++;
+//      
+//      int innerExprOpPos = predPos+2;
+//      int predOp = compiler.getOp(innerExprOpPos);
+//
+//      switch(predOp)
+//      {
+//        case OpCodes.OP_VARIABLE:
+//        	return true; // Would need more smarts to tell if this could be a number or not!
+//        case OpCodes.OP_LOCATIONPATH:
+//          // OK.
+//          break;
+//        case OpCodes.OP_NUMBER:
+//        case OpCodes.OP_NUMBERLIT:
+//          return true; // that's all she wrote!
+//        case OpCodes.OP_FUNCTION:
+//          boolean isProx 
+//            = functionProximateOrContainsProximate(compiler, innerExprOpPos);
+//          if(isProx)
+//            return true;
+//          break;
+//        case OpCodes.OP_GT:
+//        case OpCodes.OP_GTE:
+//        case OpCodes.OP_LT:
+//        case OpCodes.OP_LTE:
+//        case OpCodes.OP_EQUALS:
+//          int leftPos = compiler.getFirstChildPos(innerExprOpPos);
+//          int rightPos = compiler.getNextOpPos(leftPos);
+//          isProx = isProximateInnerExpr(compiler, leftPos);
+//          if(isProx)
+//            return true;
+//          isProx = isProximateInnerExpr(compiler, rightPos);
+//          if(isProx)
+//            return true;
+//          break;
+//        default:
+//          return true; // be conservative...
+//      }
+//
+//      predPos = compiler.getNextOpPos(predPos);
+//    }
+//
+//    return mightBeProximate;
+//  }
+//  
+//  /**
+//   * Special purpose function to see if we can optimize the pattern for 
+//   * a DescendantIterator.
+//   *
+//   * @param compiler non-null reference to compiler object that has processed
+//   *                 the XPath operations into an opcode map.
+//   * @param stepOpCodePos The opcode position for the step.
+//   * @param stepIndex The top-level step index withing the iterator.
+//   *
+//   * @return 32 bits as an integer that give information about the location
+//   * path as a whole.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  private static boolean isOptimizableForDescendantIterator(
+//          Compiler compiler, int stepOpCodePos, int stepIndex)
+//            throws javax.xml.transform.TransformerException
+//  {
+//
+//    int stepType;
+//    int ops[] = compiler.getOpMap();
+//    int stepCount = 0;
+//    boolean foundDorDS = false;
+//    boolean foundSelf = false;
+//    boolean foundDS = false;
+//    
+//    int nodeTestType = OpCodes.NODETYPE_NODE;
+//    
+//    while (OpCodes.ENDOP != (stepType = ops[stepOpCodePos]))
+//    {
+//      // The DescendantIterator can only do one node test.  If there's more 
+//      // than one, use another iterator.
+//      if(nodeTestType != OpCodes.NODETYPE_NODE && nodeTestType != OpCodes.NODETYPE_ROOT)
+//        return false;
+//        
+//      stepCount++;
+//      if(stepCount > 3)
+//        return false;
+//        
+//      boolean mightBeProximate = mightBeProximate(compiler, stepOpCodePos, stepType);
+//      if(mightBeProximate)
+//        return false;
+//
+//      switch (stepType)
+//      {
+//      case OpCodes.FROM_FOLLOWING :
+//      case OpCodes.FROM_FOLLOWING_SIBLINGS :
+//      case OpCodes.FROM_PRECEDING :
+//      case OpCodes.FROM_PRECEDING_SIBLINGS :
+//      case OpCodes.FROM_PARENT :
+//      case OpCodes.OP_VARIABLE :
+//      case OpCodes.OP_EXTFUNCTION :
+//      case OpCodes.OP_FUNCTION :
+//      case OpCodes.OP_GROUP :
+//      case OpCodes.FROM_NAMESPACE :
+//      case OpCodes.FROM_ANCESTORS :
+//      case OpCodes.FROM_ANCESTORS_OR_SELF :
+//      case OpCodes.FROM_ATTRIBUTES :
+//      case OpCodes.MATCH_ATTRIBUTE :
+//      case OpCodes.MATCH_ANY_ANCESTOR :
+//      case OpCodes.MATCH_IMMEDIATE_ANCESTOR :
+//        return false;
+//      case OpCodes.FROM_ROOT :
+//        if(1 != stepCount)
+//          return false;
+//        break;
+//      case OpCodes.FROM_CHILDREN :
+//        if(!foundDS && !(foundDorDS && foundSelf))
+//          return false;
+//        break;
+//      case OpCodes.FROM_DESCENDANTS_OR_SELF :
+//        foundDS = true;
+//      case OpCodes.FROM_DESCENDANTS :
+//        if(3 == stepCount)
+//          return false;
+//        foundDorDS = true;
+//        break;
+//      case OpCodes.FROM_SELF :
+//        if(1 != stepCount)
+//          return false;
+//        foundSelf = true;
+//        break;
+//      default :
+//        throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
+//                                  // + stepType);
+//      }
+//      
+//      nodeTestType = compiler.getStepTestType(stepOpCodePos);
+//
+//      int nextStepOpCodePos = compiler.getNextStepPos(stepOpCodePos);
+//
+//      if (nextStepOpCodePos < 0)
+//        break;
+//        
+//      if(OpCodes.ENDOP != ops[nextStepOpCodePos])
+//      {
+//        if(compiler.countPredicates(stepOpCodePos) > 0)
+//        {
+//          return false;
+//        }
+//      }
+//      
+//      stepOpCodePos = nextStepOpCodePos;
+//    }
+//
+//    return true;
+//  }
+//
+//  /**
+//   * Analyze the location path and return 32 bits that give information about
+//   * the location path as a whole.  See the BIT_XXX constants for meaning about
+//   * each of the bits.
+//   *
+//   * @param compiler non-null reference to compiler object that has processed
+//   *                 the XPath operations into an opcode map.
+//   * @param stepOpCodePos The opcode position for the step.
+//   * @param stepIndex The top-level step index withing the iterator.
+//   *
+//   * @return 32 bits as an integer that give information about the location
+//   * path as a whole.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  private static int analyze(
+//          Compiler compiler, int stepOpCodePos, int stepIndex)
+//            throws javax.xml.transform.TransformerException
+//  {
+//
+//    int stepType;
+//    int ops[] = compiler.getOpMap();
+//    int stepCount = 0;
+//    int analysisResult = 0x00000000;  // 32 bits of analysis
+//
+//    while (OpCodes.ENDOP != (stepType = ops[stepOpCodePos]))
+//    {
+//      stepCount++;
+//
+//      // String namespace = compiler.getStepNS(stepOpCodePos);
+//      // boolean isNSWild = (null != namespace) 
+//      //                   ? namespace.equals(NodeTest.WILD) : false;
+//      // String localname = compiler.getStepLocalName(stepOpCodePos);
+//      // boolean isWild = (null != localname) ? localname.equals(NodeTest.WILD) : false;
+//      boolean predAnalysis = analyzePredicate(compiler, stepOpCodePos,
+//                                              stepType);
+//
+//      if (predAnalysis)
+//        analysisResult |= BIT_PREDICATE;
+//
+//      switch (stepType)
+//      {
+//      case OpCodes.OP_VARIABLE :
+//      case OpCodes.OP_EXTFUNCTION :
+//      case OpCodes.OP_FUNCTION :
+//      case OpCodes.OP_GROUP :
+//        analysisResult |= BIT_FILTER;
+//        break;
+//      case OpCodes.FROM_ROOT :
+//        analysisResult |= BIT_ROOT;
+//        break;
+//      case OpCodes.FROM_ANCESTORS :
+//        analysisResult |= BIT_ANCESTOR;
+//        break;
+//      case OpCodes.FROM_ANCESTORS_OR_SELF :
+//        analysisResult |= BIT_ANCESTOR_OR_SELF;
+//        break;
+//      case OpCodes.FROM_ATTRIBUTES :
+//        analysisResult |= BIT_ATTRIBUTE;
+//        break;
+//      case OpCodes.FROM_NAMESPACE :
+//        analysisResult |= BIT_NAMESPACE;
+//        break;
+//      case OpCodes.FROM_CHILDREN :
+//        analysisResult |= BIT_CHILD;
+//        break;
+//      case OpCodes.FROM_DESCENDANTS :
+//        analysisResult |= BIT_DESCENDANT;
+//        break;
+//      case OpCodes.FROM_DESCENDANTS_OR_SELF :
+//
+//        // Use a special bit to to make sure we get the right analysis of "//foo".
+//        if (2 == stepCount && BIT_ROOT == analysisResult)
+//        {
+//          analysisResult |= BIT_ANY_DESCENDANT_FROM_ROOT;
+//        }
+//
+//        analysisResult |= BIT_DESCENDANT_OR_SELF;
+//        break;
+//      case OpCodes.FROM_FOLLOWING :
+//        analysisResult |= BIT_FOLLOWING;
+//        break;
+//      case OpCodes.FROM_FOLLOWING_SIBLINGS :
+//        analysisResult |= BIT_FOLLOWING_SIBLING;
+//        break;
+//      case OpCodes.FROM_PRECEDING :
+//        analysisResult |= BIT_PRECEDING;
+//        break;
+//      case OpCodes.FROM_PRECEDING_SIBLINGS :
+//        analysisResult |= BIT_PRECEDING_SIBLING;
+//        break;
+//      case OpCodes.FROM_PARENT :
+//        analysisResult |= BIT_PARENT;
+//        break;
+//      case OpCodes.FROM_SELF :
+//        analysisResult |= BIT_SELF;
+//        break;
+//      case OpCodes.MATCH_ATTRIBUTE :
+//        analysisResult |= (BIT_MATCH_PATTERN | BIT_ATTRIBUTE);
+//        break;
+//      case OpCodes.MATCH_ANY_ANCESTOR :
+//        analysisResult |= (BIT_MATCH_PATTERN | BIT_ANCESTOR);
+//        break;
+//      case OpCodes.MATCH_IMMEDIATE_ANCESTOR :
+//        analysisResult |= (BIT_MATCH_PATTERN | BIT_PARENT);
+//        break;
+//      default :
+//        throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
+//                                   //+ stepType);
+//      }
+//
+//      if (OpCodes.NODETYPE_NODE == ops[stepOpCodePos + 3])  // child::node()
+//      {
+//        analysisResult |= BIT_NODETEST_ANY;
+//      }
+//
+//      stepOpCodePos = compiler.getNextStepPos(stepOpCodePos);
+//
+//      if (stepOpCodePos < 0)
+//        break;
+//    }
+//
+//    analysisResult |= (stepCount & BITS_COUNT);
+//
+//    return analysisResult;
+//  }
+//  
+//  /**
+//   * Tell if the given axis goes downword.  Bogus name, if you can think of 
+//   * a better one, please do tell.  This really has to do with inverting 
+//   * attribute axis.
+//   * @param axis One of Axis.XXX.
+//   * @return true if the axis is not a child axis and does not go up from 
+//   * the axis root.
+//   */
+//  public static boolean isDownwardAxisOfMany(int axis)
+//  {
+//    return ((Axis.DESCENDANTORSELF == axis) ||
+//          (Axis.DESCENDANT == axis) 
+//          || (Axis.FOLLOWING == axis) 
+////          || (Axis.FOLLOWINGSIBLING == axis) 
+//          || (Axis.PRECEDING == axis) 
+////          || (Axis.PRECEDINGSIBLING == axis)
+//          );
+//  }
+//
+//  /**
+//   * Read a <a href="http://www.w3.org/TR/xpath#location-paths">LocationPath</a>
+//   * as a generalized match pattern.  What this means is that the LocationPath
+//   * is read backwards, as a test on a given node, to see if it matches the
+//   * criteria of the selection, and ends up at the context node.  Essentially,
+//   * this is a backwards query from a given node, to find the context node.
+//   * <p>So, the selection "foo/daz[2]" is, in non-abreviated expanded syntax,
+//   * "self::node()/following-sibling::foo/child::daz[position()=2]".
+//   * Taking this as a match pattern for a probable node, it works out to
+//   * "self::daz/parent::foo[child::daz[position()=2 and isPrevStepNode()]
+//   * precedingSibling::node()[isContextNodeOfLocationPath()]", adding magic
+//   * isPrevStepNode and isContextNodeOfLocationPath operations.  Predicates in
+//   * the location path have to be executed by the following step,
+//   * because they have to know the context of their execution.
+//   *
+//   * @param mpi The MatchPatternIterator to which the steps will be attached.
+//   * @param compiler The compiler that holds the syntax tree/op map to
+//   * construct from.
+//   * @param stepOpCodePos The current op code position within the opmap.
+//   * @param stepIndex The top-level step index withing the iterator.
+//   *
+//   * @return A StepPattern object, which may contain relative StepPatterns.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  static StepPattern loadSteps(
+//          MatchPatternIterator mpi, Compiler compiler, int stepOpCodePos, 
+//                                                       int stepIndex)
+//            throws javax.xml.transform.TransformerException
+//  {
+//    if (DEBUG_PATTERN_CREATION)
+//    {
+//      System.out.println("================");
+//      System.out.println("loadSteps for: "+compiler.getPatternString());
+//    }
+//    int stepType;
+//    StepPattern step = null;
+//    StepPattern firstStep = null, prevStep = null;
+//    int ops[] = compiler.getOpMap();
+//    int analysis = analyze(compiler, stepOpCodePos, stepIndex);
+//
+//    while (OpCodes.ENDOP != (stepType = ops[stepOpCodePos]))
+//    {
+//      step = createDefaultStepPattern(compiler, stepOpCodePos, mpi, analysis,
+//                                      firstStep, prevStep);
+//
+//      if (null == firstStep)
+//      {
+//        firstStep = step;
+//      }
+//      else
+//      {
+//
+//        //prevStep.setNextWalker(step);
+//        step.setRelativePathPattern(prevStep);
+//      }
+//
+//      prevStep = step;
+//      stepOpCodePos = compiler.getNextStepPos(stepOpCodePos);
+//
+//      if (stepOpCodePos < 0)
+//        break;
+//    }
+//    
+//    int axis = Axis.SELF;
+//    int paxis = Axis.SELF;
+//    StepPattern tail = step;
+//    for (StepPattern pat = step; null != pat; 
+//         pat = pat.getRelativePathPattern()) 
+//    {
+//      int nextAxis = pat.getAxis();
+//      //int nextPaxis = pat.getPredicateAxis();
+//      pat.setAxis(axis);
+//      
+//      // The predicate axis can't be moved!!!  Test Axes103
+//      // pat.setPredicateAxis(paxis);
+//      
+//      // If we have an attribute or namespace axis that went up, then 
+//      // it won't find the attribute in the inverse, since the select-to-match
+//      // axes are not invertable (an element is a parent of an attribute, but 
+//      // and attribute is not a child of an element).
+//      // If we don't do the magic below, then "@*/ancestor-or-self::*" gets
+//      // inverted for match to "self::*/descendant-or-self::@*/parent::node()",
+//      // which obviously won't work.
+//      // So we will rewrite this as:
+//      // "self::*/descendant-or-self::*/attribute::*/parent::node()"
+//      // Child has to be rewritten a little differently:
+//      // select: "@*/parent::*"
+//      // inverted match: "self::*/child::@*/parent::node()"
+//      // rewrite: "self::*/attribute::*/parent::node()"
+//      // Axes that go down in the select, do not have to have special treatment 
+//      // in the rewrite. The following inverted match will still not select 
+//      // anything.
+//      // select: "@*/child::*"
+//      // inverted match: "self::*/parent::@*/parent::node()"
+//      // Lovely business, this.
+//      // -sb
+//      int whatToShow = pat.getWhatToShow();
+//      if(whatToShow == DTMFilter.SHOW_ATTRIBUTE || 
+//         whatToShow == DTMFilter.SHOW_NAMESPACE)
+//      {
+//        int newAxis = (whatToShow == DTMFilter.SHOW_ATTRIBUTE) ? 
+//                       Axis.ATTRIBUTE : Axis.NAMESPACE;
+//        if(isDownwardAxisOfMany(axis))
+//        {
+//          StepPattern attrPat = new StepPattern(whatToShow, 
+//                                    pat.getNamespace(),
+//                                    pat.getLocalName(),
+//                                //newAxis, pat.getPredicateAxis);
+//                                                newAxis, 0); // don't care about the predicate axis
+//          XNumber score = pat.getStaticScore();
+//          pat.setNamespace(null);
+//          pat.setLocalName(NodeTest.WILD);
+//          attrPat.setPredicates(pat.getPredicates());
+//          pat.setPredicates(null);
+//          pat.setWhatToShow(DTMFilter.SHOW_ELEMENT);
+//          StepPattern rel = pat.getRelativePathPattern();
+//          pat.setRelativePathPattern(attrPat);
+//          attrPat.setRelativePathPattern(rel);
+//          attrPat.setStaticScore(score);
+//          
+//          // This is needed to inverse a following pattern, because of the 
+//          // wacky Xalan rules for following from an attribute.  See axes108.
+//          // By these rules, following from an attribute is not strictly 
+//          // inverseable.
+//          if(Axis.PRECEDING == pat.getAxis())
+//            pat.setAxis(Axis.PRECEDINGANDANCESTOR);
+//            
+//          else if(Axis.DESCENDANT == pat.getAxis())
+//            pat.setAxis(Axis.DESCENDANTORSELF);
+//          
+//          pat = attrPat;
+//        }
+//        else if(Axis.CHILD == pat.getAxis())
+//        {
+//          // In this case just change the axis.
+//          // pat.setWhatToShow(whatToShow);
+//          pat.setAxis(Axis.ATTRIBUTE);
+//        }
+//      }
+//      axis = nextAxis;
+//      //paxis = nextPaxis;
+//      tail = pat;
+//    }
+//    
+//    if(axis < Axis.ALL)
+//    {
+//      StepPattern selfPattern = new ContextMatchStepPattern(axis, paxis);
+//      // We need to keep the new nodetest from affecting the score...
+//      XNumber score = tail.getStaticScore();
+//      tail.setRelativePathPattern(selfPattern);
+//      tail.setStaticScore(score);
+//      selfPattern.setStaticScore(score);
+//    }        
+//
+//    if (DEBUG_PATTERN_CREATION)
+//    {
+//      System.out.println("Done loading steps: "+step.toString());
+//            
+//      System.out.println("");
+//    }
+//    return step;  // start from last pattern?? //firstStep;
+//  }
+//
+//  /**
+//   * Create a StepPattern that is contained within a LocationPath.
+//   *
+//   *
+//   * @param compiler The compiler that holds the syntax tree/op map to
+//   * construct from.
+//   * @param stepOpCodePos The current op code position within the opmap.
+//   * @param mpi The MatchPatternIterator to which the steps will be attached.
+//   * @param analysis 32 bits of analysis, from which the type of AxesWalker
+//   *                 may be influenced.
+//   * @param tail The step that is the first step analyzed, but the last 
+//   *                  step in the relative match linked list, i.e. the tail.
+//   *                  May be null.
+//   * @param head The step that is the current head of the relative 
+//   *                 match step linked list.
+//   *                 May be null.
+//   *
+//   * @return the head of the list.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  private static StepPattern createDefaultStepPattern(
+//          Compiler compiler, int opPos, MatchPatternIterator mpi, 
+//          int analysis, StepPattern tail, StepPattern head)
+//            throws javax.xml.transform.TransformerException
+//  {
+//
+//    int stepType = compiler.getOp(opPos);
+//    boolean simpleInit = false;
+//    int totalNumberWalkers = (analysis & BITS_COUNT);
+//    boolean prevIsOneStepDown = true;
+//    int firstStepPos = compiler.getFirstChildPos(opPos);
+//    
+//    int whatToShow = compiler.getWhatToShow(opPos);
+//    StepPattern ai = null;
+//    int axis, predicateAxis;
+//    
+//    switch (stepType)
+//    {
+//    case OpCodes.OP_VARIABLE :
+//    case OpCodes.OP_EXTFUNCTION :
+//    case OpCodes.OP_FUNCTION :
+//    case OpCodes.OP_GROUP :
+//      prevIsOneStepDown = false;
+//
+//      Expression expr;
+//
+//      switch (stepType)
+//      {
+//      case OpCodes.OP_VARIABLE :
+//      case OpCodes.OP_EXTFUNCTION :
+//      case OpCodes.OP_FUNCTION :
+//      case OpCodes.OP_GROUP :
+//        expr = compiler.compile(opPos);
+//        break;
+//      default :
+//        expr = compiler.compile(opPos + 2);
+//      }
+//
+//      axis = Axis.FILTEREDLIST;
+//      predicateAxis = Axis.FILTEREDLIST;
+//      ai = new FunctionPattern(expr, axis, predicateAxis);
+//      simpleInit = true;
+//      break;
+//    case OpCodes.FROM_ROOT :
+//      whatToShow = DTMFilter.SHOW_DOCUMENT
+//                   | DTMFilter.SHOW_DOCUMENT_FRAGMENT;
+//
+//      axis = Axis.ROOT;
+//      predicateAxis = Axis.ROOT;
+//      ai = new StepPattern(DTMFilter.SHOW_DOCUMENT | 
+//                                DTMFilter.SHOW_DOCUMENT_FRAGMENT,
+//                                axis, predicateAxis);
+//      break;
+//    case OpCodes.FROM_ATTRIBUTES :
+//      whatToShow = DTMFilter.SHOW_ATTRIBUTE;
+//      axis = Axis.PARENT;
+//      predicateAxis = Axis.ATTRIBUTE;
+//      // ai = new StepPattern(whatToShow, Axis.SELF, Axis.SELF);
+//      break;
+//    case OpCodes.FROM_NAMESPACE :
+//      whatToShow = DTMFilter.SHOW_NAMESPACE;
+//      axis = Axis.PARENT;
+//      predicateAxis = Axis.NAMESPACE;
+//      // ai = new StepPattern(whatToShow, axis, predicateAxis);
+//      break;
+//    case OpCodes.FROM_ANCESTORS :
+//      axis = Axis.DESCENDANT;
+//      predicateAxis = Axis.ANCESTOR;
+//      break;
+//    case OpCodes.FROM_CHILDREN :
+//      axis = Axis.PARENT;
+//      predicateAxis = Axis.CHILD;
+//      break;
+//    case OpCodes.FROM_ANCESTORS_OR_SELF :
+//      axis = Axis.DESCENDANTORSELF;
+//      predicateAxis = Axis.ANCESTORORSELF;
+//      break;
+//    case OpCodes.FROM_SELF :
+//      axis = Axis.SELF;
+//      predicateAxis = Axis.SELF;
+//      break;
+//    case OpCodes.FROM_PARENT :
+//      axis = Axis.CHILD;
+//      predicateAxis = Axis.PARENT;
+//      break;
+//    case OpCodes.FROM_PRECEDING_SIBLINGS :
+//      axis = Axis.FOLLOWINGSIBLING;
+//      predicateAxis = Axis.PRECEDINGSIBLING;
+//      break;
+//    case OpCodes.FROM_PRECEDING :
+//      axis = Axis.FOLLOWING;
+//      predicateAxis = Axis.PRECEDING;
+//      break;
+//    case OpCodes.FROM_FOLLOWING_SIBLINGS :
+//      axis = Axis.PRECEDINGSIBLING;
+//      predicateAxis = Axis.FOLLOWINGSIBLING;
+//      break;
+//    case OpCodes.FROM_FOLLOWING :
+//      axis = Axis.PRECEDING;
+//      predicateAxis = Axis.FOLLOWING;
+//      break;
+//    case OpCodes.FROM_DESCENDANTS_OR_SELF :
+//      axis = Axis.ANCESTORORSELF;
+//      predicateAxis = Axis.DESCENDANTORSELF;
+//      break;
+//    case OpCodes.FROM_DESCENDANTS :
+//      axis = Axis.ANCESTOR;
+//      predicateAxis = Axis.DESCENDANT;
+//      break;
+//    default :
+//      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
+//                                 //+ stepType);
+//    }
+//    if(null == ai)
+//    {
+//      whatToShow = compiler.getWhatToShow(opPos); // %REVIEW%
+//      ai = new StepPattern(whatToShow, compiler.getStepNS(opPos),
+//                                compiler.getStepLocalName(opPos),
+//                                axis, predicateAxis);
+//    }
+//   
+//    if (false || DEBUG_PATTERN_CREATION)
+//    {
+//      System.out.print("new step: "+ ai);
+//      System.out.print(", axis: " + Axis.names[ai.getAxis()]);
+//      System.out.print(", predAxis: " + Axis.names[ai.getAxis()]);
+//      System.out.print(", what: ");
+//      System.out.print("    ");
+//      ai.debugWhatToShow(ai.getWhatToShow());
+//    }
+//
+//    int argLen = compiler.getFirstPredicateOpPos(opPos);
+//
+//    ai.setPredicates(compiler.getCompiledPredicates(argLen));
+//
+//    return ai;
+//  }
+//
+//  /**
+//   * Analyze a step and give information about it's predicates.  Right now this
+//   * just returns true or false if the step has a predicate.
+//   *
+//   * @param compiler non-null reference to compiler object that has processed
+//   *                 the XPath operations into an opcode map.
+//   * @param opPos The opcode position for the step.
+//   * @param stepType The type of step, one of OP_GROUP, etc.
+//   *
+//   * @return true if step has a predicate.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  static boolean analyzePredicate(Compiler compiler, int opPos, int stepType)
+//          throws javax.xml.transform.TransformerException
+//  {
+//
+//    int argLen;
+//
+//    switch (stepType)
+//    {
+//    case OpCodes.OP_VARIABLE :
+//    case OpCodes.OP_EXTFUNCTION :
+//    case OpCodes.OP_FUNCTION :
+//    case OpCodes.OP_GROUP :
+//      argLen = compiler.getArgLength(opPos);
+//      break;
+//    default :
+//      argLen = compiler.getArgLengthOfStep(opPos);
+//    }
+//
+//    int pos = compiler.getFirstPredicateOpPos(opPos);
+//    int nPredicates = compiler.countPredicates(pos);
+//
+//    return (nPredicates > 0) ? true : false;
+//  }
+//
+//  /**
+//   * Create the proper Walker from the axes type.
+//   *
+//   * @param compiler non-null reference to compiler object that has processed
+//   *                 the XPath operations into an opcode map.
+//   * @param opPos The opcode position for the step.
+//   * @param lpi The owning location path iterator.
+//   * @param analysis 32 bits of analysis, from which the type of AxesWalker
+//   *                 may be influenced.
+//   *
+//   * @return non-null reference to AxesWalker derivative.
+//   * @throws RuntimeException if the input is bad.
+//   */
+//  private static AxesWalker createDefaultWalker(Compiler compiler, int opPos,
+//          WalkingIterator lpi, int analysis)
+//  {
+//
+//    AxesWalker ai = null;
+//    int stepType = compiler.getOp(opPos);
+//
+//    /*
+//    System.out.println("0: "+compiler.getOp(opPos));
+//    System.out.println("1: "+compiler.getOp(opPos+1));
+//    System.out.println("2: "+compiler.getOp(opPos+2));
+//    System.out.println("3: "+compiler.getOp(opPos+3));
+//    System.out.println("4: "+compiler.getOp(opPos+4));
+//    System.out.println("5: "+compiler.getOp(opPos+5));
+//    */
+//    boolean simpleInit = false;
+//    int totalNumberWalkers = (analysis & BITS_COUNT);
+//    boolean prevIsOneStepDown = true;
+//
+//    switch (stepType)
+//    {
+//    case OpCodes.OP_VARIABLE :
+//    case OpCodes.OP_EXTFUNCTION :
+//    case OpCodes.OP_FUNCTION :
+//    case OpCodes.OP_GROUP :
+//      prevIsOneStepDown = false;
+//
+//      if (DEBUG_WALKER_CREATION)
+//        System.out.println("new walker:  FilterExprWalker: " + analysis
+//                           + ", " + compiler.toString());
+//
+//      ai = new FilterExprWalker(lpi);
+//      simpleInit = true;
+//      break;
+//    case OpCodes.FROM_ROOT :
+//      ai = new AxesWalker(lpi, Axis.ROOT);
+//      break;
+//    case OpCodes.FROM_ANCESTORS :
+//      prevIsOneStepDown = false;
+//      ai = new ReverseAxesWalker(lpi, Axis.ANCESTOR);
+//      break;
+//    case OpCodes.FROM_ANCESTORS_OR_SELF :
+//      prevIsOneStepDown = false;
+//      ai = new ReverseAxesWalker(lpi, Axis.ANCESTORORSELF);
+//      break;
+//    case OpCodes.FROM_ATTRIBUTES :
+//      ai = new AxesWalker(lpi, Axis.ATTRIBUTE);
+//      break;
+//    case OpCodes.FROM_NAMESPACE :
+//      ai = new AxesWalker(lpi, Axis.NAMESPACE);
+//      break;
+//    case OpCodes.FROM_CHILDREN :
+//      ai = new AxesWalker(lpi, Axis.CHILD);
+//      break;
+//    case OpCodes.FROM_DESCENDANTS :
+//      prevIsOneStepDown = false;
+//      ai = new AxesWalker(lpi, Axis.DESCENDANT);
+//      break;
+//    case OpCodes.FROM_DESCENDANTS_OR_SELF :
+//      prevIsOneStepDown = false;
+//      ai = new AxesWalker(lpi, Axis.DESCENDANTORSELF);
+//      break;
+//    case OpCodes.FROM_FOLLOWING :
+//      prevIsOneStepDown = false;
+//      ai = new AxesWalker(lpi, Axis.FOLLOWING);
+//      break;
+//    case OpCodes.FROM_FOLLOWING_SIBLINGS :
+//      prevIsOneStepDown = false;
+//      ai = new AxesWalker(lpi, Axis.FOLLOWINGSIBLING);
+//      break;
+//    case OpCodes.FROM_PRECEDING :
+//      prevIsOneStepDown = false;
+//      ai = new ReverseAxesWalker(lpi, Axis.PRECEDING);
+//      break;
+//    case OpCodes.FROM_PRECEDING_SIBLINGS :
+//      prevIsOneStepDown = false;
+//      ai = new ReverseAxesWalker(lpi, Axis.PRECEDINGSIBLING);
+//      break;
+//    case OpCodes.FROM_PARENT :
+//      prevIsOneStepDown = false;
+//      ai = new ReverseAxesWalker(lpi, Axis.PARENT);
+//      break;
+//    case OpCodes.FROM_SELF :
+//      ai = new AxesWalker(lpi, Axis.SELF);
+//      break;
+//    default :
+//      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
+//                                 //+ stepType);
+//    }
+//
+//    if (simpleInit)
+//    {
+//      ai.initNodeTest(DTMFilter.SHOW_ALL);
+//    }
+//    else
+//    {
+//      int whatToShow = compiler.getWhatToShow(opPos);
+//
+//      /*
+//      System.out.print("construct: ");
+//      NodeTest.debugWhatToShow(whatToShow);
+//      System.out.println("or stuff: "+(whatToShow & (DTMFilter.SHOW_ATTRIBUTE
+//                             | DTMFilter.SHOW_ELEMENT
+//                             | DTMFilter.SHOW_PROCESSING_INSTRUCTION)));
+//      */
+//      if ((0 == (whatToShow
+//                 & (DTMFilter.SHOW_ATTRIBUTE | DTMFilter.SHOW_NAMESPACE | DTMFilter.SHOW_ELEMENT
+//                    | DTMFilter.SHOW_PROCESSING_INSTRUCTION))) || (whatToShow == DTMFilter.SHOW_ALL))
+//        ai.initNodeTest(whatToShow);
+//      else
+//      {
+//        ai.initNodeTest(whatToShow, compiler.getStepNS(opPos),
+//                        compiler.getStepLocalName(opPos));
+//      }
+//    }
+//
+//    return ai;
+//  }
+//  
+//  public static String getAnalysisString(int analysis)
+//  {
+//    StringBuffer buf = new StringBuffer();
+//    buf.append("count: "+getStepCount(analysis)+" ");
+//    if((analysis & BIT_NODETEST_ANY) != 0)
+//    {
+//      buf.append("NTANY|");
+//    }
+//    if((analysis & BIT_PREDICATE) != 0)
+//    {
+//      buf.append("PRED|");
+//    }
+//    if((analysis & BIT_ANCESTOR) != 0)
+//    {
+//      buf.append("ANC|");
+//    }
+//    if((analysis & BIT_ANCESTOR_OR_SELF) != 0)
+//    {
+//      buf.append("ANCOS|");
+//    }
+//    if((analysis & BIT_ATTRIBUTE) != 0)
+//    {
+//      buf.append("ATTR|");
+//    }
+//    if((analysis & BIT_CHILD) != 0)
+//    {
+//      buf.append("CH|");
+//    }
+//    if((analysis & BIT_DESCENDANT) != 0)
+//    {
+//      buf.append("DESC|");
+//    }
+//    if((analysis & BIT_DESCENDANT_OR_SELF) != 0)
+//    {
+//      buf.append("DESCOS|");
+//    }
+//    if((analysis & BIT_FOLLOWING) != 0)
+//    {
+//      buf.append("FOL|");
+//    }
+//    if((analysis & BIT_FOLLOWING_SIBLING) != 0)
+//    {
+//      buf.append("FOLS|");
+//    }
+//    if((analysis & BIT_NAMESPACE) != 0)
+//    {
+//      buf.append("NS|");
+//    }
+//    if((analysis & BIT_PARENT) != 0)
+//    {
+//      buf.append("P|");
+//    }
+//    if((analysis & BIT_PRECEDING) != 0)
+//    {
+//      buf.append("PREC|");
+//    }
+//    if((analysis & BIT_PRECEDING_SIBLING) != 0)
+//    {
+//      buf.append("PRECS|");
+//    }
+//    if((analysis & BIT_SELF) != 0)
+//    {
+//      buf.append(".|");
+//    }
+//    if((analysis & BIT_FILTER) != 0)
+//    {
+//      buf.append("FLT|");
+//    }
+//    if((analysis & BIT_ROOT) != 0)
+//    {
+//      buf.append("R|");
+//    }
+//    return buf.toString();
+//  }
+//
+//  /** Set to true for diagnostics about walker creation */
+//  static final boolean DEBUG_PATTERN_CREATION = false;
+//
+//  /** Set to true for diagnostics about walker creation */
+//  static final boolean DEBUG_WALKER_CREATION = false;
+//
+//  /** Set to true for diagnostics about iterator creation */
+//  static final boolean DEBUG_ITERATOR_CREATION = false;
+//  
+//  public static boolean hasPredicate(int analysis)
+//  {
+//    return (0 != (analysis & BIT_PREDICATE));
+//  }
+//
+//  public static boolean isWild(int analysis)
+//  {
+//    return (0 != (analysis & BIT_NODETEST_ANY));
+//  }
+//
+//  public static boolean walksAncestors(int analysis)
+//  {
+//    return isSet(analysis, BIT_ANCESTOR | BIT_ANCESTOR_OR_SELF);
+//  }
+//  
+//  public static boolean walksAttributes(int analysis)
+//  {
+//    return (0 != (analysis & BIT_ATTRIBUTE));
+//  }
+//
+//  public static boolean walksNamespaces(int analysis)
+//  {
+//    return (0 != (analysis & BIT_NAMESPACE));
+//  }  
+//
+//  public static boolean walksChildren(int analysis)
+//  {
+//    return (0 != (analysis & BIT_CHILD));
+//  }
+//
+//  public static boolean walksDescendants(int analysis)
+//  {
+//    return isSet(analysis, BIT_DESCENDANT | BIT_DESCENDANT_OR_SELF);
+//  }
+//
+//  public static boolean walksSubtree(int analysis)
+//  {
+//    return isSet(analysis, BIT_DESCENDANT | BIT_DESCENDANT_OR_SELF | BIT_CHILD);
+//  }
+//  
+//  public static boolean walksSubtreeOnlyMaybeAbsolute(int analysis)
+//  {
+//    return walksSubtree(analysis)
+//           && !walksExtraNodes(analysis) 
+//           && !walksUp(analysis) 
+//           && !walksSideways(analysis) 
+//           ;
+//  }
+//  
+//  public static boolean walksSubtreeOnly(int analysis)
+//  {
+//    return walksSubtreeOnlyMaybeAbsolute(analysis) 
+//           && !isAbsolute(analysis) 
+//           ;
+//  }
+//
+//  public static boolean walksFilteredList(int analysis)
+//  {
+//    return isSet(analysis, BIT_FILTER);
+//  }
+//  
+//  public static boolean walksSubtreeOnlyFromRootOrContext(int analysis)
+//  {
+//    return walksSubtree(analysis)
+//           && !walksExtraNodes(analysis) 
+//           && !walksUp(analysis) 
+//           && !walksSideways(analysis) 
+//           && !isSet(analysis, BIT_FILTER) 
+//           ;
+//  }
+//
+//  public static boolean walksInDocOrder(int analysis)
+//  {
+//    return (walksSubtreeOnlyMaybeAbsolute(analysis)
+//           || walksExtraNodesOnly(analysis)
+//           || walksFollowingOnlyMaybeAbsolute(analysis)) 
+//           && !isSet(analysis, BIT_FILTER) 
+//           ;
+//  }
+//  
+//  public static boolean walksFollowingOnlyMaybeAbsolute(int analysis)
+//  {
+//    return isSet(analysis, BIT_SELF | BIT_FOLLOWING_SIBLING | BIT_FOLLOWING)
+//           && !walksSubtree(analysis) 
+//           && !walksUp(analysis) 
+//           && !walksSideways(analysis) 
+//           ;
+//  }
+//  
+//  public static boolean walksUp(int analysis)
+//  {
+//    return isSet(analysis, BIT_PARENT | BIT_ANCESTOR | BIT_ANCESTOR_OR_SELF);
+//  }
+//  
+//  public static boolean walksSideways(int analysis)
+//  {
+//    return isSet(analysis, BIT_FOLLOWING | BIT_FOLLOWING_SIBLING | 
+//                           BIT_PRECEDING | BIT_PRECEDING_SIBLING);
+//  }
+//  
+//  public static boolean walksExtraNodes(int analysis)
+//  {
+//    return isSet(analysis, BIT_NAMESPACE | BIT_ATTRIBUTE);
+//  }
+//
+//  public static boolean walksExtraNodesOnly(int analysis)
+//  {
+//    return walksExtraNodes(analysis)
+//           && !isSet(analysis, BIT_SELF) 
+//           && !walksSubtree(analysis) 
+//           && !walksUp(analysis) 
+//           && !walksSideways(analysis) 
+//           && !isAbsolute(analysis) 
+//           ;
+//  }
+//
+//  public static boolean isAbsolute(int analysis)
+//  {
+//    return isSet(analysis, BIT_ROOT | BIT_FILTER);
+//  }
+//  
+//  public static boolean walksChildrenOnly(int analysis)
+//  {
+//    return walksChildren(analysis)
+//           && !isSet(analysis, BIT_SELF)
+//           && !walksExtraNodes(analysis)
+//           && !walksDescendants(analysis) 
+//           && !walksUp(analysis) 
+//           && !walksSideways(analysis) 
+//           && (!isAbsolute(analysis) || isSet(analysis, BIT_ROOT))
+//           ;
+//  }
+//  
+//  public static boolean walksChildrenAndExtraAndSelfOnly(int analysis)
+//  {
+//    return walksChildren(analysis)
+//           && !walksDescendants(analysis) 
+//           && !walksUp(analysis) 
+//           && !walksSideways(analysis) 
+//           && (!isAbsolute(analysis) || isSet(analysis, BIT_ROOT))
+//           ;
+//  }
+//  
+//  public static boolean walksDescendantsAndExtraAndSelfOnly(int analysis)
+//  {
+//    return !walksChildren(analysis)
+//           && walksDescendants(analysis) 
+//           && !walksUp(analysis) 
+//           && !walksSideways(analysis) 
+//           && (!isAbsolute(analysis) || isSet(analysis, BIT_ROOT))
+//           ;
+//  }
+//  
+//  public static boolean walksSelfOnly(int analysis)
+//  {
+//    return isSet(analysis, BIT_SELF) 
+//           && !walksSubtree(analysis) 
+//           && !walksUp(analysis) 
+//           && !walksSideways(analysis) 
+//           && !isAbsolute(analysis) 
+//           ;
+//  }
+//
+//  
+//  public static boolean walksUpOnly(int analysis)
+//  {
+//    return !walksSubtree(analysis) 
+//           && walksUp(analysis) 
+//           && !walksSideways(analysis) 
+//           && !isAbsolute(analysis) 
+//           ;
+//  }
+//  
+//  public static boolean walksDownOnly(int analysis)
+//  {
+//    return walksSubtree(analysis) 
+//           && !walksUp(analysis) 
+//           && !walksSideways(analysis) 
+//           && !isAbsolute(analysis) 
+//           ;
+//  }
+//
+//  public static boolean walksDownExtraOnly(int analysis)
+//  {
+//    return walksSubtree(analysis) &&  walksExtraNodes(analysis)
+//           && !walksUp(analysis) 
+//           && !walksSideways(analysis) 
+//           && !isAbsolute(analysis) 
+//           ;
+//  }
+//  
+//  public static boolean canSkipSubtrees(int analysis)
+//  {
+//    return isSet(analysis, BIT_CHILD) | walksSideways(analysis);
+//  }
+//  
+//  public static boolean canCrissCross(int analysis)
+//  {
+//    // This could be done faster.  Coded for clarity.
+//    if(walksSelfOnly(analysis))
+//      return false;
+//    else if(walksDownOnly(analysis) && !canSkipSubtrees(analysis))
+//      return false;
+//    else if(walksChildrenAndExtraAndSelfOnly(analysis))
+//      return false;
+//    else if(walksDescendantsAndExtraAndSelfOnly(analysis))
+//      return false;
+//    else if(walksUpOnly(analysis))
+//      return false;
+//    else if(walksExtraNodesOnly(analysis))
+//      return false;
+//    else if(walksSubtree(analysis) 
+//           && (walksSideways(analysis) 
+//            || walksUp(analysis) 
+//            || canSkipSubtrees(analysis)))
+//      return true;
+//    else
+//      return false;
+//  }
+//  
+//  /**
+//   * Tell if the pattern can be 'walked' with the iteration steps in natural 
+//   * document order, without duplicates.
+//   *
+//   * @param analysis The general analysis of the pattern.
+//   *
+//   * @return true if the walk can be done in natural order.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  static public boolean isNaturalDocOrder(int analysis)
+//  {
+//    if(canCrissCross(analysis) || isSet(analysis, BIT_NAMESPACE) ||
+//       walksFilteredList(analysis))
+//      return false;
+//      
+//    if(walksInDocOrder(analysis))
+//      return true;
+//      
+//    return false;
+//  }
+//  
+//  /**
+//   * Tell if the pattern can be 'walked' with the iteration steps in natural 
+//   * document order, without duplicates.
+//   *
+//   * @param compiler non-null reference to compiler object that has processed
+//   *                 the XPath operations into an opcode map.
+//   * @param stepOpCodePos The opcode position for the step.
+//   * @param stepIndex The top-level step index withing the iterator.
+//   * @param analysis The general analysis of the pattern.
+//   *
+//   * @return true if the walk can be done in natural order.
+//   *
+//   * @throws javax.xml.transform.TransformerException
+//   */
+//  private static boolean isNaturalDocOrder(
+//          Compiler compiler, int stepOpCodePos, int stepIndex, int analysis)
+//            throws javax.xml.transform.TransformerException
+//  {
+//    if(canCrissCross(analysis))
+//      return false;
+//      
+//    // Namespaces can present some problems, so just punt if we're looking for 
+//    // these.
+//    if(isSet(analysis, BIT_NAMESPACE))
+//      return false;
+//      
+//    // The following, preceding, following-sibling, and preceding sibling can 
+//    // be found in doc order if we get to this point, but if they occur 
+//    // together, they produce 
+//    // duplicates, so it's better for us to eliminate this case so we don't 
+//    // have to check for duplicates during runtime if we're using a 
+//    // WalkingIterator.
+//    if(isSet(analysis, BIT_FOLLOWING | BIT_FOLLOWING_SIBLING) && 
+//       isSet(analysis, BIT_PRECEDING | BIT_PRECEDING_SIBLING))
+//      return  false;
+//      
+//    // OK, now we have to check for select="@*/axis::*" patterns, which 
+//    // can also cause duplicates to happen.  But select="axis*/@::*" patterns 
+//    // are OK, as are select="@foo/axis::*" patterns.
+//    // Unfortunately, we can't do this just via the analysis bits.
+//    
+//    int stepType;
+//    int ops[] = compiler.getOpMap();
+//    int stepCount = 0;
+//    boolean foundWildAttribute = false;
+//    
+//    // Steps that can traverse anything other than down a 
+//    // subtree or that can produce duplicates when used in 
+//    // combonation are counted with this variable.
+//    int potentialDuplicateMakingStepCount = 0;
+//    
+//    while (OpCodes.ENDOP != (stepType = ops[stepOpCodePos]))
+//    {        
+//      stepCount++;
+//        
+//      switch (stepType)
+//      {
+//      case OpCodes.FROM_ATTRIBUTES :
+//      case OpCodes.MATCH_ATTRIBUTE :
+//        if(foundWildAttribute) // Maybe not needed, but be safe.
+//          return false;
+//        
+//        // This doesn't seem to work as a test for wild card.  Hmph.
+//        // int nodeTestType = compiler.getStepTestType(stepOpCodePos);  
+//        
+//        String localName = compiler.getStepLocalName(stepOpCodePos);
+//        // System.err.println("localName: "+localName);
+//        if(localName.equals("*"))
+//        {
+//          foundWildAttribute = true;
+//        }
+//        break;
+//      case OpCodes.FROM_FOLLOWING :
+//      case OpCodes.FROM_FOLLOWING_SIBLINGS :
+//      case OpCodes.FROM_PRECEDING :
+//      case OpCodes.FROM_PRECEDING_SIBLINGS :
+//      case OpCodes.FROM_PARENT :
+//      case OpCodes.OP_VARIABLE :
+//      case OpCodes.OP_EXTFUNCTION :
+//      case OpCodes.OP_FUNCTION :
+//      case OpCodes.OP_GROUP :
+//      case OpCodes.FROM_NAMESPACE :
+//      case OpCodes.FROM_ANCESTORS :
+//      case OpCodes.FROM_ANCESTORS_OR_SELF :      
+//      case OpCodes.MATCH_ANY_ANCESTOR :
+//      case OpCodes.MATCH_IMMEDIATE_ANCESTOR :
+//      case OpCodes.FROM_DESCENDANTS_OR_SELF :
+//      case OpCodes.FROM_DESCENDANTS :
+//        if(potentialDuplicateMakingStepCount > 0)
+//            return false;
+//        potentialDuplicateMakingStepCount++;
+//      case OpCodes.FROM_ROOT :
+//      case OpCodes.FROM_CHILDREN :
+//      case OpCodes.FROM_SELF :
+//        if(foundWildAttribute)
+//          return false;
+//        break;
+//      default :
+//        throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[]{Integer.toString(stepType)})); //"Programmer's assertion: unknown opcode: "
+//                                  // + stepType);
+//      }
+//
+//      int nextStepOpCodePos = compiler.getNextStepPos(stepOpCodePos);
+//
+//      if (nextStepOpCodePos < 0)
+//        break;
+//              
+//      stepOpCodePos = nextStepOpCodePos;
+//    }
+//
+//    return true;
+//  }
+//  
+//  public static boolean isOneStep(int analysis)
+//  {
+//    return (analysis & BITS_COUNT) == 0x00000001;
+//  }
+//
+//  public static int getStepCount(int analysis)
+//  {
+//    return (analysis & BITS_COUNT);
+//  }
+//
+//  /**
+//   * First 8 bits are the number of top-level location steps.  Hopefully
+//   *  there will never be more that 255 location steps!!!
+//   */
+//  public static final int BITS_COUNT = 0x000000FF;
+//
+//  /** 4 bits are reserved for future use. */
+//  public static final int BITS_RESERVED = 0x00000F00;
+//
+//  /** Bit is on if the expression contains a top-level predicate. */
+//  public static final int BIT_PREDICATE = (0x00001000);
+//
+//  /** Bit is on if any of the walkers contain an ancestor step. */
+//  public static final int BIT_ANCESTOR = (0x00001000 << 1);
+//
+//  /** Bit is on if any of the walkers contain an ancestor-or-self step. */
+//  public static final int BIT_ANCESTOR_OR_SELF = (0x00001000 << 2);
+//
+//  /** Bit is on if any of the walkers contain an attribute step. */
+//  public static final int BIT_ATTRIBUTE = (0x00001000 << 3);
+//
+//  /** Bit is on if any of the walkers contain a child step. */
+//  public static final int BIT_CHILD = (0x00001000 << 4);
+//
+//  /** Bit is on if any of the walkers contain a descendant step. */
+//  public static final int BIT_DESCENDANT = (0x00001000 << 5);
+//
+//  /** Bit is on if any of the walkers contain a descendant-or-self step. */
+//  public static final int BIT_DESCENDANT_OR_SELF = (0x00001000 << 6);
+//
+//  /** Bit is on if any of the walkers contain a following step. */
+//  public static final int BIT_FOLLOWING = (0x00001000 << 7);
+//
+//  /** Bit is on if any of the walkers contain a following-sibiling step. */
+//  public static final int BIT_FOLLOWING_SIBLING = (0x00001000 << 8);
+//
+//  /** Bit is on if any of the walkers contain a namespace step. */
+//  public static final int BIT_NAMESPACE = (0x00001000 << 9);
+//
+//  /** Bit is on if any of the walkers contain a parent step. */
+//  public static final int BIT_PARENT = (0x00001000 << 10);
+//
+//  /** Bit is on if any of the walkers contain a preceding step. */
+//  public static final int BIT_PRECEDING = (0x00001000 << 11);
+//
+//  /** Bit is on if any of the walkers contain a preceding-sibling step. */
+//  public static final int BIT_PRECEDING_SIBLING = (0x00001000 << 12);
+//
+//  /** Bit is on if any of the walkers contain a self step. */
+//  public static final int BIT_SELF = (0x00001000 << 13);
+//
+//  /**
+//   * Bit is on if any of the walkers contain a filter (i.e. id(), extension
+//   *  function, etc.) step.
+//   */
+//  public static final int BIT_FILTER = (0x00001000 << 14);
+//
+//  /** Bit is on if any of the walkers contain a root step. */
+//  public static final int BIT_ROOT = (0x00001000 << 15);
+//
+//  /**
+//   * If any of these bits are on, the expression may likely traverse outside
+//   *  the given subtree.
+//   */
+//  public static final int BITMASK_TRAVERSES_OUTSIDE_SUBTREE = (BIT_NAMESPACE  // ??
+//                                                                | BIT_PRECEDING_SIBLING
+//                                                                | BIT_PRECEDING
+//                                                                | BIT_FOLLOWING_SIBLING
+//                                                                | BIT_FOLLOWING
+//                                                                | BIT_PARENT  // except parent of attrs.
+//                                                                | BIT_ANCESTOR_OR_SELF
+//                                                                | BIT_ANCESTOR
+//                                                                | BIT_FILTER
+//                                                                | BIT_ROOT);
+//
+//  /**
+//   * Bit is on if any of the walkers can go backwards in document
+//   *  order from the context node.
+//   */
+//  public static final int BIT_BACKWARDS_SELF = (0x00001000 << 16);
+//
+//  /** Found "//foo" pattern */
+//  public static final int BIT_ANY_DESCENDANT_FROM_ROOT = (0x00001000 << 17);
+//
+//  /**
+//   * Bit is on if any of the walkers contain an node() test.  This is
+//   *  really only useful if the count is 1.
+//   */
+//  public static final int BIT_NODETEST_ANY = (0x00001000 << 18);
+//
+//  // can't go higher than 18!
+//
+//  /** Bit is on if the expression is a match pattern. */
+//  public static final int BIT_MATCH_PATTERN = (0x00001000 << 19);
+//}
diff --git a/src/org/apache/xpath/axes/WalkingIterator.java b/src/org/apache/xpath/axes/WalkingIterator.java
index a25a347..5ce5318 100644
--- a/src/org/apache/xpath/axes/WalkingIterator.java
+++ b/src/org/apache/xpath/axes/WalkingIterator.java
@@ -1,50 +1,45 @@
 package org.apache.xpath.axes;
 
-import java.util.Vector;
-
 import javax.xml.transform.TransformerException;
+
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.utils.PrefixResolver;
 import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.VariableStack;
 import org.apache.xpath.XPathVisitor;
-import org.apache.xpath.compiler.Compiler;
+import org.apache.xpath.parser.Node;
+import org.apache.xpath.parser.NonExecutableExpression;
 
 /**
  * Location path iterator that uses Walkers.
  */
 
 public class WalkingIterator extends LocPathIterator implements ExpressionOwner
-{
+{  
   /**
-   * Create a WalkingIterator iterator, including creation
-   * of step walkers from the opcode list, and call back
-   * into the Compiler to create predicate expressions.
+   * Create a WalkingIterator object.
    *
-   * @param compiler The Compiler which is creating
-   * this expression.
-   * @param opPos The position of this iterator in the
-   * opcode list from the compiler.
-   * @param shouldLoadWalkers True if walkers should be
-   * loaded, or false if this is a derived iterator and
-   * it doesn't wish to load child walkers.
-   *
-   * @throws javax.xml.transform.TransformerException
+   * @param nscontext The namespace context for this iterator,
+   * should be OK if null.
    */
-  WalkingIterator(
-          Compiler compiler, int opPos, int analysis, boolean shouldLoadWalkers)
-            throws javax.xml.transform.TransformerException
+  public WalkingIterator(PrefixResolver nscontext, org.apache.xpath.parser.PathExpr path)
   {
-    super(compiler, opPos, analysis, shouldLoadWalkers);
-    
-    int firstStepPos = compiler.getFirstChildPos(opPos);
 
-    if (shouldLoadWalkers)
+    super(nscontext);
+    
+    try
     {
-      m_firstWalker = WalkerFactory.loadWalkers(this, compiler, firstStepPos, 0);
-      m_lastUsedWalker = m_firstWalker;
+    	m_firstWalker = WalkerFactory.loadWalkers(path, this);
+    	m_lastUsedWalker = m_firstWalker;
     }
+    catch(TransformerException te)
+    {
+    	throw new org.apache.xml.utils.WrappedRuntimeException(te);
+    }
+
   }
   
   /**
@@ -55,9 +50,9 @@
    */
   public WalkingIterator(PrefixResolver nscontext)
   {
-
     super(nscontext);
   }
+
   
   
   /** 
@@ -264,7 +259,7 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
     m_predicateIndex = -1;
 
@@ -272,7 +267,7 @@
 
     while (null != walker)
     {
-      walker.fixupVariables(vars, globalsSize);
+      walker.fixupVariables(vcs);
       walker = walker.getNextWalker();
     }
   }
@@ -313,6 +308,7 @@
    */
   public void setExpression(Expression exp)
   {
+    // assertion(null != exp, "Expression owner can not be set to null!");
   	exp.exprSetParent(this);
   	m_firstWalker = (AxesWalker)exp;
   }
@@ -341,4 +337,51 @@
       return true;
     }
 
+  public Node jjtGetChild(int i) 
+  {
+    int superclassChildCount = super.jjtGetNumChildren();
+    if((null != m_firstWalker) && i == 0)
+    	return m_firstWalker;
+    else
+    	return super.jjtGetChild(i-((null == m_firstWalker) ? 0 : 1));
+  }
+
+  public int jjtGetNumChildren() 
+  {
+  	int superChildCount = super.jjtGetNumChildren();
+    return superChildCount+((null == m_firstWalker) ? 0 : 1);
+  }
+  
+  
+
+  /**
+   * @see org.apache.xpath.parser.SimpleNode#checkTreeIntegrity(int, int, boolean)
+   */
+  public boolean checkTreeIntegrity(
+    int levelCount,
+    int childNumber,
+    boolean parentOK)
+  {
+    ExpressionNode expOwner = getExpressionOwner();
+    if(null != expOwner)
+    {
+      if(!(expOwner instanceof Node))
+        parentOK = flagProblem(" Expression owner is not a Node! It's a "+expOwner.getClass().getName());
+      else if(expOwner instanceof NonExecutableExpression)
+        parentOK = flagProblem(" Expression owner is a NonExecutableExpression!");
+    }
+    return super.checkTreeIntegrity(levelCount, childNumber, parentOK);
+  
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtClose()
+   */
+  public void jjtClose()
+  {
+    if(null == getExpressionOwner())
+      flagProblem("The expression owner can not be null on jjtClose!");
+    super.jjtClose();
+  }
+
 }
\ No newline at end of file
diff --git a/src/org/apache/xpath/axes/WalkingIteratorSorted.java b/src/org/apache/xpath/axes/WalkingIteratorSorted.java
index b056d2c..197c9b2 100644
--- a/src/org/apache/xpath/axes/WalkingIteratorSorted.java
+++ b/src/org/apache/xpath/axes/WalkingIteratorSorted.java
@@ -56,12 +56,9 @@
  */
 package org.apache.xpath.axes;
 
-import org.apache.xpath.XPathContext;
-import org.apache.xml.utils.PrefixResolver;
-import org.apache.xpath.compiler.Compiler;
-import org.apache.xml.dtm.DTM;
-import org.apache.xml.dtm.DTMIterator;
 import org.apache.xml.dtm.Axis;
+import org.apache.xml.utils.PrefixResolver;
+import org.apache.xpath.VariableComposeState;
 
 /**
  * <meta name="usage" content="internal"/>
@@ -83,31 +80,9 @@
    * @param nscontext The namespace context for this iterator,
    * should be OK if null.
    */
-  public WalkingIteratorSorted(PrefixResolver nscontext)
+  public WalkingIteratorSorted(PrefixResolver nscontext, org.apache.xpath.parser.PathExpr path)
   {
-    super(nscontext);
-  }
-
-  /**
-   * Create a WalkingIterator iterator, including creation
-   * of step walkers from the opcode list, and call back
-   * into the Compiler to create predicate expressions.
-   *
-   * @param compiler The Compiler which is creating
-   * this expression.
-   * @param opPos The position of this iterator in the
-   * opcode list from the compiler.
-   * @param shouldLoadWalkers True if walkers should be
-   * loaded, or false if this is a derived iterator and
-   * it doesn't wish to load child walkers.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  WalkingIteratorSorted(
-          Compiler compiler, int opPos, int analysis, boolean shouldLoadWalkers)
-            throws javax.xml.transform.TransformerException
-  {
-    super(compiler, opPos, analysis, shouldLoadWalkers);
+    super(nscontext, path);
   }
   
   /**
@@ -120,7 +95,6 @@
   {
     return m_inNaturalOrderStatic;
   }
-
     
   /**
    * Tell if the nodeset can be walked in doc order, via static analysis. 
@@ -231,9 +205,9 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    super.fixupVariables(vars, globalsSize);
+    super.fixupVariables(vcs);
 
     int analysis = getAnalysisBits();
     if(WalkerFactory.isNaturalDocOrder(analysis))
@@ -249,4 +223,12 @@
     
   }
 
+  /**
+   * @see java.lang.Object#toString()
+   */
+  public String toString()
+  {
+    return "(sorted node list) "+super.toString();
+  }
+
 }
diff --git a/src/org/apache/xpath/conditional/Else.java b/src/org/apache/xpath/conditional/Else.java
new file mode 100644
index 0000000..6975f4a
--- /dev/null
+++ b/src/org/apache/xpath/conditional/Else.java
@@ -0,0 +1,137 @@
+/* Generated By:JJTree: Do not edit this line. Else.java */
+
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.xpath.conditional;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+public class Else extends Expression implements ExpressionOwner
+{
+	
+	private Expression m_expression;
+	
+  public Else() {
+    super();
+  }
+
+  /** Accept the visitor. **/
+  public Object jjtAccept(org.apache.xpath.parser.XPathVisitor visitor, Object data) {
+    return visitor.visit(this, data);
+  }
+  
+  /**
+   * @see Expression#deepEquals(Expression)
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    return false;
+  }
+
+  /**
+   * @see Expression#fixupVariables(Vector, int)
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+  }
+
+
+  /**
+   * @see Expression#execute(XPathContext)
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+  	// but don't call this directly!
+    return m_expression.execute(xctxt);
+  }
+
+
+  /**
+   * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
+   */
+  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
+  {
+  }
+
+
+  /**
+   * @see ExpressionOwner#getExpression()
+   */
+  public Expression getExpression()
+  {
+    return m_expression;
+  }
+
+
+  /**
+   * @see ExpressionOwner#setExpression(Expression)
+   */
+  public void setExpression(Expression exp)
+  {
+  	m_expression = exp;
+  }
+
+
+}
diff --git a/src/org/apache/xpath/conditional/If.java b/src/org/apache/xpath/conditional/If.java
new file mode 100644
index 0000000..8467d69
--- /dev/null
+++ b/src/org/apache/xpath/conditional/If.java
@@ -0,0 +1,255 @@
+/* Generated By:JJTree: Do not edit this line. IfLpar.java */
+
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.xpath.conditional;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.parser.IfExpr;
+import org.apache.xpath.parser.Node;
+
+public class If extends Expression implements ExpressionOwner
+{
+
+  public If()
+  {
+    super();
+  }
+
+  /** Accept the visitor. **/
+  public Object jjtAccept(
+    org.apache.xpath.parser.XPathVisitor visitor,
+    Object data)
+  {
+    return visitor.visit(this, data);
+  }
+
+  /**
+   * @see Expression#deepEquals(Expression)
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    return false;
+  }
+
+  /**
+   * @see Expression#fixupVariables(Vector, int)
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+  }
+
+  /**
+   * @see Expression#execute(XPathContext)
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+    
+    XObject test = m_test.execute(xctxt);
+
+      if (test.bool())
+      {
+      	// Execute Then expression
+      	return m_then.execute(xctxt);
+      	
+      }
+      else
+      {
+      	// execute else expression
+      	return m_else.execute(xctxt); 
+      }
+  }
+
+  /**
+   * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
+   */
+  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
+  {
+  }
+
+  /**
+   * @see ExpressionOwner#getExpression()
+   */
+  public Expression getExpression()
+  {
+    return null;
+  }
+
+  /**
+   * @see ExpressionOwner#setExpression(Expression)
+   */
+  public void setExpression(Expression exp)
+  {
+  }
+
+  Expression m_test;
+
+  Expression m_then;
+
+  Expression m_else;
+
+  /**
+   * Returns the e.
+   * @return Expression
+   */
+  public Expression getElse()
+  {
+    return m_else;
+  }
+
+  /**
+   * Returns the test.
+   * @return Expression
+   */
+  public Expression getTest()
+  {
+    return m_test;
+  }
+
+  /**
+   * Returns the then.
+   * @return Expression
+   */
+  public Expression getThen()
+  {
+    return m_then;
+  }
+
+  /**
+   * Sets the e.
+   * @param e The e to set
+   */
+  public void setElse(Expression e)
+  {
+    m_else = e;
+  }
+
+  /**
+   * Sets the test.
+   * @param test The test to set
+   */
+  public void setTest(Expression test)
+  {
+    m_test = test;
+  }
+
+  /**
+   * Sets the then.
+   * @param then The then to set
+   */
+  public void setThen(Expression then)
+  {
+    m_then = then;
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtSetParent(Node)
+   */
+  public void jjtSetParent(Node n)
+  {
+    super.jjtSetParent(n);
+    if (n instanceof IfExpr) // don't fix up if we're reducing
+    {
+      IfExpr ifexpr = (IfExpr) n;
+
+      // At this point all children should have been added except this node.
+      // This has a fixed number of children.
+      m_test = (Expression) ifexpr.jjtGetChild(1);
+      m_test.jjtSetParent(this);
+      m_then = (Expression) ifexpr.jjtGetChild(3);
+      m_then.jjtSetParent(this);
+      m_else = (Expression) ifexpr.jjtGetChild(5);
+      m_else.jjtSetParent(this);
+
+      ifexpr.m_exprs.setSize(1);
+    }
+  }
+  
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtGetChild(int)
+   */
+  public Node jjtGetChild(int i)
+  {
+    return (i == 0) ? m_test : (i == 1) ? m_then : (i == 2) ? m_else : null;
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtGetNumChildren()
+   */
+  public int jjtGetNumChildren()
+  {
+    return 3;
+  }
+
+  /**
+   * @see org.apache.xpath.parser.SimpleNode#isPathExprReduced()
+   */
+  public boolean isPathExprReduced()
+  {
+    return false; // never reduce.
+  }
+
+}
diff --git a/src/org/apache/xpath/conditional/Then.java b/src/org/apache/xpath/conditional/Then.java
new file mode 100644
index 0000000..1e0edcb
--- /dev/null
+++ b/src/org/apache/xpath/conditional/Then.java
@@ -0,0 +1,137 @@
+/* Generated By:JJTree: Do not edit this line. Then.java */
+
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.xpath.conditional;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+public class Then extends Expression implements ExpressionOwner
+{
+	
+	private Expression m_expression;
+	
+  public Then() {
+    super();
+  }
+
+  /** Accept the visitor. **/
+  public Object jjtAccept(org.apache.xpath.parser.XPathVisitor visitor, Object data) {
+    return visitor.visit(this, data);
+  }
+  
+  /**
+   * @see Expression#deepEquals(Expression)
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    return false;
+  }
+
+  /**
+   * @see Expression#fixupVariables(Vector, int)
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+  }
+
+
+  /**
+   * @see Expression#execute(XPathContext)
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+  	// but don't call this directly!
+    return m_expression.execute(xctxt);
+  }
+
+
+  /**
+   * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
+   */
+  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
+  {
+  }
+
+
+  /**
+   * @see ExpressionOwner#getExpression()
+   */
+  public Expression getExpression()
+  {
+    return m_expression;
+  }
+
+
+  /**
+   * @see ExpressionOwner#setExpression(Expression)
+   */
+  public void setExpression(Expression exp)
+  {
+  	m_expression = exp;
+  }
+
+
+}
diff --git a/src/org/apache/xpath/functions/FuncAddDTDurationToDT.java b/src/org/apache/xpath/functions/FuncAddDTDurationToDT.java
new file mode 100644
index 0000000..feab7c1
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncAddDTDurationToDT.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDateTime;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncAddDTDurationToDT extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dateTime = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    Duration duration = Duration.DTDuration(m_arg1.execute(xctxt).str());
+    if (dateTime == null || duration == null)
+    return new XDateTime(); 
+    DateTimeObj dt = dateTime.addDTDurationToDateTime(duration);
+    return new XDateTime(dt);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncAddDTDurationToDate.java b/src/org/apache/xpath/functions/FuncAddDTDurationToDate.java
new file mode 100644
index 0000000..b4af46d
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncAddDTDurationToDate.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDate;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncAddDTDurationToDate extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date = DateTimeObj.date(m_arg0.execute(xctxt).str());
+    Duration duration = Duration.DTDuration(m_arg1.execute(xctxt).str());
+    if (date == null || duration == null)
+    return new XDate();
+    DateTimeObj dt = date.addDTDurationToDate(duration);
+    return new XDate(dt);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncAddDTDurationToTime.java b/src/org/apache/xpath/functions/FuncAddDTDurationToTime.java
new file mode 100644
index 0000000..199c1a7
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncAddDTDurationToTime.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XTime;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncAddDTDurationToTime extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj time = DateTimeObj.time(m_arg0.execute(xctxt).str());
+    Duration duration = Duration.DTDuration(m_arg1.execute(xctxt).str());
+    if (time == null || duration == null)
+    return new XTime();   
+    DateTimeObj dt = time.addDTDurationToTime(duration);
+    return new XTime(dt);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncAddDayTimeDuration.java b/src/org/apache/xpath/functions/FuncAddDayTimeDuration.java
new file mode 100644
index 0000000..343e8a4
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncAddDayTimeDuration.java
@@ -0,0 +1,103 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncAddDayTimeDuration extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration1 = Duration.DTDuration(m_arg0.execute(xctxt).str());
+    Duration duration2 = Duration.DTDuration(m_arg1.execute(xctxt).str());
+    if (duration1 == null || duration2 == null)
+    return new XDuration();
+    Duration du = duration1.addDTDuration(duration2);
+    return new XDuration(du);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncAddDays.java b/src/org/apache/xpath/functions/FuncAddDays.java
new file mode 100644
index 0000000..9a9e119
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncAddDays.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDate;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncAddDays extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    String dateTime = m_arg0.execute(xctxt).str();
+    DateTimeObj date = DateTimeObj.date(dateTime);
+    if (date == null)
+    return new XDate();
+    DateTimeObj dt = date.addDays(m_arg1.num(xctxt));
+    return new XDate(dt);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncAddYMDurationToDT.java b/src/org/apache/xpath/functions/FuncAddYMDurationToDT.java
new file mode 100644
index 0000000..b15af7f
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncAddYMDurationToDT.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDateTime;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncAddYMDurationToDT extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dateTime = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    Duration duration = Duration.YMDuration(m_arg1.execute(xctxt).str());
+    if (dateTime == null || duration == null)
+    return new XDateTime();
+    DateTimeObj dt = dateTime.addYMDurationToDateTime(duration);
+    return new XDateTime(dt);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncAddYMDurationToDate.java b/src/org/apache/xpath/functions/FuncAddYMDurationToDate.java
new file mode 100644
index 0000000..1d46774
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncAddYMDurationToDate.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDate;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncAddYMDurationToDate extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date = DateTimeObj.date(m_arg0.execute(xctxt).str());
+    Duration duration = Duration.YMDuration(m_arg1.execute(xctxt).str());
+    if (date == null || duration == null)
+    return new XDate();
+    DateTimeObj dt = date.addYMDurationToDate(duration);
+    return new XDate(dt);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncAddYearMonthDuration.java b/src/org/apache/xpath/functions/FuncAddYearMonthDuration.java
new file mode 100644
index 0000000..b83e81a
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncAddYearMonthDuration.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncAddYearMonthDuration extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration1 = Duration.YMDuration(m_arg0.execute(xctxt).str());
+    Duration duration2 = Duration.YMDuration(m_arg1.execute(xctxt).str());
+    if (duration1 == null || duration2 == null)
+    return new XDuration();
+    Duration du = duration1.addYMDuration(duration2);
+    return new XDuration(du);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncCeiling.java b/src/org/apache/xpath/functions/FuncCeiling.java
index 19b2c0d..e8dabd0 100644
--- a/src/org/apache/xpath/functions/FuncCeiling.java
+++ b/src/org/apache/xpath/functions/FuncCeiling.java
@@ -56,16 +56,10 @@
  */
 package org.apache.xpath.functions;
 
-import java.lang.Math;
-
-//import org.w3c.dom.Node;
-
-import java.util.Vector;
-
+import javax.xml.transform.TransformerException;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XDouble;
 import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -84,6 +78,6 @@
    */
   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
   {
-    return new XNumber(Math.ceil(m_arg0.execute(xctxt).num()));
+    return new XDouble(Math.ceil(m_arg0.execute(xctxt).num()));
   }
 }
diff --git a/src/org/apache/xpath/functions/FuncCount.java b/src/org/apache/xpath/functions/FuncCount.java
index 2368fd2..1a81b4a 100644
--- a/src/org/apache/xpath/functions/FuncCount.java
+++ b/src/org/apache/xpath/functions/FuncCount.java
@@ -69,6 +69,7 @@
 import org.apache.xpath.XPath;
 import org.apache.xpath.objects.XObject;
 import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XSequence;
 import org.apache.xpath.objects.XString;
 
 /**
@@ -100,10 +101,10 @@
 //      i++;
 //    }
 //    nl.detach();
-	DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
+	XSequence nl = m_arg0.execute(xctxt).xseq();
 	int i = nl.getLength();	
 	nl.detach();
 
-    return new XNumber((double) i);
+    return new org.apache.xpath.objects.XInteger(i);
   }
 }
diff --git a/src/org/apache/xpath/functions/FuncCurrent.java b/src/org/apache/xpath/functions/FuncCurrent.java
index ea7e2e4..bf628fb 100644
--- a/src/org/apache/xpath/functions/FuncCurrent.java
+++ b/src/org/apache/xpath/functions/FuncCurrent.java
@@ -56,23 +56,14 @@
  */
 package org.apache.xpath.functions;
 
-import org.apache.xpath.res.XPATHErrorResources;
-
-//import org.w3c.dom.Node;
-//import org.w3c.dom.traversal.NodeIterator;
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMIterator;
-
-import java.util.Vector;
-
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.XPath;
-import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNodeSet;
-import org.apache.xpath.axes.PredicatedNodeTest;
 import org.apache.xpath.axes.LocPathIterator;
-import org.apache.xpath.axes.ContextNodeList;
-import org.apache.xpath.axes.SubContextList;
+import org.apache.xpath.axes.PredicatedNodeTest;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XObject;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -137,7 +128,7 @@
   /**
    * No arguments to process, so this does nothing.
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
     // no-op
   }
diff --git a/src/org/apache/xpath/functions/FuncCurrentDate.java b/src/org/apache/xpath/functions/FuncCurrentDate.java
new file mode 100644
index 0000000..3c14266
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncCurrentDate.java
@@ -0,0 +1,86 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XDate;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncCurrentDate extends FunctionDef1Arg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+
+    return new XDate(DateTimeObj.currentDateTime(DateTimeObj.dt1));
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncCurrentDateTime.java b/src/org/apache/xpath/functions/FuncCurrentDateTime.java
new file mode 100644
index 0000000..9270990
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncCurrentDateTime.java
@@ -0,0 +1,99 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDateTime;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncCurrentDateTime extends FunctionDef1Arg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+
+    return new XDateTime(DateTimeObj.currentDateTime(DateTimeObj.dt1));
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDTDuration.java b/src/org/apache/xpath/functions/FuncDTDuration.java
new file mode 100644
index 0000000..fbef67e
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDTDuration.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDTDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncDTDuration extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    String du = m_arg0.execute(xctxt).str();
+    Duration d = Duration.DTDuration(du);
+    if (d == null)
+    return new XDTDuration();
+    else 
+    return new XDTDuration(d);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDTDurationEqual.java b/src/org/apache/xpath/functions/FuncDTDurationEqual.java
new file mode 100644
index 0000000..1dbcea4
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDTDurationEqual.java
@@ -0,0 +1,107 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xml.utils.Duration;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncDTDurationEqual extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration1 = Duration.DTDuration(m_arg0.execute(xctxt).str());
+    Duration duration2 = Duration.DTDuration(m_arg1.execute(xctxt).str());
+    if (duration1 == null || duration2 == null)
+    return new XBoolean(false);
+    else
+    {
+    boolean eq = duration1.DTEqual(duration2);
+    return new XBoolean(eq);
+    }
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDTDurationFromSecs.java b/src/org/apache/xpath/functions/FuncDTDurationFromSecs.java
new file mode 100644
index 0000000..3c0cfca
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDTDurationFromSecs.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncDTDurationFromSecs extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    double secs = m_arg0.execute(xctxt).num();
+    Duration d = Duration.DTDurationFromSecs(secs);
+    if (d == null)
+    return new XDuration();
+    else 
+    return new XDuration(d);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDTDurationGT.java b/src/org/apache/xpath/functions/FuncDTDurationGT.java
new file mode 100644
index 0000000..e52bea0
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDTDurationGT.java
@@ -0,0 +1,107 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xml.utils.Duration;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncDTDurationGT extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration1 = Duration.DTDuration(m_arg0.execute(xctxt).str());
+    Duration duration2 = Duration.DTDuration(m_arg1.execute(xctxt).str());
+    if (duration1 == null || duration2 == null)
+    return new XBoolean(false);
+    else
+    { 
+    boolean eq = duration1.DTGreaterThan(duration2);
+    return new XBoolean(eq);
+    }
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDTDurationLT.java b/src/org/apache/xpath/functions/FuncDTDurationLT.java
new file mode 100644
index 0000000..41259e0
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDTDurationLT.java
@@ -0,0 +1,107 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xml.utils.Duration;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncDTDurationLT extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration1 = Duration.DTDuration(m_arg0.execute(xctxt).str());
+    Duration duration2 = Duration.DTDuration(m_arg1.execute(xctxt).str());
+    if (duration1 == null || duration2 == null)
+    return new XBoolean(false);
+    else
+    {
+    boolean eq = duration1.DTLessThan(duration2);
+    return new XBoolean(eq);
+    }
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncData.java b/src/org/apache/xpath/functions/FuncData.java
new file mode 100644
index 0000000..b739ed3
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncData.java
@@ -0,0 +1,132 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xalan.res.XSLMessages;
+import org.apache.xalan.res.XSLTErrorResources;
+import org.apache.xml.dtm.DTMSequence;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XJavaObject;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the data() function. Not supported before
+ * XPath/XSLT 2.0.
+ */
+public class FuncData extends FunctionOneArg
+{
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    XObject src=m_arg0.execute(xctxt);
+    
+//    /* This should have been checked at stylesheet build,
+//     * and hence ought to be superfluous.
+//     * %REVIEW% %OPT%
+//     * */
+//    if("1.0".equals(xctxt.getXPathVersion()))
+//    {
+//    	xctxt.getErrorListener().error(
+//    		new TransformerException(
+//    		XSLMessages.createMessage(XSLTErrorResources.ER_NOT_SUPPORTED,
+//    			new Object[]{"XSLT 2.0 data()"}), 
+//    			xctxt.getSAXLocator())); 
+//    		//"Illegal value for xml:space", locator));
+//    	// If error listener returns...
+//    	return src;
+//    }
+    
+    if(src.getType()==src.CLASS_NODESET)
+    {      
+    	int sourceHandle=src.iter().item(0);
+    	
+	    if(sourceHandle==org.apache.xml.dtm.DTM.NULL)
+    	return /*new XJavaObject*/(org.apache.xpath.objects.XSequence.EMPTY);
+    	
+    	org.apache.xml.dtm.DTM sourceDTM=xctxt.getDTM(sourceHandle);
+
+		DTMSequence seq=sourceDTM.getTypedValue(sourceHandle);
+		
+		// %TODO% Other kinds of objects?
+		return new org.apache.xpath.objects.XDTMSequence(seq);
+    }
+    
+    // %TODO% %REVIEW% See issues 80, 81, 231, ....
+    // There seem to be some conflicts here.
+    //
+    // "Consensus is to define data() on only singleton node and empty sequence"
+    // "Open issue as to whether data() should be defined on node sequences."
+    // "NB: Current definition of data() applied to a text node is the empty sequence."
+    // "data() applied to simple value is identity function (no-op)"
+    //
+    // "xf:data(): decided that it should return the error object when applied to document, PI,
+    // comment and namespace nodes." (What is "the error object"?)
+    
+    else return src; // %TODO% Awaiting typed non-nodes...
+  }
+  
+}
diff --git a/src/org/apache/xpath/functions/FuncDate.java b/src/org/apache/xpath/functions/FuncDate.java
new file mode 100644
index 0000000..28427a1
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDate.java
@@ -0,0 +1,87 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XDate;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncDate extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date = DateTimeObj.date(m_arg0.execute(xctxt).str());
+    return new XDate(date);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDateTime.java b/src/org/apache/xpath/functions/FuncDateTime.java
new file mode 100644
index 0000000..158a20a
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDateTime.java
@@ -0,0 +1,102 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDateTime;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:dateTime() function.
+ */
+public class FuncDateTime extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    if (date == null)
+    return new XDateTime(); 
+    return new XDateTime(date);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDateTimeEq.java b/src/org/apache/xpath/functions/FuncDateTimeEq.java
new file mode 100644
index 0000000..0f5e0d7
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDateTimeEq.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:dateTime() function.
+ */
+public class FuncDateTimeEq extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date1 = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    DateTimeObj date2 = DateTimeObj.dateTime(m_arg1.execute(xctxt).str());
+    if (date1 == null || date2 == null)
+    return new XBoolean(false);
+    boolean eq = date1.equals(date2);
+    return new XBoolean(eq);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDateTimeGT.java b/src/org/apache/xpath/functions/FuncDateTimeGT.java
new file mode 100644
index 0000000..93591cc
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDateTimeGT.java
@@ -0,0 +1,107 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:dateTime() function.
+ */
+public class FuncDateTimeGT extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date1 = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    DateTimeObj date2 = DateTimeObj.dateTime(m_arg1.execute(xctxt).str());
+    if (date1 == null || date2 == null)
+    return new XBoolean(false);
+    else
+    {
+    boolean eq = date1.greaterThan(date2);
+    return new XBoolean(eq);
+    }
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDateTimeLT.java b/src/org/apache/xpath/functions/FuncDateTimeLT.java
new file mode 100644
index 0000000..b6b47ab
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDateTimeLT.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:dateTime() function.
+ */
+public class FuncDateTimeLT extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date1 = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    DateTimeObj date2 = DateTimeObj.dateTime(m_arg1.execute(xctxt).str());
+    if (date1 == null || date2 == null)
+    return new XBoolean(false); 
+    boolean eq = date1.lessThan(date2);
+    return new XBoolean(eq);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDivDayTimeDuration.java b/src/org/apache/xpath/functions/FuncDivDayTimeDuration.java
new file mode 100644
index 0000000..4da7422
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDivDayTimeDuration.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:divide-dayTimeDuration() function.
+ */
+public class FuncDivDayTimeDuration extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration = Duration.DTDuration(m_arg0.execute(xctxt).str());
+    if (duration == null)
+    return new XDuration();
+    Duration du = duration.divideDTDuration(m_arg1.num(xctxt));
+    return new XDuration(du);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDivYearMonthDuration.java b/src/org/apache/xpath/functions/FuncDivYearMonthDuration.java
new file mode 100644
index 0000000..75ba9c5
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDivYearMonthDuration.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:divide-yearMonthDuration() function.
+ */
+public class FuncDivYearMonthDuration extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration = Duration.YMDuration(m_arg0.execute(xctxt).str());
+    if (duration == null)
+    return new XDuration();
+    Duration du = duration.divideYMDuration(m_arg1.num(xctxt));
+    return new XDuration(du);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDuration.java b/src/org/apache/xpath/functions/FuncDuration.java
new file mode 100644
index 0000000..25fce5d
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDuration.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncDuration extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    String du = m_arg0.execute(xctxt).str();
+    Duration d = Duration.duration(new Duration(du));
+    if (d == null)
+    return new XDuration();
+    else 
+    return new XDuration(d);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncDurationEqual.java b/src/org/apache/xpath/functions/FuncDurationEqual.java
new file mode 100644
index 0000000..55cc5e4
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncDurationEqual.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xml.utils.Duration;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncDurationEqual extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration1 = Duration.duration(new Duration(m_arg0.execute(xctxt).str()));
+    Duration duration2 = Duration.duration(new Duration(m_arg1.execute(xctxt).str()));
+    if(duration1 == null || duration2 == null)
+    return new XBoolean(false); 
+    boolean eq = duration1.equals(duration2);
+    return new XBoolean(eq);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncExtFunction.java b/src/org/apache/xpath/functions/FuncExtFunction.java
index 1d9aba9..a89a610 100644
--- a/src/org/apache/xpath/functions/FuncExtFunction.java
+++ b/src/org/apache/xpath/functions/FuncExtFunction.java
@@ -58,22 +58,14 @@
 
 import java.util.Vector;
 
-import org.apache.xpath.Expression;
-import org.apache.xpath.XPathContext;
-import org.apache.xpath.ExtensionsProvider;
-import org.apache.xpath.objects.*;
-import org.apache.xalan.transformer.TransformerImpl;
-import org.apache.xalan.extensions.ExtensionsTable;
-import org.apache.xml.dtm.DTMIterator;
-
-//import org.w3c.dom.Node;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.traversal.NodeIterator;
-
-import org.apache.xml.dtm.*;
-import org.apache.xpath.axes.*;
-import org.apache.xpath.res.XPATHErrorResources;
 import org.apache.xalan.res.XSLMessages;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExtensionsProvider;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XNull;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.res.XPATHErrorResources;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -122,7 +114,7 @@
    * to be offset to the current stack frame).
    * NEEDSDOC @param globalsSize
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
 
     if (null != m_argVec)
@@ -133,7 +125,7 @@
       {
         Expression arg = (Expression) m_argVec.elementAt(i);
 
-        arg.fixupVariables(vars, globalsSize);
+        arg.fixupVariables(vcs);
       }
     }
   }
@@ -188,6 +180,12 @@
       Expression arg = (Expression) m_argVec.elementAt(i);
       
       XObject xobj = arg.execute(xctxt);
+      
+      if(null == xobj)
+        throw new RuntimeException("Arg executed to a null XObject!!! arg: "+arg);
+        
+      if(null == xobj.object())
+        throw new RuntimeException("Arg executed to a null object!!! arg: "+arg);
 
       argVec.addElement(xobj);
     }
@@ -198,6 +196,7 @@
 
     if (null != val)
     {
+      // If val is an XObject, it will just pass through create.
       result = XObject.create(val, xctxt);
     }
     else
@@ -221,7 +220,11 @@
   public void setArg(Expression arg, int argNum)
           throws WrongNumberArgsException
   {
-    m_argVec.addElement(arg);
+    // m_argVec.addElement(arg);
+    if(argNum >= m_argVec.size())
+      m_argVec.setSize(argNum+1);
+    
+    m_argVec.setElementAt(arg, argNum);
   }
 
   /**
diff --git a/src/org/apache/xpath/functions/FuncExtFunctionAvailable.java b/src/org/apache/xpath/functions/FuncExtFunctionAvailable.java
index c71a2e0..3a9261c 100644
--- a/src/org/apache/xpath/functions/FuncExtFunctionAvailable.java
+++ b/src/org/apache/xpath/functions/FuncExtFunctionAvailable.java
@@ -56,21 +56,14 @@
  */
 package org.apache.xpath.functions;
 
-import org.apache.xml.utils.PrefixResolver;
+import javax.xml.transform.TransformerException;
 import org.apache.xalan.templates.Constants;
-//import org.apache.xalan.transformer.TransformerImpl;
-//import org.apache.xalan.extensions.ExtensionsTable;
-
-//import org.w3c.dom.Node;
-
-import java.util.Vector;
-
-import org.apache.xpath.XPathContext;
-import org.apache.xpath.XPath;
+import org.apache.xml.utils.QName;
 import org.apache.xpath.ExtensionsProvider;
-import org.apache.xpath.compiler.Keywords;
-import org.apache.xpath.objects.XObject;
+import org.apache.xpath.XPathContext;
 import org.apache.xpath.objects.XBoolean;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.parser.SimpleNode;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -116,7 +109,9 @@
     {
       try
       {
-        return Keywords.functionAvailable(methName) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      	// TBD: At least properly construct the QName object.
+      	Object funcObj = SimpleNode.m_builtInFunctions.get(new QName(methName));
+        return (null != funcObj) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
       }
       catch (Exception e)
       {
diff --git a/src/org/apache/xpath/functions/FuncFalse.java b/src/org/apache/xpath/functions/FuncFalse.java
index 99f0491..4568fa4 100644
--- a/src/org/apache/xpath/functions/FuncFalse.java
+++ b/src/org/apache/xpath/functions/FuncFalse.java
@@ -58,12 +58,10 @@
 
 //import org.w3c.dom.Node;
 
-import java.util.Vector;
-
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.XPath;
-import org.apache.xpath.objects.XObject;
 import org.apache.xpath.objects.XBoolean;
+import org.apache.xpath.objects.XObject;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -88,7 +86,7 @@
   /**
    * No arguments to process, so this does nothing.
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
     // no-op
   }
diff --git a/src/org/apache/xpath/functions/FuncFloor.java b/src/org/apache/xpath/functions/FuncFloor.java
index d7dc0e1..0f1e9ef 100644
--- a/src/org/apache/xpath/functions/FuncFloor.java
+++ b/src/org/apache/xpath/functions/FuncFloor.java
@@ -58,12 +58,10 @@
 
 //import org.w3c.dom.Node;
 
-import java.util.Vector;
-
+import javax.xml.transform.TransformerException;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XDouble;
 import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -82,6 +80,6 @@
    */
   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
   {
-    return new XNumber(java.lang.Math.floor(m_arg0.execute(xctxt).num()));
+    return new XDouble(java.lang.Math.floor(m_arg0.execute(xctxt).num()));
   }
 }
diff --git a/src/org/apache/xpath/functions/FuncGDay.java b/src/org/apache/xpath/functions/FuncGDay.java
new file mode 100644
index 0000000..f994d10
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGDay.java
@@ -0,0 +1,100 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XGDay;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncGDay extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date = DateTimeObj.gDay(m_arg0.execute(xctxt).str());
+    return new XGDay(date);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGMonth.java b/src/org/apache/xpath/functions/FuncGMonth.java
new file mode 100644
index 0000000..674a18c
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGMonth.java
@@ -0,0 +1,100 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XGMonth;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncGMonth extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date = DateTimeObj.gMonth(m_arg0.execute(xctxt).str());
+    return new XGMonth(date);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGMonthDay.java b/src/org/apache/xpath/functions/FuncGMonthDay.java
new file mode 100644
index 0000000..bebe590
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGMonthDay.java
@@ -0,0 +1,100 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XGMonthDay;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncGMonthDay extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date = DateTimeObj.gMonthDay(m_arg0.execute(xctxt).str());
+    return new XGMonthDay(date);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGYear.java b/src/org/apache/xpath/functions/FuncGYear.java
new file mode 100644
index 0000000..be57a02
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGYear.java
@@ -0,0 +1,100 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XGYearObj;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncGYear extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date = DateTimeObj.gYear(m_arg0.execute(xctxt).str());
+    return new XGYearObj(date);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGYearMonth.java b/src/org/apache/xpath/functions/FuncGYearMonth.java
new file mode 100644
index 0000000..588defb
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGYearMonth.java
@@ -0,0 +1,100 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XGYearMonth;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncGYearMonth extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date = DateTimeObj.gYearMonth(m_arg0.execute(xctxt).str());
+    return new XGYearMonth(date);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetDFromDT.java b/src/org/apache/xpath/functions/FuncGetDFromDT.java
new file mode 100644
index 0000000..7156834
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetDFromDT.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetDFromDT extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XInteger();
+    else
+    return new XInteger(dt.getDays());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetDFromDTDuration.java b/src/org/apache/xpath/functions/FuncGetDFromDTDuration.java
new file mode 100644
index 0000000..9e98220
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetDFromDTDuration.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetDFromDTDuration extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration du = Duration.DTDuration(m_arg0.execute(xctxt).str());
+    if (du == null)
+    return new XInteger();
+    else
+    return new XInteger(du.getDays());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetDFromDate.java b/src/org/apache/xpath/functions/FuncGetDFromDate.java
new file mode 100644
index 0000000..b4a5f6a
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetDFromDate.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetDFromDate extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.date(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XInteger();
+    else
+    return new XInteger(dt.getDays());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetDTDuration.java b/src/org/apache/xpath/functions/FuncGetDTDuration.java
new file mode 100644
index 0000000..e80d70d
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetDTDuration.java
@@ -0,0 +1,107 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:get-yearMonthDuration() function.
+ */
+public class FuncGetDTDuration extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    String dt1 = m_arg0.execute(xctxt).str();
+    String dt2 = m_arg1.execute(xctxt).str();
+    
+    if (dt1.length() == 0 || dt2.length() == 0)
+    return new XDuration();
+    
+    Duration du = (new DateTimeObj(dt1)).getDTDuration(new DateTimeObj(dt2));
+    return new XDuration(du);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetHFromDT.java b/src/org/apache/xpath/functions/FuncGetHFromDT.java
new file mode 100644
index 0000000..3d60ab2
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetHFromDT.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetHFromDT extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XInteger();
+    else
+    return new XInteger(dt.getHours());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetHFromDTDuration.java b/src/org/apache/xpath/functions/FuncGetHFromDTDuration.java
new file mode 100644
index 0000000..6a353af
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetHFromDTDuration.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetHFromDTDuration extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration du = Duration.DTDuration(m_arg0.execute(xctxt).str());
+    if (du == null)
+    return new XInteger();
+    else
+    return new XInteger(du.getHours());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetHFromTime.java b/src/org/apache/xpath/functions/FuncGetHFromTime.java
new file mode 100644
index 0000000..2091a74
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetHFromTime.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetHFromTime extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.time(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XInteger();
+    else
+    return new XInteger(dt.getHours());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetMFromDT.java b/src/org/apache/xpath/functions/FuncGetMFromDT.java
new file mode 100644
index 0000000..1b3aa51
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetMFromDT.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetMFromDT extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XInteger();
+    else
+    return new XInteger(dt.getMonths());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetMFromDate.java b/src/org/apache/xpath/functions/FuncGetMFromDate.java
new file mode 100644
index 0000000..46eeda5
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetMFromDate.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetMFromDate extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.date(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XInteger();
+    else
+    return new XInteger(dt.getMonths());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetMFromYMDuration.java b/src/org/apache/xpath/functions/FuncGetMFromYMDuration.java
new file mode 100644
index 0000000..acd0609
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetMFromYMDuration.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetMFromYMDuration extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration du = Duration.YMDuration(m_arg0.execute(xctxt).str());
+    if (du == null)
+    return new XInteger();
+    else
+    return new XInteger(du.getMonths());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetMnFromDT.java b/src/org/apache/xpath/functions/FuncGetMnFromDT.java
new file mode 100644
index 0000000..a6b0aaf
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetMnFromDT.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetMnFromDT extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XInteger();
+    else
+    return new XInteger(dt.getMinutes());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetMnFromDTDuration.java b/src/org/apache/xpath/functions/FuncGetMnFromDTDuration.java
new file mode 100644
index 0000000..74a7d65
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetMnFromDTDuration.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetMnFromDTDuration extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration du = Duration.DTDuration(m_arg0.execute(xctxt).str());
+    if (du == null)
+    return new XInteger();
+    else
+    return new XInteger(du.getMinutes());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetMnFromTime.java b/src/org/apache/xpath/functions/FuncGetMnFromTime.java
new file mode 100644
index 0000000..7f00d73
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetMnFromTime.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetMnFromTime extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.time(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XInteger();
+    else
+    return new XInteger(dt.getMinutes());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetSFromDT.java b/src/org/apache/xpath/functions/FuncGetSFromDT.java
new file mode 100644
index 0000000..4ff0f70
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetSFromDT.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetSFromDT extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XDouble();
+    else
+    return new XDouble(dt.getSeconds());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetSFromDTDuration.java b/src/org/apache/xpath/functions/FuncGetSFromDTDuration.java
new file mode 100644
index 0000000..088db43
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetSFromDTDuration.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetSFromDTDuration extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration du = Duration.DTDuration(m_arg0.execute(xctxt).str());
+    if (du == null)
+    return new XDouble();
+    else
+    return new XDouble(du.getSeconds());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetSFromTime.java b/src/org/apache/xpath/functions/FuncGetSFromTime.java
new file mode 100644
index 0000000..cb810c9
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetSFromTime.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetSFromTime extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.time(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XDouble();
+    else
+    return new XDouble(dt.getSeconds());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetTZFromDT.java b/src/org/apache/xpath/functions/FuncGetTZFromDT.java
new file mode 100644
index 0000000..0113cfd
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetTZFromDT.java
@@ -0,0 +1,103 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetTZFromDT extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XString("");
+    else
+    return new XString(dt.getZone());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetTZFromDate.java b/src/org/apache/xpath/functions/FuncGetTZFromDate.java
new file mode 100644
index 0000000..558a737
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetTZFromDate.java
@@ -0,0 +1,103 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetTZFromDate extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.date(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XString("");
+    else
+    return new XString(dt.getZone());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetTZFromTime.java b/src/org/apache/xpath/functions/FuncGetTZFromTime.java
new file mode 100644
index 0000000..73aa620
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetTZFromTime.java
@@ -0,0 +1,103 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetTZFromTime extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.time(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XString("");
+    else
+    return new XString(dt.getZone());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetYFromDT.java b/src/org/apache/xpath/functions/FuncGetYFromDT.java
new file mode 100644
index 0000000..e2cd706
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetYFromDT.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetYFromDT extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XInteger();
+    else
+    return new XInteger(dt.getYears());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetYFromDate.java b/src/org/apache/xpath/functions/FuncGetYFromDate.java
new file mode 100644
index 0000000..eb83cf1
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetYFromDate.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetYFromDate extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dt = DateTimeObj.date(m_arg0.execute(xctxt).str());
+    if (dt == null)
+    return new XInteger();
+    else
+    return new XInteger(dt.getYears());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetYFromYMDuration.java b/src/org/apache/xpath/functions/FuncGetYFromYMDuration.java
new file mode 100644
index 0000000..2244724
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetYFromYMDuration.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncGetYFromYMDuration extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration du = Duration.YMDuration(m_arg0.execute(xctxt).str());
+    if (du == null)
+    return new XInteger();
+    else
+    return new XInteger(du.getYears());
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncGetYMDuration.java b/src/org/apache/xpath/functions/FuncGetYMDuration.java
new file mode 100644
index 0000000..f8d0eef
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncGetYMDuration.java
@@ -0,0 +1,107 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:get-yearMonthDuration() function.
+ */
+public class FuncGetYMDuration extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    String dt1 = m_arg0.execute(xctxt).str();
+    String dt2 = m_arg1.execute(xctxt).str();
+    
+    if (dt1.length() == 0 || dt2.length() == 0)
+    return new XDuration();
+    
+    Duration du = (new DateTimeObj(dt1)).getYMDuration(new DateTimeObj(dt2));
+    return new XDuration(du);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncId.java b/src/org/apache/xpath/functions/FuncId.java
index 1bfa3d1..9e32e52 100644
--- a/src/org/apache/xpath/functions/FuncId.java
+++ b/src/org/apache/xpath/functions/FuncId.java
@@ -69,7 +69,6 @@
 import java.util.Vector;
 
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.DOMHelper;
 import org.apache.xpath.XPath;
 import org.apache.xpath.NodeSetDTM;
 import org.apache.xpath.objects.XObject;
diff --git a/src/org/apache/xpath/functions/FuncLast.java b/src/org/apache/xpath/functions/FuncLast.java
index f1627e0..5d45a0d 100644
--- a/src/org/apache/xpath/functions/FuncLast.java
+++ b/src/org/apache/xpath/functions/FuncLast.java
@@ -58,20 +58,14 @@
 
 //import org.w3c.dom.Node;
 //import org.w3c.dom.Element;
-import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMIterator;
-
-import java.util.Vector;
-
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.XPath;
-import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
-import org.apache.xpath.NodeSetDTM;
-import org.apache.xpath.axes.LocPathIterator;
-import org.apache.xpath.axes.ContextNodeList;
 import org.apache.xpath.axes.SubContextList;
-import org.apache.xpath.compiler.Compiler;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XSequence;
 
 
 /**
@@ -89,7 +83,8 @@
    */
   public void postCompileStep(Compiler compiler)
   {
-    m_isTopLevel = compiler.getLocationPathDepth() == -1;
+  	// TBD: Figure out isTopLevel for new parser world.
+    // m_isTopLevel = compiler.getLocationPathDepth() == -1;
   }
 
   /**
@@ -113,7 +108,7 @@
     if (null != iter)
       return iter.getLastPos(xctxt);
 
-    DTMIterator cnl = xctxt.getContextNodeList();
+    XSequence cnl = xctxt.getContextSequence();
     int count;
     if(null != cnl)
     {
@@ -135,7 +130,7 @@
    */
   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
   {
-    XNumber xnum = new XNumber((double) getCountOfContextNodeList(xctxt));
+    XNumber xnum = new XInteger(getCountOfContextNodeList(xctxt));
     // System.out.println("last: "+xnum.num());
     return xnum;
   }
@@ -143,7 +138,7 @@
   /**
    * No arguments to process, so this does nothing.
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
     // no-op
   }
diff --git a/src/org/apache/xpath/functions/FuncMultDayTimeDuration.java b/src/org/apache/xpath/functions/FuncMultDayTimeDuration.java
new file mode 100644
index 0000000..15adf6a
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncMultDayTimeDuration.java
@@ -0,0 +1,103 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncMultDayTimeDuration extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration = Duration.DTDuration(m_arg0.execute(xctxt).str());
+    if (duration == null)
+    return new XDuration();
+    Duration du = duration.multiplyDTDuration(m_arg1.num(xctxt));
+    return new XDuration(du);
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncMultYearMonthDuration.java b/src/org/apache/xpath/functions/FuncMultYearMonthDuration.java
new file mode 100644
index 0000000..4358c31
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncMultYearMonthDuration.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncMultYearMonthDuration extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration = Duration.YMDuration(m_arg0.execute(xctxt).str());
+    if (duration == null)
+    return new XDuration();
+    Duration du = duration.multiplyYMDuration(m_arg1.num(xctxt));
+    return new XDuration(du);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncNumber.java b/src/org/apache/xpath/functions/FuncNumber.java
index dbe9257..8a25d61 100644
--- a/src/org/apache/xpath/functions/FuncNumber.java
+++ b/src/org/apache/xpath/functions/FuncNumber.java
@@ -56,17 +56,10 @@
  */
 package org.apache.xpath.functions;
 
-import org.apache.xpath.res.XPATHErrorResources;
-
-//import org.w3c.dom.Node;
-
-import java.util.Vector;
-
+import javax.xml.transform.TransformerException;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XDouble;
 import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
-import org.apache.xpath.objects.XNodeSet;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -85,6 +78,6 @@
    */
   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
   {
-    return new XNumber(getArg0AsNumber(xctxt));
+    return new XDouble(getArg0AsNumber(xctxt));
   }
 }
diff --git a/src/org/apache/xpath/functions/FuncPosition.java b/src/org/apache/xpath/functions/FuncPosition.java
index 40b74d3..b7be86e 100644
--- a/src/org/apache/xpath/functions/FuncPosition.java
+++ b/src/org/apache/xpath/functions/FuncPosition.java
@@ -60,17 +60,12 @@
 //import org.w3c.dom.traversal.NodeIterator;
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMIterator;
-
-import java.util.Vector;
-
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.XPath;
-import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.axes.SubContextList;
-import org.apache.xpath.axes.ContextNodeList;
-import org.apache.xpath.NodeSetDTM;
-import org.apache.xpath.compiler.Compiler;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XSequence;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -86,8 +81,73 @@
    */
   public void postCompileStep(Compiler compiler)
   {
-    m_isTopLevel = compiler.getLocationPathDepth() == -1;
+  	// TBD: Figure out isTopLevel for new parser world.
+    // m_isTopLevel = compiler.getLocationPathDepth() == -1;
   }
+  
+//    /**
+//   * Get the position in the current context node list.
+//   *
+//   * @param xctxt Runtime XPath context.
+//   *
+//   * @return The current position of the itteration in the context node list, 
+//   *         or -1 if there is no active context node list.
+//   */
+//  public int getPositionInContextNodeList(XPathContext xctxt)
+//  {
+//
+//    // System.out.println("FuncPosition- entry");
+//    // If we're in a predicate, then this will return non-null.
+//    SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();
+//
+//    if (null != iter)
+//    {
+//      int prox = iter.getProximityPosition(xctxt);
+// 
+//      // System.out.println("FuncPosition- prox: "+prox);
+//      return prox;
+//    }
+//
+//    DTMIterator cnl = xctxt.getContextNodeList();
+//
+//    if (null != cnl)
+//    {
+//      int n = cnl.getCurrentNode();
+//      if(n == DTM.NULL)
+//      {
+//        if(cnl.getCurrentPos() == 0)
+//          return 0;
+//          
+//        // Then I think we're in a sort.  See sort21.xsl. So the iterator has 
+//        // already been spent, and is not on the node we're processing. 
+//        // It's highly possible that this is an issue for other context-list 
+//        // functions.  Shouldn't be a problem for last(), and it shouldn't be 
+//        // a problem for current().
+//        try 
+//        { 
+//          cnl = cnl.cloneWithReset(); 
+//        }
+//        catch(CloneNotSupportedException cnse)
+//        {
+//          throw new org.apache.xml.utils.WrappedRuntimeException(cnse);
+//        }
+//        int currentNode = xctxt.getContextNode();
+//        // System.out.println("currentNode: "+currentNode);
+//        while(DTM.NULL != (n = cnl.nextNode()))
+//        {
+//          if(n == currentNode)
+//            break;
+//        }
+//      }
+//      // System.out.println("n: "+n);
+//      // System.out.println("FuncPosition- cnl.getCurrentPos(): "+cnl.getCurrentPos());
+//      return cnl.getCurrentPos();
+//    }
+//
+//    // System.out.println("FuncPosition - out of guesses: -1");
+//    return -1;
+//  }
+
 
   /**
    * Get the position in the current context node list.
@@ -106,20 +166,21 @@
 
     if (null != iter)
     {
-      int prox = iter.getProximityPosition(xctxt);
+      int prox = iter.getProximityPosition(xctxt)-1;
  
       // System.out.println("FuncPosition- prox: "+prox);
       return prox;
     }
 
-    DTMIterator cnl = xctxt.getContextNodeList();
+    XSequence cnl = xctxt.getContextSequence();
 
     if (null != cnl)
     {
-      int n = cnl.getCurrentNode();
-      if(n == DTM.NULL)
+      XObject current = cnl.getCurrent();
+      if(current == null)
       {
-        if(cnl.getCurrentPos() == 0)
+        int pos = cnl.getCurrentPos();
+        if(pos == 0)
           return 0;
           
         // Then I think we're in a sort.  See sort21.xsl. So the iterator has 
@@ -129,17 +190,19 @@
         // a problem for current().
         try 
         { 
-          cnl = cnl.cloneWithReset(); 
+          cnl = (XSequence)cnl.clone(); 
+          cnl.reset();
         }
         catch(CloneNotSupportedException cnse)
         {
           throw new org.apache.xml.utils.WrappedRuntimeException(cnse);
         }
-        int currentNode = xctxt.getContextNode();
+        XObject currentItem = xctxt.getCurrentItem();
+        XObject item;
         // System.out.println("currentNode: "+currentNode);
-        while(DTM.NULL != (n = cnl.nextNode()))
+        while(null != (item = cnl.next()))
         {
-          if(n == currentNode)
+          if(item.equals(currentItem))
             break;
         }
       }
@@ -162,15 +225,15 @@
    */
   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
   {
-    double pos = (double) getPositionInContextNodeList(xctxt);
+    int pos = getPositionInContextNodeList(xctxt);
     
-    return new XNumber(pos);
+    return new XInteger(pos+1);
   }
   
   /**
    * No arguments to process, so this does nothing.
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
     // no-op
   }
diff --git a/src/org/apache/xpath/functions/FuncRound.java b/src/org/apache/xpath/functions/FuncRound.java
index d1bb54d..d25f9b8 100644
--- a/src/org/apache/xpath/functions/FuncRound.java
+++ b/src/org/apache/xpath/functions/FuncRound.java
@@ -58,12 +58,10 @@
 
 //import org.w3c.dom.Node;
 
-import java.util.Vector;
-
+import javax.xml.transform.TransformerException;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XDouble;
 import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -82,7 +80,7 @@
    */
   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
   {
-    return new XNumber(java.lang.Math.floor(m_arg0.execute(xctxt).num()
+    return new XDouble(java.lang.Math.floor(m_arg0.execute(xctxt).num()
                                             + 0.5));
   }
 }
diff --git a/src/org/apache/xpath/functions/FuncStringLength.java b/src/org/apache/xpath/functions/FuncStringLength.java
index 057c1f2..1e42b25 100644
--- a/src/org/apache/xpath/functions/FuncStringLength.java
+++ b/src/org/apache/xpath/functions/FuncStringLength.java
@@ -56,17 +56,10 @@
  */
 package org.apache.xpath.functions;
 
-import org.apache.xpath.res.XPATHErrorResources;
-
-//import org.w3c.dom.Node;
-
-import java.util.Vector;
-
+import javax.xml.transform.TransformerException;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XInteger;
 import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
-import org.apache.xpath.objects.XNodeSet;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -85,6 +78,6 @@
    */
   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
   {
-    return new XNumber(getArg0AsString(xctxt).length());
+    return new XInteger(getArg0AsString(xctxt).length());
   }
 }
diff --git a/src/org/apache/xpath/functions/FuncSubDayTimeDuration.java b/src/org/apache/xpath/functions/FuncSubDayTimeDuration.java
new file mode 100644
index 0000000..0af397e
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncSubDayTimeDuration.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncSubDayTimeDuration extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration1 = Duration.DTDuration(m_arg0.execute(xctxt).str());
+    Duration duration2 = Duration.DTDuration(m_arg1.execute(xctxt).str());
+    if (duration1 == null || duration2 == null)
+    return new XDuration();
+    Duration du = duration1.subtractDTDuration(duration2);
+    return new XDuration(du);
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncSubYearMonthDuration.java b/src/org/apache/xpath/functions/FuncSubYearMonthDuration.java
new file mode 100644
index 0000000..f25d4d8
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncSubYearMonthDuration.java
@@ -0,0 +1,104 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:current-dateTime() function.
+ */
+public class FuncSubYearMonthDuration extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration1 = Duration.YMDuration(m_arg0.execute(xctxt).str());
+    Duration duration2 = Duration.YMDuration(m_arg1.execute(xctxt).str());
+    if (duration1 == null || duration2 == null)
+    return new XDuration();
+    Duration du = duration1.subtractYMDuration(duration2);
+    return new XDuration(du);
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncSubtractDTDurationFromDT.java b/src/org/apache/xpath/functions/FuncSubtractDTDurationFromDT.java
new file mode 100644
index 0000000..ebaed3e
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncSubtractDTDurationFromDT.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDateTime;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncSubtractDTDurationFromDT extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    String dateTime = m_arg0.execute(xctxt).str();
+    Duration duration = Duration.DTDuration(m_arg1.execute(xctxt).str());
+    if (duration == null)
+    return new XDateTime(new DateTimeObj(dateTime));
+    DateTimeObj dt = (new DateTimeObj(dateTime)).subtractDTDurationFromDateTime(duration);
+    return new XDateTime(dt);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncSubtractDTDurationFromDate.java b/src/org/apache/xpath/functions/FuncSubtractDTDurationFromDate.java
new file mode 100644
index 0000000..3a84bbc
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncSubtractDTDurationFromDate.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDate;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncSubtractDTDurationFromDate extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date = DateTimeObj.date(m_arg0.execute(xctxt).str());
+    Duration duration = Duration.DTDuration(m_arg1.execute(xctxt).str());
+    if (date == null || duration == null)
+    return new XDate();
+    DateTimeObj dt = date.subtractDTDurationFromDate(duration);
+    return new XDate(dt);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncSubtractDTDurationFromTime.java b/src/org/apache/xpath/functions/FuncSubtractDTDurationFromTime.java
new file mode 100644
index 0000000..43a6b32
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncSubtractDTDurationFromTime.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XTime;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncSubtractDTDurationFromTime extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj time = DateTimeObj.time(m_arg0.execute(xctxt).str());
+    Duration duration = Duration.DTDuration(m_arg1.execute(xctxt).str());
+    if (time == null || duration == null)
+    return new XTime();
+    DateTimeObj dt = time.subtractDTDurationFromTime(duration);
+    return new XTime(dt);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncSubtractYMDurationFromDT.java b/src/org/apache/xpath/functions/FuncSubtractYMDurationFromDT.java
new file mode 100644
index 0000000..537ff20
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncSubtractYMDurationFromDT.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDateTime;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:subtractYearMonthDurationFromDateTime() function.
+ */
+public class FuncSubtractYMDurationFromDT extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    String dateTime = m_arg0.execute(xctxt).str();
+    Duration duration = Duration.YMDuration(m_arg1.execute(xctxt).str());
+    if (duration == null)
+    return new XDateTime(new DateTimeObj(dateTime));
+    DateTimeObj dt = (new DateTimeObj(dateTime)).subtractYMDurationFromDateTime(duration);
+    return new XDateTime(dt);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncSubtractYMDurationFromDate.java b/src/org/apache/xpath/functions/FuncSubtractYMDurationFromDate.java
new file mode 100644
index 0000000..32db663
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncSubtractYMDurationFromDate.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDate;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncSubtractYMDurationFromDate extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj date = DateTimeObj.date(m_arg0.execute(xctxt).str());
+    Duration duration = Duration.YMDuration(m_arg1.execute(xctxt).str());
+    if (date == null || duration == null)
+    return new XDate();
+    DateTimeObj dt = date.subtractYMDurationFromDate(duration);
+    return new XDate(dt);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncSum.java b/src/org/apache/xpath/functions/FuncSum.java
index 6ee8615..988853d 100644
--- a/src/org/apache/xpath/functions/FuncSum.java
+++ b/src/org/apache/xpath/functions/FuncSum.java
@@ -56,19 +56,13 @@
  */
 package org.apache.xpath.functions;
 
+import javax.xml.transform.TransformerException;
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMIterator;
-
-import java.util.Vector;
-
-import org.apache.xpath.XPathContext;
-import org.apache.xpath.DOMHelper;
-import org.apache.xpath.XPath;
-import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
-import org.apache.xpath.objects.XString;
-
 import org.apache.xml.utils.XMLString;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xpath.objects.XObject;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -102,6 +96,6 @@
     }
     nodes.detach();
 
-    return new XNumber(sum);
+    return new XDouble(sum);
   }
 }
diff --git a/src/org/apache/xpath/functions/FuncSystemProperty.java b/src/org/apache/xpath/functions/FuncSystemProperty.java
index 05e67cb..263885a 100644
--- a/src/org/apache/xpath/functions/FuncSystemProperty.java
+++ b/src/org/apache/xpath/functions/FuncSystemProperty.java
@@ -61,7 +61,6 @@
 import java.io.BufferedInputStream;
 import java.io.InputStream;
 
-import java.lang.ClassLoader;
 
 import org.apache.xml.utils.PrefixResolver;
 import org.apache.xpath.res.XPATHErrorResources;
@@ -72,6 +71,7 @@
 
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XDouble;
 import org.apache.xpath.objects.XObject;
 import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.objects.XString;
@@ -194,7 +194,13 @@
       try
       {
         // Needs to return the version number of the spec we conform to.
-        return new XNumber(1.0);
+        String verStr = xctxt.getXPathVersion();
+        if(Double.valueOf(verStr).doubleValue() == 2.0)
+          return new XString(verStr);
+        else if(Double.valueOf(verStr).doubleValue() < 1.9)
+          return new XDouble(1.0);
+        else
+          return new XString("2.0");
       }
       catch (Exception ex)
       {
diff --git a/src/org/apache/xpath/functions/FuncTime.java b/src/org/apache/xpath/functions/FuncTime.java
new file mode 100644
index 0000000..c7d035b
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncTime.java
@@ -0,0 +1,100 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XTime;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:time() function.
+ */
+public class FuncTime extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+  	DateTimeObj time = DateTimeObj.time(m_arg0.execute(xctxt).str());
+    return new XTime(time);
+        
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncTrue.java b/src/org/apache/xpath/functions/FuncTrue.java
index 2b13449..96a574f 100644
--- a/src/org/apache/xpath/functions/FuncTrue.java
+++ b/src/org/apache/xpath/functions/FuncTrue.java
@@ -58,12 +58,10 @@
 
 //import org.w3c.dom.Node;
 
-import java.util.Vector;
-
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.XPath;
-import org.apache.xpath.objects.XObject;
 import org.apache.xpath.objects.XBoolean;
+import org.apache.xpath.objects.XObject;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -88,7 +86,7 @@
   /**
    * No arguments to process, so this does nothing.
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
     // no-op
   }
diff --git a/src/org/apache/xpath/functions/FuncYMDuration.java b/src/org/apache/xpath/functions/FuncYMDuration.java
new file mode 100644
index 0000000..46d1873
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncYMDuration.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XYMDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncYMDuration extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    String du = m_arg0.execute(xctxt).str();
+    Duration d = Duration.YMDuration(du);
+    if (d == null)
+    return new XYMDuration();
+    else 
+    return new XYMDuration(d);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncYMDurationEqual.java b/src/org/apache/xpath/functions/FuncYMDurationEqual.java
new file mode 100644
index 0000000..a96d66b
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncYMDurationEqual.java
@@ -0,0 +1,107 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xml.utils.Duration;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncYMDurationEqual extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration1 = Duration.YMDuration(m_arg0.execute(xctxt).str());
+    Duration duration2 = Duration.YMDuration(m_arg1.execute(xctxt).str());
+    if (duration1 == null || duration2 == null)
+    return new XBoolean(false);
+    else
+    { 
+    boolean eq = duration1.YMEqual(duration2);
+    return new XBoolean(eq);
+    }
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncYMDurationFromDT.java b/src/org/apache/xpath/functions/FuncYMDurationFromDT.java
new file mode 100644
index 0000000..3c65785
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncYMDurationFromDT.java
@@ -0,0 +1,108 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDateTime;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncYMDurationFromDT extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    DateTimeObj dateTime = DateTimeObj.dateTime(m_arg0.execute(xctxt).str());
+    Duration duration = Duration.YMDuration(m_arg1.execute(xctxt).str());
+    if (dateTime == null || duration == null)
+    return new XDateTime();
+    else
+    {
+    DateTimeObj dt = dateTime.subtractYMDurationFromDateTime(duration);
+    return new XDateTime(dt);
+    }
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncYMDurationFromMonths.java b/src/org/apache/xpath/functions/FuncYMDurationFromMonths.java
new file mode 100644
index 0000000..2e1ec65
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncYMDurationFromMonths.java
@@ -0,0 +1,105 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:duration() function.
+ */
+public class FuncYMDurationFromMonths extends FunctionOneArg
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    int months = new Double(m_arg0.execute(xctxt).num()).intValue();
+    Duration d = Duration.YMDurationFromMonths(months);
+    if (d == null)
+    return new XDuration();
+    else 
+    return new XDuration(d);
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncYMDurationGT.java b/src/org/apache/xpath/functions/FuncYMDurationGT.java
new file mode 100644
index 0000000..dc7a225
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncYMDurationGT.java
@@ -0,0 +1,107 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xml.utils.Duration;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncYMDurationGT extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration1 = Duration.YMDuration(m_arg0.execute(xctxt).str());
+    Duration duration2 = Duration.YMDuration(m_arg1.execute(xctxt).str());
+    if (duration1 == null || duration2 == null)
+    return new XBoolean(false);
+    else
+    {
+    boolean eq = duration1.YMGreaterThan(duration2);
+    return new XBoolean(eq);
+    }
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/FuncYMDurationLT.java b/src/org/apache/xpath/functions/FuncYMDurationLT.java
new file mode 100644
index 0000000..8ef98d8
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncYMDurationLT.java
@@ -0,0 +1,107 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.functions;
+
+//import org.w3c.dom.Node;
+//import org.w3c.dom.traversal.NodeIterator;
+import org.apache.xml.dtm.DTM;
+
+import java.util.Vector;
+
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPath;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xml.utils.Duration;
+
+/**
+ * <meta name="usage" content="advanced"/>
+ * Execute the xs:addYearMonthDuration() function.
+ */
+public class FuncYMDurationLT extends Function2Args
+{
+
+  /**
+   * Execute the function.  The function must return
+   * a valid object.
+   * @param xctxt The current execution context.
+   * @return A valid XObject.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+  {
+    Duration duration1 = Duration.YMDuration(m_arg0.execute(xctxt).str());
+    Duration duration2 = Duration.YMDuration(m_arg1.execute(xctxt).str());
+    if (duration1 == null || duration2 == null)
+    return new XBoolean(false);
+    else
+    {  
+    boolean eq = duration1.YMLessThan(duration2);
+    return new XBoolean(eq);
+    }
+    
+  }
+}
diff --git a/src/org/apache/xpath/functions/Function.java b/src/org/apache/xpath/functions/Function.java
index b2e22e4..12db741 100644
--- a/src/org/apache/xpath/functions/Function.java
+++ b/src/org/apache/xpath/functions/Function.java
@@ -61,11 +61,13 @@
 import javax.xml.transform.TransformerException;
 import org.apache.xalan.res.XSLMessages;
 import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
 import org.apache.xpath.ExpressionOwner;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
-import org.apache.xpath.compiler.Compiler;
 import org.apache.xpath.objects.XObject;
+import org.apache.xpath.parser.Node;
+import org.apache.xpath.parser.PathExpr;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -77,7 +79,7 @@
  * the arguments don't have to be added to an array, but causes
  * a larger code footprint.
  */
-public abstract class Function extends Expression
+public abstract class Function extends Expression implements Cloneable
 {
 
   /**
@@ -96,6 +98,24 @@
 			// throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("zero", null));
       reportWrongNumberArgs();
   }
+  
+  
+  /**
+   * @see ExpressionOwner#setExpression(Expression)
+   */
+  public void jjtAddChild(Node exp, int argNum)
+  {
+  	try
+  	{
+  		exp = fixupPrimarys(exp);
+  		setArg((Expression)exp, argNum);
+  	}
+  	catch(WrongNumberArgsException wnae)
+  	{
+  		throw new org.apache.xml.utils.WrappedRuntimeException(wnae);
+  	}
+  }
+
 
   /**
    * Check that the number of arguments passed to this function is correct.
@@ -179,4 +199,32 @@
   {
     // no default action
   }
+  
+//  public void jjtAddChild(org.apache.xpath.parser.Node n, int i) {
+//    // at least for now, just ignore this.
+//  }
+  
+  /** This method tells the node to add its argument to the node's
+    list of children.  */
+  public void exprAddChild(ExpressionNode n, int i)
+  {
+  	try
+  	{
+  		setArg((Expression)n, i);
+  	}
+  	catch(WrongNumberArgsException wnae)
+  	{
+  		throw new RuntimeException(wnae.getMessage());
+  	}
+  }
+
+  /**
+   * Tell if this node should have it's PathExpr ancestory reduced.
+   */
+  public boolean isPathExprReduced()
+  {
+   	Node pathOwner = jjtGetParent().jjtGetParent();
+  	return pathOwner.jjtGetNumChildren() == 1 ? true : false;
+  }
+
 }
diff --git a/src/org/apache/xpath/functions/Function2Args.java b/src/org/apache/xpath/functions/Function2Args.java
index c99a102..8c54383 100644
--- a/src/org/apache/xpath/functions/Function2Args.java
+++ b/src/org/apache/xpath/functions/Function2Args.java
@@ -56,11 +56,11 @@
  */
 package org.apache.xpath.functions;
 
-import java.util.Vector;
-
 import org.apache.xalan.res.XSLMessages;
 import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathVisitor;
 
 /**
@@ -95,11 +95,11 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    super.fixupVariables(vars, globalsSize);
+    super.fixupVariables(vcs);
     if(null != m_arg1)
-      m_arg1.fixupVariables(vars, globalsSize);
+      m_arg1.fixupVariables(vcs);
   }
 
 
@@ -217,5 +217,20 @@
   		
   	return true;
   }
+  
+  /** This method returns a child node.  The children are numbered
+     from zero, left to right. */
+  public ExpressionNode exprGetChild(int i)
+  {
+  	assertion(i <= 1, "Function2Args only allows index one or less to be accessed at this level!");
+  	return (1 == i) ? m_arg1 : super.exprGetChild(i);
+  }
+
+  /** Return the number of children the node has. */
+  public int exprGetNumChildren()
+  {
+  	return 2;
+  }
+
 
 }
diff --git a/src/org/apache/xpath/functions/Function3Args.java b/src/org/apache/xpath/functions/Function3Args.java
index ccb63b3..04e09ac 100644
--- a/src/org/apache/xpath/functions/Function3Args.java
+++ b/src/org/apache/xpath/functions/Function3Args.java
@@ -56,11 +56,11 @@
  */
 package org.apache.xpath.functions;
 
-import java.util.Vector;
-
 import org.apache.xalan.res.XSLMessages;
 import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathVisitor;
 
 /**
@@ -95,11 +95,11 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    super.fixupVariables(vars, globalsSize);
+    super.fixupVariables(vcs);
     if(null != m_arg2)
-      m_arg2.fixupVariables(vars, globalsSize);
+      m_arg2.fixupVariables(vcs);
   }
 
   /**
@@ -216,5 +216,18 @@
   	return true;
   }
 
+  /** This method returns a child node.  The children are numbered
+     from zero, left to right. */
+  public ExpressionNode exprGetChild(int i)
+  {
+  	assertion(i <= 2, "Function2Args only allows index two or less to be accessed at this level!");
+  	return (2 == i) ? m_arg2 : super.exprGetChild(i);
+  }
+
+  /** Return the number of children the node has. */
+  public int exprGetNumChildren()
+  {
+  	return 2;
+  }
 
 }
diff --git a/src/org/apache/xpath/functions/FunctionDef1Arg.java b/src/org/apache/xpath/functions/FunctionDef1Arg.java
index 32dab0f..a2111e8 100644
--- a/src/org/apache/xpath/functions/FunctionDef1Arg.java
+++ b/src/org/apache/xpath/functions/FunctionDef1Arg.java
@@ -58,16 +58,14 @@
 
 //import org.w3c.dom.Node;
 
-import org.apache.xpath.XPathContext;
-import org.apache.xpath.objects.XNodeSet;
-import org.apache.xpath.objects.XNumber;
-import org.apache.xpath.objects.XString;
+import javax.xml.transform.TransformerException;
 import org.apache.xalan.res.XSLMessages;
-import org.apache.xpath.res.XPATHErrorResources;
-
-import org.apache.xml.utils.XMLString;
-
 import org.apache.xml.dtm.DTM;
+import org.apache.xml.utils.XMLString;
+import org.apache.xpath.ExpressionNode;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.res.XPATHErrorResources;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -205,4 +203,19 @@
   {
     return (null == m_arg0) ? false : super.canTraverseOutsideSubtree();
   }
+  
+  /** This method returns a child node.  The children are numbered
+     from zero, left to right. */
+  public ExpressionNode exprGetChild(int i)
+  {
+  	assertion(i == 0, "FunctionDef1Arg only allows index zero to be accessed at this level!");
+  	return m_arg0;
+  }
+
+  /** Return the number of children the node has. */
+  public int exprGetNumChildren()
+  {
+  	return (null == m_arg0) ? 0 : 1;
+  }
+
 }
diff --git a/src/org/apache/xpath/functions/FunctionMultiArgs.java b/src/org/apache/xpath/functions/FunctionMultiArgs.java
index 46b299a..7c7b51e 100644
--- a/src/org/apache/xpath/functions/FunctionMultiArgs.java
+++ b/src/org/apache/xpath/functions/FunctionMultiArgs.java
@@ -56,14 +56,13 @@
  */
 package org.apache.xpath.functions;
 
-import java.util.Vector;
-
-import org.apache.xpath.Expression;
-import org.apache.xpath.ExpressionOwner;
-import org.apache.xpath.XPathVisitor;
-import org.apache.xpath.functions.Function3Args.Arg2Owner;
-import org.apache.xpath.res.XPATHErrorResources;
 import org.apache.xalan.res.XSLMessages;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.res.XPATHErrorResources;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -95,21 +94,24 @@
       super.setArg(arg, argNum);
     else
     {
+      argNum-=3;
       if (null == m_args)
       {
-        m_args = new Expression[1];
-        m_args[0] = arg;
+        m_args = new Expression[argNum+1];
+        m_args[argNum] = arg;
       }
       else
       {
-
         // Slow but space conservative.
-        Expression[] args = new Expression[m_args.length + 1];
+        if(argNum >= m_args.length)
+        {
+          Expression[] args = new Expression[argNum + 1];
+          System.arraycopy(m_args, 0, args, 0, m_args.length);
+          m_args = args;
+        }
 
-        System.arraycopy(m_args, 0, args, 0, m_args.length);
-
-        args[m_args.length] = arg;
-        m_args = args;
+        m_args[argNum] = arg;
+        
       }
       arg.exprSetParent(this);
     }
@@ -125,14 +127,14 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    super.fixupVariables(vars, globalsSize);
+    super.fixupVariables(vcs);
     if(null != m_args)
     {
       for (int i = 0; i < m_args.length; i++) 
       {
-        m_args[i].fixupVariables(vars, globalsSize);
+        m_args[i].fixupVariables(vcs);
       }
     }
   }
@@ -261,4 +263,18 @@
 
       return true;
     }
+    
+  /** This method returns a child node.  The children are numbered
+     from zero, left to right. */
+  public ExpressionNode exprGetChild(int i)
+  {
+  	return (i < 3) ? super.exprGetChild(i) : m_args[i - 3];
+  }
+
+  /** Return the number of children the node has. */
+  public int exprGetNumChildren()
+  {
+  	return ((null != m_args) ? m_args.length : 0)+super.exprGetNumChildren();
+  }
+
 }
diff --git a/src/org/apache/xpath/functions/FunctionOneArg.java b/src/org/apache/xpath/functions/FunctionOneArg.java
index 92c5532..6c1d458 100644
--- a/src/org/apache/xpath/functions/FunctionOneArg.java
+++ b/src/org/apache/xpath/functions/FunctionOneArg.java
@@ -56,11 +56,11 @@
  */
 package org.apache.xpath.functions;
 
-import java.util.Vector;
-
 import org.apache.xalan.res.XSLMessages;
 import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathVisitor;
 
 /**
@@ -152,10 +152,10 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
     if(null != m_arg0)
-      m_arg0.fixupVariables(vars, globalsSize);
+      m_arg0.fixupVariables(vcs);
   }
   
   /**
@@ -207,5 +207,19 @@
   	return true;
   }
 
+  /** This method returns a child node.  The children are numbered
+     from zero, left to right. */
+  public ExpressionNode exprGetChild(int i)
+  {
+  	assertion(i == 0, "FunctionOneArg only allows index zero to be accessed!");
+  	return m_arg0;
+  }
+
+  /** Return the number of children the node has. */
+  public int exprGetNumChildren()
+  {
+  	return 1;
+  }
+
 
 }
diff --git a/src/org/apache/xpath/objects/NodeSequence.java b/src/org/apache/xpath/objects/NodeSequence.java
new file mode 100644
index 0000000..25be0c2
--- /dev/null
+++ b/src/org/apache/xpath/objects/NodeSequence.java
@@ -0,0 +1,717 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 2002 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+import java.io.Serializable;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMIterator;
+import org.apache.xml.dtm.DTMManager;
+import org.apache.xml.dtm.DTMFilter;
+import org.apache.xml.utils.NodeVector;
+import org.apache.xpath.Expression;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.axes.PathComponent;
+
+/**
+ * This class is the dynamic wrapper for a Xalan DTMIterator instance, and 
+ * provides random access capabilities.
+ * 
+ * (This used to be in the axes package. But in fact it's only
+ * referenced in the objects package, and since it implements
+ * XObject it probably belongs with the latter.)
+ */
+public class NodeSequence extends XObject
+  implements DTMIterator, Cloneable, PathComponent
+{
+	NodeVector m_obj; // Accessed directly by subclasses...?
+	
+	
+  /** The index of the last node in the iteration. */
+  protected int m_last = -1;
+  
+  /**
+   * The index of the next node to be fetched.  Useful if this
+   * is a cached iterator, and is being used as random access
+   * NodeList.
+   */
+  protected int m_next = 0;
+    
+  /**
+   * If this iterator needs to cache nodes that are fetched, they
+   * are stored in the Vector in the generic object.
+   */
+  protected NodeVector getVector()
+  {
+  	return (NodeVector)m_obj;
+  }
+  
+  /**
+   * Set the vector where nodes will be stored.
+   */
+  protected void SetVector(NodeVector v)
+  {
+  	m_obj = v;
+  }
+
+  
+  /**
+   * If this iterator needs to cache nodes that are fetched, they
+   * are stored here.
+   */
+  public boolean hasCache()
+  {
+  	return (m_obj != null);
+  }
+
+
+  /**
+   * The functional iterator that fetches nodes.
+   */
+  protected DTMIterator m_iter;
+  
+  /**
+   * Set the functional iterator that fetches nodes.
+   * @param iter The iterator that is to be contained.
+   */
+  public final void setIter(DTMIterator iter)
+  {
+  	m_iter = iter;
+    if(null == m_dtmMgr)
+      m_dtmMgr = iter.getDTMManager();
+  }
+  
+  /**
+   * Get the functional iterator that fetches nodes.
+   * @return The contained iterator.
+   */
+  public final DTMIterator getContainedIter()
+  {
+  	return m_iter;
+  }
+  
+  /**
+   * The DTMManager to use if we're using a NodeVector only.
+   * We may well want to do away with this, and store it in the NodeVector.
+   */
+  protected DTMManager m_dtmMgr;
+  
+  // ==== Constructors ====
+  
+  /**
+   * Create a new NodeSequence from a (already cloned) iterator.
+   * 
+   * @param iter Cloned (not static) DTMIterator.
+   * @param context The initial context node.
+   * @param xctxt The execution context.
+   * @param shouldCacheNodes True if this sequence can random access.
+   */
+  public NodeSequence(DTMIterator iter, int context, 
+                      XPathContext xctxt, boolean shouldCacheNodes)
+  {
+    m_dtmMgr = xctxt.getDTMManager();
+  	setIter(iter);
+  	setRoot(context, xctxt);
+  	setShouldCache(shouldCacheNodes);
+  }
+  
+  /**
+   * Create a new NodeSequence from a (already cloned) iterator.
+   * 
+   * @param iter Cloned (not static) DTMIterator.
+   */
+  public NodeSequence(NodeVector nodeVector)
+  {
+  	m_obj=nodeVector;
+  	if(null != nodeVector)
+  	{
+  		if(nodeVector instanceof DTMIterator)
+  		{
+	        m_dtmMgr = ((DTMIterator)nodeVector).getDTMManager();
+  			setIter((DTMIterator)nodeVector);
+  			m_last = ((DTMIterator)nodeVector).getLength();
+  		}
+  		
+  	}
+  }
+  
+  /**
+   * Construct an empty XNodeSet object.  This is used to create a mutable 
+   * nodeset to which random nodes may be added.
+   */
+  public NodeSequence(DTMManager dtmMgr)
+  {
+    this(new NodeVector());
+    m_last = 0;
+    m_dtmMgr = dtmMgr;
+  }
+  
+  /**
+   * Passthrough for XRTreeFrag(Expression) constructor, since
+   * c'tors are not inherited and there seems to be no way to 
+   * invoke super.super.super().
+   *
+   * @param frag Document fragment this will wrap
+   */
+  /*
+  protected NodeSequence(org.apache.xpath.Expression expr)
+  {
+    super(expr);
+  }
+  */
+  
+
+  
+  /**
+   * Create a new NodeSequence in an invalid (null) state.
+   */
+  public NodeSequence()
+  {
+  }
+  
+  public Object object()
+  {
+  	return m_obj;
+  }
+
+
+  /**
+   * @see DTMIterator#getDTM(int)
+   */
+  public DTM getDTM(int nodeHandle)
+  {
+  	DTMManager mgr = getDTMManager();
+  	if(null != mgr)
+    	return getDTMManager().getDTM(nodeHandle);
+    else
+    {
+    	assertion(false, "Can not get a DTM Unless a DTMManager has been set!");
+    	return null;
+    }
+  }
+
+  /**
+   * @see DTMIterator#getDTMManager()
+   */
+  public DTMManager getDTMManager()
+  {
+    return m_dtmMgr;
+  }
+
+  /**
+   * @see DTMIterator#getRoot()
+   */
+  public int getRoot()
+  {
+  	if(null != m_iter)
+    	return m_iter.getRoot();
+  	else
+  	{
+  		// NodeSetDTM will call this, and so it's not a good thing to throw 
+  		// an assertion here.
+  		// assertion(false, "Can not get the root from a non-iterated NodeSequence!");
+  		return DTM.NULL;
+  	}
+  }
+
+  /**
+   * @see DTMIterator#setRoot(int, Object)
+   */
+  public void setRoot(int nodeHandle, Object environment)
+  {
+  	if(null != m_iter)
+  	{
+  		XPathContext xctxt = (XPathContext)environment;
+  		m_dtmMgr = xctxt.getDTMManager();
+  		m_iter.setRoot(nodeHandle, environment);
+  		if(!m_iter.isDocOrdered())
+  		{
+  			if(!hasCache())
+  				setShouldCache(true);
+  			runTo(-1);
+  			m_next=0;
+  		}
+  	}
+  	else
+  		assertion(false, "Can not setRoot on a non-iterated NodeSequence!");
+  }
+
+  /**
+   * @see DTMIterator#reset()
+   */
+  public void reset()
+  {
+  	m_next = 0;
+  	// not resetting the iterator on purpose!!!
+  }
+
+  /**
+   * @see DTMIterator#getWhatToShow()
+   */
+  public int getWhatToShow()
+  {
+    return hasCache() ? (DTMFilter.SHOW_ALL & ~DTMFilter.SHOW_ENTITY_REFERENCE) 
+    	: m_iter.getWhatToShow();
+  }
+
+  /**
+   * @see DTMIterator#getExpandEntityReferences()
+   */
+  public boolean getExpandEntityReferences()
+  {
+  	if(null != m_iter)
+  		return m_iter.getExpandEntityReferences();
+  	else
+    	return true;
+  }
+
+  /**
+   * @see DTMIterator#nextNode()
+   */
+  public int nextNode()
+  {
+    // If the cache is on, and the node has already been found, then 
+    // just return from the list.
+    NodeVector vec = getVector();
+    if (null != vec)
+    {	
+    	if(m_next < vec.size())
+    	{
+			int next = vec.elementAt(m_next);
+	    	m_next++;
+	    	return next;
+    	}
+    	else if((-1 != m_last) || (null == m_iter))
+    	{
+    		m_next++;
+    		return DTM.NULL;
+    	}
+    }
+    
+  if (null == m_iter)
+    return DTM.NULL;
+  
+ 	int next = m_iter.nextNode();
+    if(DTM.NULL != next)
+    {
+    	if(hasCache())
+    	{
+    		if(m_iter.isDocOrdered())
+    	    {
+    			getVector().addElement(next);
+    			m_next++;
+    		}
+    		else
+    		{
+    			int insertIndex = addNodeInDocOrder(next);
+    			if(insertIndex >= 0)
+    				m_next++;
+    		}
+    	}
+    	else
+    		m_next++;
+    }
+    else
+    {
+    	m_last = m_next;
+    	m_next++;
+    }
+    	
+    return next;
+  }
+
+  /**
+   * @see DTMIterator#previousNode()
+   */
+  public int previousNode()
+  {
+  	if(hasCache())
+  	{
+  		if(m_next <= 0)
+  			return DTM.NULL;
+  		else
+  		{
+  			m_next--;
+  			return item(m_next);
+  		}
+  	}
+  	else
+  	{
+	    int n = m_iter.previousNode();
+	    m_next = m_iter.getCurrentPos();
+	    return m_next;
+  	}
+  }
+
+  /**
+   * @see DTMIterator#detach()
+   */
+  public void detach()
+  {
+  	if(null != m_iter)
+  		m_iter.detach();
+  	super.detach();
+  }
+
+  /**
+   * Calling this with a value of false will cause the nodeset 
+   * to be cached.
+   * @see DTMIterator#allowDetachToRelease(boolean)
+   */
+  public void allowDetachToRelease(boolean allowRelease)
+  {
+  	if((false == allowRelease) && !hasCache())
+  	{
+  		setShouldCache(true);
+  	}
+  	
+  	if(null != m_iter)
+  		m_iter.allowDetachToRelease(allowRelease);
+  	super.allowDetachToRelease(allowRelease);
+  }
+
+  /**
+   * @see DTMIterator#getCurrentNode()
+   */
+  public int getCurrentNode()
+  {
+  	if(hasCache())
+  	{
+  		int currentIndex = m_next-1;
+  		NodeVector vec = getVector();
+  		if((currentIndex >= 0) && (currentIndex < vec.size()))
+  			return vec.elementAt(currentIndex);
+  		else
+  			return DTM.NULL;
+  	}
+  	
+  	if(null != m_iter)
+  	{
+    	return m_iter.getCurrentNode();
+  	}
+  	else
+  		return DTM.NULL;
+  }
+
+  /**
+   * @see DTMIterator#isFresh()
+   */
+  public boolean isFresh()
+  {
+    return (0 == m_next);
+  }
+
+  /**
+   * @see DTMIterator#setShouldCache(boolean)
+   */
+  public void setShouldCache(boolean b)
+  {
+    if (b)
+    {
+      if(!hasCache())
+      {
+        SetVector(new NodeVector());
+      }
+//	  else
+//	    getVector().RemoveAllNoClear();  // Is this good?
+    }
+    else
+      SetVector(null);
+  }
+
+  /**
+   * @see DTMIterator#isMutable()
+   */
+  public boolean isMutable()
+  {
+    return hasCache(); // though may be surprising if it also has an iterator!
+  }
+
+  /**
+   * @see DTMIterator#getCurrentPos()
+   */
+  public int getCurrentPos()
+  {
+    return m_next-1;
+  }
+
+  /**
+   * @see DTMIterator#runTo(int)
+   */
+  public void runTo(int index)
+  {
+    int n;
+    
+    if (-1 == index)
+    {
+      int pos = m_next;
+      while (DTM.NULL != (n = nextNode()));
+      m_next = pos;
+    }
+    else if(m_next == index)
+    {
+      return;
+    }
+    else if(hasCache() && m_next < getVector().size())
+    {
+      m_next = index;
+    }
+    else if((null == getVector()) && (index < m_next))
+    {
+      while ((m_next >= index) && DTM.NULL != (n = previousNode()));
+    }
+    else
+    {   
+      while ((m_next < index) && DTM.NULL != (n = nextNode()));
+    }
+    
+  }
+
+  /**
+   * @see DTMIterator#setCurrentPos(int)
+   */
+  public void setCurrentPos(int i)
+  {
+  	runTo(i);
+  }
+
+  /**
+   * @see DTMIterator#item(int)
+   */
+  public int item(int index)
+  {
+  	setCurrentPos(index);
+  	int n = nextNode();
+  	m_next = index;
+  	return n;
+  }
+
+  /**
+   * @see DTMIterator#setItem(int, int)
+   */
+  public void setItem(int node, int index)
+  {
+  	NodeVector vec = getVector();
+  	if(null != vec)
+  	{
+  		vec.setElementAt(node, index);
+  		m_last = vec.size();
+  	}
+  	else
+  		m_iter.setItem(node, index);
+  }
+
+  /**
+   * @see DTMIterator#getLength()
+   */
+  public int getLength()
+  {
+  	if(hasCache())
+  	{
+	  	if(-1 == m_last)
+	  	{
+	  		int pos = m_next;
+	  		runTo(-1);
+	  		m_next = pos;
+	  	}
+	    return m_last;
+  	}
+  	else
+  	{
+  		return m_iter.getLength();
+  	}
+  }
+
+  /**
+   * Note: Not a deep clone.
+   * @see DTMIterator#cloneWithReset()
+   */
+  public DTMIterator cloneWithReset() throws CloneNotSupportedException
+  {
+  	NodeSequence seq = (NodeSequence)super.clone();
+    seq.m_next = 0;
+    return seq;
+  }
+  
+  /**
+   * Get a clone of this iterator, but don't reset the iteration in the 
+   * process, so that it may be used from the current position.
+   * Note: Not a deep clone.
+   *
+   * @return A clone of this object.
+   *
+   * @throws CloneNotSupportedException
+   */
+  public Object clone() throws CloneNotSupportedException
+  {
+  	return super.clone();
+  }
+
+
+  /**
+   * @see DTMIterator#isDocOrdered()
+   */
+  public boolean isDocOrdered()
+  {
+  	if(null != m_iter)
+  		return m_iter.isDocOrdered();
+  	else
+    	return true; // can't be sure?
+  }
+
+  /**
+   * @see DTMIterator#getAxis()
+   */
+  public int getAxis()
+  {
+  	if(null != m_iter)
+    	return m_iter.getAxis();
+    else
+    {
+    	assertion(false, "Can not getAxis from a non-iterated node sequence!");
+    	return 0;
+    }
+  }
+
+  /**
+   * @see PathComponent#getAnalysisBits()
+   */
+  public int getAnalysisBits()
+  {
+  	if((null != m_iter) && (m_iter instanceof PathComponent))
+    	return ((PathComponent)m_iter).getAnalysisBits();
+    else
+    	return 0;
+  }
+
+  /**
+   * @see Expression#fixupVariables(Vector, int)
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+  	super.fixupVariables(vcs);
+  }  
+  
+  /**
+   * Add the node into a vector of nodes where it should occur in
+   * document order.
+   * @param v Vector of nodes, presumably containing Nodes
+   * @param obj Node object.
+   *
+   * @param node The node to be added.
+   * @param test true if we should test for doc order
+   * @param support The XPath runtime context.
+   * @return insertIndex.
+   * @throws RuntimeException thrown if this NodeSetDTM is not of 
+   * a mutable type.
+   */
+   protected int addNodeInDocOrder(int node)
+   {
+      assertion(hasCache(), "addNodeInDocOrder must be done on a mutable sequence!");
+
+      int insertIndex = -1;
+      
+      NodeVector vec = getVector();
+
+      // This needs to do a binary search, but a binary search 
+      // is somewhat tough because the sequence test involves 
+      // two nodes.
+      int size = vec.size(), i;
+
+      for (i = size - 1; i >= 0; i--)
+      {
+        int child = vec.elementAt(i);
+
+        if (child == node)
+        {
+          i = -2; // Duplicate, suppress insert
+
+          break;
+        }
+
+        DTM dtm = m_dtmMgr.getDTM(node);
+        if (!dtm.isNodeAfter(node, child))
+        {
+          break;
+        }
+      }
+
+      if (i != -2)
+      {
+        insertIndex = i + 1;
+
+        vec.insertElementAt(node, insertIndex);
+      }
+
+      // checkDups();
+      return insertIndex;
+    } // end addNodeInDocOrder(Vector v, Object obj)
+
+    
+  /**
+   * @see org.apache.xpath.Expression#isNodesetExpr()
+   */
+  public boolean isNodesetExpr()
+  {
+    return true;
+  }
+    
+}
+
diff --git a/src/org/apache/xpath/objects/TypeOperations.java b/src/org/apache/xpath/objects/TypeOperations.java
new file mode 100644
index 0000000..89197fd
--- /dev/null
+++ b/src/org/apache/xpath/objects/TypeOperations.java
@@ -0,0 +1,311 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+/**
+ * The responsibility of TypeOperations is to .
+ * 
+ * Created Jul 18, 2002
+ * @author sboag
+ */
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 18, 2002
+ * @author sboag
+ */
+public interface TypeOperations
+{
+  /**
+   * Method add.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject add(XObject left, XObject right);
+  
+  /**
+   * Method and.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject and(XObject left, XObject right);
+  
+  /**
+   * Method bool.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject bool(XObject left, XObject right);
+  
+  /**
+   * Method div.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject div(XObject left, XObject right);
+  
+  /**
+   * Method equals.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject equals(XObject left, XObject right);
+  
+  /**
+   * Method follows.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject follows(XObject left, XObject right);
+  
+  /**
+   * Method fortraneq.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject fortraneq(XObject left, XObject right);
+  
+  /**
+   * Method fortrange.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject fortrange(XObject left, XObject right);
+  
+  /**
+   * Method fortrangt.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject fortrangt(XObject left, XObject right);
+  
+  /**
+   * Method fortranle.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject fortranle(XObject left, XObject right);
+  
+  /**
+   * Method fortranlt.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject fortranlt(XObject left, XObject right);
+  /**
+   * Method fortranne.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject fortranne(XObject left, XObject right);
+  
+  /**
+   * Method gt.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject gt(XObject left, XObject right);
+  
+  /**
+   * Method gte.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject gte(XObject left, XObject right);
+  
+  /**
+   * Method gtgt.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject gtgt(XObject left, XObject right);
+  
+  /**
+   * Method idiv.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject idiv(XObject left, XObject right);
+  
+  /**
+   * Method is.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject is(XObject left, XObject right);
+  
+  /**
+   * Method isnot.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject isnot(XObject left, XObject right);
+  
+  /**
+   * Method lt.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject lt(XObject left, XObject right);
+  
+  /**
+   * Method lte.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject lte(XObject left, XObject right);
+  
+  /**
+   * Method ltlt.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject ltlt(XObject left, XObject right);
+  
+  /**
+   * Method mod.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject mod(XObject left, XObject right);
+  
+  /**
+   * Method mult.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject mult(XObject left, XObject right);
+  
+  /**
+   * Method neg.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject neg(XObject left, XObject right);
+  
+  /**
+   * Method notequals.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject notequals(XObject left, XObject right);
+  
+  /**
+   * Method or.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject or(XObject left, XObject right);
+  
+  /**
+   * Method pos.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject pos(XObject left, XObject right);
+  
+  /**
+   * Method precedes.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject precedes(XObject left, XObject right);
+  
+  /**
+   * Method quo.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject quo(XObject left, XObject right);
+  
+  /**
+   * Method subtract.
+   * @param left
+   * @param right
+   * @return XObject
+   */
+  public XObject subtract(XObject left, XObject right);
+}
diff --git a/src/org/apache/xpath/objects/XBoolean.java b/src/org/apache/xpath/objects/XBoolean.java
index 6d406ee..9c04f03 100644
--- a/src/org/apache/xpath/objects/XBoolean.java
+++ b/src/org/apache/xpath/objects/XBoolean.java
@@ -56,6 +56,7 @@
  */
 package org.apache.xpath.objects;
 
+import org.apache.xml.dtm.XType;
 import org.w3c.dom.*;
 
 /**
@@ -65,33 +66,26 @@
  */
 public class XBoolean extends XObject
 {
+	boolean m_val;
 
-  /**
-   * <meta name="usage" content="internal"/>
-   * A true boolean object so we don't have to keep creating them.
-   */
-  public static XBoolean S_TRUE = new XBooleanStatic(true);
+  public final static XBoolean S_TRUE = new XBoolean(true);
+  public final static XBoolean S_FALSE = new XBoolean(false);
 
-  /**
-   * <meta name="usage" content="internal"/>
-   * A true boolean object so we don't have to keep creating them.
-   */
-  public static XBoolean S_FALSE = new XBooleanStatic(false);
-
-  /** Value of the object.
-   *  @serial         */
-  boolean m_val;
 
   /**
    * Construct a XBoolean object.
+   * 
+   * NOTE: Arguably, this should not be a public ctor; folks
+   * should instead be calling a factory which returns one of
+   * the statics. Problem with that: If XBoolean ever directly
+   * implements XSequence, and XSequence behaves as a singleton
+   * iterator... Count this as downside of that approach.
+   * %REVIEW%
    *
    * @param b Value of the boolean object
    */
   public XBoolean(boolean b)
   {
-
-    super();
-
     m_val = b;
   }
   
@@ -102,13 +96,17 @@
    */
   public XBoolean(Boolean b)
   {
-
-    super();
-
     m_val = b.booleanValue();
-    m_obj = b;
   }
-
+  
+  /**
+   * Return the sequence representing this object.
+   * @return XSequence
+   */
+  public XSequence xseq()
+  {
+    return new XSequenceSingleton(this);
+  }
 
   /**
    * Tell that this is a CLASS_BOOLEAN.
@@ -169,9 +167,7 @@
    */
   public Object object()
   {
-    if(null == m_obj)
-      m_obj = m_val ? S_TRUE : S_FALSE;
-    return m_obj;
+	return m_val ? Boolean.TRUE : Boolean.FALSE;
   }
 
   /**
@@ -185,12 +181,13 @@
    */
   public boolean equals(XObject obj2)
   {
-
+  	// Alternative approach would be implement equals(XNodeset)...?
+  	
     // In order to handle the 'all' semantics of 
     // nodeset comparisons, we always call the 
     // nodeset function.
-    if (obj2.getType() == XObject.CLASS_NODESET)
-      return obj2.equals(this);
+    if (obj2.isNodesetExpr())
+      return ((XNodeSet)obj2).equalsExistential(this);
 
     try
     {
diff --git a/src/org/apache/xpath/objects/XDTDuration.java b/src/org/apache/xpath/objects/XDTDuration.java
new file mode 100644
index 0000000..6714046
--- /dev/null
+++ b/src/org/apache/xpath/objects/XDTDuration.java
@@ -0,0 +1,278 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+//import org.w3c.dom.*;
+import java.util.Locale;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import javax.xml.transform.TransformerException;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.utils.CharacterBlockEnumeration;
+import org.apache.xml.utils.XMLCharacterRecognizer;
+import org.apache.xml.utils.XMLString;
+import org.apache.xml.utils.XMLStringFactory;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xml.utils.Duration;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.parser.Token;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * <meta name="usage" content="general"/>
+ * This class represents an XPath string object, and is capable of
+ * converting the string to other types, such as a number.
+ */
+public class XDTDuration extends XDuration 
+{
+
+  /** Empty string XString object */
+  public static XString EMPTYSTRING = new XString("");
+  
+  /**
+   * Construct a XDate object, with a null value.
+   * This one's actually being used, unlike most XObject empty ctors
+   * ... but I'm not sure why; it's equivalent to passing in null.
+   */
+  public XDTDuration()
+  {
+    super();
+  }
+
+
+  /**
+   * Construct a XDate object.  This constructor exists for derived classes.
+   *
+   * @param val Date object this will wrap.
+   */
+  //protected XDuration(Object val)
+  //{
+  //  super(val);
+  //}
+
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  //public XDuration(String val)
+  //{
+  //  super(val);
+  //}
+  
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  public XDTDuration(Duration val)
+  {
+    //super(val);
+    m_val = val;
+  }
+  
+
+  /**
+   * Tell that this is a CLASS_DURATION.
+   *
+   * @return type CLASS_DURATION
+   */
+  public int getType()
+  {
+    return this.CLASS_DTDURATION;
+  }
+
+  /**
+   * Given a request type, return the equivalent string.
+   * For diagnostic purposes.
+   *
+   * @return type string "#DURATION"
+   */
+  public String getTypeString()
+  {
+    return "#DAYTIMEDURATION";
+  }  
+  
+  
+  /**
+   * Tell if two objects are functionally equal.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return true if the two objects are equal
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean equals(XObject obj2)
+  {
+
+    // In order to handle the 'all' semantics of 
+    // nodeset comparisons, we always call the 
+    // nodeset function.
+    int t = obj2.getType();
+    if(XObject.CLASS_DTDURATION == t)
+	    	return m_val.DTEqual(((XDuration)obj2).m_val);	
+    
+
+    // Otherwise, both objects to be compared are converted to strings as 
+    // if by applying the string function. 
+    return xstr().equals(obj2.xstr());
+  }
+  
+  /**
+   * Tell if one object is less than the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is less than the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean lessThan(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    int t = obj2.getType();
+    if(XObject.CLASS_DTDURATION == t)
+    {
+    	Duration du = ((XDuration)obj2).m_val;
+	   return m_val.DTLessThan(du);
+    }
+     else
+       return this.num() < obj2.num();
+  }
+  
+  /**
+   * Tell if one object is less than or equal to the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is less than or equal to the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean lessThanOrEqual(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    int t = obj2.getType();
+    if(XObject.CLASS_DTDURATION == t)
+	   {
+    	Duration du = ((XDuration)obj2).m_val;
+	   return m_val.DTLessThanOrEqual(du);
+    }
+     else
+       return this.num() <= obj2.num();
+  }
+  
+  
+   /**
+   * Tell if one object is greater than the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is greater than the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean greaterThan(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+    int t = obj2.getType();
+    if(XObject.CLASS_DTDURATION == t)
+	  {
+    	Duration du = ((XDuration)obj2).m_val;
+	   return m_val.DTGreaterThan(du);
+      }
+    else
+      return this.num() > obj2.num();
+  }
+
+
+  /**
+   * Tell if one object is greater than or equal to the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is greater than or equal to the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean greaterThanOrEqual(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    int t = obj2.getType();
+    if(XObject.CLASS_DTDURATION == t)
+	  {
+    	Duration du = ((XDuration)obj2).m_val;
+	   return m_val.DTGreaterThanOrEqual(du);
+      }
+    else
+      return this.num() >= obj2.num();
+  }
+ 
+}
diff --git a/src/org/apache/xpath/objects/XDTMSequence.java b/src/org/apache/xpath/objects/XDTMSequence.java
new file mode 100644
index 0000000..0dcfc4a
--- /dev/null
+++ b/src/org/apache/xpath/objects/XDTMSequence.java
@@ -0,0 +1,560 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.DTMSequence;
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.WrappedRuntimeException;
+import org.apache.xml.utils.XMLString;
+
+/** This class provides an API representation for the XPath 2 Data Model's "Sequences"
+ * -- which are the basic representation for typed values. Only built-in types, 
+ * types derived from built-ins, and sets thereof are returned directly by the XPath2
+ * DM; complex schema-types must be accessed through the document tree.
+ * 
+ * This implementation exists as a wrapper/proxy for the primitive
+ * DTMSequence object. DTM is not aware of XPath, and DTMSequence
+ * returns its values as primitive Java objects; we need to re-express
+ * that in XPath objects.
+ * */
+public class XDTMSequence extends XObject implements XSequence
+{
+	DTMSequence m_dtmseq;
+
+	protected int m_pos = -1;
+	protected int m_homogtype = -1; // cache getTypes()
+  
+  /** Create a sequence, initially empty.
+   * */
+  public XDTMSequence(DTMSequence seq)
+  {
+  	m_dtmseq=seq;
+  }
+
+	
+	/** @return the number of members in this sequence. */
+	public int getLength()
+	{
+		return m_dtmseq.getLength();
+	}
+	
+	/** Retrieve the value for this member of the sequence. Since values may be
+	 * a heterogenous mix, and their type may not be known until they're examined,
+	 * they're returned as Objects. This is storage-inefficient if the value(s)
+	 * is/are builtins that map to Java primitives. Tough.
+	 * 
+	 * @param index 0-based index into the sequence.
+	 * @return the specified value
+	 * @throws exception if index <0 or >=length	 
+	 * */
+	public XObject next()
+	{
+	    if(m_pos >= m_dtmseq.getLength()-1)
+    	  return null;
+	  	return XObjectFactory.create(m_dtmseq.getValue(++m_pos));
+	}
+  
+	/**
+	 * @see org.apache.xml.dtm.XSequence#previous()
+	 */
+	public XObject previous()
+	{
+	    if(m_pos <= 0)
+    	  return null;
+	  	return XObjectFactory.create(m_dtmseq.getValue(--m_pos));
+	}
+	
+	/** %REVIEW% Format not yet firmly settled. Primarily for debugging purposes!
+	 * */
+	public String toString()
+	{
+		return m_dtmseq.toString();
+	}
+  
+  /**
+   * @see org.apache.xml.dtm.XSequence#allowDetachToRelease(boolean)
+   */
+  public void allowDetachToRelease(boolean allowRelease)
+  {
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#detach()
+   */
+  public void detach()
+  {
+    // Do nothing
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getCurrent()
+   */
+  public XObject getCurrent()
+  {
+    int pos = m_pos;
+    
+  	return XObjectFactory.create(m_dtmseq.getValue(m_pos));
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getCurrentPos()
+   */
+  public int getCurrentPos()
+  {
+    return m_pos;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getTypeLocalName()
+   */
+  public String getTypeLocalName()
+  {
+  	return m_dtmseq.getTypeLocalName(m_pos);
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getTypeNS()
+   */
+  public String getTypeNS()
+  {
+  	return m_dtmseq.getTypeNS(m_pos);
+  }
+
+  /**
+   * If this iterator holds homogenous primitive types, return that type ID.
+   * 
+   * @return The homogenous type, or NOTHOMOGENOUS, or EMPTYSEQ.
+   */
+  public int getTypes()
+  {
+  	if(m_homogtype==-1) // Return cached value if available
+  	{
+		if(m_dtmseq.getLength()==0)
+  			m_homogtype=XType.EMPTYSEQ;
+  		else
+  		{
+		  	// AT THIS TIME, DTMSequences are always homogenous
+		  	// collections of primitives,
+  			// so I can just check the current element. If that 
+  			// changes, we'll have to loop and check for conflicts.
+	  		//
+		  	// %REVIEW% Should we do so now, as safety net?
+		  	// Probably safer...
+			m_homogtype=getType();
+  		}
+  	}  	
+  	return m_homogtype;
+  }
+  
+  
+  /**
+   * @see org.apache.xml.dtm.XSequence#getType()
+   */
+  public int getType()
+  {
+  	if(m_dtmseq.getLength()==0)
+  		return m_homogtype=XType.EMPTYSEQ;
+
+  	String[] names=XType.getNames();
+
+  	// Need to check for derivation, rather than just doing lookup
+  	// against the name table as in XType.getTypeFromLocalName()
+  	//
+  	// %REVIEW% What if m_pos is still -1?
+  	// ... XSequenceImpl doesn't deal either. Ignored for now.
+  	for(int whichtype=names.length-1;whichtype>=0;--whichtype)
+  	{
+  		if(m_dtmseq.isSchemaType(m_pos,XType.XMLSCHEMA_NAMESPACE,names[whichtype]))
+  			return m_homogtype=whichtype;
+  	}
+  	
+    return XType.SEQ; // ANYTYPE? NOTHOMOGENOUS? Shouldn't arise...
+  }
+  
+  /**
+   * @see org.apache.xml.dtm.XSequence#getType()
+   */
+  public int getValueType(int pos)
+  {
+    String ns = m_dtmseq.getTypeNS(pos);
+    String localName = m_dtmseq.getTypeLocalName(pos);
+    int typeID = XType.getTypeID(ns, localName);
+    return typeID;
+  }
+  
+  /**
+   * @see org.apache.xml.dtm.XSequence#getType()
+   */
+  public int getValueType()
+  {m_dtmseq.getTypeLocalName(m_pos);
+    String ns = getTypeNS();
+    String localName = getTypeLocalName();
+    int typeID = XType.getTypeID(ns, localName);
+    return typeID;
+  }
+
+
+  /** @return false -- this type is not used for nodes
+   * */
+  public boolean isPureNodeSequence()
+  {
+  	return false;	
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isFresh()
+   */
+  public boolean isFresh()
+  {
+    return (m_pos == -1) ? true : false;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isMutable()
+   */
+  public boolean isMutable()
+  {
+    return false;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isSchemaType(String, String)
+   */
+  public boolean isSchemaType(String namespace, String localname)
+  {
+  	return m_dtmseq.isSchemaType(m_pos,namespace,localname);
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isSingletonOrEmpty()
+   */
+  public boolean isSingletonOrEmpty()
+  {
+    return m_dtmseq.getLength() <= 1;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#setCurrentPos(int)
+   */
+  public void setCurrentPos(int i)
+  {
+  	// %REVIEW% What if i is out of range?
+    m_pos = i-1;
+  }
+
+  /**
+   * This method performs no actions.
+   * @see org.apache.xml.dtm.XSequence#setShouldCache(boolean)
+   */
+  public void setShouldCache(boolean b)
+  {
+    // Ignore.  We always cache.
+  }
+
+  /**
+   * @return true -- setCurrentPos() works for this object
+   * @see org.apache.xml.dtm.XSequence#getIsRandomAccess()
+   */
+  public boolean getIsRandomAccess()
+  {
+    return true;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#reset()
+   */
+  public void reset()
+  {
+    m_pos = -1;
+  }
+
+
+  /**
+   * @see java.lang.Object#clone()
+   */
+  public Object clone() throws CloneNotSupportedException
+  {
+    return super.clone();
+  }
+
+  /**
+   * Return a (fresh) sequence representing this object.
+   * @return XSequence
+   */
+  public XSequence xseq()
+  {
+    if(isFresh())
+      return this;
+    try
+    {
+      XSequence xseq = (XSequence)this.clone();
+      xseq.reset();
+      return xseq;
+    }
+    catch (CloneNotSupportedException e)
+    {
+      // will never happen
+      throw new WrappedRuntimeException(e);
+    }
+  }
+  
+  public Object object()
+  {
+  	return m_dtmseq;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequenceMutable#getItem(int)
+   */
+  public XObject getItem(int pos)
+  {
+  	Object value=m_dtmseq.getValue(pos);
+
+  	// %TODO% At the low level, date/time are being returned as
+  	// int[8] (because Xerces hasn't yet defined its own class
+  	// to represent these). DateTimeObj isn't currently 
+  	// set up to take this array and a type hint, and DTM is
+  	// not currently set up to return the original strings.
+  	// We could change either end of that equation. Improving
+  	// DateTimeObj would be more efficient but bind us
+  	// explicitly to Xerces' current stopgap...
+  	//
+  	// Durations are treated similarly.  	
+  	if(value instanceof int[])
+  	{
+  		if("duration".equals(getTypeLocalName()) &&
+  			XType.XMLSCHEMA_NAMESPACE.equals(getTypeNS()))
+  			value=new Duration((int[])value);
+  	
+	  	else // It's a date of some flavor
+      {
+        DateTimeObj dt=new DateTimeObj((int[])value,getTypeLocalName());
+
+        // The following is only good enough for now.  Needs more work. -sb
+        int t = getValueType(pos);
+        if(XType.DATE == t)
+          return new XDate(dt);
+        else if(XType.TIME == t)
+          return new XTime(dt);
+          
+        value = dt;
+          
+      }
+  	}
+
+  	return XObjectFactory.create(value);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#isSequenceProper()
+   */
+  public boolean isSequenceProper()
+  {
+    return true;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#bool()
+   */
+  public boolean bool() throws TransformerException
+  {
+  	try
+  	{
+	    return getItem(0).bool();
+  	}
+  	catch(ArrayIndexOutOfBoundsException e)
+  	{
+  		return false; // Boolean has no NAN
+  	}
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#boolWithSideEffects()
+   */
+  public boolean boolWithSideEffects() throws TransformerException
+  {
+  	try
+  	{
+	    return getItem(0).boolWithSideEffects();
+  	}
+  	catch(ArrayIndexOutOfBoundsException e)
+  	{
+  		return false; // Boolean has no NAN
+  	}
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#date()
+   */
+  public DateTimeObj date() throws TransformerException
+  {
+    return getItem(0).date();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#datetime()
+   */
+  public DateTimeObj datetime() throws TransformerException
+  {
+    return getItem(0).datetime();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#daytimeDuration()
+   */
+  public Duration daytimeDuration() throws TransformerException
+  {
+    return getItem(0).daytimeDuration();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#duration()
+   */
+  public Duration duration() throws TransformerException
+  {
+    return getItem(0).duration();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#floatVal()
+   */
+  public float floatVal() throws TransformerException
+  {
+  	try
+  	{
+	    return getItem(0).floatVal();
+  	}
+  	catch(ArrayIndexOutOfBoundsException e)
+  	{
+  		return Float.NaN;
+  	}
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#integer()
+   */
+  public int integer() throws TransformerException
+  {
+  	try
+  	{
+	    return getItem(0).integer();
+  	}
+  	catch(ArrayIndexOutOfBoundsException e)
+  	{
+  		return 0; // Integer has no NAN
+  	}
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#num()
+   */
+  public double num() throws TransformerException
+  {
+  	try
+  	{
+	    return getItem(0).num();
+  	}
+  	catch(ArrayIndexOutOfBoundsException e)
+  	{
+  		return Double.NaN;
+  	}
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#str()
+   */
+  public String str()
+  {
+  	try
+  	{
+	    return getItem(0).str();
+  	}
+  	catch(ArrayIndexOutOfBoundsException e)
+  	{
+  		return "";
+  	}
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#xstr()
+   */
+  public XMLString xstr()
+  {
+  	try
+  	{
+	    return getItem(0).xstr();
+  	}
+  	catch(ArrayIndexOutOfBoundsException e)
+  	{
+  		return XString.EMPTYSTRING;
+  	}
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#yearmonthDuration()
+   */
+  public Duration yearmonthDuration() throws TransformerException
+  {
+    return getItem(0).yearmonthDuration();
+  }
+
+}
+
diff --git a/src/org/apache/xpath/objects/XDate.java b/src/org/apache/xpath/objects/XDate.java
new file mode 100644
index 0000000..ed112fd
--- /dev/null
+++ b/src/org/apache/xpath/objects/XDate.java
@@ -0,0 +1,152 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+//import org.w3c.dom.*;
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xpath.res.XPATHErrorResources;
+
+/**
+ * <meta name="usage" content="general"/>
+ * This class represents an XPath string object, and is capable of
+ * converting the string to other types, such as a number.
+ */
+public class XDate extends XDateTime 
+{
+
+  /**
+   * Construct a XDate object, with a null value.
+   */
+  public XDate()
+  {
+    super();
+  }
+
+
+  /**
+   * Construct a XDate object.  This constructor exists for derived classes.
+   *
+   * @param val Date object this will wrap.
+   */
+  //protected XDate(Object val)
+  //{
+  //  super(val);
+  //}
+
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  //public XDate(Date val)
+  //{
+  //  super(val);
+  //}
+  
+  /**
+   * Construct a XDate object.
+   *
+   * @param val DateTimeObj object this will wrap.
+   */
+  public XDate(DateTimeObj val)
+  {
+    super(val);
+  }
+
+  /**
+   * Tell that this is a CLASS_DATE.
+   *
+   * @return type CLASS_DATE
+   */
+  public int getType()
+  {
+    return CLASS_DATE;
+  }
+
+  /**
+   * Given a request type, return the equivalent string.
+   * For diagnostic purposes.
+   *
+   * @return type string "#DATE"
+   */
+  public String getTypeString()
+  {
+    return "#DATE";
+  }
+  
+  /**
+   * @see org.apache.xpath.objects.XObject#datetime()
+   */
+  public DateTimeObj datetime() throws TransformerException
+  {
+    error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
+          new Object[]{ getTypeString(), "DATETIME" });  //"Can not convert "+getTypeString()+" to a number");
+
+    return new DateTimeObj(""); // To shut up compiler
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#date()
+   */
+  public DateTimeObj date() throws TransformerException
+  {
+    return m_val;
+  }
+
+}
diff --git a/src/org/apache/xpath/objects/XDateTime.java b/src/org/apache/xpath/objects/XDateTime.java
new file mode 100644
index 0000000..12e01f5
--- /dev/null
+++ b/src/org/apache/xpath/objects/XDateTime.java
@@ -0,0 +1,405 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+//import org.w3c.dom.*;
+import java.util.Locale;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import javax.xml.transform.TransformerException;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.utils.CharacterBlockEnumeration;
+import org.apache.xml.utils.XMLCharacterRecognizer;
+import org.apache.xml.utils.XMLString;
+import org.apache.xml.utils.XMLStringFactory;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.parser.Token;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * <meta name="usage" content="general"/>
+ * This class represents an XPath string object, and is capable of
+ * converting the string to other types, such as a number.
+ */
+public class XDateTime extends XObject 
+{
+
+  /** Empty string XString object */
+  public static XString EMPTYSTRING = new XString("");
+  
+  /**
+   * Construct a XDate object, with a null value.
+   */
+  public XDateTime()
+  {
+    //super(null);
+  }
+
+
+  /**
+   * Construct a XDate object.  This constructor exists for derived classes.
+   *
+   * @param val Date object this will wrap.
+   */
+  //protected XDateTime(Object val)
+  //{
+  //  super(val);
+  //}
+
+  /**
+   * Construct a XDate object.
+   *
+   * @param val Date object this will wrap.
+   */
+  //public XDateTime(Date val)
+  //{
+  //  super(val);
+  //}
+  
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  //public XDateTime(String val)
+  //{
+  //  super(val);
+  //}
+  
+  DateTimeObj m_val;
+  
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  public XDateTime(DateTimeObj val)
+  {
+    //super(val);
+    m_val = val; 
+  }
+
+  /**
+   * Tell that this is a CLASS_DATE.
+   *
+   * @return type CLASS_DATE
+   */
+  public int getType()
+  {
+    return CLASS_DATETIME;
+  }
+
+  /**
+   * Given a request type, return the equivalent string.
+   * For diagnostic purposes.
+   *
+   * @return type string "#DATE"
+   */
+  public String getTypeString()
+  {
+    return "#DATETIME";
+  }
+
+	public Object object()
+	{
+		return m_val;
+	}
+  
+
+  /**
+   * Cast result object to a number.
+   *
+   * @return 0.0 if this string is null, numeric value of this string
+   * or NaN
+   */
+  public double num()
+  {
+  	return new Long(m_val.getDate().getTime()).doubleValue();
+  	/*
+  	if (m_obj instanceof DateTimeObj)
+  	return (new Long(((DateTimeObj)m_obj).getDate().getTime()).doubleValue());
+  	else if (m_obj instanceof Date)
+  	{
+  	long time = ((Date)m_obj).getTime();
+  	return (new Long(time)).doubleValue();
+  	}
+    else if (m_obj instanceof String)
+    return xstr().toDouble();
+     else
+    return Double.NaN;
+    */
+  }
+
+  
+  /**
+   * Cast result object to a boolean.
+   *
+   * @return True if the length of this string object is greater
+   * than 0.
+   */
+  public boolean bool()
+  {
+    return str().length() > 0;
+  }
+  
+
+  /**
+   * Cast result object to a string.
+   *
+   * @return The string this wraps or the empty string if null
+   */
+  public String str()
+  {
+  	if (m_val != null)
+	  	return m_val.toString();
+    else
+      return "";
+  }
+  
+  
+
+  /**
+   * Cast result object to a result tree fragment.
+   *
+   * @param support Xpath context to use for the conversion
+   *
+   * @return A document fragment with this string as a child node
+   */
+  public int rtf(XPathContext support)
+  {
+
+    DTM frag = support.createDocumentFragment();
+
+    frag.appendTextChild(str());
+
+    return frag.getDocument();
+  }
+
+  /**
+   * Directly call the
+   * characters method on the passed ContentHandler for the
+   * string-value. Multiple calls to the
+   * ContentHandler's characters methods may well occur for a single call to
+   * this method.
+   *
+   * @param ch A non-null reference to a ContentHandler.
+   *
+   * @throws org.xml.sax.SAXException
+   */
+  public void dispatchCharactersEvents(org.xml.sax.ContentHandler ch)
+          throws org.xml.sax.SAXException
+  {
+
+    String str = str();
+
+    ch.characters(str.toCharArray(), 0, str.length());
+  }
+  
+  /**
+   * Tell if two objects are functionally equal.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return true if the two objects are equal
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean equals(XObject obj2)
+  {
+
+    // In order to handle the 'all' semantics of 
+    // nodeset comparisons, we always call the 
+    // nodeset function.
+    int t = obj2.getType();
+    if(XObject.CLASS_DATETIME == t ||
+	              XObject.CLASS_DATE == t ||
+	              XObject.CLASS_TIME == t )
+	   return m_val.equals(((XDateTime)obj2).m_val);
+     else
+       return false;
+     
+  }
+  
+ 
+  /**
+   * Tell if two objects are functionally not equal.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is not equal to the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean notEquals(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    // In order to handle the 'all' semantics of 
+    // nodeset comparisons, we always call the 
+    // nodeset function.
+    return !equals(obj2);
+  }
+  
+  /**
+   * Tell if one object is less than the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is less than the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean lessThan(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    int t = obj2.getType();
+    if(XObject.CLASS_DATETIME == t ||
+	              XObject.CLASS_DATE == t ||
+	              XObject.CLASS_TIME == t )
+	   return m_val.lessThan(((XDateTime)obj2).m_val);
+     else
+       return this.num() < obj2.num();
+  }
+  
+  /**
+   * Tell if one object is less than or equal to the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is less than or equal to the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean lessThanOrEqual(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    int t = obj2.getType();
+    if(XObject.CLASS_DATETIME == t ||
+	              XObject.CLASS_DATE == t ||
+	              XObject.CLASS_TIME == t )
+	   return m_val.lessThanOrEqual(((XDateTime)obj2).m_val);
+     else
+       return this.num() <= obj2.num();
+  }
+  
+  
+   /**
+   * Tell if one object is greater than the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is greater than the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean greaterThan(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+    int t = obj2.getType();
+    if(XObject.CLASS_DATETIME == t ||
+	              XObject.CLASS_DATE == t ||
+	              XObject.CLASS_TIME == t )
+	  return m_val.greaterThan(((XDateTime)obj2).m_val);
+    else
+      return this.num() > obj2.num();
+  }
+
+
+  /**
+   * Tell if one object is greater than or equal to the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is greater than or equal to the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean greaterThanOrEqual(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    int t = obj2.getType();
+    if(XObject.CLASS_DATETIME == t ||
+	              XObject.CLASS_DATE == t ||
+	              XObject.CLASS_TIME == t )
+	  return m_val.greaterThanOrEqual(((XDateTime)obj2).m_val);
+    else
+      return this.num() >= obj2.num();
+  }
+  
+  /**
+   * @see org.apache.xpath.objects.XObject#datetime()
+   */
+  public DateTimeObj datetime() throws TransformerException
+  {
+    return m_val;
+  }
+  
+
+}
diff --git a/src/org/apache/xpath/objects/XDecimal.java b/src/org/apache/xpath/objects/XDecimal.java
new file mode 100644
index 0000000..7dc8b52
--- /dev/null
+++ b/src/org/apache/xpath/objects/XDecimal.java
@@ -0,0 +1,20 @@
+package org.apache.xpath.objects;
+
+import org.apache.xml.dtm.XType;
+
+public class XDecimal extends XDouble  // TBD: For now, just use this as a double.
+{
+  /**
+   * Constructor for Decimal
+   * 
+   * This one's actually being used, unlike most XObject empty ctors,
+   * because it may be created and _then_ set (by processToken)
+   * during stylesheet parsing.
+   */
+  public XDecimal()
+  {
+    super();
+  }
+
+}
+
diff --git a/src/org/apache/xpath/objects/XDouble.java b/src/org/apache/xpath/objects/XDouble.java
new file mode 100644
index 0000000..a3e6024
--- /dev/null
+++ b/src/org/apache/xpath/objects/XDouble.java
@@ -0,0 +1,94 @@
+package org.apache.xpath.objects;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.parser.Token;
+
+public class XDouble extends XNumber
+{
+  double m_val;
+  //Double m_doubleobj;		// Cache; best guess is we don't need it
+
+  /**
+   * Constructor for XDouble
+   */
+  public XDouble(double num)
+  {
+    m_val = num;
+  }
+  
+  /**
+   * Constructor for XDouble
+   */
+  public XDouble(Double num)
+  {
+    m_val = num.doubleValue();
+    //m_doubleobj = num;
+  }
+  
+  /**
+   * Constructor for XDouble
+   */
+  public XDouble()
+  {
+  }
+  
+  public Object object()
+  {
+  	//if(m_doubleobj==null)
+  	//	m_doubleobj=new Double(m_val);
+  	//return m_doubleobj;
+  	return new Double(m_val);
+  }
+
+  /**
+   * Cast result object to a number.
+   *
+   * @return the value of the XNumber object
+   */
+  public double num()
+  {
+    return m_val;
+  }
+  
+  /**
+   * Evaluate expression to a number.
+   *
+   * @return 0.0
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public double num(XPathContext xctxt) 
+    throws javax.xml.transform.TransformerException
+  {
+    return m_val;
+  }
+
+  /**
+   * Cast result object to a boolean.
+   *
+   * @return false if the value is NaN or exactly equal to 0.0
+   */
+  public boolean bool()
+  {
+    return (Double.isNaN(m_val) || (m_val == 0.0)) ? false : true;
+  }
+  
+  public void processToken(Token t) 
+  { 
+  	String strNum = t.image;
+  	m_val = Double.parseDouble(strNum);
+  	//m_doubleobj=null; // Reset/defer
+  }
+
+  /**
+   * Return the sequence representing this object.
+   * @return XSequence
+   */
+  public XSequence xseq()
+  {
+    return new XSequenceSingleton(this);
+  }
+
+}
+
diff --git a/src/org/apache/xpath/objects/XDuration.java b/src/org/apache/xpath/objects/XDuration.java
new file mode 100644
index 0000000..6437db1
--- /dev/null
+++ b/src/org/apache/xpath/objects/XDuration.java
@@ -0,0 +1,401 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+//import org.w3c.dom.*;
+import java.util.Locale;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import javax.xml.transform.TransformerException;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.utils.CharacterBlockEnumeration;
+import org.apache.xml.utils.XMLCharacterRecognizer;
+import org.apache.xml.utils.XMLString;
+import org.apache.xml.utils.XMLStringFactory;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xml.utils.Duration;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.parser.Token;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * <meta name="usage" content="general"/>
+ * This class represents an XPath string object, and is capable of
+ * converting the string to other types, such as a number.
+ */
+public class XDuration extends XObject 
+{
+
+  /** Empty string XString object */
+  public static XString EMPTYSTRING = new XString("");
+  
+  /**
+   * Construct a XDate object, with a null value.
+   * This one's actually being used, unlike most XObject empty ctors
+   * ... but I'm not sure why; it's equivalent to passing in null.
+   */
+  public XDuration()
+  {
+    //super(null);
+  }
+
+
+  /**
+   * Construct a XDate object.  This constructor exists for derived classes.
+   *
+   * @param val Date object this will wrap.
+   */
+  //protected XDuration(Object val)
+  //{
+  //  super(val);
+  //}
+
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  //public XDuration(String val)
+  //{
+  //  super(val);
+  //}
+  
+  Duration m_val;
+  
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  public XDuration(Duration val)
+  {
+    //super(val);
+    m_val = val;
+  }
+  
+  public Object object()
+  {
+  	return m_val;
+  }
+
+  /**
+   * Tell that this is a CLASS_DURATION.
+   *
+   * @return type CLASS_DURATION
+   */
+  public int getType()
+  {
+    return CLASS_DURATION;
+  }
+
+  /**
+   * Given a request type, return the equivalent string.
+   * For diagnostic purposes.
+   *
+   * @return type string "#DURATION"
+   */
+  public String getTypeString()
+  {
+    return "#DURATION";
+  }
+
+  
+
+  /**
+   * Cast result object to a number.
+   *
+   * @return 0.0 if this string is null, numeric value of this string
+   * or NaN
+   */
+  public double num()
+  {
+    XMLString s = xstr();
+
+    return s.toDouble();
+  }
+
+  
+  /**
+   * Cast result object to a boolean.
+   *
+   * @return True if the length of this string object is greater
+   * than 0.
+   */
+  public boolean bool()
+  {
+    return str().length() > 0;
+  }
+  
+
+  /**
+   * Cast result object to a string.
+   *
+   * @return The object this wraps or the empty string if null
+   */
+  public String str()
+  {
+  	return m_val.toString();
+  	/**
+  	if(m_obj instanceof Duration)
+  	return (m_val).toString();
+  	else if(m_obj instanceof String)
+  	return (String)m_obj;
+  	else
+  	return m_obj.toString(); 
+  	*/
+  }
+  
+  /**
+   * Cast result object to a result tree fragment.
+   *
+   * @param support Xpath context to use for the conversion
+   *
+   * @return A document fragment with this string as a child node
+   */
+  public int rtf(XPathContext support)
+  {
+
+    DTM frag = support.createDocumentFragment();
+
+    frag.appendTextChild(str());
+
+    return frag.getDocument();
+  }
+
+  /**
+   * Directly call the
+   * characters method on the passed ContentHandler for the
+   * string-value. Multiple calls to the
+   * ContentHandler's characters methods may well occur for a single call to
+   * this method.
+   *
+   * @param ch A non-null reference to a ContentHandler.
+   *
+   * @throws org.xml.sax.SAXException
+   */
+  public void dispatchCharactersEvents(org.xml.sax.ContentHandler ch)
+          throws org.xml.sax.SAXException
+  {
+
+    String str = str();
+
+    ch.characters(str.toCharArray(), 0, str.length());
+  }
+
+  
+
+  
+  
+  /**
+   * Tell if two objects are functionally equal.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return true if the two objects are equal
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean equals(XObject obj2)
+  {
+
+    // In order to handle the 'all' semantics of 
+    // nodeset comparisons, we always call the 
+    // nodeset function.
+    int t = obj2.getType();
+    if(XObject.CLASS_DURATION == t)
+	    	return m_val.equals(((XDuration)obj2).m_val);	
+    
+
+    // Otherwise, both objects to be compared are converted to strings as 
+    // if by applying the string function. 
+    return xstr().equals(obj2.xstr());
+  }
+  
+  /**
+   * Tell if two objects are functionally not equal.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is not equal to the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean notEquals(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    // In order to handle the 'all' semantics of 
+    // nodeset comparisons, we always call the 
+    // nodeset function.
+    return !equals(obj2);
+  }
+  
+  /**
+   * Tell if one object is less than the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is less than the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean lessThan(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    int t = obj2.getType();
+    if(XObject.CLASS_DURATION == t)
+    {
+    	Duration du = ((XDuration)obj2).m_val;
+	   return (m_val.DTLessThan(du) && m_val.YMLessThan(du));
+    }
+     else
+       return this.num() < obj2.num();
+  }
+  
+  /**
+   * Tell if one object is less than or equal to the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is less than or equal to the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean lessThanOrEqual(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    int t = obj2.getType();
+    if(XObject.CLASS_DURATION == t)
+	   {
+    	Duration du = ((XDuration)obj2).m_val;
+	   return (m_val.DTLessThanOrEqual(du) && m_val.YMLessThanOrEqual(du));
+    }
+     else
+       return this.num() <= obj2.num();
+  }
+  
+  
+   /**
+   * Tell if one object is greater than the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is greater than the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean greaterThan(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+    int t = obj2.getType();
+    if(XObject.CLASS_DURATION == t)
+	  {
+    	Duration du = ((XDuration)obj2).m_val;
+	   return (m_val.DTGreaterThan(du) && m_val.YMGreaterThan(du));
+      }
+    else
+      return this.num() > obj2.num();
+  }
+
+
+  /**
+   * Tell if one object is greater than or equal to the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is greater than or equal to the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean greaterThanOrEqual(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    int t = obj2.getType();
+    if(XObject.CLASS_DURATION == t)
+	  {
+    	Duration du = ((XDuration)obj2).m_val;
+	   return (m_val.DTGreaterThanOrEqual(du) && m_val.YMGreaterThanOrEqual(du));
+      }
+    else
+      return this.num() >= obj2.num();
+  }
+
+  /**
+   * Cast result object to a DURATION.
+   *
+   * @return Duration
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public Duration duration() throws javax.xml.transform.TransformerException
+  {
+    return m_val;
+  }
+ 
+}
diff --git a/src/org/apache/xpath/objects/XFloat.java b/src/org/apache/xpath/objects/XFloat.java
new file mode 100644
index 0000000..56e573c
--- /dev/null
+++ b/src/org/apache/xpath/objects/XFloat.java
@@ -0,0 +1,101 @@
+package org.apache.xpath.objects;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.parser.Token;
+
+public class XFloat extends XNumber
+{
+  float m_val;
+
+  /**
+   * Constructor for XDouble
+   */
+  public XFloat(float num)
+  {
+    m_val = num;
+  }
+  
+  /**
+   * Constructor for XDouble
+   */
+  public XFloat(Float num)
+  {
+    m_val = num.floatValue();
+  }
+  
+  /**
+   * Constructor for XDouble
+   */
+  public XFloat()
+  {
+  }
+  
+  public Object object()
+  {
+  	return new Float(m_val);
+  }
+
+  /**
+   * Cast result object to a number.
+   *
+   * @return the value of the XNumber object
+   */
+  public double num()
+  {
+    return m_val;
+  }
+  
+  /**
+   * Get result object as a integer.
+   *
+   * @return At this level, the num() value cast to an integer.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public float floatVal() throws javax.xml.transform.TransformerException
+  {
+
+    return m_val;
+  }
+  
+  /**
+   * Evaluate expression to a number.
+   *
+   * @return 0.0
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public double num(XPathContext xctxt) 
+    throws javax.xml.transform.TransformerException
+  {
+    return m_val;
+  }
+
+  /**
+   * Cast result object to a boolean.
+   *
+   * @return false if the value is NaN or exactly equal to 0.0
+   */
+  public boolean bool()
+  {
+    return (Double.isNaN(m_val) || (m_val == 0.0)) ? false : true;
+  }
+  
+  public void processToken(Token t) 
+  { 
+  	String strNum = t.image;
+  	m_val = Float.parseFloat(strNum);
+  }
+
+  /**
+   * Return the sequence representing this object.
+   * @return XSequence
+   */
+  public XSequence xseq()
+  {
+    return new XSequenceSingleton(this);
+  }
+
+}
+
diff --git a/src/org/apache/xpath/objects/XGDay.java b/src/org/apache/xpath/objects/XGDay.java
new file mode 100644
index 0000000..f0ed80d
--- /dev/null
+++ b/src/org/apache/xpath/objects/XGDay.java
@@ -0,0 +1,196 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+//import org.w3c.dom.*;
+import java.util.Locale;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import javax.xml.transform.TransformerException;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.utils.CharacterBlockEnumeration;
+import org.apache.xml.utils.XMLCharacterRecognizer;
+import org.apache.xml.utils.XMLString;
+import org.apache.xml.utils.XMLStringFactory;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.parser.Token;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * <meta name="usage" content="general"/>
+ * This class represents an XPath string object, and is capable of
+ * converting the string to other types, such as a number.
+ */
+public class XGDay extends XDate 
+{
+
+  /**
+   * Construct a XDate object, with a null value.
+   */
+  protected XGDay()
+  {
+    super();
+  }
+
+
+  /**
+   * Construct a XDate object.  This constructor exists for derived classes.
+   *
+   * @param val Date object this will wrap.
+   */
+  //protected XGDay(Object val)
+  //{
+  // super(val);
+  //}
+
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  //public XGDay(Date val)
+  //{
+  //  super(val);
+  //}
+  
+  /**
+   * Construct a XDate object.
+   *
+   * @param val DateTimeObj object this will wrap.
+   */
+  public XGDay(DateTimeObj val)
+  {
+    super(val);
+  }
+
+  /**
+   * Tell that this is a CLASS_GDAY.
+   *
+   * @return type CLASS_GDAY
+   */
+  public int getType()
+  {
+    return CLASS_GDAY;
+  }
+
+  /**
+   * Given a request type, return the equivalent string.
+   * For diagnostic purposes.
+   *
+   * @return type string "#DATE"
+   */
+  public String getTypeString()
+  {
+    return "#GDAY";
+  }
+
+
+  /**
+   * Cast result object to a string.
+   *
+   * @return The string this wraps or the empty string if null
+   */
+  public String str()
+  {
+  	return super.str();
+
+  	/**
+  	if (m_obj!= null)
+  	{
+  		if (m_obj instanceof Date)
+  		{
+  	Date date = (Date) m_obj;
+  	SimpleDateFormat dateFormat = new SimpleDateFormat(DateTimeObj.gd);      
+    return dateFormat.format(date);
+  		}
+  		else if (m_obj instanceof DateTimeObj)
+  		return ((DateTimeObj)m_obj).toString();
+  		else if(m_obj instanceof String)
+  	   return (String)m_obj;
+  	}
+      return "";
+      **/
+  }
+  
+  
+
+  
+
+  
+
+  
+  
+  
+
+  
+
+  
+
+  
+  
+ 
+}
diff --git a/src/org/apache/xpath/objects/XGMonth.java b/src/org/apache/xpath/objects/XGMonth.java
new file mode 100644
index 0000000..048379c
--- /dev/null
+++ b/src/org/apache/xpath/objects/XGMonth.java
@@ -0,0 +1,195 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+//import org.w3c.dom.*;
+import java.util.Locale;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import javax.xml.transform.TransformerException;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.utils.CharacterBlockEnumeration;
+import org.apache.xml.utils.XMLCharacterRecognizer;
+import org.apache.xml.utils.XMLString;
+import org.apache.xml.utils.XMLStringFactory;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.parser.Token;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * <meta name="usage" content="general"/>
+ * This class represents an XPath string object, and is capable of
+ * converting the string to other types, such as a number.
+ */
+public class XGMonth extends XDate 
+{
+
+  /**
+   * Construct a XDate object, with a null value.
+   */
+  protected XGMonth()
+  {
+    super();
+  }
+
+
+  /**
+   * Construct a XDate object.  This constructor exists for derived classes.
+   *
+   * @param val Date object this will wrap.
+   */
+  //protected XGMonth(Object val)
+  //{
+  //  super(val);
+  //}
+
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  //public XGMonth(Date val)
+  //{
+  //  super(val);
+  //}
+  
+  /**
+   * Construct a XDate object.
+   *
+   * @param val DateTimeObj object this will wrap.
+   */
+  public XGMonth(DateTimeObj val)
+  {
+    super(val);
+  }
+
+  /**
+   * Tell that this is a CLASS_GMONTH.
+   *
+   * @return type CLASS_GMONTH
+   */
+  public int getType()
+  {
+    return CLASS_GMONTH;
+  }
+
+  /**
+   * Given a request type, return the equivalent string.
+   * For diagnostic purposes.
+   *
+   * @return type string "#GMONTH"
+   */
+  public String getTypeString()
+  {
+    return "#GMONTH";
+  }
+
+  /**
+   * Cast result object to a string.
+   *
+   * @return The string this wraps or the empty string if null
+   */
+  public String str()
+  {
+  	return super.str();
+
+  	/*
+  	if (m_obj!= null)
+  	{
+  		if (m_obj instanceof Date)
+  		{
+  	Date date = (Date) m_obj;
+  	SimpleDateFormat dateFormat = new SimpleDateFormat(DateTimeObj.gm);      
+    return dateFormat.format(date);
+  		}
+  		else if (m_obj instanceof DateTimeObj)
+  		return ((DateTimeObj)m_obj).toString();
+  		else if(m_obj instanceof String)
+  	   return (String)m_obj;
+  	}
+      return "";
+      */
+  }
+  
+  
+
+  
+
+  
+
+  
+  
+  
+
+  
+
+  
+
+  
+  
+ 
+}
diff --git a/src/org/apache/xpath/objects/XGMonthDay.java b/src/org/apache/xpath/objects/XGMonthDay.java
new file mode 100644
index 0000000..7c55721
--- /dev/null
+++ b/src/org/apache/xpath/objects/XGMonthDay.java
@@ -0,0 +1,200 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+//import org.w3c.dom.*;
+import java.util.Locale;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import javax.xml.transform.TransformerException;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.utils.CharacterBlockEnumeration;
+import org.apache.xml.utils.XMLCharacterRecognizer;
+import org.apache.xml.utils.XMLString;
+import org.apache.xml.utils.XMLStringFactory;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.parser.Token;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * <meta name="usage" content="general"/>
+ * This class represents an XPath string object, and is capable of
+ * converting the string to other types, such as a number.
+ */
+public class XGMonthDay extends XDate 
+{
+
+  /**
+   * Construct a XDate object, with a null value.
+   */
+  protected XGMonthDay()
+  {
+    super();
+  }
+
+
+  /**
+   * Construct a XDate object.  This constructor exists for derived classes.
+   *
+   * @param val Date object this will wrap.
+   */
+  //protected XGMonthDay(Object val)
+  //{
+  //  super(val);
+  //}
+
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  //public XGMonthDay(Date val)
+  //{
+  //  super(val);
+  //}
+  
+  /**
+   * Construct a XDate object.
+   *
+   * @param val DateTimeObj object this will wrap.
+   */
+  public XGMonthDay(DateTimeObj val)
+  {
+    super(val);
+  }
+
+  /**
+   * Tell that this is a CLASS_GMONTHDAY.
+   *
+   * @return type CLASS_GMONTHDAY
+   */
+  public int getType()
+  {
+    return CLASS_GMONTHDAY;
+  }
+
+  /**
+   * Given a request type, return the equivalent string.
+   * For diagnostic purposes.
+   *
+   * @return type string "#GMONTHDAY"
+   */
+  public String getTypeString()
+  {
+    return "#GMONTHDAY";
+  }
+
+  
+
+  
+  
+
+  /**
+   * Cast result object to a string.
+   *
+   * @return The string this wraps or the empty string if null
+   */
+  public String str()
+  {
+  	return super.str();
+
+  	/*
+  	if (m_obj!= null)
+  	{
+  		if (m_obj instanceof Date)
+  		{
+  	Date date = (Date) m_obj;
+  	SimpleDateFormat dateFormat = new SimpleDateFormat(DateTimeObj.gmd);      
+    return dateFormat.format(date);
+  		}
+  		else if (m_obj instanceof DateTimeObj)
+  		return ((DateTimeObj)m_obj).toString();
+  		else if(m_obj instanceof String)
+  	   return (String)m_obj;
+  	}
+      return "";
+      */
+  }
+  
+  
+
+  
+
+  
+
+  
+  
+  
+
+  
+
+  
+
+  
+  
+ 
+}
diff --git a/src/org/apache/xpath/objects/XGYearMonth.java b/src/org/apache/xpath/objects/XGYearMonth.java
new file mode 100644
index 0000000..463ee6b
--- /dev/null
+++ b/src/org/apache/xpath/objects/XGYearMonth.java
@@ -0,0 +1,199 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+//import org.w3c.dom.*;
+import java.util.Locale;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import javax.xml.transform.TransformerException;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.utils.CharacterBlockEnumeration;
+import org.apache.xml.utils.XMLCharacterRecognizer;
+import org.apache.xml.utils.XMLString;
+import org.apache.xml.utils.XMLStringFactory;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.parser.Token;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * <meta name="usage" content="general"/>
+ * This class represents an XPath string object, and is capable of
+ * converting the string to other types, such as a number.
+ */
+public class XGYearMonth extends XDate 
+{
+
+  /**
+   * Construct a XDate object, with a null value.
+   */
+  protected XGYearMonth()
+  {
+    super();
+  }
+
+
+  /**
+   * Construct a XDate object.  This constructor exists for derived classes.
+   *
+   * @param val Date object this will wrap.
+   */
+  //protected XGYearMonth(Object val)
+  //{
+  //  super(val);
+  //}
+
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  //public XGYearMonth(Date val)
+  //{
+  //  super(val);
+  //}
+  
+  /**
+   * Construct a XDate object.
+   *
+   * @param val DateTimeObj object this will wrap.
+   */
+  public XGYearMonth(DateTimeObj val)
+  {
+    super(val);
+  }
+
+  /**
+   * Tell that this is a CLASS_GYEARMONTH.
+   *
+   * @return type CLASS_GYEARMONTH
+   */
+  public int getType()
+  {
+    return CLASS_GYEARMONTH;
+  }
+
+  /**
+   * Given a request type, return the equivalent string.
+   * For diagnostic purposes.
+   *
+   * @return type string "#GYEARMONTH"
+   */
+  public String getTypeString()
+  {
+    return "#GYEARMONTH";
+  }
+
+  
+
+  
+  
+
+  /**
+   * Cast result object to a string.
+   *
+   * @return The string this wraps or the empty string if null
+   */
+  public String str()
+  {
+  	return super.str();
+  	/*
+  	if (m_obj!= null)
+  	{
+  		if (m_obj instanceof Date)
+  		{
+  	Date date = (Date) m_obj;
+  	SimpleDateFormat dateFormat = new SimpleDateFormat(DateTimeObj.gym);      
+    return dateFormat.format(date);
+  		}
+  		else if (m_obj instanceof DateTimeObj)
+  		return ((DateTimeObj)m_obj).toString();
+  		else if(m_obj instanceof String)
+  	   return (String)m_obj;
+  	}
+      return "";
+      */
+  }
+  
+  
+
+  
+
+  
+
+  
+  
+  
+
+  
+
+  
+
+  
+  
+ 
+}
diff --git a/src/org/apache/xpath/objects/XGYearObj.java b/src/org/apache/xpath/objects/XGYearObj.java
new file mode 100644
index 0000000..756254f
--- /dev/null
+++ b/src/org/apache/xpath/objects/XGYearObj.java
@@ -0,0 +1,181 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+//import org.w3c.dom.*;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.xml.utils.DateTimeObj;
+
+/**
+ * <meta name="usage" content="general"/>
+ * This class represents an XPath string object, and is capable of
+ * converting the string to other types, such as a number.
+ */
+public class XGYearObj extends XDate 
+{
+
+  /**
+   * Construct a XDate object, with a null value.
+   */
+  protected XGYearObj()
+  {
+    super();
+  }
+
+
+  /**
+   * Construct a XDate object.  This constructor exists for derived classes.
+   *
+   * @param val Date object this will wrap.
+   */
+  //protected XGYearObj(Object val)
+  //{
+  //  super(val);
+  //}
+
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  //public XGYearObj(Date val)
+  //{
+  //  super(val);
+  //}
+  
+  /**
+   * Construct a XDate object.
+   *
+   * @param val DateTimeObj object this will wrap.
+   */
+  public XGYearObj(DateTimeObj val)
+  {
+    super(val);
+  }
+
+  /**
+   * Tell that this is a CLASS_GYEAR.
+   *
+   * @return type CLASS_GYEAR
+   */
+  public int getType()
+  {
+    return CLASS_GYEAR;
+  }
+
+  /**
+   * Given a request type, return the equivalent string.
+   * For diagnostic purposes.
+   *
+   * @return type string "#GYEAR"
+   */
+  public String getTypeString()
+  {
+    return "#GYEAR";
+  }
+
+  
+
+  
+  
+
+  /**
+   * Cast result object to a string.
+   *
+   * @return The string this wraps or the empty string if null
+   */
+  public String str()
+  {
+  	return super.str();
+  	/*
+  	if (m_obj!= null)
+  	{
+  		if (m_obj instanceof Date)
+  		{
+  	Date date = (Date) m_obj;
+  	SimpleDateFormat dateFormat = new SimpleDateFormat(DateTimeObj.gy);      
+    return dateFormat.format(date);
+  		}
+  		else if (m_obj instanceof DateTimeObj)
+  		return ((DateTimeObj)m_obj).toString();
+  		else if(m_obj instanceof String)
+  	   return (String)m_obj;
+  	}
+      return "";
+      */
+  }
+  
+  
+
+  
+
+  
+
+  
+  
+  
+
+  
+
+  
+
+  
+  
+ 
+}
diff --git a/src/org/apache/xpath/objects/XInteger.java b/src/org/apache/xpath/objects/XInteger.java
new file mode 100644
index 0000000..b56b546
--- /dev/null
+++ b/src/org/apache/xpath/objects/XInteger.java
@@ -0,0 +1,121 @@
+package org.apache.xpath.objects;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.parser.Token;
+
+public class XInteger extends XNumber
+{
+  int m_val;
+  //Integer m_intobj; // Cache; current guess is we don't need it
+
+  /**
+   * Constructor for XInteger
+   * 
+   * This one's actually being used, unlike most XObject empty ctors,
+   * because it may be created and _then_ set (by processToken)
+   * during stylesheet parsing.
+   */
+  public XInteger()
+  {
+  }
+
+  /**
+   * Constructor for XInteger
+   */
+  public XInteger(int num)
+  {
+    m_val = num;
+  }
+  
+  /**
+   * Constructor for XInteger
+   */
+  public XInteger(Integer num)
+  {
+  	//m_intobj=num;
+    m_val = num.intValue();
+  }
+  
+  /**
+   * Cast result object to a number.
+   *
+   * @return the value of the XNumber object
+   */
+  public double num()
+  {
+    return (double)m_val;
+  }
+  
+  /**
+   * Evaluate expression to a number.
+   *
+   * @return 0.0
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public double num(XPathContext xctxt) 
+    throws javax.xml.transform.TransformerException
+  {
+    return (double)m_val;
+  }
+  
+  /**
+   * Get result object as a integer.
+   *
+   * @return At this level, the num() value cast to an integer.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public int integer() throws javax.xml.transform.TransformerException
+  {
+
+    return m_val;
+  }
+
+
+  /**
+   * Cast result object to a boolean.
+   *
+   * @return false if the value is NaN or equal to 0.0
+   */
+  public boolean bool()
+  {
+    return (m_val == 0) ? false : true;
+  }
+
+
+  public void processToken(Token t) 
+  { 
+  	String strNum = t.image;
+  	try
+    {
+      m_val = Integer.parseInt(strNum);
+      //m_intobj=null; // Reset/defer
+    }
+    catch (java.lang.NumberFormatException e)
+    {
+      // TBD: Use error listener. -sb
+      throw e;
+    }
+  }
+  
+  /**
+   * Return the sequence representing this object.
+   * @return XSequence
+   */
+  public XSequence xseq()
+  {
+    return new XSequenceSingleton(this);
+  }
+
+
+  public Object object()
+  {
+  	//if(m_intobj==null)
+  	//	m_intobj=new Integer(m_val);
+  	//return m_intobj;
+  	return new Integer(m_val);
+  }
+}
+
diff --git a/src/org/apache/xpath/objects/XJavaObject.java b/src/org/apache/xpath/objects/XJavaObject.java
new file mode 100644
index 0000000..afb47a1
--- /dev/null
+++ b/src/org/apache/xpath/objects/XJavaObject.java
@@ -0,0 +1,44 @@
+package org.apache.xpath.objects;
+
+/** Wrap an arbitrary Java object for passing through the XPath
+ * datatype system.
+ * 
+ * %REVIEW% This is currently being used to wrap XSequences
+ * in FuncData.java. Makes some sense because a sequence can contain
+ * non-XPath datatypes, and that's exactly what FuncData is returning.
+ * But it feels like we'd prefer an XSequenceObject...
+ * 
+ * @author keshlam
+ * @since Jul 24, 2002
+ */
+public class XJavaObject extends XObject
+{
+	Object m_obj=null;
+	
+	public XJavaObject(Object obj)
+	{
+		m_obj=obj;
+	}
+	
+	public Object object()
+	{
+		return m_obj;
+	}
+	
+  /**
+   * Forces the object to release it's resources.  This is more harsh than
+   * detach().
+   */
+  public void destruct()
+  {
+
+    if (null != m_obj)
+    {
+      allowDetachToRelease(true);
+      detach();
+
+      m_obj = null; //******
+    }
+  }
+  
+}
diff --git a/src/org/apache/xpath/objects/XNodeSequenceSingleton.java b/src/org/apache/xpath/objects/XNodeSequenceSingleton.java
new file mode 100644
index 0000000..8823277
--- /dev/null
+++ b/src/org/apache/xpath/objects/XNodeSequenceSingleton.java
@@ -0,0 +1,884 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMIterator;
+import org.apache.xml.dtm.XType;
+import org.apache.xml.dtm.ref.DTMNodeList;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xml.utils.WrappedRuntimeException;
+import org.apache.xml.utils.XMLString;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.traversal.NodeIterator;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 20, 2002
+ * @author sboag
+ */
+public class XNodeSequenceSingleton extends XObject
+  implements XSequence
+{	
+  DTM m_dtm;
+  int m_nodeHandle;
+  int m_pos = -1;
+  
+  /**
+   * Constructor for XNodeSequenceSingleton.
+   */
+  public XNodeSequenceSingleton(int nodeHandle, XNodeSet owningNodeSet)
+  {
+  	this(nodeHandle,owningNodeSet.getDTM(nodeHandle));
+  }
+  
+  /**
+   * Constructor for XNodeSequenceSingleton.
+   */
+  public XNodeSequenceSingleton(int nodeHandle, DTM dtm)
+  {
+    m_dtm=dtm;
+    m_nodeHandle = nodeHandle;
+  }
+  
+  
+  /**
+   * Tell what kind of class this is.
+   *
+   * @return CLASS_UNKNOWN
+   * @see org.apache.xpath.objects.XObject@getType()
+   */
+  /*
+  public int getType()
+  {
+  	// %REVIEW% May not be the right thing. Makes extensions work,
+  	// but currently causes InstanceofExpr to cast it incorrectly
+  	// (to XNodeSet, not compatable). 
+  	// Should we be subclassing XNodeSet rather than XObject? 
+  	// Should we change this type?
+  	// Should we change InstanceOfExpr to cast to XSequence,
+  	//		which is a shared superclass?
+  	return CLASS_NODESET; 
+  }
+  */
+
+  /**
+   * Given a request type, return the equivalent string.
+   * For diagnostic purposes.
+   *
+   * @return type string "#UNKNOWN" + object class name
+   * @see org.apache.xpath.objects.XObject@getTypeString()
+   */
+  /*
+  public String getTypeString()
+  {
+    return "#NODESET";
+  }
+  */
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getTypes()
+   */
+  public int getTypes()
+  {
+    DTM dtm = getDTM();
+    return XType.getTypeID(dtm, m_nodeHandle);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#next()
+   */
+  public XObject next()
+  {
+      if(m_pos == -1)
+      {
+        m_pos++;
+        return this;
+      }
+      else
+        return null;
+///    try
+//    {
+//      if(m_pos == -1)
+//      {
+//        XObject next = (XObject)this.clone();
+//        next.reset();
+//        m_pos++;
+//        return next;
+//      }
+//      else
+//        return null;
+//    }
+//    catch (CloneNotSupportedException e)
+//    {
+//      throw new WrappedRuntimeException(e);
+//    }
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#previous()
+   */
+  public XObject previous()
+  {
+    if(m_pos == 0)
+    {
+      m_pos--;
+      return this;
+    }
+    else
+      return null;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getCurrent()
+   */
+  public XObject getCurrent()
+  {
+    if(m_pos == 0)
+    {
+      return this;
+    }
+    else
+      return null;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isFresh()
+   */
+  public boolean isFresh()
+  {
+    return m_pos == -1;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getTypeNS()
+   */
+  public String getTypeNS()
+  {
+    DTM dtm = getDTM();
+    return dtm.getSchemaTypeNamespace(m_nodeHandle);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getTypeLocalName()
+   */
+  public String getTypeLocalName()
+  {
+    DTM dtm = getDTM();
+    return dtm.getSchemaTypeLocalName(m_nodeHandle);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isSchemaType(String, String)
+   */
+  public boolean isSchemaType(String namespace, String localname)
+  {
+    DTM dtm = getDTM();
+    return dtm.isNodeSchemaType(m_nodeHandle, namespace, localname);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isPureNodeSequence()
+   */
+  public boolean isPureNodeSequence()
+  {
+    return true;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#setShouldCache(boolean)
+   */
+  public void setShouldCache(boolean b)
+  {
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getIsRandomAccess()
+   */
+  public boolean getIsRandomAccess()
+  {
+    return true;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isMutable()
+   */
+  public boolean isMutable()
+  {
+    return false;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getCurrentPos()
+   */
+  public int getCurrentPos()
+  {
+    return m_pos;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#setCurrentPos(int)
+   */
+  public void setCurrentPos(int i)
+  {
+    m_pos = i;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getLength()
+   */
+  public int getLength()
+  {
+    return 1;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isSingletonOrEmpty()
+   */
+  public boolean isSingletonOrEmpty()
+  {
+    return true;
+  }
+  
+  /**
+   * @see java.lang.Object#clone()
+   */
+  public Object clone() throws CloneNotSupportedException
+  {
+    return super.clone();
+  }
+
+  /**
+   * Get numeric value of the string conversion from a single node.
+   *
+   * @param n Node to convert
+   *
+   * @return numeric value of the string conversion from a single node.
+   */
+  public double getNumberFromNode(int n)
+  {
+    XMLString xstr = getDTM().getStringValue(n);
+    // String str = xstr.toString();
+    return xstr.toDouble();
+  }
+
+  /**
+   * Cast result object to a number.
+   *
+   * @return numeric value of the string conversion from the 
+   * next node in the NodeSetDTM, or NAN if no node was found
+   */
+  public double num()
+  {
+
+    int node = m_nodeHandle;
+    return (node != DTM.NULL) ? getNumberFromNode(node) : Double.NaN;
+  }
+  
+  /**
+   * @see org.apache.xpath.objects.XObject#floatVal()
+   */
+  public float floatVal() throws TransformerException
+  {
+    int node = m_nodeHandle;
+    return (node != DTM.NULL) ? (float)getNumberFromNode(node) : Float.NaN;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#integer()
+   */
+  public int integer() throws TransformerException
+  {
+    int node = m_nodeHandle;
+    return (node != DTM.NULL) ? (int)getNumberFromNode(node) : 0;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#numWithSideEffects()
+   */
+  public double numWithSideEffects() throws TransformerException
+  {
+    return super.numWithSideEffects();
+  }
+
+  
+  /**
+   * Cast result object to a boolean.
+   *
+   * @return True if there is a next node in the nodeset
+   */
+  public boolean bool()
+  {
+    // Check the new rules about this.  -sb
+    return (m_nodeHandle != DTM.NULL);
+  }
+  
+  /**
+   * Cast result object to a boolean, but allow side effects, such as the 
+   * incrementing of an iterator.
+   *
+   * @return True if there is a next node in the nodeset
+   */
+  public boolean boolWithSideEffects()
+  {
+    return (m_nodeHandle != DTM.NULL);
+  }
+
+  
+  /**
+   * Get the string conversion from a single node.
+   *
+   * @param n Node to convert
+   *
+   * @return the string conversion from a single node.
+   */
+  public XMLString getStringFromNode(int n)
+  {
+    // %OPT%
+    // I guess we'll have to get a static instance of the DTM manager...
+    if(DTM.NULL != n)
+    {
+      return getDTM().getStringValue(n);
+    }
+    else
+    {
+      return org.apache.xpath.objects.XString.EMPTYSTRING;
+    }
+  }
+  
+  /**
+   * Directly call the
+   * characters method on the passed ContentHandler for the
+   * string-value. Multiple calls to the
+   * ContentHandler's characters methods may well occur for a single call to
+   * this method.
+   *
+   * @param ch A non-null reference to a ContentHandler.
+   *
+   * @throws org.xml.sax.SAXException
+   */
+  public void dispatchCharactersEvents(org.xml.sax.ContentHandler ch)
+          throws org.xml.sax.SAXException
+  {
+    int node = m_nodeHandle;
+  
+    if(node != DTM.NULL)
+    {
+      getDTM().dispatchCharactersEvents(node, ch, false);
+    }
+    
+  }
+  
+  /**
+   * Cast result object to an XMLString.
+   *
+   * @return The document fragment node data or the empty string. 
+   */
+  public XMLString xstr()
+  {
+    int node = m_nodeHandle;
+    return (node != DTM.NULL) ? getStringFromNode(node) : XString.EMPTYSTRING;
+  }
+  
+  /**
+   * Cast result object to a string.
+   *
+   * @return The string this wraps or the empty string if null
+   */
+  public void appendToFsb(org.apache.xml.utils.FastStringBuffer fsb)
+  {
+    XString xstring = (XString)xstr();
+    xstring.appendToFsb(fsb);
+  }
+  
+
+  /**
+   * Cast result object to a string.
+   *
+   * @return the string conversion from the next node in the nodeset
+   * or "" if there is no next node
+   */
+  public String str()
+  {
+    int node = m_nodeHandle;
+    return (node != DTM.NULL) ? getStringFromNode(node).toString() : "";   
+  }
+  
+  /**
+   * Return a java object that's closest to the representation
+   * that should be handed to an extension.
+   *
+   * @return The object that this class wraps
+   */
+  public Object object()
+  {
+    if(null == m_dtm)	// Should this case ever arise???
+      return this;	// And is this response useful? %REVIEW% 
+    else
+      //return m_dtm;
+      return m_dtm.getNode(m_nodeHandle);
+  }
+
+  /**
+   * Returns the dtm.
+   * @return DTM
+   */
+  public DTM getDTM()
+  {
+    return m_dtm;
+  }
+
+  /**
+   * Returns the nodeHandle.
+   * @return int
+   */
+  public int getNodeHandle()
+  {
+    return m_nodeHandle;
+  }
+
+  /**
+   * Sets the dtm.
+   * @param dtm The dtm to set
+   */
+  public void setDTM(DTM dtm)
+  {
+    m_dtm = dtm;
+  }
+
+  /**
+   * Sets the nodeHandle.
+   * @param nodeHandle The nodeHandle to set
+   */
+  public void setNodeHandle(int nodeHandle)
+  {
+    m_nodeHandle = nodeHandle;
+  }
+
+  /**
+   * Tell if one object is less than the other.
+   *
+   * @param obj2 object to compare this nodeset to
+   *
+   * @return see this.compare(...) 
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean lessThan(XObject obj2) throws javax.xml.transform.TransformerException
+  {
+    return compare(obj2, XNodeSet.S_LT);
+  }
+
+  /**
+   * Tell if one object is less than or equal to the other.
+   *
+   * @param obj2 object to compare this nodeset to
+   *
+   * @return see this.compare(...) 
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean lessThanOrEqual(XObject obj2) throws javax.xml.transform.TransformerException
+  {
+    return compare(obj2, XNodeSet.S_LTE);
+  }
+
+  /**
+   * Tell if one object is less than the other.
+   *
+   * @param obj2 object to compare this nodeset to
+   *
+   * @return see this.compare(...) 
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean greaterThan(XObject obj2) throws javax.xml.transform.TransformerException
+  {
+    return compare(obj2, XNodeSet.S_GT);
+  }
+
+  /**
+   * Tell if one object is less than the other.
+   *
+   * @param obj2 object to compare this nodeset to
+   *
+   * @return see this.compare(...) 
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean greaterThanOrEqual(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+    return compare(obj2, XNodeSet.S_GTE);
+  }
+
+  /**
+   * Tell if two objects are functionally equal.
+   *
+   * @param obj2 object to compare this nodeset to
+   *
+   * @return see this.compare(...) 
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean equalsExistential(XObject obj2)
+  {
+    try
+    {
+      return compare(obj2, XNodeSet.S_EQ);
+    }
+    catch(javax.xml.transform.TransformerException te)
+    {
+      throw new org.apache.xml.utils.WrappedRuntimeException(te);
+    }
+  }
+
+  /**
+   * Tell if two objects are functionally not equal.
+   *
+   * @param obj2 object to compare this nodeset to
+   *
+   * @return see this.compare(...) 
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean notEquals(XObject obj2) throws javax.xml.transform.TransformerException
+  {
+    return compare(obj2, XNodeSet.S_NEQ);
+  }
+  
+  /**
+   * @see java.lang.Object#equals(Object)
+   */
+  public boolean equals(XObject arg0)
+  {
+    int nodeHandle = ((XObject) arg0).getNodeHandle();
+    return nodeHandle == m_nodeHandle;
+  }
+
+
+  /**
+   * @see java.lang.Object#equals(Object)
+   */
+  public boolean equals(Object arg0)
+  {
+    if(arg0 instanceof XObject)
+    {
+      equals((XObject)arg0);
+    }
+    return super.equals(arg0);
+  }
+  
+  /**
+   * Tell if one object is less than the other.
+   *
+   * @param obj2 Object to compare this nodeset to
+   * @param comparator Comparator to use
+   *
+   * @return See the comments below for each object type comparison 
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean compare(XObject obj2, Comparator comparator)
+    throws javax.xml.transform.TransformerException
+  {
+
+    boolean result = false;
+    int type = obj2.getType();
+
+    if (obj2.isNodesetExpr())
+    {
+      // %OPT% This should be XMLString based instead of string based...
+
+      // From http://www.w3.org/TR/xpath: 
+      // If both objects to be compared are node-sets, then the comparison 
+      // will be true if and only if there is a node in the first node-set 
+      // and a node in the second node-set such that the result of performing 
+      // the comparison on the string-values of the two nodes is true.
+      // Note this little gem from the draft:
+      // NOTE: If $x is bound to a node-set, then $x="foo" 
+      // does not mean the same as not($x!="foo"): the former 
+      // is true if and only if some node in $x has the string-value 
+      // foo; the latter is true if and only if all nodes in $x have 
+      // the string-value foo.
+      XSequence list2 = obj2.xseq();
+      int node1 = m_nodeHandle;
+      java.util.Vector node2Strings = null;
+
+      XMLString s1 = getStringFromNode(node1);
+
+      if (null == node2Strings)
+      {
+        
+        XObject next;
+        while (null != (next = list2.next()))
+        {
+           XMLString s2 = next.xstr();
+
+          if (comparator.compareStrings(s1, s2))
+          {
+            result = true;
+
+            break;
+          }
+
+          if (null == node2Strings)
+            node2Strings = new java.util.Vector();
+
+          node2Strings.addElement(s2);
+        }
+      }
+      else
+      {
+        int n = node2Strings.size();
+
+        for (int i = 0; i < n; i++)
+        {
+          if (comparator
+            .compareStrings(s1, (XMLString) node2Strings.elementAt(i)))
+          {
+            result = true;
+
+            break;
+          }
+        }
+      }
+      list2.reset();
+    }
+    else
+      if (XObject.CLASS_BOOLEAN == type)
+      {
+
+        // From http://www.w3.org/TR/xpath: 
+        // If one object to be compared is a node-set and the other is a boolean, 
+        // then the comparison will be true if and only if the result of 
+        // performing the comparison on the boolean and on the result of 
+        // converting the node-set to a boolean using the boolean function 
+        // is true.
+        double num1 = bool() ? 1.0 : 0.0;
+        double num2 = obj2.num();
+
+        result = comparator.compareNumbers(num1, num2);
+      }
+      else
+        if (XObject.CLASS_NUMBER == type)
+        {
+
+          // From http://www.w3.org/TR/xpath: 
+          // If one object to be compared is a node-set and the other is a number, 
+          // then the comparison will be true if and only if there is a 
+          // node in the node-set such that the result of performing the 
+          // comparison on the number to be compared and on the result of 
+          // converting the string-value of that node to a number using 
+          // the number function is true. 
+          double num2 = obj2.num();
+          int node = m_nodeHandle;
+
+          double num1 = getNumberFromNode(node);
+
+          if (comparator.compareNumbers(num1, num2))
+          {
+            result = true;
+          }
+        }
+        else
+          if (XObject.CLASS_RTREEFRAG == type)
+          {
+            XMLString s2 = obj2.xstr();
+            int node = m_nodeHandle;
+
+            XMLString s1 = getStringFromNode(node);
+
+            if (comparator.compareStrings(s1, s2))
+            {
+              result = true;
+            }
+          }
+          else
+            if (XObject.CLASS_STRING == type)
+            {
+
+              // From http://www.w3.org/TR/xpath: 
+              // If one object to be compared is a node-set and the other is a 
+              // string, then the comparison will be true if and only if there 
+              // is a node in the node-set such that the result of performing 
+              // the comparison on the string-value of the node and the other 
+              // string is true. 
+              XMLString s2 = obj2.xstr();
+              int node = m_nodeHandle;
+
+              XMLString s1 = getStringFromNode(node);
+              if (comparator.compareStrings(s1, s2))
+              {
+                result = true;
+              }
+            }
+            else
+            {
+              result = comparator.compareNumbers(this.num(), obj2.num());
+            }
+
+    return result;
+  }
+
+
+  /**
+   * @see org.apache.xpath.Expression#isNodesetExpr()
+   */
+  public boolean isNodesetExpr()
+  {
+    return true;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#xseq()
+   */
+  public XSequence xseq()
+  {
+    try
+    {
+      XSequence newXSeq = (XSequence)clone();
+      // newXSeq.reset();
+      return newXSeq;
+    }
+    catch (CloneNotSupportedException e)
+    {
+      throw new WrappedRuntimeException(e);
+    }
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#reset()
+   */
+  public void reset()
+  {
+    super.reset();
+    m_pos = -1;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#nodelist()
+   */
+  public NodeList nodelist() throws TransformerException
+  {
+    return new DTMNodeList(getDTM(),getNodeHandle(), false);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#nodeset()
+   */
+  public NodeIterator nodeset() throws TransformerException
+  {
+    DTM dtm = getDTM();
+    DTMIterator iter = new XNodeSet(getNodeHandle(), dtm.getManager());
+    return new org.apache.xml.dtm.ref.DTMNodeIterator(iter);
+  }
+  
+  /**
+   * Cast result object to a nodelist. Always issues an error.
+   *
+   * @return null
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public DTMIterator iter() throws javax.xml.transform.TransformerException
+  {
+
+    DTM dtm = getDTM();
+    DTMIterator iter = new XNodeSet(getNodeHandle(), dtm.getManager());
+
+    return iter;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#getType()
+   */
+  public int getType()
+  {
+    return XType.NODE;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#getValueType()
+   */
+  public int getValueType()
+  {
+    int nodeHandle = getNodeHandle();
+    if (DTM.NULL != nodeHandle)
+    {
+      DTM dtm = getDTM();
+      
+      return XType.getTypeID(dtm, nodeHandle);
+    }
+    else
+      return XType.ANYTYPE;
+  }
+  
+//  /**
+//   * @see org.apache.xpath.objects.XObject#date()
+//   */
+//  public DateTimeObj date() throws TransformerException
+//  {
+//    DTM dtm = getDTM();
+//    dtm.getN
+//    return super.date();
+//  }
+
+}
diff --git a/src/org/apache/xpath/objects/XNodeSet.java b/src/org/apache/xpath/objects/XNodeSet.java
index 9db3b52..b399023 100644
--- a/src/org/apache/xpath/objects/XNodeSet.java
+++ b/src/org/apache/xpath/objects/XNodeSet.java
@@ -59,34 +59,38 @@
 //import org.w3c.dom.Node;
 //import org.w3c.dom.Text;
 //import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.traversal.NodeIterator;
-import org.w3c.dom.NodeList;
-
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMIterator;
 import org.apache.xml.dtm.DTMManager;
-
-import org.apache.xpath.DOMHelper;
-import org.apache.xpath.XPathContext;
-import org.apache.xpath.NodeSetDTM;
-import org.apache.xpath.axes.ContextNodeList;
-import org.apache.xpath.axes.NodeSequence;
-import org.apache.xml.utils.StringVector;
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.WrappedRuntimeException;
 import org.apache.xml.utils.XMLString;
+import org.apache.xpath.NodeSetDTM;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.traversal.NodeIterator;
 
 /**
  * <meta name="usage" content="general"/>
  * This class represents an XPath nodeset object, and is capable of
  * converting the nodeset to other types, such as a string.
  */
-public class XNodeSet extends NodeSequence
+public class XNodeSet extends NodeSequence implements XSequence
 {  
+  XNodeSequenceSingleton m_current;
+  
+  
+  // XNodeSetForDOM (subclass) accesses this member as NodeSetDTM
+  // NodeSequence (superclass) sometimes uses it as NodeVector
+  //NodeSetDTM m_obj;
+  
   /**
    * Default constructor for derived objects.
    */
+  /*
   protected XNodeSet()
   {
   }
+  */
 
   /**
    * Construct a XNodeSet object.
@@ -95,50 +99,78 @@
    */
   public XNodeSet(DTMIterator val)
   {
-  	super();
   	if(val instanceof XNodeSet)
   	{
-	    setIter(((XNodeSet)val).m_iter);
-	    m_dtmMgr = ((XNodeSet)val).m_dtmMgr;
-	    m_last = ((XNodeSet)val).m_last;
-	    if(!((XNodeSet)val).hasCache())
-	    	((XNodeSet)val).setShouldCacheNodes(true);
-	    m_obj = ((XNodeSet)val).m_obj;
+		// One would expect an explicit copy ctor to take precedence,
+		// but apparently it doesn't always do so;
+		// moving this alternative into XNodeSet(XNodeSet)
+		// yields erroneous results. I don't quite understand why.
+
+  		XNodeSet xns=(XNodeSet)val;
+	    setIter(xns.m_iter);
+	    m_dtmMgr = xns.m_dtmMgr;
+	    m_last = xns.m_last;
+	    if(!xns.hasCache())
+	    	xns.setShouldCache(true);
+	    m_obj = xns.m_obj;
   	}
   	else
+  	{
     	setIter(val);
+  		m_dtmMgr=val.getDTMManager(); // Hadn't been being done..?
+  	}
   }
   
   /**
-   * Construct a XNodeSet object.
+   * Construct a XNodeSet object by copying from another XNodeSet
+   *
+   * Currently, all copy constructions are being caught by the
+   * XNodeSet(DTMIterator) ctor. I've disabled this one for
+   * clarity; we should consider deleting it entirely.
    *
    * @param val Value of the XNodeSet object
    */
+  /*
   public XNodeSet(XNodeSet val)
   {
-  	super();
+  	super(val.getDTMManager());
     setIter(val.m_iter);
     m_dtmMgr = val.m_dtmMgr;
     m_last = val.m_last;
     if(!val.hasCache())
-    	val.setShouldCacheNodes(true);
+    	val.setShouldCache(true);
     m_obj = val.m_obj;
   }
-
-
+  */
+  
+  /**
+   * Passthrough for XRTreeFrag(Expression) constructor, since
+   * c'tors are not inherited and there seems to be no way to 
+   * invoke super.super.super().
+   *
+   * @param frag Document fragment this will wrap
+   */
+  /*
+  protected XNodeSet(org.apache.xpath.Expression expr)
+  {
+    super(expr);
+  }
+  */
+    
   /**
    * Construct an empty XNodeSet object.  This is used to create a mutable 
    * nodeset to which random nodes may be added.
    */
   public XNodeSet(DTMManager dtmMgr) 
   {
-    super(dtmMgr);
+    this(DTM.NULL,dtmMgr);
   }
 
   /**
-   * Construct a XNodeSet object for one node.
+   * Construct a XNodeSet object for one node. (Or empty, if
+   * the node handle is DTM.NULL.)
    *
-   * @param n Node to add to the new XNodeSet object
+   * @param n Handle of DTM node to add to the new XNodeSet object
    */
   public XNodeSet(int n, DTMManager dtmMgr)
   {
@@ -148,7 +180,7 @@
 
     if (DTM.NULL != n)
     {
-      ((NodeSetDTM) m_obj).addNode(n);
+      ((NodeSetDTM)m_obj).addNode(n);
       m_last = 1;
     }
     else
@@ -164,6 +196,22 @@
   {
     return CLASS_NODESET;
   }
+  
+  /**
+   * @see org.apache.xpath.objects.XObject#getValueType()
+   */
+  public int getValueType()
+  {
+    int nodeHandle = getCurrentNode();
+    if (DTM.NULL != nodeHandle)
+    {
+      DTM dtm = getDTM(nodeHandle);
+      
+      return XType.getTypeID(dtm, nodeHandle);
+    }
+    else
+      return XType.ANYTYPE;
+  }
 
   /**
    * Given a request type, return the equivalent string.
@@ -409,6 +457,15 @@
   }
   
   /**
+   * Return the sequence representing this object.
+   * @return XSequence
+   */
+  public XSequence xseq()
+  {
+    return this;
+  }
+  
+  /**
    * Cast result object to a nodelist.
    *
    * @return The nodeset as a nodelist
@@ -455,20 +512,19 @@
    */
   public NodeSetDTM mutableNodeset()
   {
-    NodeSetDTM mnl;
-
-    if(m_obj instanceof NodeSetDTM)
-    {
-      mnl = (NodeSetDTM) m_obj;
-    }
-    else
-    {
-      mnl = new NodeSetDTM(iter());
-      m_obj = mnl;
-      setCurrentPos(0);
-    }
-
-    return mnl;
+     NodeSetDTM mnl;
+ 
+     if(m_obj instanceof NodeSetDTM)
+     {
+       mnl = (NodeSetDTM) m_obj;
+     }
+     else
+     {
+       mnl = new NodeSetDTM(iter());
+       m_obj = mnl;
+       setCurrentPos(0);
+     }
+     return mnl;  	
   }
 
   /** Less than comparator         */
@@ -507,7 +563,7 @@
     boolean result = false;
     int type = obj2.getType();
 
-    if (XObject.CLASS_NODESET == type)
+    if (obj2.isNodesetExpr())
     {
       // %OPT% This should be XMLString based instead of string based...
 
@@ -719,7 +775,7 @@
   {
     return compare(obj2, S_GTE);
   }
-
+  
   /**
    * Tell if two objects are functionally equal.
    *
@@ -731,6 +787,21 @@
    */
   public boolean equals(XObject obj2)
   {
+    int nodeHandle = obj2.getNodeHandle();
+    return nodeHandle == getNodeHandle();
+  }
+
+  /**
+   * Tell if two objects are functionally equal.
+   *
+   * @param obj2 object to compare this nodeset to
+   *
+   * @return see this.compare(...) 
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean equalsExistential(XObject obj2)
+  {
     try
     {
       return compare(obj2, S_EQ);
@@ -754,6 +825,172 @@
   {
     return compare(obj2, S_NEQ);
   }
+  
+  /**
+   * @see org.apache.xpath.Expression#cloneDeep()
+   */
+  public Object cloneDeep() throws CloneNotSupportedException
+  {
+    XNodeSet xns = (XNodeSet)super.clone();
+    if(null != m_iter)
+      xns.m_iter = (DTMIterator)m_iter.clone();
+    return xns;
+  }
+
+//  /**
+//   * @see org.apache.xml.dtm.DTMIterator#cloneWithReset()
+//   */
+//  public DTMIterator cloneWithReset() throws CloneNotSupportedException
+//  {
+//    DTMIterator clone = super.cloneWithReset();
+//    return clone;
+//  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getCurrent()
+   */
+  public XObject getCurrent()
+  {
+    if (null == m_current)
+    {
+      if (null != m_iter)
+      {
+        int nodeHandle = getCurrentNode();
+        // I don't think it's a good idea here to have m_current 
+        // get assigned, since next or previous didn't already assign it! 
+        return new XNodeSequenceSingleton(
+          nodeHandle,
+          m_iter.getDTM(nodeHandle));
+      }
+      else
+      {
+        return null;
+      }
+    }
+    return m_current;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getIsRandomAccess()
+   */
+  public boolean getIsRandomAccess()
+  {
+    return true; // though I'm not sure about this.
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getTypeLocalName()
+   */
+  public String getTypeLocalName()
+  {
+    int nodeHandle = getCurrentNode();
+    if (DTM.NULL != nodeHandle)
+    {
+      DTM dtm = getDTM(nodeHandle);
+
+      return dtm.getSchemaTypeLocalName(nodeHandle);
+    }
+    else
+      return null;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getTypeNS()
+   */
+  public String getTypeNS()
+  {
+    int nodeHandle = getCurrentNode();
+    if (DTM.NULL != nodeHandle)
+    {
+      DTM dtm = getDTM(nodeHandle);
+      return dtm.getSchemaTypeNamespace(nodeHandle);
+    }
+    else
+      return null;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getTypes()
+   */
+  public int getTypes()
+  {
+    return XType.ANYTYPE; // don't try to predict yet.
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isPureNodeSequence()
+   */
+  public boolean isPureNodeSequence()
+  {
+    return true;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isSchemaType(String, String)
+   */
+  public boolean isSchemaType(String namespace, String localname)
+  {
+    int nodeHandle = getCurrentNode();
+    if (DTM.NULL != nodeHandle)
+    {
+      DTM dtm = getDTM(nodeHandle);
+      return dtm.isNodeSchemaType(nodeHandle, namespace, localname);
+    }
+    else
+      return false;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isSingletonOrEmpty()
+   */
+  public boolean isSingletonOrEmpty()
+  {
+    return false;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#next()
+   */
+  public XObject next()
+  {
+    int node = nextNode();
+    if (DTM.NULL == node)
+      m_current = null;
+    else
+      m_current = new XNodeSequenceSingleton(node, this);
+    return m_current;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#previous()
+   */
+  public XObject previous()
+  {
+    int node = previousNode();
+    if (DTM.NULL == node)
+      m_current = null;
+    else
+      m_current = new XNodeSequenceSingleton(node, this);
+    return m_current;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#isSequenceProper()
+   */
+  public boolean isSequenceProper()
+  {
+    return true;
+  }
+
+
+  /**
+   * @see org.apache.xpath.objects.XObject#getNodeHandle()
+   */
+  public int getNodeHandle()
+  {
+    return getCurrentNode();
+  }
+
 }
 
 /**
diff --git a/src/org/apache/xpath/objects/XNodeSetForDOM.java b/src/org/apache/xpath/objects/XNodeSetForDOM.java
index d23b4f7..1e8a7e8 100644
--- a/src/org/apache/xpath/objects/XNodeSetForDOM.java
+++ b/src/org/apache/xpath/objects/XNodeSetForDOM.java
@@ -16,43 +16,65 @@
 {
   Object m_origObj;
 
-  public XNodeSetForDOM(Node node, DTMManager dtmMgr)
-  {
-    m_dtmMgr = dtmMgr;
-    m_origObj = node;
-    int dtmHandle = dtmMgr.getDTMHandleFromNode(node);
-    m_obj = new NodeSetDTM(dtmMgr);
-    ((NodeSetDTM) m_obj).addNode(dtmHandle);
-  }
-  
   /**
-   * Construct a XNodeSet object.
+   * Wrap an XNodeSetForDOM around another XNodeset
    *
    * @param val Value of the XNodeSet object
    */
+  /*
   public XNodeSetForDOM(XNodeSet val)
   {
   	super(val);
   	if(val instanceof XNodeSetForDOM)
+  	{
     	m_origObj = ((XNodeSetForDOM)val).m_origObj;
+  	}
+  }
+  */
+
+  /**
+   * Wrap an XNodeSetForDOM around a single DOM Node.
+   * 
+   * (Interesting that this one takes the DTM Manager explicitly
+   * while others get it via the xctxt. Should we reconcile?)
+   *
+   */
+  public XNodeSetForDOM(Node node, DTMManager dtmMgr)
+  {
+    super(dtmMgr);
+    m_origObj = node;
+    int dtmHandle = dtmMgr.getDTMHandleFromNode(node);
+    
+	NodeSetDTM nsdtm = new NodeSetDTM(dtmMgr);
+    nsdtm.addNode(dtmHandle);  
+    m_obj=nsdtm;
   }
   
+  /**
+   * Wrap an XNodeSetForDOM around a DOM NodeList
+   *
+   */
   public XNodeSetForDOM(NodeList nodeList, XPathContext xctxt)
   {
-    m_dtmMgr = xctxt.getDTMManager();
+    super(xctxt.getDTMManager());
     m_origObj = nodeList;
 
     // JKESS 20020514: Longer-term solution is to force
     // folks to request length through an accessor, so we can defer this
     // retrieval... but that requires an API change.
     // m_obj=new org.apache.xpath.NodeSetDTM(nodeList, xctxt);
-    org.apache.xpath.NodeSetDTM nsdtm=new org.apache.xpath.NodeSetDTM(nodeList, xctxt);
+    NodeSetDTM nsdtm=new org.apache.xpath.NodeSetDTM(nodeList, xctxt);
     m_last=nsdtm.getLength();
     m_obj = nsdtm;   
   }
 
+  /**
+   * Wrap an XNodeSetForDOM around a DOM NodeIterator
+   *
+   */
   public XNodeSetForDOM(NodeIterator nodeIter, XPathContext xctxt)
   {
+    super(xctxt.getDTMManager());
     m_dtmMgr = xctxt.getDTMManager();
     m_origObj = nodeIter;
 
@@ -60,7 +82,7 @@
     // folks to request length through an accessor, so we can defer this
     // retrieval... but that requires an API change.
     // m_obj = new org.apache.xpath.NodeSetDTM(nodeIter, xctxt);
-    org.apache.xpath.NodeSetDTM nsdtm=new org.apache.xpath.NodeSetDTM(nodeIter, xctxt);
+    NodeSetDTM nsdtm=new org.apache.xpath.NodeSetDTM(nodeIter, xctxt);
     m_last=nsdtm.getLength();
     m_obj = nsdtm;   
   }
diff --git a/src/org/apache/xpath/objects/XNull.java b/src/org/apache/xpath/objects/XNull.java
index 9be0b3e..9f7f3d6 100644
--- a/src/org/apache/xpath/objects/XNull.java
+++ b/src/org/apache/xpath/objects/XNull.java
@@ -60,10 +60,8 @@
 //import org.w3c.dom.DocumentFragment;
 
 import org.apache.xml.dtm.DTM;
-import org.apache.xml.dtm.DTMIterator;
-
+import org.apache.xml.dtm.DTMManager;
 import org.apache.xpath.XPathContext;
-import org.apache.xpath.NodeSetDTM;
 
 /**
  * <meta name="usage" content="general"/>
@@ -78,7 +76,7 @@
    */
   public XNull()
   {
-    super();
+    super((DTMManager)null); // compile-time cast is needed
   }
 
   /**
@@ -168,4 +166,14 @@
   {
     return obj2.getType() == CLASS_NULL;
   }
+  
+  /**
+   * Return the sequence representing this object.
+   * @return XSequence
+   */
+  public XSequence xseq()
+  {
+    return XSequence.EMPTY;
+  }
+
 }
diff --git a/src/org/apache/xpath/objects/XNumber.java b/src/org/apache/xpath/objects/XNumber.java
index dd07c63..bc50524 100644
--- a/src/org/apache/xpath/objects/XNumber.java
+++ b/src/org/apache/xpath/objects/XNumber.java
@@ -66,38 +66,29 @@
  * This class represents an XPath number, and is capable of
  * converting the number to other types, such as a string.
  */
-public class XNumber extends XObject
+public abstract class XNumber extends XObject
 {
-
-  /** Value of the XNumber object.
-   *  @serial         */
-  double m_val;
-
   /**
    * Construct a XNodeSet object.
    *
    * @param d Value of the object
    */
-  public XNumber(double d)
+  protected XNumber()
   {
-    super();
-
-    m_val = d;
   }
-  
+
+
   /**
    * Construct a XNodeSet object.
    *
    * @param d Value of the object
    */
+  /*
   public XNumber(Number num)
   {
-
-    super();
-
-    m_val = num.doubleValue();
-    m_obj = num;
+    super(num);
   }
+  */
 
   /**
    * Tell that this is a CLASS_NUMBER.
@@ -120,39 +111,6 @@
     return "#NUMBER";
   }
 
-  /**
-   * Cast result object to a number.
-   *
-   * @return the value of the XNumber object
-   */
-  public double num()
-  {
-    return m_val;
-  }
-  
-  /**
-   * Evaluate expression to a number.
-   *
-   * @return 0.0
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  public double num(XPathContext xctxt) 
-    throws javax.xml.transform.TransformerException
-  {
-
-    return m_val;
-  }
-
-  /**
-   * Cast result object to a boolean.
-   *
-   * @return false if the value is NaN or equal to 0.0
-   */
-  public boolean bool()
-  {
-    return (Double.isNaN(m_val) || (m_val == 0.0)) ? false : true;
-  }
 
 //  /**
 //   * Cast result object to a string.
@@ -312,20 +270,27 @@
    */
   public String str()
   {
-
-    if (Double.isNaN(m_val))
+  	double num;
+  	try 
+  	{
+    	num = num(); 
+    } 
+    catch(TransformerException te) 
+    {
+    	throw new RuntimeException(te.getMessage()); 
+    }
+    if (Double.isNaN(num))
     {
       return "NaN";
     }
-    else if (Double.isInfinite(m_val))
+    else if (Double.isInfinite(num))
     {
-      if (m_val > 0)
+      if (num > 0)
         return "Infinity";
       else
         return "-Infinity";
     }
 
-    double num = m_val;
     String s = Double.toString(num);
     int len = s.length();
 
@@ -401,12 +366,26 @@
    *
    * @return The value of this XNumber as a Double object
    */
-  public Object object()
+  abstract public Object object();
+  /*
   {
     if(null == m_obj)
-      m_obj = new Double(m_val);
+    {
+	  double num;
+	  try 
+	  {
+	    num = num(); 
+	  } 
+	  catch(TransformerException te) 
+	  {
+	    throw new RuntimeException(te.getMessage()); 
+	  }
+
+      m_obj = new Double(num);
+    }
     return m_obj;
   }
+  */
 
   /**
    * Tell if two objects are functionally equal.
@@ -427,11 +406,13 @@
     try
     {
 	    if (t == XObject.CLASS_NODESET)
-	      return obj2.equals(this);
+	      return ((XNodeSet)obj2).equalsExistential(this);
 	    else if(t == XObject.CLASS_BOOLEAN)
 	      return obj2.bool() == bool();
 		else
-	       return m_val == obj2.num();
+		{
+	       return num() == obj2.num();
+		}
     }
     catch(javax.xml.transform.TransformerException te)
     {
diff --git a/src/org/apache/xpath/objects/XObject.java b/src/org/apache/xpath/objects/XObject.java
index a10aeaa..c70edff 100644
--- a/src/org/apache/xpath/objects/XObject.java
+++ b/src/org/apache/xpath/objects/XObject.java
@@ -56,24 +56,26 @@
  */
 package org.apache.xpath.objects;
 
-import org.w3c.dom.DocumentFragment;
-//import org.w3c.dom.Text;
-//import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.traversal.NodeIterator;
-import org.apache.xml.dtm.*;
-
 import java.io.Serializable;
 
-import org.apache.xpath.res.XPATHErrorResources;
+import org.apache.xalan.res.XSLMessages;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMIterator;
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xml.utils.Duration;
+import org.apache.xml.utils.XMLString;
+import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionOwner;
-import org.apache.xpath.XPathContext;
 import org.apache.xpath.NodeSetDTM;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathException;
 import org.apache.xpath.XPathVisitor;
-import org.apache.xalan.res.XSLMessages;
-import org.apache.xpath.Expression;
-import org.apache.xml.utils.XMLString;
+import org.apache.xpath.res.XPATHErrorResources;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.traversal.NodeIterator;
 
 /**
  * <meta name="usage" content="general"/>
@@ -81,31 +83,36 @@
  * converting the object to various types, such as a string.
  * This class acts as the base class to other XPath type objects,
  * such as XString, and provides polymorphic casting capabilities.
+ * 
+ * Caveat: Default method implementations provided herein may be
+ * inefficient, since they have to retrieve the "contained object"
+ * which may not exist until demanded.
  */
-public class XObject extends Expression implements Serializable, Cloneable
+public abstract class XObject extends Expression implements Serializable, Cloneable
 {
-
   /**
-   * The java object which this object wraps.
-   *  @serial  
+   * Create an undifferentiated XObject.
+   * Note: Abstract methods can't be constructed...
+   * ... and constructors don't inherit, even as abstracts.
    */
-  protected Object m_obj;  // This may be NULL!!!
+  /*
+  protected XObject(){}
+  */
 
   /**
    * Create an XObject.
-   */
-  public XObject(){}
-
-  /**
-   * Create an XObject.
+   * Note: Abstract methods can't be constructed...
+   * ... and constructors don't inherit, even as abstracts.
    *
    * @param obj Can be any object, should be a specific type
    * for derived classes, or null.
    */
-  public XObject(Object obj)
+  /*
+  protected XObject(Object obj)
   {
-    m_obj = obj;
+    //m_obj = obj;
   }
+  */
 
   /**
    * For support of literal objects in xpaths.
@@ -150,12 +157,15 @@
   public void destruct()
   {
 
-    if (null != m_obj)
+    if (null != object())
     {
       allowDetachToRelease(true);
       detach();
-
-      m_obj = null;
+      
+      // %BUG% When m_obj was part of this class, we were
+      // nulling it out at this point. Do we need to move
+      // this logic down into the subclasses?
+	  //	  m_obj = null;
     }
   }
   
@@ -216,22 +226,57 @@
   public static final int CLASS_NULL = -1;
 
   /** Constant for UNKNOWN object type */
-  public static final int CLASS_UNKNOWN = 0;
+  public static final int CLASS_UNKNOWN = XType.ANYTYPE;
 
   /** Constant for BOOLEAN  object type */
-  public static final int CLASS_BOOLEAN = 1;
+  public static final int CLASS_BOOLEAN = XType.BOOLEAN;
 
   /** Constant for NUMBER object type */
-  public static final int CLASS_NUMBER = 2;
+  public static final int CLASS_NUMBER = XType.DOUBLE;
 
   /** Constant for STRING object type */
-  public static final int CLASS_STRING = 3;
+  public static final int CLASS_STRING = XType.STRING;
 
   /** Constant for NODESET object type */
-  public static final int CLASS_NODESET = 4;
+  public static final int CLASS_NODESET = XType.NODE;
 
   /** Constant for RESULT TREE FRAGMENT object type */
-  public static final int CLASS_RTREEFRAG = 5;
+  public static final int CLASS_RTREEFRAG = XType.RTREEFRAG;
+	
+	/** Constant for DATE object type */
+  public static final int CLASS_DATE = XType.DATE;
+  
+  /** Constant for DATETIME object type */
+  public static final int CLASS_DATETIME = XType.DATETIME;
+  
+  /** Constant for DURATION object type */
+  public static final int CLASS_DURATION = XType.DURATION;
+  
+  /** Constant for DURATION object type */
+  public static final int CLASS_YMDURATION = XType.YEARMONTHDURATION;
+
+
+/** Constant for DURATION object type */
+  public static final int CLASS_DTDURATION = XType.DAYTIMEDURATION;
+
+  
+  /** Constant for TIME object type */
+  public static final int CLASS_TIME = XType.TIME;
+  
+  /** Constant for GDAY object type */
+  public static final int CLASS_GDAY = XType.GDAY;
+  
+  /** Constant for GMONTH object type */
+  public static final int CLASS_GMONTH = XType.GMONTH;
+  
+  /** Constant for GMONTHDAY object type */
+  public static final int CLASS_GMONTHDAY = XType.GMONTHDAY;
+  
+  /** Constant for GYEAR object type */
+  public static final int CLASS_GYEAR = XType.GYEAR;
+  
+  /** Constant for GYEARMONTH object type */
+  public static final int CLASS_GYEARMONTH = XType.GYEARMONTH;
 
   /** Represents an unresolved variable type as an integer. */
   public static final int CLASS_UNRESOLVEDVARIABLE = 600;
@@ -245,6 +290,19 @@
   {
     return CLASS_UNKNOWN;
   }
+  
+  /**
+   * Get the type of the value that this object represents.
+   * For most objects this is the same as getType(), but for 
+   * nodes it is the type of the inner value.
+   *
+   * @return one of the 19 simple types from XType.
+   */
+  public int getValueType()
+  {
+    return getType();
+  }
+
 
   /**
    * Given a request type, return the equivalent string.
@@ -274,6 +332,34 @@
   }
   
   /**
+   * Get result object as a integer.
+   *
+   * @return At this level, the num() value cast to an integer.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public int integer() throws javax.xml.transform.TransformerException
+  {
+
+    return (int)num();
+  }
+  
+  /**
+   * Get result object as a integer.
+   *
+   * @return At this level, the num() value cast to an integer.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public float floatVal() throws javax.xml.transform.TransformerException
+  {
+
+    return (float)num();
+  }
+
+
+  
+  /**
    * Cast result object to a number, but allow side effects, such as the 
    * incrementing of an iterator.
    *
@@ -330,7 +416,8 @@
    */
   public String str()
   {
-    return (m_obj != null) ? m_obj.toString() : "";
+  	Object obj=object();
+    return (obj != null) ? obj.toString() : "";
   }
 
   /**
@@ -426,9 +513,30 @@
    *
    * @return The object that this class wraps
    */
-  public Object object()
+  abstract public Object object();
+  
+  /**
+   * Return the sequence representing this object.
+   * @return XSequence
+   */
+  public XSequence xseq()
   {
-    return m_obj;
+  	Object obj=object();
+    try
+    {
+      // This feels a bit heavy weight, but most of the 
+      // derived classes will override this method.
+      if(null == obj || getType() == CLASS_NULL)
+        return XSequence.EMPTY;
+      else if(obj instanceof XSequence)
+        return (XSequence)((XSequence)obj).clone(); // Clone??
+      else
+        return new XSequenceSingleton(this);
+    }
+    catch (CloneNotSupportedException e)
+    {
+      return (XSequence)obj;
+    }
   }
 
   /**
@@ -489,6 +597,18 @@
 
     return null;
   }
+  
+  /**
+   * Get the node representation of this object, or return DTM.NULL if 
+   * there is no node representation.
+   * 
+   * @return int DTM.NULL if there is no node representation, or the 
+   * node handle.
+   */
+  public int getNodeHandle()
+  {
+    return DTM.NULL;
+  }
 
 
   /**
@@ -505,7 +625,7 @@
     error(XPATHErrorResources.ER_CANT_CONVERT_TO_MUTABLENODELIST,
           new Object[]{ getTypeString() });  //"Can not convert "+getTypeString()+" to a NodeSetDTM!");
 
-    return (NodeSetDTM) m_obj;
+    return (NodeSetDTM) object();
   }
 
   /**
@@ -539,7 +659,7 @@
       result = new Boolean(bool());
       break;
     case CLASS_UNKNOWN :
-      result = m_obj;
+      result = object();
       break;
 
     // %TBD%  What to do here?
@@ -662,25 +782,44 @@
    *
    * @throws javax.xml.transform.TransformerException
    */
-  public boolean equals(XObject obj2)
+  public boolean equalsExistential(XObject obj2)
   {
-
     // In order to handle the 'all' semantics of 
     // nodeset comparisons, we always call the 
     // nodeset function.
-    if (obj2.getType() == XObject.CLASS_NODESET)
-      return obj2.equals(this);
-
-    if (null != m_obj)
+    if (obj2.isNodesetExpr())
     {
-      return m_obj.equals(obj2.m_obj);
+      // Note: obj2 _must_ overload this function, or we
+      // dive into infinite recursion if "this" is also a
+      // nodeset.
+      return obj2.equalsExistential(this);
     }
+
+    return equals(obj2);
+  }
+
+  /**
+   * Tell if two objects are functionally equal.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is equal to the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean equals(XObject obj2)
+  {
+    Object obj = object();
+    if (null != obj)
+      return obj.equals(obj2.object());
     else
     {
-      return obj2.m_obj == null;
+      return obj2.object() == null;
     }
   }
 
+  
+
   /**
    * Tell if two objects are functionally not equal.
    *
@@ -746,7 +885,7 @@
   /**
    * XObjects should not normally need to fix up variables.
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
     // no-op
   }
@@ -783,10 +922,138 @@
   	// If equals at the expression level calls deepEquals, I think we're 
   	// still safe from infinite recursion since this object overrides 
   	// equals.  I hope.
-  	if(!this.equals((XObject)expr))
+  	if(!this.equalsExistential((XObject)expr))
   		return false;
   		
   	return true;
   }
+  
+  /**
+   * Tell if this node should have it's PathExpr ancestory reduced.
+   */
+  public boolean isPathExprReduced()
+  {
+  	return true;
+  }
+  
+  /**
+   * Tell if this item is a proper sequence, or should be treated as a 
+   * value.  This is needed for nested sequences (we implement sequences 
+   * as nested, even though it appears from the caller's perspective and 
+   * from XPath's perspective that sequences are not nested).  XObjects 
+   * that return true from this method must implement XSequence, though not 
+   * all XObjects that implement XSequence must return true from this 
+   * method.
+   * @return true if this sequence can be treated as a value or node, falst 
+   *          if this is a proper sequence.
+   */
+  public boolean isSequenceProper()
+  {
+    return false;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isSingletonOrEmpty()
+   */
+  public boolean isSingletonOrEmpty()
+  {
+    return true;
+  }
+
+  /**
+   * Cast result object to a DURATION.
+   *
+   * @return Duration
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public Duration duration() throws javax.xml.transform.TransformerException
+  {
+
+    error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
+          new Object[]{ getTypeString(), "DURATION" });  //"Can not convert "+getTypeString()+" to a number");
+
+    return null; // To shut up compiler
+  }
+  
+  /**
+   * Cast result object to a DAYTIMEDURATION.
+   *
+   * @return Duration
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public Duration daytimeDuration() throws javax.xml.transform.TransformerException
+  {
+
+    error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
+          new Object[]{ getTypeString(), "DAYTIMEDURATION" });  //"Can not convert "+getTypeString()+" to a number");
+
+    return null; // To shut up compiler
+  }
+  
+  /**
+   * Cast result object to a YEARMONTHDURATION.
+   *
+   * @return Duration
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public Duration yearmonthDuration() throws javax.xml.transform.TransformerException
+  {
+
+    error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
+          new Object[]{ getTypeString(), "YEARMONTHDURATION" });  //"Can not convert "+getTypeString()+" to a number");
+
+    return null; // To shut up compiler
+  }
+
+  /**
+   * Cast result object to a DATE.
+   *
+   * @return DateTimeObj
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public DateTimeObj date() throws javax.xml.transform.TransformerException
+  {
+
+    error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
+          new Object[]{ getTypeString(), "DATE" });  //"Can not convert "+getTypeString()+" to a number");
+
+    return null; // To shut up compiler
+  }
+  
+  /**
+   * Cast result object to a DATETIME.
+   *
+   * @return DateTimeObj
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public DateTimeObj datetime() throws javax.xml.transform.TransformerException
+  {
+
+    error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
+          new Object[]{ getTypeString(), "DATETIME" });  //"Can not convert "+getTypeString()+" to a number");
+
+    return null; // To shut up compiler
+  }
+
+  /**
+   * Cast result object to a TIME.
+   *
+   * @return DateTimeObj
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public DateTimeObj time() throws javax.xml.transform.TransformerException
+  {
+
+    error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
+          new Object[]{ getTypeString(), "TIME" });  //"Can not convert "+getTypeString()+" to a number");
+
+    return null; // To shut up compiler
+  }
 
 }
diff --git a/src/org/apache/xpath/objects/XObjectFactory.java b/src/org/apache/xpath/objects/XObjectFactory.java
index 6d873b6..cdcce35 100644
--- a/src/org/apache/xpath/objects/XObjectFactory.java
+++ b/src/org/apache/xpath/objects/XObjectFactory.java
@@ -1,6 +1,8 @@
 package org.apache.xpath.objects;
 
 import org.apache.xml.dtm.*;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xml.utils.Duration;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.NodeSetDTM;
 import org.apache.xpath.axes.OneStepIterator;
@@ -37,16 +39,21 @@
     }
     else if (val instanceof Double)
     {
-      result = new XNumber(((Double) val));
+      result = new XDouble(((Double) val));
+    }
+    else if (val instanceof Integer)
+    {
+      result = new XInteger(((Integer) val)); 
     }
     else
-    {
-      result = new XObject(val);
+    { 
+      result = new XJavaObject(val);
     }
 
     return result;
   }
   
+  
   /**
    * Create the right XObject based on the type of the object passed.
    * This function <emph>can</emph> make an XObject that exposes DOM Nodes, NodeLists, and 
@@ -74,9 +81,21 @@
     {
       result = new XBoolean((Boolean)val);
     }
-    else if (val instanceof Number)
+    else if (val instanceof Double)
     {
-      result = new XNumber(((Number) val));
+      result = new XDouble(((Double) val));
+    }
+    else if (val instanceof Integer)
+    {
+      result = new XInteger(((Integer) val));
+    }
+    else if (val instanceof DateTimeObj)
+    {
+      result = new XDateTime((DateTimeObj) val);
+    }
+    else if (val instanceof Duration)
+    {
+      result = new XDuration((Duration) val);
     }
     else if (val instanceof DTM)
     {
@@ -131,7 +150,7 @@
     }
     else
     {
-      result = new XObject(val);
+      result = new XJavaObject(val);
     }
 
     return result;
diff --git a/src/org/apache/xpath/objects/XRTreeFrag.java b/src/org/apache/xpath/objects/XRTreeFrag.java
index a805b32..4aa5ea4 100644
--- a/src/org/apache/xpath/objects/XRTreeFrag.java
+++ b/src/org/apache/xpath/objects/XRTreeFrag.java
@@ -58,6 +58,7 @@
 
 import javax.xml.transform.TransformerException;
 import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMManager;
 import org.apache.xml.dtm.DTMIterator;
 import org.apache.xml.utils.FastStringBuffer;
 import org.apache.xml.utils.XMLString;
@@ -66,34 +67,16 @@
 import org.apache.xpath.XPathContext;
 import org.w3c.dom.NodeList;
 
-import org.apache.xml.dtm.Axis;
-import org.apache.xpath.axes.RTFIterator;
-
 /**
  * <meta name="usage" content="general"/>
  * This class represents an XPath result tree fragment object, and is capable of
  * converting the RTF to other types, such as a string.
  */
-public class XRTreeFrag extends XObject implements Cloneable
+public class XRTreeFrag extends XNodeSet implements Cloneable
 {
-  DTM m_dtm;
-  int m_dtmRoot;
-  XPathContext m_xctxt;
-  boolean m_allowRelease = false;
+  DTM m_dtm=null; // For possible storage management during finalize/destruct
+  boolean m_allowRelease;
 
-//  /**
-//   * Create an XRTreeFrag Object.
-//   *
-//   * @param frag Document fragment this will wrap
-//   */
-//  public XRTreeFrag(DTMIterator frag)
-//  {
-//    super(frag);
-//    
-//    // Obviously, this constructor should be avoided when possible.
-//    m_dtmRoot = frag.cloneWithReset().nextNode();
-//  }
-  
   /**
    * Create an XRTreeFrag Object.
    *
@@ -101,13 +84,13 @@
    */
   public XRTreeFrag(int root, XPathContext xctxt, ExpressionNode parent)
   {
-    super(null);
+    super(root,xctxt);
     
-    // Obviously, this constructor should be avoided when possible.
     exprSetParent(parent);
-    m_dtmRoot = root;
-    m_xctxt = xctxt;
+
     m_dtm = xctxt.getDTM(root);
+    
+    m_iter=xctxt.createDTMIterator(root);
   }
   
   /**
@@ -117,43 +100,36 @@
    */
   public XRTreeFrag(int root, XPathContext xctxt)
   {
-    super(null);
-    
-    // Obviously, this constructor should be avoided when possible.
-    m_dtmRoot = root;
-    m_xctxt = xctxt;
+    super(root,xctxt);
+
     m_dtm = xctxt.getDTM(root);
+    m_iter=xctxt.createDTMIterator(root);
   }
 
-  
-  /**
-   * Return a java object that's closest to the representation
-   * that should be handed to an extension.
-   *
-   * @return The object that this class wraps
-   */
-  public Object object()
-  {
-    if (m_xctxt != null)
-      return new org.apache.xml.dtm.ref.DTMNodeIterator((DTMIterator)(new org.apache.xpath.NodeSetDTM(m_dtmRoot, m_xctxt.getDTMManager())));
-    else
-      return super.object();
-  }
-  
   /**
    * Create an XRTreeFrag Object.
    *
    * @param frag Document fragment this will wrap
    */
-  public XRTreeFrag(Expression expr)
+  /*
+  private XRTreeFrag(Expression expr)
   {
     super(expr);
+    
+    // Can't retrieve m_iter until the expression has been executed.
+    // Can't execute without an XCTXT.
+    // Can't win.
+    // Should this constructor exist at all? It seems to be here to support
+    // XRTreeFragSelectWrapper... but I'm not sure that should be considered
+    // an RTF rather than an XNodeSet!!!
   }
-  
+  */
+
   /**
    * Release any resources this object may have by calling destruct().
-   * %ISSUE% This release will occur asynchronously. Resources it manipulates
-   * MUST be thread-safe!
+   * 
+   * STRONG WARNING: This release will occur asynchronously. Resources it 
+   * manipulates MUST be thread-safe!
    *
    * @throws Throwable
    */
@@ -193,16 +169,14 @@
   {
     if(m_allowRelease)
     {
-    	// %REVIEW% Do we actually _need_ detach, now that DTM RTF
-    	// storage is managed as a stack?
       // See #destruct() for a comment about this next check.
-      int ident = m_xctxt.getDTMIdentity(m_dtm);
-      DTM foundDTM = m_xctxt.getDTM(ident);      
+      int ident = m_dtmMgr.getDTMIdentity(m_dtm);
+      DTM foundDTM = m_dtmMgr.getDTM(ident);      
       if(foundDTM == m_dtm)
       {
-        m_xctxt.release(m_dtm, true);
+        m_dtmMgr.release(m_dtm, true);
         m_dtm = null;
-        m_xctxt = null;
+        m_dtmMgr = null;
       }
       m_obj = null;
     }
@@ -234,13 +208,13 @@
       //    getDTMIdentity(dtm)).
       // 6) Transform#2 tries to reference DTMManagerDefault#m_dtms[2], finds it is 
       //    null, and chaos results.
-      int ident = m_xctxt.getDTMIdentity(m_dtm);
-      DTM foundDTM = m_xctxt.getDTM(ident);      
+      int ident = m_dtmMgr.getDTMIdentity(m_dtm);
+      DTM foundDTM = m_dtmMgr.getDTM(ident);      
       if(foundDTM == m_dtm)
       {
-        m_xctxt.release(m_dtm, true);
+        m_dtmMgr.release(m_dtm, true);
         m_dtm = null;
-        m_xctxt = null;
+        m_dtmMgr = null;
       }
     }
     m_obj = null;
@@ -248,6 +222,7 @@
 
   /**
    * Tell what kind of class this is.
+   * %REVIEW% Should we really be distinguishing RTF from other NodeSets?
    *
    * @return type CLASS_RTREEFRAG 
    */
@@ -259,6 +234,7 @@
   /**
    * Given a request type, return the equivalent string.
    * For diagnostic purposes.
+   * %REVIEW% Should we really be distinguishing RTF from other NodeSets?
    *
    * @return type string "#RTREEFRAG"
    */
@@ -269,13 +245,13 @@
 
   /**
    * Cast result object to a number.
+   * Note that this is different from XNodeSet's definition; we convert
+   * the entire string content, not just item(0).
    *
    * @return The result tree fragment as a number or NaN
    */
   public double num()
-    throws javax.xml.transform.TransformerException
   {
-
     XMLString s = xstr();
 
     return s.toDouble();
@@ -296,19 +272,23 @@
   
   /**
    * Cast result object to an XMLString.
+   * Note that this is different from XNodeSet's definition; we convert
+   * the entire string content, not just item(0).
    *
    * @return The document fragment node data or the empty string. 
    */
   public XMLString xstr()
   {
     if(null == m_xmlStr)
-      m_xmlStr = m_dtm.getStringValue(m_dtmRoot);
+      m_xmlStr = m_dtm.getStringValue(item(0));
     
     return m_xmlStr;
   }
   
   /**
-   * Cast result object to a string.
+   * Append result object's content to a FastStringBuffer.
+   * Note that this is different from XNodeSet's definition; we convert
+   * the entire string content, not just item(0).
    *
    * @return The string this wraps or the empty string if null
    */
@@ -321,12 +301,14 @@
 
   /**
    * Cast result object to a string.
+   * Note that this is different from XNodeSet's definition; we convert
+   * the entire string content, not just item(0).
    *
    * @return The document fragment node data or the empty string. 
    */
   public String str()
   {
-    String str = m_dtm.getStringValue(m_dtmRoot).toString();
+    String str = m_dtm.getStringValue(item(0)).toString();
 
     return (null == str) ? "" : str;
   }
@@ -334,41 +316,61 @@
   /**
    * Cast result object to a result tree fragment.
    *
-   * @return The document fragment this wraps
+   * @return The DTM Node Handle of the root node of the 
+   * document fragment this wraps
    */
   public int rtf()
   {
-    return m_dtmRoot;
+    return item(0);
   }
 
   /**
-   * Cast result object to a DTMIterator.
-   * dml - modified to return an RTFIterator for
-   * benefit of EXSLT object-type function in 
-   * {@link org.apache.xalan.lib.ExsltCommon}.
+   * Cast result object to a DTMIterator. Standard XObject method,
+   * replaces special-case asNodeIterator()
    * @return The document fragment as a DTMIterator
    */
+  public DTMIterator iter()
+  {
+    //return m_dtmMgr.createDTMIterator(item(0));
+    return super.iter();
+  }
+  
+  /** @deprecated Unnecessarily nonstandard.
+   * @see iter()
+   * */
   public DTMIterator asNodeIterator()
   {
-    DTMIterator iter = new RTFIterator(Axis.SELF);
-    iter.setRoot(m_dtmRoot, m_xctxt);    
-    return iter;
+    return iter();
   }
+  
 
   /**
-   * Cast result object to a nodelist. (special function).
+   * Cast result object to a DOM nodelist, primarily
+   * for use as an extension function argument.
+   * (tandard XObject function, replaces special-case convertToNodeset()
    *
    * @return The document fragment as a nodelist
    */
-  public NodeList convertToNodeset()
+  public NodeList nodelist() throws javax.xml.transform.TransformerException
   {
-
+  	return super.nodelist();
+	/*
     if (m_obj instanceof NodeList)
       return (NodeList) m_obj;
     else
-      return new org.apache.xml.dtm.ref.DTMNodeList(asNodeIterator());
+      return new org.apache.xml.dtm.ref.DTMNodeList(iter());
+     */
   }
 
+  /** @deprecated Unnecessarily nonstandard.
+   * @see nodeList()
+   * */
+  public NodeList convertToNodeset() throws javax.xml.transform.TransformerException
+  {
+  	return nodelist();
+  }
+
+
   /**
    * Tell if two objects are functionally equal.
    *
@@ -389,7 +391,7 @@
         // In order to handle the 'all' semantics of 
         // nodeset comparisons, we always call the 
         // nodeset function.
-        return obj2.equals(this);
+        return ((XNodeSet)obj2).equalsExistential(this);
       }
       else if (XObject.CLASS_BOOLEAN == obj2.getType())
       {
diff --git a/src/org/apache/xpath/objects/XRTreeFragSelectWrapper.java b/src/org/apache/xpath/objects/XRTreeFragSelectWrapper.java
index f5af9e0..21e8b1d 100644
--- a/src/org/apache/xpath/objects/XRTreeFragSelectWrapper.java
+++ b/src/org/apache/xpath/objects/XRTreeFragSelectWrapper.java
@@ -6,22 +6,37 @@
 
 import org.apache.xml.utils.XMLString;
 
-import org.apache.xpath.DOMHelper;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.Expression;
 import org.apache.xalan.res.XSLMessages;
 import org.apache.xpath.res.XPATHErrorResources;
 
 /**
- * This class makes an select statement act like an result tree fragment.
+ * This class makes an select statement act like an result tree fragment...
+ * at least in its returned values and comparisons. Actually, a
+ * more accurate description might be that its "values", like those of an
+ * RTF, spans all the selected content rather than being taken only from the
+ * first matching node.
+ * 
+ * But this really  _isn't_ a result tree fragment. The rtf() method is 
+ * hardwired to throw an exception, and the type() method returns STRING.
+ * 
+ * (Some of the logic is swiped from XRTreeFrag, but we no longer
+ * inherit from that class. Doing so was a bit of a kluge, and became
+ * impractical when XRTreeFrag was rewritten as an XNodeSet derivitive.)
+ * 
+ * %REVIEW% Should we rename this class?
  */
-public class XRTreeFragSelectWrapper extends XRTreeFrag implements Cloneable
+public class XRTreeFragSelectWrapper extends XObject implements Cloneable
 {
   XObject m_selected;
+  boolean m_allowRelease;
+  Expression m_expr;
 
   public XRTreeFragSelectWrapper(Expression expr)
   {
-    super(expr);
+    m_expr=expr;
   }
   
   /**
@@ -34,9 +49,9 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    ((Expression)m_obj).fixupVariables(vars, globalsSize);
+    m_expr.fixupVariables(vcs);
   }
   
   /**
@@ -53,7 +68,7 @@
   {
     try
     {
-      m_selected = ((Expression)m_obj).execute(xctxt);
+      m_selected = m_expr.execute(xctxt);
       m_selected.allowDetachToRelease(m_allowRelease);
       XRTreeFragSelectWrapper xrtf = (XRTreeFragSelectWrapper)this.clone();
       return xrtf;
@@ -80,24 +95,12 @@
     {
       m_selected.detach();
       m_selected = null;
+      m_expr=null;
     }
     
     super.detach();
   }
-  
-  /**
-   * Cast result object to a number.
-   *
-   * @return The result tree fragment as a number or NaN
-   */
-  public double num()
-    throws javax.xml.transform.TransformerException
-  {
-
-    return m_selected.num();
-  }
-
-  
+   
   /**
    * Cast result object to an XMLString.
    *
@@ -125,13 +128,14 @@
    */
   public int getType()
   {
-    return CLASS_STRING; // hmm...
+    return CLASS_STRING;
   }
 
   /**
    * Cast result object to a result tree fragment.
+   * Probably not needed since we no longer claim to inherit XRTreeFrag...
    *
-   * @return The document fragment this wraps
+   * @throws method-not-supported runtime expection.
    */
   public int rtf()
   {
@@ -147,5 +151,102 @@
   {
     throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_RTF_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"asNodeIterator() not supported by XRTreeFragSelectWrapper!");
   }
+  
+  public Object object()
+  {
+  	/* Would this be preferable?
+  	if(m_selected!=null)
+  		return m_selected.object();
+  	else
+  	*/
+  		return m_expr;
+  }
+  
+
+  //-------------------------------------------------------------
+  // Code swiped from XRTreeFrag since we no longer inherit therefrom
+
+ /**
+   * Tell if two objects are functionally equal.
+   * Use logic from XRTreeFrag, not standard XObject.equals()
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if the two objects are equal
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean equals(XObject obj2)
+  {
+
+    try
+    {
+      if (XObject.CLASS_NODESET == obj2.getType())
+      {
+  
+        // In order to handle the 'all' semantics of 
+        // nodeset comparisons, we always call the 
+        // nodeset function.
+        return ((XNodeSet)obj2).equalsExistential(this);
+      }
+      else if (XObject.CLASS_BOOLEAN == obj2.getType())
+      {
+        return bool() == obj2.bool();
+      }
+      else if (XObject.CLASS_NUMBER == obj2.getType())
+      {
+        return num() == obj2.num();
+      }
+      else if (XObject.CLASS_NODESET == obj2.getType())
+      {
+        return xstr().equals(obj2.xstr());
+      }
+      else if (XObject.CLASS_STRING == obj2.getType())
+      {
+        return xstr().equals(obj2.xstr());
+      }
+      else if (XObject.CLASS_RTREEFRAG == obj2.getType())
+      {
+  
+        // Probably not so good.  Think about this.
+        return xstr().equals(obj2.xstr());
+      }
+      else
+      {
+        return super.equals(obj2);
+      }
+    }
+    catch(javax.xml.transform.TransformerException te)
+    {
+      throw new org.apache.xml.utils.WrappedRuntimeException(te);
+    }
+  }
+
+  /**
+   * Cast result object to a number.
+   * Note that this is different from XNodeSet's definition; we convert
+   * the entire string content, not just item(0).
+   *
+   * @return The result tree fragment as a number or NaN
+   */
+  public double num()
+  {
+    XMLString s = xstr();
+
+    return s.toDouble();
+  }
+  
+  /**
+   * Cast result object to a boolean.  This always returns true for an
+   * XRTreeFragSelectWrapper. (I'm not entirely sure why it should, but some
+   * of the regression tests fail if it doesn't.)
+   *
+   * @return true
+   */
+  public boolean bool()
+  {
+    return true;
+  }
+    
 
 }
\ No newline at end of file
diff --git a/src/org/apache/xpath/objects/XSequence.java b/src/org/apache/xpath/objects/XSequence.java
new file mode 100644
index 0000000..d3fbaec
--- /dev/null
+++ b/src/org/apache/xpath/objects/XSequence.java
@@ -0,0 +1,277 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+/**
+ * The responsibility of XSequence is to provide an interface to XPath 2.0
+ * sequences.
+ * 
+ * Created Jul 16, 2002
+ * @author sboag
+ * @author jkesselman
+ */
+public interface XSequence extends Cloneable
+{  
+  /** MANAFEST CONSTANT: An empty XSequence, which can be returned when no
+   * typed value exists.
+   * */ 
+  public static final XSequenceEmpty EMPTY = new XSequenceEmpty();
+  
+  //========= Type methods on the sequence as a whole ==========
+
+  /**
+   * If this iterator holds homogenous types, return that type ID.
+   * 
+   * @return The homogenous type, or NOTHOMOGENOUS, or EMPTYSEQ.
+   */
+  public int getTypes();
+  
+  
+  //========= Itteration ==========
+
+  /**
+   * Returns the next object in the set and advances the position of the
+   * iterator in the set.
+   * 
+   * @return The next item in the set being iterated over, or
+   *  <code>null</code> if there are no more members in that set.
+   */
+  public XObject next();
+
+  /**
+   * Returns the previous object in the set and moves the position of the
+   * <code>XSequence</code> backwards in the set.
+   * 
+   * @return The previous item in the set being iterated over,
+   *   or <code>null</code> if there are no more members in that set.
+   */
+  public XObject previous();
+
+  /**
+   * Detaches the <code>XSequence</code> from the set which it iterated
+   * over, releasing any computational resources and placing the iterator
+   * in the INVALID state. After <code>detach</code> has been invoked,
+   * calls to <code>next</code> or <code>previous</code> will
+   * raise a runtime exception.
+   */
+  public void detach();
+  
+  /**
+   * Specify if it's OK for detach to release the iterator for reuse.
+   * 
+   * @param allowRelease true if it is OK for detach to release this iterator 
+   * for pooling.
+   */
+  public void allowDetachToRelease(boolean allowRelease);
+
+  /**
+   * Get the current item in the iterator.
+   *
+   * @return The item or null if there is no current item.
+   */
+  public XObject getCurrent();
+
+  /**
+   * Tells if this iterator is "fresh", in other words, if
+   * the first next() that is called will return the
+   * first item in the set.
+   *
+   * @return true if the iteration of this list has not yet begun.
+   */
+  public boolean isFresh();
+  
+  /** 
+   * Retrieve the current item's datatype namespace URI.
+   * 
+   * @return the namespace for the current value's type
+   * @throws exception if there is no current item.
+   */
+  public String getTypeNS();
+
+  /** 
+   * Retrieve current item's datatype namespace URI.
+   * 
+   * @return the localname of the current value's type
+   * @throws exception if there is no current item.
+   */
+  public String getTypeLocalName();
+
+  /** 
+   * Ask whether the current item's datatype equals or is derived from a specified
+   * schema NSURI/localname pair.
+   * 
+   * @return true if the type is an instance of this schema datatype,
+   * false if it isn't.
+   * @throws exception if there is no current item.
+   */
+  public boolean isSchemaType(String namespace, String localname);
+  
+  /**
+   * Retrieve the built-in atomic type of the current item
+   * 
+   * @return NODE, ANYTYPE, etc. as defined in XType
+   * @throws exception if there is no current item.
+   */
+  public int getType();
+  
+  /** @return true if the sequence is known to contain only NODEs.
+   * (%REVIEW%: If false, that may not mean it doesn't, just that
+   * we don't know this a priori and can't optimize.)
+   * */
+  public boolean isPureNodeSequence();
+  
+  /**
+   * Reset the iterator to the beginning of the itteration.  After this 
+   * is called, isFresh will return true, and there will be no current 
+   * node.
+   */
+  public void reset();
+
+
+  //========= Random Access ==========
+
+  /**
+   * If setShouldCache(true) is called, then items will
+   * be cached, enabling random access, and giving the ability to do 
+   * sorts and the like.  They are not cached by default.
+   *
+   * %REVIEW% Shouldn't the other random-access methods throw an exception
+   * if they're called with this flag set false?
+   * 
+   * %REVIEW% Is this method still needed, given that we *removed*
+   * most of the random-access methods (except setCurrentPos)?
+   *
+   * @param b true if the items should be cached.
+   * @throws exception if XSequence can't cache.
+   */
+  public void setShouldCache(boolean b);
+  
+  /**
+   * Tell if the random access methods (i.e. those methods 
+   * that take an index) can be used.  This is the normally the  
+   * same value set with setShouldCache(boolean b).
+   * 
+   * %REVIEW% Is this method still needed, given that we *removed*
+   * most of the random-access methods (except setCurrentPos)?
+   *
+   * @return true if the random access methods can be used.
+   */
+  public boolean getIsRandomAccess();
+  
+  /**
+   * Tells if this iterator can have items added to it.
+   * 
+   * @return True if the XSequence can be mutated -- in which case
+   * it presumably implements XSequenceMutable. (However, not all
+   * sequences which implement that interface can be mutated; they
+   * may have been locked.)
+   * 
+   * @see XSequenceMutable.lock()
+   */
+  public boolean isMutable();
+
+  /**
+   * Get the current position within the cached list, which is one
+   * less than the next next() call will retrieve.  i.e. if you
+   * call getCurrentPos() and the return is 0, the next fetch will
+   * take place at index 1.  If the itterator is fresh, this will return 
+   * -1.
+   *
+   * @return The position of the iteration.
+   */
+  public int getCurrentPos();
+
+  /**
+   * Set the current position in the sequence.  If the index is 
+   * at the end of the sequence, the return value will be null.
+   * This is mainly to support setting the index to zero without 
+   * caring if the sequence contains a value.
+   * 
+   * @param i Must be a valid index.
+   * @return the object at the given index, or null if 
+   * index == length.
+   * @throws exception if index &lt; 0 or &gt;= length. 
+   * @throws exception if the sequence implementation does not 
+   * support random access.
+   */
+  public void setCurrentPos(int i);
+    
+  /**
+   * The number of items in the list. The range of valid item indices
+   * is 0 to <code>length-1</code> inclusive. Note that this requires running
+   * the iterator to completion, and presumably filling the cache.
+   * <i>Warning: Use of this function can be expensive and detrimental to 
+   * performance.</i> 
+   *
+   * @return The number of items in the list.
+   */
+  public int getLength();
+  
+  /**
+   * Tell if this item is a singleton.  This method will also 
+   * return true for an empty sequence.
+   * @return true if this sequence is a singleton, or an empty sequence.
+   */
+  public boolean isSingletonOrEmpty();
+  
+  /**
+   * @return XSequence object.
+   * @see java.lang.Object#clone()
+   */
+  public Object clone() throws CloneNotSupportedException;
+        
+}
diff --git a/src/org/apache/xpath/objects/XSequenceCachedBase.java b/src/org/apache/xpath/objects/XSequenceCachedBase.java
new file mode 100644
index 0000000..3c754b0
--- /dev/null
+++ b/src/org/apache/xpath/objects/XSequenceCachedBase.java
@@ -0,0 +1,349 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+import java.util.Vector;
+
+import org.apache.xpath.XPathContext;
+
+/**
+ * XSequenceCachedBase is an abstract superclass for classes that
+ * want to use XSequenceImpl as a base for caching but are otherwise
+ * incremental.
+ * 
+ * Created Jul 20, 2002
+ * @author sboag
+ */
+public abstract class XSequenceCachedBase extends XSequenceImpl implements XSequence
+{
+  protected boolean m_cached = false;
+  protected XObject m_current;
+  protected XPathContext m_xctxt; 
+  protected boolean m_foundLast = false;
+  
+  /**
+   * Constructor for XSequenceCachedBase.
+   */
+  public XSequenceCachedBase(XPathContext xctxt)
+  {
+    m_xctxt = xctxt;
+  }
+
+
+  /**
+   * Return the next object in the iteration from a next() method.
+   * @param xobj the next Object in the itterator, or null.
+   * @return XObject The same reference that was passed in.
+   */
+  public XObject next()
+  {
+  	// Start by asking the cache
+    XObject next = super.next();
+    
+    // If not in cache, and not done iterating, request
+    // new value from getNext() (provided by subclass)
+    if(null == next && !m_foundLast)
+    {
+      next = getNext();
+      if(null != next)
+      {
+      	// Add it to the cache.
+        m_pos++;
+        if(m_cached)
+        {
+          // Note: The first case arises only if the cache
+          // actually contained a null. May happen if a
+          // subclass knows the expected count and preallocates
+          // the cache; unlikely otherwise.
+          if(m_pos < getValues().size()-1)
+            insertItemAt(next, m_pos);
+          else
+            concat(next);
+        }
+      }
+      else
+      {
+        m_foundLast = true; // Off the end...
+        m_pos++; // go off the end.
+      }
+    }
+    m_current = next;
+    return next;
+  }
+
+  /**
+   * Return the previous object in the iteration from a previous() method.
+   * @param xobj the next Object in the iterator, or null.
+   * @return XObject The same reference that was passed in.
+   */
+  public XObject previous()
+  {
+  	// Start by asking the cache
+    XObject prev = super.previous();
+    
+    // If not in cache, and not done iterating, request
+    // new value from getNext() (provided by subclass)
+    if(null == prev)
+    {
+      m_pos--;
+      prev = getPrevious();
+      if(null != prev)
+      {
+      	// Add it to the cache.
+        // Note: This case arises only if the cache
+        // actually contained a null. May happen if a
+        // subclass knows the expected count and preallocates
+        // the cache; unlikely otherwise.
+        if(m_cached)
+          super.insertItemAt(prev, m_pos);
+      }
+    }
+    m_current = prev;
+    return prev;
+  }
+  
+  /**
+   * This method must be implemented by the derived class to return the 
+   * next item in the iteration, and is called by the next() method.  The 
+   * item returned will be inserted into the cache if the cache property 
+   * is true.
+   * @return XObject The next item, or null.
+   */
+  protected abstract XObject getNext();
+  
+  /**
+   * This method must be implemented by the derived class to return the 
+   * previous item in the iteration, and is called by the next() method.  The 
+   * item returned will be inserted into the cache if the cache property 
+   * is true.
+   * @return XObject The previous item, or null.
+   * @throws RuntimeException if this iterator doesn't support non-cached 
+   * previous operations.
+   */
+  protected abstract XObject getPrevious();
+
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getCurrent()
+   */
+  public XObject getCurrent()
+  {
+    return m_current;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isFresh()
+   */
+  public boolean isFresh()
+  {
+    return (null == m_current) && super.isFresh();
+  }
+  
+  /**
+   * @see org.apache.xpath.objects.XSequence#getTypeNS()
+   */
+  public String getTypeNS()
+  {
+    assertion((null != m_current), "Current node can not be null for getTypeNS()!");
+    return m_current.xseq().getTypeNS();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getTypeLocalName()
+   */
+  public String getTypeLocalName()
+  {
+    assertion((null != m_current), "Current node can not be null for getTypeLocalName()!");
+    return m_current.xseq().getTypeLocalName();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isSchemaType(String, String)
+   */
+  public boolean isSchemaType(String namespace, String localname)
+  {
+    assertion((null != m_current), "Current node can not be null for isSchemaType()!");
+    return m_current.xseq().isSchemaType(namespace, localname);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isPureNodeSequence()
+   */
+  public boolean isPureNodeSequence()
+  {
+    // Not totally sure what to do about this yet.
+    return false;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#setShouldCache(boolean)
+   */
+  public void setShouldCache(boolean b)
+  {
+    if(!isFresh())
+     throw new RuntimeException(this.getClass().getName()+" cache can not be changed after it has started!");
+    if(b)
+    {
+      if(null == getValues())
+        setValues(new Vector());
+    }
+    m_cached = b;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getIsRandomAccess()
+   */
+  public boolean getIsRandomAccess()
+  {
+    return m_cached;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isMutable()
+   */
+  public boolean isMutable()
+  {
+    return false;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getCurrentPos()
+   */
+  public int getCurrentPos()
+  {
+    return m_pos;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#setCurrentPos(int)
+   */
+  public void setCurrentPos(int i)
+  {
+    if (!m_cached)
+      throw new RuntimeException("This "+this.getClass().getName()+" is not set for random access!");
+
+    if (i < 0)
+    {
+      m_current = null;
+      m_pos = -1;
+    }
+    else
+      if (i > m_pos)
+      {
+        while (i > m_pos)
+        {
+          XObject xobj = next(); 	// Sets m_current implicitly
+          if (null == xobj)
+            break;
+        }
+      }
+      else
+      {
+        m_pos = i;
+        m_current = (XObject) getValues().elementAt(i);
+      }
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getLength()
+   */
+  public int getLength()
+  {
+    if(isFresh())
+      setShouldCache(true);
+    else if(!getIsRandomAccess())
+      throw new RuntimeException("This "+this.getClass().getName()+" is not set for random access!");
+    
+    if(m_foundLast)
+      return getValues().size();
+      
+    int origPos = m_pos;
+    while(next() != null);
+    int len = m_pos;
+    m_pos = origPos;
+    return len;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isSingletonOrEmpty()
+   */
+  public boolean isSingletonOrEmpty()
+  {
+    return false;  // hard to tell at this point.
+  }
+
+
+
+  /**
+   * @return XSequence object.
+   * @see java.lang.Object#clone()
+   */
+  public Object clone() throws CloneNotSupportedException
+  {
+    return super.clone();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#reset()
+   */
+  public void reset()
+  {
+    super.reset();
+    m_current = null;
+  }
+
+}
diff --git a/src/org/apache/xpath/objects/XSequenceEmpty.java b/src/org/apache/xpath/objects/XSequenceEmpty.java
new file mode 100644
index 0000000..fda5250
--- /dev/null
+++ b/src/org/apache/xpath/objects/XSequenceEmpty.java
@@ -0,0 +1,272 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+import org.apache.xml.dtm.XType;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 15, 2002
+ * @author sboag
+ */
+class XSequenceEmpty extends XObject implements XSequence, Cloneable
+{
+  /**
+   * Calling this method doesn't do anything.
+   * @see org.apache.xml.dtm.XSequence#allowDetachToRelease(boolean)
+   */
+  public void allowDetachToRelease(boolean allowRelease)
+  {
+  }
+
+  /**
+   * Calling this method doesn't do anything.
+   * @see org.apache.xml.dtm.XSequence#detach()
+   */
+  public void detach()
+  {
+  }
+
+  /**
+   * Always return null.
+   * @see org.apache.xml.dtm.XSequence#getCurrent()
+   */
+  public XObject getCurrent()
+  {
+    return null;
+  }
+  
+  public Object object()
+  {
+  	return null;
+  }
+
+  /**
+   * Always returns -1.
+   * @see org.apache.xml.dtm.XSequence#getCurrentPos()
+   */
+  public int getCurrentPos()
+  {
+    return 0;
+  }
+
+  /**
+   * Always returns 0.
+   * @see org.apache.xml.dtm.XSequence#getLength()
+   */
+  public int getLength()
+  {
+    return 0;
+  }
+
+  /**
+   * Always throws IndexOutOfBoundsException.
+   * @see org.apache.xml.dtm.XSequence#getType()
+   */
+  public int getType()
+  {
+    throw new IndexOutOfBoundsException("No current item!");
+  }
+
+  /** @return true if the sequence is known to contain only NODEs.
+   * %REVIEW% I can argue for either calling this an empty sequence
+   * of nodes, or a sequence which does not contain any nodes
+   * (or we could throw an exception, though I don't think that's
+   * useful). Which response is most useful?
+   * */
+  public boolean isPureNodeSequence()
+  {
+  	return false;	
+  }
+
+  /**
+   * Always throws IndexOutOfBoundsException.
+   * @see org.apache.xml.dtm.XSequence#getTypeLocalName()
+   */
+  public String getTypeLocalName()
+  {
+    throw new IndexOutOfBoundsException("No current item!");
+  }
+
+  /**
+   * Always throws IndexOutOfBoundsException.
+   * @see org.apache.xml.dtm.XSequence#getTypeNS()
+   */
+  public String getTypeNS()
+  {
+    throw new IndexOutOfBoundsException("No current item!");
+  }
+
+  /**
+   * Always return XType.EMPTYSEQ.
+   * @see org.apache.xml.dtm.XSequence#getTypes()
+   */
+  public int getTypes()
+  {
+    return XType.EMPTYSEQ;
+  }
+
+  /**
+   * Always return true.
+   * @see org.apache.xml.dtm.XSequence#isFresh()
+   */
+  public boolean isFresh()
+  {
+    return true;
+  }
+
+  /**
+   * Always return false.
+   * @see org.apache.xml.dtm.XSequence#isMutable()
+   */
+  public boolean isMutable()
+  {
+    return false;
+  }
+
+  /**
+   * Always throw IndexOutOfBoundsException.
+   * @see org.apache.xml.dtm.XSequence#isSchemaType(String, String)
+   */
+  public boolean isSchemaType(String namespace, String localname)
+  {
+    throw new IndexOutOfBoundsException("No current item!");
+  }
+
+  /**
+   * Always return true;
+   * @see org.apache.xml.dtm.XSequence#isSingleton()
+   */
+  public boolean isSingletonOrEmpty()
+  {
+    return true;
+  }
+
+  /**
+   * Always return null.
+   * @see org.apache.xml.dtm.XSequence#next()
+   */
+  public XObject next()
+  {
+    return null;
+  }
+
+  /**
+   * Always return null.
+   * @see org.apache.xml.dtm.XSequence#previous()
+   */
+  public XObject previous()
+  {
+    return null;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#setCurrentPos(int)
+   */
+  public void setCurrentPos(int i)
+  {
+    if(0 != i)
+      return;
+    else
+      throw new IndexOutOfBoundsException("No item at that index!");
+  }
+
+  /**
+   * Calling this method doesn't do anything.
+   * @see org.apache.xml.dtm.XSequence#setShouldCache(boolean)
+   */
+  public void setShouldCache(boolean b)
+  {
+  }
+
+  /**
+   * %REVIEW% Format not yet firmly settled. Primarily for debugging purposes!
+   * @see java.lang.Object#toString()
+   */
+  public String toString()
+  {
+    return super.toString();
+  }
+
+  /**
+   * @see java.lang.Object#clone()
+   */
+  public Object clone() throws CloneNotSupportedException
+  {
+    return super.clone();
+  }
+
+  /**
+   * Always return true.
+   * @see org.apache.xml.dtm.XSequence#getIsRandomAccess()
+   */
+  public boolean getIsRandomAccess()
+  {
+    return true; // as far as it goes.
+  }
+
+  /**
+   * Calling this method doesn't do anything.
+   * @see org.apache.xml.dtm.XSequence#reset()
+   */
+  public void reset()
+  {
+    // do nothing.
+  }
+
+}
diff --git a/src/org/apache/xpath/objects/XSequenceImpl.java b/src/org/apache/xpath/objects/XSequenceImpl.java
new file mode 100644
index 0000000..aab6b32
--- /dev/null
+++ b/src/org/apache/xpath/objects/XSequenceImpl.java
@@ -0,0 +1,598 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+import java.util.Vector;
+
+import org.apache.xml.dtm.DTMIterator;
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.IntVector;
+import org.apache.xml.utils.WrappedRuntimeException;
+
+/** This class provides an API representation for the XPath 2 Data Model's "Sequences"
+ * -- which are the basic representation for typed values. Only built-in types, 
+ * types derived from built-ins, and sets thereof are returned directly by the XPath2
+ * DM; complex schema-types must be accessed through the document tree.
+ * */
+public class XSequenceImpl extends XObject
+  implements XSequenceMutable
+{
+	// %OPT% Four vectors is not exactly compact.
+	// Do we want to try to improve this?
+	private Vector m_values=new Vector();
+	protected Vector m_typeNamespaces=new Vector();
+	protected Vector m_typeNames=new Vector();
+  
+  // We really shouldn't need xTypes, since the XObject should be cabable of 
+  // storing the type.
+	// private IntVector xTypes=new IntVector();
+
+	protected int m_pos = -1;
+	protected boolean m_unlocked=true;
+	
+	protected int m_homogtype=XType.EMPTYSEQ;
+  
+  /** Create a sequence, initially empty.
+   * */
+  public XSequenceImpl()
+  {
+    setValues(new Vector());
+  }
+
+	
+	/** Create a sequence, initially empty.
+	 * */
+	public XSequenceImpl(boolean shouldCache)
+	{
+    if(shouldCache)
+      setValues(new Vector());
+	}
+
+	/**
+	 * %REVIEW% If the type is in the XMLSchema or XMLSchema-datatype
+	 * namespaces, should we also assign a primitive XType?
+	 *
+	 * @param value Item value to add to the iteration.
+	 * @param typeNamespace String containing namespace URI of schema type
+	 * @param typeNamespace String containing local name of schema type
+	 * 
+	 * @return Sequence containing old plus new data. IT MAY BE A NEW
+	 * OBJECT; user is responsible for always invoking this as
+	 * <code>myseq=myseq.concat(val,ns,typename);</code>. However, IT MAY
+	 * NOT BE A NEW OBJECT; don't assume that the old sequence will
+	 * still be available after this operation returns.
+	 * 
+	 * @see XSequenceMutable.append(Object value,String typeNamespace,String typeName)
+	 * */
+	public XSequenceMutable concat(Object value,String typeNamespace,String typeName)
+	{
+		if(!m_unlocked)
+		    throw new RuntimeException("Sequence is locked, hence not muteable!");
+		
+		int xtype=0;
+		if(XType.XMLSCHEMA_DATATYPE_NAMESPACE.equals(typeNamespace)
+			|| XType.XMLSCHEMA_NAMESPACE.equals(typeNamespace))
+			xtype=XType.getTypeFromLocalName(typeName);
+			
+    XObject xvalue = XObjectFactory.create(value);
+    getValues().addElement(xvalue);
+		
+		// If it's an XType, we may save some space by not
+		// storing the strings and instead retrieving them
+		// from the manefest-constant tables.
+		// (Though storing them would simplify retrieval...)
+		// %REVIEW%
+		m_typeNames.addElement(xtype!=0 ? null : typeName);
+		m_typeNamespaces.addElement(xtype!=0 ? null : typeNamespace);
+
+    // Ignore xtype for right now.  -sb
+		// xTypes.addElement(xtype);
+		
+		if(m_homogtype==XType.EMPTYSEQ)
+			m_homogtype=xtype;
+		else if(m_homogtype!=xtype)
+			m_homogtype=XType.NOTHOMOGENOUS;
+			
+		return this;
+	}
+  
+	/** Add an object to the sequence, along with its
+	 * primitive datatype as defined in XType
+	 * @param value Item value to add to the iteration.
+	 * @param xtype Primitive type number, as defined in XType.
+	 * 
+	 * @return Sequence containing old plus new data. IT MAY BE A NEW
+	 * OBJECT; user is responsible for always invoking this as
+	 * <code>myseq=myseq.concat(val,type);</code>. However, IT MAY
+	 * NOT BE A NEW OBJECT; don't assume that the old sequence will
+	 * still be available after this operation returns.
+	 * 
+	 * @see XSequenceMutable.concat(Object value,int xtype)
+	 * */
+	public XSequenceMutable concat(Object value,int xtype)
+	{
+		if(!m_unlocked)
+		    throw new RuntimeException("Sequence is locked, hence not mutable!");
+		
+    XObject xvalue = XObjectFactory.create(value);
+		getValues().addElement(xvalue);
+
+		// Could store the strings. But given that I'm suppressing
+		// them for efficiency reasons when type was set by strings,
+		// I'll suppress them here for consistancy.
+		// %REVIEW%
+		m_typeNames.addElement(null);
+		m_typeNamespaces.addElement(null);
+		
+    // Ignore xTypes for right now.  See comment at commented out member var. -sb
+		// xTypes.addElement(xtype);
+		
+		if(m_homogtype==XType.EMPTYSEQ)
+			m_homogtype=xtype;
+		else if(m_homogtype!=xtype)
+			m_homogtype=XType.NOTHOMOGENOUS;
+			
+		return this;
+	}
+  
+  /**
+   * @see org.apache.xpath.objects.XSequenceMutable#concat(XObject)
+   */
+  public XSequenceMutable concat(XObject xvalue)
+  {
+    if(!m_unlocked)
+        throw new RuntimeException("Sequence is locked, hence not muteable!");
+    
+    getValues().addElement(xvalue);
+
+    // Could store the strings. But given that I'm suppressing
+    // them for efficiency reasons when type was set by strings,
+    // I'll suppress them here for consistancy.
+    // %REVIEW%
+    m_typeNames.addElement(null);
+    m_typeNamespaces.addElement(null);
+    
+    // Ignore xTypes for right now.  See comment at commented out member var. -sb
+    // xTypes.addElement(xvalue.getType());
+    
+    return this;
+  }
+	
+	
+	/** Append complete contents of another XSequence
+	 * 
+	 * @return Sequence containing old plus new data. IT MAY BE A NEW
+	 * OBJECT; user is responsible for always invoking this as
+	 * <code>myseq=myseq.concat(otherseq);</code>. However, IT MAY
+	 * NOT BE A NEW OBJECT; don't assume that the old sequence will
+	 * still be available after this operation returns.
+	 * 
+	 * @see XSequenceMutable.append(XSequence)
+	 * */
+	public XSequenceMutable concat(XSequence other)
+	{
+		if(!m_unlocked)
+		    throw new RuntimeException("Sequence is locked, hence not muteable!");
+
+		for(Object value=other.next();
+			value!=null;
+			value=other.next())
+		{
+			getValues().addElement(value);
+					
+			int xtype=other.getType();
+      
+      // Ignore xTypes for right now.  See comment at commented out member var. -sb
+			// xTypes.addElement(xtype);
+	
+			m_typeNames.addElement(xtype==0 ? null : other.getTypeLocalName());
+			m_typeNamespaces.addElement(xtype==0 ? null : other.getTypeNS());
+
+			if(m_homogtype==XType.EMPTYSEQ)
+				m_homogtype=xtype;
+			else if(m_homogtype!=xtype)
+				m_homogtype=XType.NOTHOMOGENOUS;
+		}
+		
+		return this;
+	}
+	  	
+
+	/** Prevent further mutation of this sequence. After this has
+	 * been called, isMutable should return false.
+	 * @see XSequence.isMutable()
+	 * */
+	public void lock()
+	{
+		m_unlocked=false;
+	}
+
+	/** @return the number of members in this sequence. */
+	public int getLength()
+	{
+		return getValues().size();
+	}
+	
+	/** Retrieve the value for this member of the sequence. Since values may be
+	 * a heterogenous mix, and their type may not be known until they're examined,
+	 * they're returned as Objects. This is storage-inefficient if the value(s)
+	 * is/are builtins that map to Java primitives. Tough.
+	 * 
+	 * @param index 0-based index into the sequence.
+	 * @return the specified value
+	 * @throws exception if index <0 or >=length	 
+	 * */
+	public XObject next()
+	{
+    if(m_pos >= getValues().size()-1)
+      return null;
+		return (XObject)getValues().elementAt(++m_pos);
+	}
+  
+	/**
+	 * @see org.apache.xml.dtm.XSequence#previous()
+	 */
+	public XObject previous()
+	{
+    if(m_pos <= 0)
+      return null;
+		return (XObject)getValues().elementAt(--m_pos);
+	}
+	
+	/** %REVIEW% Format not yet firmly settled. Primarily for debugging purposes!
+	 * */
+	public String toString()
+	{
+		StringBuffer b=new StringBuffer("Sequence[");
+		String start="";
+		
+		for(int i=0;i<getValues().size();++i)
+		{
+			XObject xvalue=(XObject)getValues().elementAt(i);
+			String tns,tn;
+			// int xtype=xTypes.elementAt(i);
+      int xtype=xvalue.getType();
+			if(xtype!=XType.ANYTYPE)
+			{
+				tns=XType.XMLSCHEMA_NAMESPACE;
+				tn=XType.getLocalNameFromType(xtype);
+			}
+			else
+			{
+				// %OPT% Is it faster to cast to String, or
+				// to call .toString()? The latter is _safer_...
+				// (Opinion from Sun: Depends on your JVM.)
+				tns=(String)m_typeNamespaces.elementAt(i);
+				tn=(String)m_typeNames.elementAt(i);
+				
+			}
+			b.append(start)
+			    .append(tns).append(':').append(tn);
+			if(xtype!=0)
+				b.append(" (").append(xtype).append(')');
+			b.append(" = ")
+				.append(xvalue);
+			if(xvalue!=null)
+			    b.append(" {"+xvalue.getClass().getName()+"}");
+			start=", ";
+		}
+		return b.append(']').toString();
+	}
+  
+  /**
+   * @see org.apache.xml.dtm.XSequence#allowDetachToRelease(boolean)
+   */
+  public void allowDetachToRelease(boolean allowRelease)
+  {
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#detach()
+   */
+  public void detach()
+  {
+    // Do nothing
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getCurrent()
+   */
+  public XObject getCurrent()
+  {
+    return (XObject)getValues().elementAt(m_pos);
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getCurrentPos()
+   */
+  public int getCurrentPos()
+  {
+    return m_pos;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getTypeLocalName()
+   */
+  public String getTypeLocalName()
+  {
+    XObject xobj = getCurrent();
+    int xtype = xobj.getType();
+    if (xtype != XType.ANYTYPE)
+      return XType.getLocalNameFromType(xtype);
+    else
+      return (String) m_typeNames.elementAt(m_pos);
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getTypeNS()
+   */
+  public String getTypeNS()
+  {
+    XObject xobj = getCurrent();
+    int xtype = xobj.getType();
+    if (xtype != XType.ANYTYPE)
+      return XType.XMLSCHEMA_NAMESPACE;
+    else
+      return (String) m_typeNamespaces.elementAt(m_pos);
+  }
+
+  /**
+   * If this iterator holds homogenous primitive types, return that type ID.
+   * 
+   * @return The homogenous type, or NOTHOMOGENOUS, or EMPTYSEQ.
+   */
+  public int getTypes()
+  {
+    return m_homogtype;
+  }
+  
+  /**
+   * @see org.apache.xml.dtm.XSequence#getType()
+   */
+  public int getType()
+  {
+    XObject xobj = getCurrent();
+    if(null == xobj)
+      return XType.SEQ; // %REVIEW% Not sure what this should return.
+    int xtype = xobj.getType();
+    return xtype;
+  }
+
+  /** @return false, since I don't think we're ever going to put
+   * nodes into an XSequenceImpl (they aren't objects, unless we
+   * are handling DOM nodes...)
+   * %REVIEW%
+   * */
+  public boolean isPureNodeSequence()
+  {
+  	return false;	
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isFresh()
+   */
+  public boolean isFresh()
+  {
+    return (m_pos == -1) ? true : false;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isMutable()
+   */
+  public boolean isMutable()
+  {
+    return m_unlocked;
+  }
+
+  /** %BUG% Problem here -- to recognize inheritance we need to
+   * reach into the schemas. Currently that can be done by using
+   * the XPathContext (which we ain't got) to query the AbstractSchema
+   * for an XPath2Type (both of which are Xerces-specific and buried 
+   * in XNI2DTM) and asking it... We need a higher-level API for that
+   * test.
+   * 
+   * %REVIEW% As a stopgap, match literal type name directly.
+   * 
+   * @see org.apache.xml.dtm.XSequence#isSchemaType(String, String)
+   */
+  public boolean isSchemaType(String namespace, String localname)
+  {
+  	String tns=getTypeNS();
+  	String tn=getTypeLocalName();  	
+  	return 
+  		((tns==null) ? namespace==null : tns.equals(namespace))
+  		&&
+  		((tn==null) ? localname==null : tn.equals(localname))
+  		;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isSingletonOrEmpty()
+   */
+  public boolean isSingletonOrEmpty()
+  {
+    return getLength() <= 1;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#setCurrentPos(int)
+   */
+  public void setCurrentPos(int i)
+  {
+    m_pos = i-1;
+  }
+
+  /**
+   * This method performs no actions.
+   * @see org.apache.xml.dtm.XSequence#setShouldCache(boolean)
+   */
+  public void setShouldCache(boolean b)
+  {
+    // Ignore.  We always cache.
+  }
+
+  /**
+   * @return true -- setCurrentPos() works for this object
+   * @see org.apache.xml.dtm.XSequence#getIsRandomAccess()
+   */
+  public boolean getIsRandomAccess()
+  {
+    return true;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#reset()
+   */
+  public void reset()
+  {
+    m_pos = -1;
+  }
+
+
+  /**
+   * @see java.lang.Object#clone()
+   */
+  public Object clone() throws CloneNotSupportedException
+  {
+    return super.clone();
+  }
+
+  /**
+   * Return a (fresh) sequence representing this object.
+   * @return XSequence
+   */
+  public XSequence xseq()
+  {
+    if(isFresh())
+      return this;
+    try
+    {
+      XSequence xseq = (XSequence)this.clone();
+      xseq.reset();
+      return xseq;
+    }
+    catch (CloneNotSupportedException e)
+    {
+      // will never happen
+      throw new WrappedRuntimeException(e);
+    }
+  }
+
+  /**
+   * Returns the values.
+   * @return Vector
+   */
+  public Vector getValues()
+  {
+    return m_values;
+  }
+
+  /**
+   * Returns the values.
+   * @return Vector
+   */
+  public Object object()
+  {
+    return m_values;
+  }
+
+  /**
+   * Sets the values.
+   * @param values The values to set
+   */
+  public void setValues(Vector values)
+  {
+    this.m_values = values;
+  }
+  
+
+  /**
+   * @see org.apache.xpath.objects.XSequenceMutable#getItem(int)
+   */
+  public XObject getItem(int pos)
+  {
+    return (XObject)getValues().elementAt(pos);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequenceMutable#insertItemAt(XObject, int)
+   */
+  public void insertItemAt(XObject value, int pos)
+  {
+    // TBD: Update homogtype?
+    getValues().insertElementAt(value, pos);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequenceMutable#setItem(XObject, int)
+   */
+  public void setItem(XObject value, int pos)
+  {
+    // TBD: Update homogtype?
+    getValues().setElementAt(value, pos);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#isSequenceProper()
+   */
+  public boolean isSequenceProper()
+  {
+    return true;
+  }
+
+}
+
diff --git a/src/org/apache/xpath/objects/XSequenceMutable.java b/src/org/apache/xpath/objects/XSequenceMutable.java
new file mode 100644
index 0000000..8134f5b
--- /dev/null
+++ b/src/org/apache/xpath/objects/XSequenceMutable.java
@@ -0,0 +1,149 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+
+
+/** Interface for constructable version of XSequence.
+ * 
+ * Defined in DTM because XSequence is defined her; if the superclass
+ * is moved, this should be moved with it.
+ * 
+ * @author keshlam
+ * @since 7/18/02
+ */
+public interface XSequenceMutable extends XSequence
+{
+	/** Add an object to the sequence, along with its Schema-based
+	 * datatype.  Within the sequence, wrap the object in an XObject. 
+	 *
+	 * @param value Item value to add to the iteration.
+	 * @param typeNamespace String containing namespace URI of schema type
+	 * @param typeNamespace String containing local name of schema type
+	 * 
+	 * @return Sequence containing old plus new data. IT MAY BE A NEW
+	 * OBJECT; user is responsible for always invoking this as
+	 * <code>myseq=myseq.concat(newval,...);</code>. However, IT MAY
+	 * NOT BE A NEW OBJECT; don't assume that the old sequence will
+	 * still be available after this operation returns.
+	 * */
+	public XSequenceMutable concat(Object value,String typeNamespace,String typeName);
+
+	/** Add an object to the sequence, along with its
+	 * primitive datatype as defined in XType.  Within the sequence, 
+   * wrap the object in an XObject.
+	 * @param value Item value to add to the iteration.
+	 * @param xtype Primitive type number, as defined in XType.
+	 * 
+	 * @return Sequence containing old plus new data. IT MAY BE A NEW
+	 * OBJECT; user is responsible for always invoking this as
+	 * <code>myseq=myseq.concat(newval,...);</code>. However, IT MAY
+	 * NOT BE A NEW OBJECT; don't assume that the old sequence will
+	 * still be available after this operation returns.
+	 * */
+	public XSequenceMutable concat(Object value,int xtype);
+  
+  /** Add an XObject to the sequence.
+   * 
+   * @return Sequence containing old plus new data. IT MAY BE A NEW
+   * OBJECT; user is responsible for always invoking this as
+   * <code>myseq=myseq.concat(newval,...);</code>. However, IT MAY
+   * NOT BE A NEW OBJECT; don't assume that the old sequence will
+   * still be available after this operation returns.
+   * */
+  public XSequenceMutable concat(XObject value);
+
+  /**
+   * Set the item at the position.  For sorting type operations.
+   * @param value An XObject that should not be a sequence with 
+   *               multiple values.
+   * @param pos The position to set the value, which must be valid.
+   */
+  public void setItem(XObject value, int pos);
+
+  /**
+   * Insert the item at the position.  For sorting type operations.
+   * @param value An XObject that should not be a sequence with 
+   *               multiple values.
+   * @param pos The position to set the value, which must be valid.
+   */
+  public void insertItemAt(XObject value, int pos);
+  
+  /**
+   * Convenience method to get the current item.
+   * @param pos
+   */
+  public XObject getItem(int pos);
+	
+	/** Append complete contents of another XSequence
+	 * 
+	 * @return Sequence containing old plus new data. IT MAY BE A NEW
+	 * OBJECT; user is responsible for always invoking this as
+	 * <code>myseq=myseq.concat(newval,...);</code>. However, IT MAY
+	 * NOT BE A NEW OBJECT; don't assume that the old sequence will
+	 * still be available after this operation returns.
+	 * */
+	public XSequenceMutable concat(XSequence other);
+	  	
+
+	/** Prevent further mutation of this sequence. After this has
+	 * been called, isMutable should return false.
+   * 
+	 * @see XSequence.isMutable()
+	 * */
+	public void lock();
+}
diff --git a/src/org/apache/xpath/objects/XSequenceSingleton.java b/src/org/apache/xpath/objects/XSequenceSingleton.java
new file mode 100644
index 0000000..18a581e
--- /dev/null
+++ b/src/org/apache/xpath/objects/XSequenceSingleton.java
@@ -0,0 +1,862 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+import java.io.PrintStream;
+import java.net.URL;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMIterator;
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.FastStringBuffer;
+import org.apache.xml.utils.QName;
+import org.apache.xml.utils.XMLString;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.NodeSetDTM;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.parser.Node;
+import org.apache.xpath.parser.Token;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.traversal.NodeIterator;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 18, 2002
+ * @author sboag
+ */
+public class XSequenceSingleton extends XObject implements XSequence
+{
+	XObject m_xobject;
+	
+  int m_pos = 0;
+
+  /**
+   * Constructor for XSequenceSingleton.
+   * @param obj
+   */
+  public XSequenceSingleton(XObject obj)
+  {
+    m_xobject=obj;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getTypes()
+   */
+  public int getTypes()
+  {
+    return m_xobject.getType();
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#next()
+   */
+  public XObject next()
+  {
+    if(m_pos == 0)
+    {
+      m_pos++;
+      return this;
+    }
+    else
+      return null;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#previous()
+   */
+  public XObject previous()
+  {
+    if(m_pos == 1)
+    {
+      m_pos--;
+      return this;
+    }
+    else
+      return null;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getCurrent()
+   */
+  public XObject getCurrent()
+  {
+    if(m_pos == 0)
+    {
+      return this;
+    }
+    else
+      return null;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isFresh()
+   */
+  public boolean isFresh()
+  {
+    return (m_pos == 0);
+  }
+
+  /**
+   * At this level, assume that the contained type is always an 
+   * atomic type.
+   * @see org.apache.xml.dtm.XSequence#getTypeNS()
+   */
+  public String getTypeNS()
+  {
+    return XType.XMLSCHEMA_DATATYPE_NAMESPACE;
+  }
+
+  /**
+   * At this level, assume that the contained type is always an 
+   * atomic type.
+   * @see org.apache.xml.dtm.XSequence#getTypeLocalName()
+   */
+  public String getTypeLocalName()
+  {
+    if(m_pos != 0)
+      return null;
+    // For now, I'm going to do this ssslllloooowwww.
+    return XType.getLocalNameFromType(m_xobject.getType());
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isSchemaType(String, String)
+   */
+  public boolean isSchemaType(String namespace, String localname)
+  {
+    String uri = getTypeNS();
+    String thisname = getTypeLocalName();
+    if(null == namespace)
+      return false;
+    return uri.equals(uri) && thisname.equals(localname);
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#setShouldCache(boolean)
+   */
+  public void setShouldCache(boolean b)
+  {
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getIsRandomAccess()
+   */
+  public boolean getIsRandomAccess()
+  {
+    return true; // as far as it goes.
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isMutable()
+   */
+  public boolean isMutable()
+  {
+    return false;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getCurrentPos()
+   */
+  public int getCurrentPos()
+  {
+    return m_pos;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#setCurrentPos(int)
+   */
+  public void setCurrentPos(int i)
+  {
+    m_pos = i;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#getLength()
+   */
+  public int getLength()
+  {
+    return (null == m_xobject) ? 0 : 1;
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isSingletonOrEmpty()
+   */
+  public boolean isSingletonOrEmpty()
+  {
+    return true;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#getType()
+   */
+  public int getType()
+  {
+    if(m_pos != 0)
+      return XType.SEQ;
+    return m_xobject.getType();
+  }
+
+  /**
+   * @see org.apache.xml.dtm.XSequence#isPureNodeSequence()
+   */
+  public boolean isPureNodeSequence()
+  {
+    return false;
+  }
+
+  /**
+   * @see java.lang.Object#clone()
+   */
+  public Object clone() throws CloneNotSupportedException
+  {
+    return super.clone();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#allowDetachToRelease(boolean)
+   */
+  public void allowDetachToRelease(boolean allowRelease)
+  {
+    m_xobject.allowDetachToRelease(allowRelease);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#appendToFsb(FastStringBuffer)
+   */
+  public void appendToFsb(FastStringBuffer fsb)
+  {
+    m_xobject.appendToFsb(fsb);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#bool()
+   */
+  public boolean bool() throws TransformerException
+  {
+    return m_xobject.bool();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#boolWithSideEffects()
+   */
+  public boolean boolWithSideEffects() throws TransformerException
+  {
+    return m_xobject.boolWithSideEffects();
+  }
+
+  /**
+   * @see org.apache.xpath.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
+   */
+  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
+  {
+    m_xobject.callVisitors(owner, visitor);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#castToType(int, XPathContext)
+   */
+  public Object castToType(int t, XPathContext support)
+    throws TransformerException
+  {
+    return m_xobject.castToType(t, support);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#deepEquals(Expression)
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    return m_xobject.deepEquals(expr);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#destruct()
+   */
+  public void destruct()
+  {
+    m_xobject.destruct();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#detach()
+   */
+  public void detach()
+  {
+    m_xobject.detach();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#dispatchCharactersEvents(ContentHandler)
+   */
+  public void dispatchCharactersEvents(ContentHandler ch) throws SAXException
+  {
+    m_xobject.dispatchCharactersEvents(ch);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#equals(XObject)
+   */
+  public boolean equals(XObject obj2)
+  {
+    return m_xobject.equals(obj2);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#error(int, Object[])
+   */
+  protected void error(int msg, Object[] args) throws TransformerException
+  {
+    m_xobject.error(msg, args);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#error(int)
+   */
+  protected void error(int msg) throws TransformerException
+  {
+    m_xobject.error(msg);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#execute(XPathContext)
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+    return m_xobject.execute(xctxt);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#fixupVariables(VariableComposeState)
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+    m_xobject.fixupVariables(vcs);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#getFresh()
+   */
+  public XObject getFresh()
+  {
+    return m_xobject.getFresh();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#getTypeString()
+   */
+  public String getTypeString()
+  {
+    return m_xobject.getTypeString();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#greaterThan(XObject)
+   */
+  public boolean greaterThan(XObject obj2) throws TransformerException
+  {
+    return m_xobject.greaterThan(obj2);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#greaterThanOrEqual(XObject)
+   */
+  public boolean greaterThanOrEqual(XObject obj2) throws TransformerException
+  {
+    return m_xobject.greaterThanOrEqual(obj2);
+  }
+
+  /**
+   * @see org.apache.xpath.parser.SimpleNode#isPathExprReduced()
+   */
+  public boolean isPathExprReduced()
+  {
+    return m_xobject.isPathExprReduced();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#iter()
+   */
+  public DTMIterator iter() throws TransformerException
+  {
+    return m_xobject.iter();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#lessThan(XObject)
+   */
+  public boolean lessThan(XObject obj2) throws TransformerException
+  {
+    return m_xobject.lessThan(obj2);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#lessThanOrEqual(XObject)
+   */
+  public boolean lessThanOrEqual(XObject obj2) throws TransformerException
+  {
+    return m_xobject.lessThanOrEqual(obj2);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#mutableNodeset()
+   */
+  public NodeSetDTM mutableNodeset() throws TransformerException
+  {
+    return m_xobject.mutableNodeset();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#nodelist()
+   */
+  public NodeList nodelist() throws TransformerException
+  {
+    return m_xobject.nodelist();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#nodeset()
+   */
+  public NodeIterator nodeset() throws TransformerException
+  {
+    return m_xobject.nodeset();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#notEquals(XObject)
+   */
+  public boolean notEquals(XObject obj2) throws TransformerException
+  {
+    return m_xobject.notEquals(obj2);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#num()
+   */
+  public double num() throws TransformerException
+  {
+    return m_xobject.num();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#numWithSideEffects()
+   */
+  public double numWithSideEffects() throws TransformerException
+  {
+    return m_xobject.numWithSideEffects();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#object()
+   */
+  public Object object()
+  {
+    return m_xobject.object();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#reset()
+   */
+  public void reset()
+  {
+    m_xobject.reset();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#rtf()
+   */
+  public int rtf()
+  {
+    return m_xobject.rtf();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#rtf(XPathContext)
+   */
+  public int rtf(XPathContext support)
+  {
+    return m_xobject.rtf(support);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#rtree()
+   */
+  public DocumentFragment rtree()
+  {
+    return m_xobject.rtree();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#rtree(XPathContext)
+   */
+  public DocumentFragment rtree(XPathContext support)
+  {
+    return m_xobject.rtree(support);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#str()
+   */
+  public String str()
+  {
+    return m_xobject.str();
+  }
+
+  /**
+   * @see java.lang.Object#toString()
+   */
+  public String toString()
+  {
+    return m_xobject.toString();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#xseq()
+   */
+  public XSequence xseq()
+  {
+    return m_xobject.xseq();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#xstr()
+   */
+  public XMLString xstr()
+  {
+    return m_xobject.xstr();
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#asIterator(XPathContext, int)
+   */
+  public DTMIterator asIterator(XPathContext xctxt, int contextNode)
+    throws TransformerException
+  {
+    return m_xobject.asIterator(xctxt, contextNode);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#asIteratorRaw(XPathContext, int)
+   */
+  public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode)
+    throws TransformerException
+  {
+    return m_xobject.asIteratorRaw(xctxt, contextNode);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#asNode(XPathContext)
+   */
+  public int asNode(XPathContext xctxt) throws TransformerException
+  {
+    return m_xobject.asNode(xctxt);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#assertion(boolean, String)
+   */
+  public void assertion(boolean b, String msg)
+  {
+    m_xobject.assertion(b, msg);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#bool(XPathContext)
+   */
+  public boolean bool(XPathContext xctxt) throws TransformerException
+  {
+    return m_xobject.bool(xctxt);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#canTraverseOutsideSubtree()
+   */
+  public boolean canTraverseOutsideSubtree()
+  {
+    return m_xobject.canTraverseOutsideSubtree();
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#cloneDeep()
+   */
+  public Object cloneDeep() throws CloneNotSupportedException
+  {
+    return m_xobject.cloneDeep();
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#error(XPathContext, int, Object[])
+   */
+  public void error(XPathContext xctxt, int msg, Object[] args)
+    throws TransformerException
+  {
+    m_xobject.error(xctxt, msg, args);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#execute(XPathContext, boolean)
+   */
+  public XObject execute(XPathContext xctxt, boolean destructiveOK)
+    throws TransformerException
+  {
+    return m_xobject.execute(xctxt, destructiveOK);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#execute(XPathContext, int, DTM, int)
+   */
+  public XObject execute(
+    XPathContext xctxt,
+    int currentNode,
+    DTM dtm,
+    int expType)
+    throws TransformerException
+  {
+    return m_xobject.execute(xctxt, currentNode, dtm, expType);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#execute(XPathContext, int)
+   */
+  public XObject execute(XPathContext xctxt, int currentNode)
+    throws TransformerException
+  {
+    return m_xobject.execute(xctxt, currentNode);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#executeCharsToContentHandler(XPathContext, ContentHandler)
+   */
+  public void executeCharsToContentHandler(
+    XPathContext xctxt,
+    ContentHandler handler)
+    throws TransformerException, SAXException
+  {
+    m_xobject.executeCharsToContentHandler(xctxt, handler);
+  }
+
+  /**
+   * @see org.apache.xpath.ExpressionNode#exprAddChild(ExpressionNode, int)
+   */
+  public void exprAddChild(ExpressionNode n, int i)
+  {
+    m_xobject.exprAddChild(n, i);
+  }
+
+  /**
+   * @see org.apache.xpath.ExpressionNode#exprGetChild(int)
+   */
+  public ExpressionNode exprGetChild(int i)
+  {
+    return m_xobject.exprGetChild(i);
+  }
+
+  /**
+   * @see org.apache.xpath.ExpressionNode#exprGetNumChildren()
+   */
+  public int exprGetNumChildren()
+  {
+    return m_xobject.exprGetNumChildren();
+  }
+
+  /**
+   * @see org.apache.xpath.ExpressionNode#exprGetParent()
+   */
+  public ExpressionNode exprGetParent()
+  {
+    return m_xobject.exprGetParent();
+  }
+
+  /**
+   * @see org.apache.xpath.ExpressionNode#exprSetParent(ExpressionNode)
+   */
+  public void exprSetParent(ExpressionNode n)
+  {
+    m_xobject.exprSetParent(n);
+  }
+
+  /**
+   * @see javax.xml.transform.SourceLocator#getColumnNumber()
+   */
+  public int getColumnNumber()
+  {
+    return m_xobject.getColumnNumber();
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#getExpressionOwner()
+   */
+  public ExpressionNode getExpressionOwner()
+  {
+    return m_xobject.getExpressionOwner();
+  }
+
+  /**
+   * @see javax.xml.transform.SourceLocator#getLineNumber()
+   */
+  public int getLineNumber()
+  {
+    return m_xobject.getLineNumber();
+  }
+
+  /**
+   * @see javax.xml.transform.SourceLocator#getPublicId()
+   */
+  public String getPublicId()
+  {
+    return m_xobject.getPublicId();
+  }
+
+  /**
+   * @see javax.xml.transform.SourceLocator#getSystemId()
+   */
+  public String getSystemId()
+  {
+    return m_xobject.getSystemId();
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#isNodesetExpr()
+   */
+  public boolean isNodesetExpr()
+  {
+    return m_xobject.isNodesetExpr();
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#isStableNumber()
+   */
+  public boolean isStableNumber()
+  {
+    return m_xobject.isStableNumber();
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#num(XPathContext)
+   */
+  public double num(XPathContext xctxt) throws TransformerException
+  {
+    return m_xobject.num(xctxt);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#warn(XPathContext, int, Object[])
+   */
+  public void warn(XPathContext xctxt, int msg, Object[] args)
+    throws TransformerException
+  {
+    m_xobject.warn(xctxt, msg, args);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#xstr(XPathContext)
+   */
+  public XMLString xstr(XPathContext xctxt) throws TransformerException
+  {
+    return m_xobject.xstr(xctxt);
+  }
+
+  /**
+   * @see org.apache.xpath.parser.SimpleNode#dump(String, PrintStream)
+   */
+  public void dump(String prefix, PrintStream ps)
+  {
+    m_xobject.dump(prefix, ps);
+  }
+
+  /**
+   * @see org.apache.xpath.parser.SimpleNode#dump(String)
+   */
+  public void dump(String prefix)
+  {
+    m_xobject.dump(prefix);
+  }
+
+  /**
+   * @see org.apache.xpath.parser.SimpleNode#toString(String)
+   */
+  public String toString(String prefix)
+  {
+    return m_xobject.toString(prefix);
+  }
+
+  /**
+   * @see java.lang.Object#hashCode()
+   */
+  public int hashCode()
+  {
+    return m_xobject.hashCode();
+  }
+
+  /**
+   * @see java.lang.Object#equals(Object)
+   */
+  public boolean equals(Object arg0)
+  {
+    return m_xobject.equals(arg0);
+  }
+
+}
diff --git a/src/org/apache/xpath/objects/XString.java b/src/org/apache/xpath/objects/XString.java
index 5bc70f1..70a5458 100644
--- a/src/org/apache/xpath/objects/XString.java
+++ b/src/org/apache/xpath/objects/XString.java
@@ -60,15 +60,14 @@
 import java.util.Locale;
 
 import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.XType;
 import org.apache.xml.utils.XMLCharacterRecognizer;
 import org.apache.xml.utils.XMLString;
 import org.apache.xml.utils.XMLStringFactory;
 import org.apache.xpath.ExpressionOwner;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.ext.LexicalHandler;
+import org.apache.xpath.parser.Token;
 
 /**
  * <meta name="usage" content="general"/>
@@ -77,19 +76,38 @@
  */
 public class XString extends XObject implements XMLString
 {
+	/** Java String object representing this XString.
+	 * Note that this field is also used as a cache by
+	 * XString's subclasses
+	 * */
+	protected String m_stringValue=null;
 
   /** Empty string XString object */
   public static XString EMPTYSTRING = new XString("");
+  
+  /**
+   * Construct a XString object, with a null value.
+   * 
+   * This one's actually being used, unlike most XObject empty ctors,
+   * because it may be created and _then_ set (by processToken)
+   * during stylesheet parsing.
+   */
+  public XString()
+  {
+  }
+
 
   /**
    * Construct a XString object.  This constructor exists for derived classes.
    *
    * @param val String object this will wrap.
    */
+  /*
   protected XString(Object val)
   {
     super(val);
   }
+  */
 
   /**
    * Construct a XNodeSet object.
@@ -98,8 +116,18 @@
    */
   public XString(String val)
   {
-    super(val);
+    m_stringValue=val;
   }
+  
+  /**
+   * Return the sequence representing this object.
+   * @return XSequence
+   */
+  public XSequence xseq()
+  {
+    return new XSequenceSingleton(this);
+  }
+
 
   /**
    * Tell that this is a CLASS_STRING.
@@ -131,6 +159,11 @@
   {
     return true;
   }
+  
+  public Object object()
+  {
+  	return m_stringValue; // str()?
+  }
 
   /**
    * Cast result object to a number.
@@ -271,7 +304,17 @@
    */
   public String str()
   {
-    return (null != m_obj) ? ((String) m_obj) : "";
+  	// Should this actively replace null with ""?
+  	return (m_stringValue==null) ? "" : m_stringValue;
+  }
+  
+  /** Yield result object's string value as a sequence of Character Blocks
+	* @return a CharacterBlockEnumeration displaying the contents of
+	* this object's string value (as in str()). May be empty.
+	* */
+  public org.apache.xml.utils.CharacterBlockEnumeration enumerateCharacterBlocks()
+  {
+  	return new org.apache.xml.utils.CharacterBlockEnumeration(str());
   }
 
   /**
@@ -402,8 +445,8 @@
     int t = obj2.getType();
     try
     {
-	    if (XObject.CLASS_NODESET == t)
-	      return obj2.equals(this);
+	    if (obj2.isNodesetExpr())
+	      return ((XNodeSet)obj2).equalsExistential(this);
 	    // If at least one object to be compared is a boolean, then each object 
 	    // to be compared is converted to a boolean as if by applying the 
 	    // boolean function. 
@@ -471,7 +514,7 @@
       // nodeset comparisons, we always call the 
       // nodeset function.
     else if (obj2 instanceof XNodeSet)
-      return obj2.equals(this);
+      return ((XNodeSet)obj2).equalsExistential(this);
     else if(obj2 instanceof XNumber)
     	return obj2.equals(this);
     else
@@ -1207,5 +1250,25 @@
   {
   	visitor.visitStringLiteral(owner, this);
   }
+  
+  public void processToken(Token t) 
+  { 
+  	int strLen = t.image.length();
+  	
+  	if(strLen >= 2)
+  	{
+  		assertion(t.image.charAt(0) == '"' || t.image.charAt(0) == '\'', 
+  			"First character of string literal must be a quote or apos!");
+  		assertion(t.image.charAt(strLen-1) == '"' || t.image.charAt(strLen-1) == '\'', 
+  			"Last character of string literal must be a quote or apos!");
+  		m_stringValue = t.image.substring(1, strLen-1);
+  	}
+  	else
+  	{
+      m_stringValue = "";
+  	}
+  		
+  }
+
 
 }
diff --git a/src/org/apache/xpath/objects/XStringForChars.java b/src/org/apache/xpath/objects/XStringForChars.java
index 8904b78..5c797ab 100644
--- a/src/org/apache/xpath/objects/XStringForChars.java
+++ b/src/org/apache/xpath/objects/XStringForChars.java
@@ -16,14 +16,15 @@
  */
 public class XStringForChars extends XString
 {
-  /** The start position in the fsb. */
+	/** Pointer to the block containing this string */
+	char[] m_chars;
+	
+  /** The start position in the character array. */
   int m_start;
   
   /** The length of the string. */
   int m_length;
   
-  protected String m_strCache = null;
-  
   /**
    * Construct a XNodeSet object.
    *
@@ -33,26 +34,28 @@
    */
   public XStringForChars(char[] val, int start, int length)
   {
-    super(val);
-    m_start = start;
-    m_length = length;
     if(null == val)
       throw new IllegalArgumentException(
                           XSLMessages.createXPATHMessage(XPATHErrorResources.ER_FASTSTRINGBUFFER_CANNOT_BE_NULL, null)); //"The FastStringBuffer argument can not be null!!");
+    m_chars=val;
+    m_start = start;
+    m_length = length;
   }
 
 
   /**
-   * Construct a XNodeSet object.
+   * Block inherited constructor. (DO ctors inherit?)
    *
    * @param val String object this will wrap.
    */
+  /*
   private XStringForChars(String val)
   {
     super(val);
     throw new IllegalArgumentException(
                       XSLMessages.createXPATHMessage(XPATHErrorResources.ER_XSTRINGFORCHARS_CANNOT_TAKE_STRING, null)); //"XStringForChars can not take a string for an argument!");
   }
+  */
   
   /**
    * Cast result object to a string.
@@ -71,7 +74,7 @@
    */
   public void appendToFsb(org.apache.xml.utils.FastStringBuffer fsb)
   {
-    fsb.append((char[])m_obj, m_start, m_length);
+    fsb.append(m_chars, m_start, m_length);
   }
 
   
@@ -82,7 +85,7 @@
    */
   public boolean hasString()
   {
-    return (null != m_strCache);
+    return (null != m_stringValue);
   }
 
   
@@ -93,13 +96,23 @@
    */
   public String str()
   {
-    if(null == m_strCache)
-      m_strCache = new String((char[])m_obj, m_start, m_length);
+    if(null == m_stringValue)
+      m_stringValue = new String(m_chars, m_start, m_length);
     
-    return m_strCache;
+    return m_stringValue;
   }
   
 
+  /** Yield result object's string value as a sequence of Character Blocks
+	* @return a CharacterBlockEnumeration displaying the contents of
+	* this object's string value (as in str()). May be empty.
+	* */
+  public org.apache.xml.utils.CharacterBlockEnumeration enumerateCharacterBlocks()
+  {
+  	return new org.apache.xml.utils.CharacterBlockEnumeration(
+		m_chars, m_start, m_length);
+  }
+
   /**
    * Since this object is incomplete without the length and the offset, we 
    * have to convert to a string when this function is called.
@@ -125,7 +138,7 @@
   public void dispatchCharactersEvents(org.xml.sax.ContentHandler ch)
       throws org.xml.sax.SAXException
   {
-    ch.characters((char[])m_obj, m_start, m_length);
+    ch.characters(m_chars, m_start, m_length);
   }
       
   /**
@@ -140,7 +153,7 @@
   public void dispatchAsComment(org.xml.sax.ext.LexicalHandler lh)
       throws org.xml.sax.SAXException
   {
-    lh.comment((char[])m_obj, m_start, m_length);
+    lh.comment(m_chars, m_start, m_length);
   }
   
   /**
@@ -169,7 +182,7 @@
    */
   public char charAt(int index)
   {
-    return ((char[])m_obj)[index+m_start];
+    return (m_chars)[index+m_start];
   }
 
   /**
@@ -195,7 +208,7 @@
    */
   public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin)
   {
-    System.arraycopy((char[])m_obj, m_start+srcBegin, dst, dstBegin, srcEnd);
+    System.arraycopy(m_chars, m_start+srcBegin, dst, dstBegin, srcEnd);
   }
   
 }
\ No newline at end of file
diff --git a/src/org/apache/xpath/objects/XStringForFSB.java b/src/org/apache/xpath/objects/XStringForFSB.java
index 56cf68b..b3c7cc4 100644
--- a/src/org/apache/xpath/objects/XStringForFSB.java
+++ b/src/org/apache/xpath/objects/XStringForFSB.java
@@ -61,9 +61,6 @@
 import org.apache.xml.utils.XMLStringFactory;
 import org.apache.xml.utils.XMLCharacterRecognizer;
 
-import org.apache.xpath.res.XPATHErrorResources;
-import org.apache.xalan.res.XSLMessages;
-
 import java.util.Locale;
 
 /**
@@ -71,6 +68,7 @@
  */
 public class XStringForFSB extends XString
 {
+	FastStringBuffer m_fsb;
 
   /** The start position in the fsb. */
   int m_start;
@@ -78,9 +76,6 @@
   /** The length of the string. */
   int m_length;
 
-  /** If the str() function is called, the string will be cached here. */
-  protected String m_strCache = null;
-
   /** cached hash code */
   protected int m_hash = 0;
 
@@ -93,30 +88,30 @@
    */
   public XStringForFSB(FastStringBuffer val, int start, int length)
   {
-
-    super(val);
-
-    m_start = start;
-    m_length = length;
-
     if (null == val)
       throw new IllegalArgumentException(
-        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_FASTSTRINGBUFFER_CANNOT_BE_NULL, null));
+        "The FastStringBuffer argument can not be null!!");
+
+    m_fsb=val;
+    m_start = start;
+    m_length = length;
   }
 
   /**
-   * Construct a XNodeSet object.
+   * Block inherited ctor. (DO ctors inherit?)
    *
    * @param val String object this will wrap.
    */
+  /*
   private XStringForFSB(String val)
   {
 
     super(val);
 
     throw new IllegalArgumentException(
-      XSLMessages.createXPATHMessage(XPATHErrorResources.ER_FSB_CANNOT_TAKE_STRING, null)); // "XStringForFSB can not take a string for an argument!");
+      "XStringForFSB can not take a string for an argument!");
   }
+  */
 
   /**
    * Cast result object to a string.
@@ -125,7 +120,7 @@
    */
   public FastStringBuffer fsb()
   {
-    return ((FastStringBuffer) m_obj);
+    return (m_fsb);
   }
   
   /**
@@ -146,15 +141,9 @@
    */
   public boolean hasString()
   {
-    return (null != m_strCache);
+    return (null != m_stringValue);
   }
 
-//  /** NEEDSDOC Field strCount */
-//  public static int strCount = 0;
-//
-//  /** NEEDSDOC Field xtable */
-//  static java.util.Hashtable xtable = new java.util.Hashtable();
-
   /**
    * Since this object is incomplete without the length and the offset, we 
    * have to convert to a string when this function is called.
@@ -174,9 +163,9 @@
   public String str()
   {
 
-    if (null == m_strCache)
+    if (null == m_stringValue)
     {
-      m_strCache = fsb().getString(m_start, m_length);
+      m_stringValue = fsb().getString(m_start, m_length);
 
 //      strCount++;
 //
@@ -202,8 +191,26 @@
       // System.exit(-1);
     }
 
-    return m_strCache;
+    return m_stringValue;
   }
+  
+  /** Yield result object's string value as a sequence of Character Blocks
+	* @return a CharacterBlockEnumeration displaying the contents of
+	* this object's string value (as in str()). May be empty, may
+	* yield multiple blocks depending on the FSB's contents. (The latter
+	* case is why we need to enumerate, of course!)
+	* */
+  public org.apache.xml.utils.CharacterBlockEnumeration enumerateCharacterBlocks()
+  {
+  	// %REVIEW% %OPT% I'm not sure this is an optimization. Depends on
+  	// how retrieval of char[] from String works in any given JVM.
+  	// See comments in CharacterBlockEnumeration, and run some tests.
+    if (null != m_stringValue)
+    	return new org.apache.xml.utils.CharacterBlockEnumeration(m_stringValue);
+	else  	
+	  	return fsb().enumerateCharacterBlocks(m_start,m_length);
+  }
+  
 
   /**
    * Directly call the
@@ -375,7 +382,7 @@
       return true;
     }
     if(obj2.getType() == XObject.CLASS_NUMBER)
-    	return obj2.equals(this);
+    	return ((XNodeSet)obj2).equalsExistential(this);
 
     String str = obj2.str();
     int n = m_length;
@@ -470,7 +477,7 @@
       // nodeset comparisons, we always call the 
       // nodeset function.
     else if (obj2 instanceof XNodeSet)
-      return obj2.equals(this);
+      return ((XNodeSet)obj2).equalsExistential(this);
     else if (obj2 instanceof XStringForFSB)
       return equals((XMLString) this);
     else
@@ -698,6 +705,7 @@
     return startsWith(prefix, 0);
   }
 
+
   /**
    * Returns the index within this string of the first occurrence of the
    * specified character. If a character with value <code>ch</code> occurs
diff --git a/src/org/apache/xpath/objects/XTime.java b/src/org/apache/xpath/objects/XTime.java
new file mode 100644
index 0000000..66be74f
--- /dev/null
+++ b/src/org/apache/xpath/objects/XTime.java
@@ -0,0 +1,185 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+//import org.w3c.dom.*;
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xpath.res.XPATHErrorResources;
+
+/**
+ * <meta name="usage" content="general"/>
+ * This class represents an XPath string object, and is capable of
+ * converting the string to other types, such as a number.
+ */
+public class XTime extends XDateTime 
+{
+
+  /**
+   * Construct a XDate object, with a null value.
+   */
+  public XTime()
+  {
+    super();
+  }
+
+
+  /**
+   * Construct a XDate object.  This constructor exists for derived classes.
+   *
+   * @param val Date object this will wrap.
+   */
+  //protected XTime(Object val)
+  //{
+  //  super(val);
+  //}
+
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  //public XTime(String val)
+  //{
+  //  super(val);
+  //}
+  
+  /**
+   * Construct a XDate object.
+   *
+   * @param val DateTimeObj object this will wrap.
+   */
+  public XTime(DateTimeObj val)
+  {
+    super(val);
+  }
+
+
+  /**
+   * Tell that this is a CLASS_DATE.
+   *
+   * @return type CLASS_DATE
+   */
+  public int getType()
+  {
+    return CLASS_TIME;
+  }
+
+  /**
+   * Given a request type, return the equivalent string.
+   * For diagnostic purposes.
+   *
+   * @return type string "#DATE"
+   */
+  public String getTypeString()
+  {
+    return "#TIME";
+  }
+
+  
+
+  
+
+  /**
+   * Cast result object to a string.
+   *
+   * @return The string this wraps or the empty string if null
+   */
+  public String str()
+  {
+  	return super.str();
+  	/*
+  	if (m_obj!= null)
+  	{
+  		if (m_obj instanceof Date)
+  		{
+  	Date date = (Date) m_obj;
+  	SimpleDateFormat dateFormat = new SimpleDateFormat(DateTimeObj.t1);      
+    return dateFormat.format(date);
+  		}
+  		else if (m_obj instanceof DateTimeObj)
+  		return ((DateTimeObj)m_obj).toString();
+  		else if(m_obj instanceof String)
+  	   return (String)m_obj;
+  	}
+      return "";
+    */
+  }
+  
+  /**
+   * @see org.apache.xpath.objects.XObject#datetime()
+   */
+  public DateTimeObj datetime() throws TransformerException
+  {
+    error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
+          new Object[]{ getTypeString(), "DATETIME" });  //"Can not convert "+getTypeString()+" to a number");
+
+    return new DateTimeObj(""); // To shut up compiler
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#date()
+   */
+  public DateTimeObj time() throws TransformerException
+  {
+    return m_val;
+  }
+
+  
+ 
+}
diff --git a/src/org/apache/xpath/objects/XYMDuration.java b/src/org/apache/xpath/objects/XYMDuration.java
new file mode 100644
index 0000000..514f448
--- /dev/null
+++ b/src/org/apache/xpath/objects/XYMDuration.java
@@ -0,0 +1,278 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.objects;
+
+//import org.w3c.dom.*;
+import java.util.Locale;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import javax.xml.transform.TransformerException;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.utils.CharacterBlockEnumeration;
+import org.apache.xml.utils.XMLCharacterRecognizer;
+import org.apache.xml.utils.XMLString;
+import org.apache.xml.utils.XMLStringFactory;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xml.utils.Duration;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.parser.Token;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * <meta name="usage" content="general"/>
+ * This class represents an XPath string object, and is capable of
+ * converting the string to other types, such as a number.
+ */
+public class XYMDuration extends XDuration 
+{
+
+  /** Empty string XString object */
+  public static XString EMPTYSTRING = new XString("");
+  
+  /**
+   * Construct a XDate object, with a null value.
+   * This one's actually being used, unlike most XObject empty ctors
+   * ... but I'm not sure why; it's equivalent to passing in null.
+   */
+  public XYMDuration()
+  {
+    super();
+  }
+
+
+  /**
+   * Construct a XDate object.  This constructor exists for derived classes.
+   *
+   * @param val Date object this will wrap.
+   */
+  //protected XDuration(Object val)
+  //{
+  //  super(val);
+  //}
+
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  //public XDuration(String val)
+  //{
+  //  super(val);
+  //}
+  
+  /**
+   * Construct a XDate object.
+   *
+   * @param val String object this will wrap.
+   */
+  public XYMDuration(Duration val)
+  {
+    //super(val);
+    m_val = val;
+  }
+  
+
+  /**
+   * Tell that this is a CLASS_DURATION.
+   *
+   * @return type CLASS_DURATION
+   */
+  public int getType()
+  {
+    return this.CLASS_YMDURATION;
+  }
+
+  /**
+   * Given a request type, return the equivalent string.
+   * For diagnostic purposes.
+   *
+   * @return type string "#DURATION"
+   */
+  public String getTypeString()
+  {
+    return "#YEARMONTHDURATION";
+  }  
+  
+  
+  /**
+   * Tell if two objects are functionally equal.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return true if the two objects are equal
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean equals(XObject obj2)
+  {
+
+    // In order to handle the 'all' semantics of 
+    // nodeset comparisons, we always call the 
+    // nodeset function.
+    int t = obj2.getType();
+    if(XObject.CLASS_YMDURATION == t)
+	    	return m_val.YMEqual(((XDuration)obj2).m_val);	
+    
+
+    // Otherwise, both objects to be compared are converted to strings as 
+    // if by applying the string function. 
+    return xstr().equals(obj2.xstr());
+  }
+  
+  /**
+   * Tell if one object is less than the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is less than the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean lessThan(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    int t = obj2.getType();
+    if(XObject.CLASS_YMDURATION == t)
+    {
+    	Duration du = ((XDuration)obj2).m_val;
+	   return m_val.YMLessThan(du);
+    }
+     else
+       return this.num() < obj2.num();
+  }
+  
+  /**
+   * Tell if one object is less than or equal to the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is less than or equal to the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean lessThanOrEqual(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    int t = obj2.getType();
+    if(XObject.CLASS_YMDURATION == t)
+	   {
+    	Duration du = ((XDuration)obj2).m_val;
+	   return m_val.YMLessThanOrEqual(du);
+    }
+     else
+       return this.num() <= obj2.num();
+  }
+  
+  
+   /**
+   * Tell if one object is greater than the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is greater than the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean greaterThan(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+    int t = obj2.getType();
+    if(XObject.CLASS_YMDURATION == t)
+	  {
+    	Duration du = ((XDuration)obj2).m_val;
+	   return m_val.YMGreaterThan(du);
+      }
+    else
+      return this.num() > obj2.num();
+  }
+
+
+  /**
+   * Tell if one object is greater than or equal to the other.
+   *
+   * @param obj2 Object to compare this to
+   *
+   * @return True if this object is greater than or equal to the given object
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean greaterThanOrEqual(XObject obj2)
+          throws javax.xml.transform.TransformerException
+  {
+
+    int t = obj2.getType();
+    if(XObject.CLASS_YMDURATION == t)
+	  {
+    	Duration du = ((XDuration)obj2).m_val;
+	   return m_val.YMGreaterThanOrEqual(du);
+      }
+    else
+      return this.num() >= obj2.num();
+  }
+ 
+}
diff --git a/src/org/apache/xpath/operations/Add.java b/src/org/apache/xpath/operations/Add.java
new file mode 100644
index 0000000..3e1c1a6
--- /dev/null
+++ b/src/org/apache/xpath/operations/Add.java
@@ -0,0 +1,274 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xml.utils.Duration;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XDate;
+import org.apache.xpath.objects.XDateTime;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xpath.objects.XFloat;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XTime;
+
+/**
+ * The '+' operation expression executer.
+ */
+public class Add extends OperationNormalized
+{
+  static OpFuncLookupTable m_funcs;
+  {
+    m_funcs = new OpFuncLookupTable();
+    m_funcs.setFunc(XType.DOUBLE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XDouble(lhs.num() + rhs.num());
+      }
+    });
+    m_funcs.setFunc(XType.FLOAT, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XFloat(lhs.floatVal() + rhs.floatVal());
+      }
+    });
+    m_funcs.setFunc(XType.INTEGER, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XInteger(lhs.integer() + rhs.integer());
+      }
+    });
+    m_funcs.setFunc(XType.DECIMAL, NOTSUPPORTED);
+
+    m_funcs.setFunc(XType.DURATION, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        Duration duration1 = lhs.duration();
+        // The normalizer should make sure the second argument is always 
+        // a duration!
+        Duration duration2 = rhs.duration();
+        Duration du = duration1.addDTDuration(duration2);
+        return new XDuration(du);
+      }
+    });
+    m_funcs.setFunc(XType.DAYTIMEDURATION, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        Duration duration1 = lhs.duration();
+        int rhsVT = rhs.getValueType();
+         if(XType.DATETIME == rhsVT || XType.DATE == rhsVT)
+        {
+        	DateTimeObj dt = rhs.datetime();
+        	DateTimeObj dateTime = dt.addDTDurationToDateTime(duration1);
+            return new XDateTime(dateTime);
+        }
+         if(XType.DATE == rhsVT)
+        {
+        	DateTimeObj dt = rhs.date();
+        	DateTimeObj dateTime = dt.addDTDurationToDate(duration1);
+            return new XDateTime(dateTime);
+        }
+         if(XType.TIME == rhsVT)
+        {
+        	DateTimeObj dt = rhs.time();
+        	DateTimeObj dateTime = dt.addDTDurationToTime(duration1);
+            return new XDateTime(dateTime);
+        }
+        else
+        {
+        // The normalizer should make sure the second argument is always 
+        // a duration!
+        Duration duration2 = rhs.duration();
+        Duration du = duration1.addDTDuration(duration2);
+        return new XDuration(du);
+        }
+      }
+    });
+    m_funcs.setFunc(XType.YEARMONTHDURATION, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+      	Duration duration1 = lhs.duration();
+      	int rhsVT = rhs.getValueType();
+        if(XType.DATETIME == rhsVT || XType.DATE == rhsVT)
+        {
+        	DateTimeObj dt = rhs.datetime();
+        	DateTimeObj dateTime = dt.addYMDurationToDateTime(duration1);
+            return new XDateTime(dateTime);
+        }
+         if(XType.DATE == rhsVT)
+        {
+        	DateTimeObj dt = rhs.date();
+        	DateTimeObj dateTime = dt.addYMDurationToDate(duration1);
+            return new XDateTime(dateTime);
+        }
+        else
+        {
+        // The normalizer should make sure the second argument is always 
+        // a duration!
+        Duration duration2 = rhs.duration();
+        Duration du = duration1.addYMDuration(duration2);
+        return new XDuration(du);
+        }
+      }
+    });
+    
+    m_funcs.setFunc(XType.DATETIME, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        DateTimeObj dt = lhs.datetime();
+        int rhsVT = rhs.getValueType();
+        if(XType.DURATION == rhsVT)
+        {
+          // The normalizer should
+          Duration duration2 = rhs.duration();
+          DateTimeObj du = dt.addYMDurationToDateTime(duration2);
+          du = du.addDTDurationToDateTime(duration2);
+         return new XDateTime(du);
+        }
+        if( XType.DAYTIMEDURATION == rhsVT)
+        {
+          // The normalizer should
+          Duration duration2 = rhs.duration();
+          DateTimeObj du = dt.addDTDurationToDateTime(duration2);
+         return new XDateTime(du);
+        }
+        else //if(XType.YEARMONTHDURATION == rhsVT)
+        {
+          Duration duration2 = rhs.duration();
+          DateTimeObj du = dt.addYMDurationToDateTime(duration2);
+         return new XDateTime(du);
+        }        	
+      }
+    });
+    m_funcs.setFunc(XType.TIME, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        DateTimeObj oldTime = lhs.time();
+        // The normalizer should
+        Duration duration2 = rhs.duration();
+        DateTimeObj newTime = oldTime.addDTDurationToTime(duration2);
+        return new XTime(newTime);
+      }
+    });
+    m_funcs.setFunc(XType.DATE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        DateTimeObj dt = lhs.date();
+       int rhsVT = rhs.getValueType();
+        if(XType.DURATION == rhsVT 
+          || XType.DAYTIMEDURATION == rhsVT)
+        {
+         // The normalizer should
+         Duration duration2 = rhs.duration();
+         DateTimeObj newDate = dt.addDTDurationToDate(duration2);
+        return new XDate(newDate);
+        }
+       else //if(XType.YEARMONTHDURATION == rhsVT)
+        {
+          Duration duration2 = rhs.duration();
+          DateTimeObj newDate = dt.addYMDurationToDate(duration2);
+         return new XDate(newDate);
+        }
+      }
+    });
+    m_funcs.setFunc(XType.GYEARMONTH, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GYEAR, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GMONTHDAY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GDAY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GMONTH, NOTSUPPORTED);
+
+    m_funcs.setFunc(XType.BOOLEAN, NOTSUPPORTED);
+    m_funcs.setFunc(XType.STRING, NOTSUPPORTED);
+    m_funcs.setFunc(XType.BASE64BINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.HEXBINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.ANYURI, NOTSUPPORTED);
+    m_funcs.setFunc(XType.QNAME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.NOTATION, NOTSUPPORTED);
+  }
+  
+  /**
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
+   */
+  public OpFuncLookupTable getLookupTable()
+  {
+    return m_funcs;
+  }
+
+}
diff --git a/src/org/apache/xpath/operations/And.java b/src/org/apache/xpath/operations/And.java
index 51cb3f8..4bf00c3 100644
--- a/src/org/apache/xpath/operations/And.java
+++ b/src/org/apache/xpath/operations/And.java
@@ -69,7 +69,6 @@
  */
 public class And extends Operation
 {
-
   /**
    * AND two expressions and return the boolean result. Override
    * superclass method for optimization purposes.
@@ -83,7 +82,6 @@
    */
   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
   {
-
     XObject expr1 = m_left.execute(xctxt);
 
     if (expr1.bool())
diff --git a/src/org/apache/xpath/operations/Div.java b/src/org/apache/xpath/operations/Div.java
index 58e857f..fd637dc 100644
--- a/src/org/apache/xpath/operations/Div.java
+++ b/src/org/apache/xpath/operations/Div.java
@@ -56,47 +56,102 @@
  */
 package org.apache.xpath.operations;
 
-import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
 import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xpath.objects.XFloat;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XYMDuration;
+import org.apache.xpath.objects.XDTDuration;
+import org.apache.xml.utils.Duration;
 
 /**
  * The 'div' operation expression executer.
  */
-public class Div extends Operation
+public class Div extends OperationNormalized
 {
-
-  /**
-   * Apply the operation to two operands, and return the result.
-   *
-   *
-   * @param left non-null reference to the evaluated left operand.
-   * @param right non-null reference to the evaluated right operand.
-   *
-   * @return non-null reference to the XObject that represents the result of the operation.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  public XObject operate(XObject left, XObject right)
-          throws javax.xml.transform.TransformerException
+  static OpFuncLookupTable m_funcs;
   {
-    return new XNumber(left.num() / right.num());
+    m_funcs = new OpFuncLookupTable();
+    m_funcs.setFunc(XType.DOUBLE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XDouble(lhs.num() / rhs.num());
+      }
+    });
+    m_funcs.setFunc(XType.FLOAT, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XFloat(lhs.floatVal() / rhs.floatVal());
+      }
+    });
+    m_funcs.setFunc(XType.INTEGER, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XInteger(lhs.integer() / rhs.integer());
+      }
+    });
+    m_funcs.setFunc(XType.DAYTIMEDURATION, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+      	Duration duration = lhs.duration();
+        Duration du = duration.divideDTDuration(rhs.num());
+        
+        return new XDTDuration(du);
+      }
+    });
+    m_funcs.setFunc(XType.YEARMONTHDURATION, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        Duration duration = lhs.duration();
+        Duration du = duration.divideYMDuration(rhs.num());
+        
+        return new XYMDuration(du);
+      }
+    });
+    m_funcs.setFunc(XType.DECIMAL, NOTSUPPORTED);
+
+    m_funcs.setFunc(XType.DURATION, NOTSUPPORTED);
+   // m_funcs.setFunc(XType.DAYTIMEDURATION, NOTSUPPORTED);
+   // m_funcs.setFunc(XType.YEARMONTHDURATION, NOTSUPPORTED);
+    
+    m_funcs.setFunc(XType.DATETIME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.TIME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.DATE, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GYEARMONTH, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GYEAR, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GMONTHDAY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GDAY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GMONTH, NOTSUPPORTED);
+
+    m_funcs.setFunc(XType.BOOLEAN, NOTSUPPORTED);
+    m_funcs.setFunc(XType.STRING, NOTSUPPORTED);
+    m_funcs.setFunc(XType.BASE64BINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.HEXBINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.ANYURI, NOTSUPPORTED);
+    m_funcs.setFunc(XType.QNAME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.NOTATION, NOTSUPPORTED);
   }
   
   /**
-   * Evaluate this operation directly to a double.
-   *
-   * @param xctxt The runtime execution context.
-   *
-   * @return The result of the operation as a double.
-   *
-   * @throws javax.xml.transform.TransformerException
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
    */
-  public double num(XPathContext xctxt)
-          throws javax.xml.transform.TransformerException
+  public OpFuncLookupTable getLookupTable()
   {
-
-    return (m_left.num(xctxt) / m_right.num(xctxt));
+    return m_funcs;
   }
 
 }
diff --git a/src/org/apache/xpath/operations/Equals.java b/src/org/apache/xpath/operations/Equals.java
index ca5250b..2278985 100644
--- a/src/org/apache/xpath/operations/Equals.java
+++ b/src/org/apache/xpath/operations/Equals.java
@@ -56,7 +56,6 @@
  */
 package org.apache.xpath.operations;
 
-import javax.xml.transform.TransformerException;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.objects.XBoolean;
 import org.apache.xpath.objects.XObject;
@@ -64,9 +63,8 @@
 /**
  * The '=' operation expression executer.
  */
-public class Equals extends Operation
+public class Equals extends OperationSimple
 {
-
   /**
    * Apply the operation to two operands, and return the result.
    *
@@ -81,7 +79,7 @@
   public XObject operate(XObject left, XObject right)
           throws javax.xml.transform.TransformerException
   {
-    return left.equals(right) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+    return left.equalsExistential(right) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
   }
   
   /**
@@ -96,14 +94,14 @@
    * @throws javax.xml.transform.TransformerException
    */
   public boolean bool(XPathContext xctxt)
-          throws javax.xml.transform.TransformerException
+    throws javax.xml.transform.TransformerException
   {
     XObject left = m_left.execute(xctxt, true);
     XObject right = m_right.execute(xctxt, true);
 
-    boolean result = left.equals(right) ? true : false;
-	left.detach();
-	right.detach();
+    boolean result = left.equalsExistential(right) ? true : false;
+    left.detach();
+    right.detach();
     return result;
   }
 
diff --git a/src/org/apache/xpath/operations/Follows.java b/src/org/apache/xpath/operations/Follows.java
new file mode 100644
index 0000000..9264534
--- /dev/null
+++ b/src/org/apache/xpath/operations/Follows.java
@@ -0,0 +1,83 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XBoolean;
+
+/**
+ * The '!=' operation expression executer.
+ */
+public class Follows extends OperationSimple
+{
+  /**
+   * Apply the operation to two operands, and return the result.
+   *
+   *
+   * @param left non-null reference to the evaluated left operand.
+   * @param right non-null reference to the evaluated right operand.
+   *
+   * @return non-null reference to the XObject that represents the result of the operation.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject operate(XObject left, XObject right)
+          throws javax.xml.transform.TransformerException
+  {
+  	throw new javax.xml.transform.TransformerException("'Follows' not yet implemented!", this);
+  }
+}
diff --git a/src/org/apache/xpath/operations/FortranEq.java b/src/org/apache/xpath/operations/FortranEq.java
new file mode 100644
index 0000000..4c77cdf
--- /dev/null
+++ b/src/org/apache/xpath/operations/FortranEq.java
@@ -0,0 +1,148 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xml.utils.Duration;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xpath.objects.XDate;
+import org.apache.xpath.objects.XDateTime;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XTime;
+
+/**
+ * The 'eq' operation expression executer.
+ */
+public class FortranEq extends OperationNormalized
+{
+  static GenericOpFunc IsEqualObj = new GenericOpFunc()
+  {
+    /**
+     * @see org.apache.xpath.operations.opfuncs.GenericOpFunc#operate(XPathContext, XObject, XObject)
+     */
+    public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+    {
+      return lhs.equals(rhs) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+    }
+
+  };
+
+  static OpFuncLookupTable m_funcs;
+  {
+    m_funcs = new OpFuncLookupTable();
+    m_funcs.setFunc(XType.DOUBLE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.num() == rhs.num()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.FLOAT, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.floatVal() == rhs.floatVal()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.INTEGER, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.integer() == rhs.integer()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.DECIMAL, IsEqualObj);
+
+    m_funcs.setFunc(XType.DURATION, IsEqualObj);
+    m_funcs.setFunc(XType.DAYTIMEDURATION, IsEqualObj);
+    m_funcs.setFunc(XType.YEARMONTHDURATION, IsEqualObj);
+    
+    m_funcs.setFunc(XType.DATETIME, IsEqualObj);
+    m_funcs.setFunc(XType.TIME, IsEqualObj);
+    m_funcs.setFunc(XType.DATE, IsEqualObj);
+    m_funcs.setFunc(XType.GYEARMONTH, IsEqualObj);
+    m_funcs.setFunc(XType.GYEAR, IsEqualObj);
+    m_funcs.setFunc(XType.GMONTHDAY, IsEqualObj);
+    m_funcs.setFunc(XType.GDAY, IsEqualObj);
+    m_funcs.setFunc(XType.GMONTH, IsEqualObj);
+
+    m_funcs.setFunc(XType.BOOLEAN, IsEqualObj);
+    m_funcs.setFunc(XType.STRING, IsEqualObj);
+    m_funcs.setFunc(XType.BASE64BINARY, IsEqualObj);
+    m_funcs.setFunc(XType.HEXBINARY, IsEqualObj);
+    m_funcs.setFunc(XType.ANYURI, IsEqualObj);
+    m_funcs.setFunc(XType.QNAME, IsEqualObj);
+    m_funcs.setFunc(XType.NOTATION, IsEqualObj);
+  }
+  
+  /**
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
+   */
+  public OpFuncLookupTable getLookupTable()
+  {
+    return m_funcs;
+  }
+
+}
diff --git a/src/org/apache/xpath/operations/FortranGe.java b/src/org/apache/xpath/operations/FortranGe.java
new file mode 100644
index 0000000..9666fc6
--- /dev/null
+++ b/src/org/apache/xpath/operations/FortranGe.java
@@ -0,0 +1,148 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.WrappedRuntimeException;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * The 'eq' operation expression executer.
+ */
+public class FortranGe extends OperationNormalized
+{
+  static GenericOpFunc GreaterThanOrEqualObj = new GenericOpFunc()
+  {
+    /**
+     * @see org.apache.xpath.operations.opfuncs.GenericOpFunc#operate(XPathContext, XObject, XObject)
+     */
+    public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+    {
+      try
+      {
+        return lhs.greaterThanOrEqual(rhs) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+      catch (TransformerException e)
+      {
+        throw new WrappedRuntimeException(e);
+      }
+    }
+  };
+
+  static OpFuncLookupTable m_funcs;
+  {
+    m_funcs = new OpFuncLookupTable();
+    m_funcs.setFunc(XType.DOUBLE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.num() >= rhs.num()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.FLOAT, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.floatVal() >= rhs.floatVal()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.INTEGER, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.integer() >= rhs.integer()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.DECIMAL, GreaterThanOrEqualObj);
+
+    m_funcs.setFunc(XType.DURATION, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.DAYTIMEDURATION, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.YEARMONTHDURATION, GreaterThanOrEqualObj);
+    
+    m_funcs.setFunc(XType.DATETIME, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.TIME, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.DATE, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.GYEARMONTH, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.GYEAR, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.GMONTHDAY, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.GDAY, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.GMONTH, GreaterThanOrEqualObj);
+
+    m_funcs.setFunc(XType.BOOLEAN, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.STRING, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.BASE64BINARY, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.HEXBINARY, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.ANYURI, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.QNAME, GreaterThanOrEqualObj);
+    m_funcs.setFunc(XType.NOTATION, GreaterThanOrEqualObj);
+  }
+  
+  /**
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
+   */
+  public OpFuncLookupTable getLookupTable()
+  {
+    return m_funcs;
+  }
+}
diff --git a/src/org/apache/xpath/operations/FortranGt.java b/src/org/apache/xpath/operations/FortranGt.java
new file mode 100644
index 0000000..7e804d9
--- /dev/null
+++ b/src/org/apache/xpath/operations/FortranGt.java
@@ -0,0 +1,148 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.WrappedRuntimeException;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * The 'gt' operation expression executer.
+ */
+public class FortranGt extends OperationNormalized
+{
+  static GenericOpFunc GreaterThanObj = new GenericOpFunc()
+  {
+    /**
+     * @see org.apache.xpath.operations.opfuncs.GenericOpFunc#operate(XPathContext, XObject, XObject)
+     */
+    public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+    {
+      try
+      {
+        return lhs.greaterThan(rhs) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+      catch (TransformerException e)
+      {
+        throw new WrappedRuntimeException(e);
+      }
+    }
+  };
+
+  static OpFuncLookupTable m_funcs;
+  {
+    m_funcs = new OpFuncLookupTable();
+    m_funcs.setFunc(XType.DOUBLE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.num() > rhs.num()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.FLOAT, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.floatVal() > rhs.floatVal()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.INTEGER, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.integer() > rhs.integer()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.DECIMAL, GreaterThanObj);
+
+    m_funcs.setFunc(XType.DURATION, GreaterThanObj);
+    m_funcs.setFunc(XType.DAYTIMEDURATION, GreaterThanObj);
+    m_funcs.setFunc(XType.YEARMONTHDURATION, GreaterThanObj);
+    
+    m_funcs.setFunc(XType.DATETIME, GreaterThanObj);
+    m_funcs.setFunc(XType.TIME, GreaterThanObj);
+    m_funcs.setFunc(XType.DATE, GreaterThanObj);
+    m_funcs.setFunc(XType.GYEARMONTH, GreaterThanObj);
+    m_funcs.setFunc(XType.GYEAR, GreaterThanObj);
+    m_funcs.setFunc(XType.GMONTHDAY, GreaterThanObj);
+    m_funcs.setFunc(XType.GDAY, GreaterThanObj);
+    m_funcs.setFunc(XType.GMONTH, GreaterThanObj);
+
+    m_funcs.setFunc(XType.BOOLEAN, GreaterThanObj);
+    m_funcs.setFunc(XType.STRING, GreaterThanObj);
+    m_funcs.setFunc(XType.BASE64BINARY, GreaterThanObj);
+    m_funcs.setFunc(XType.HEXBINARY, GreaterThanObj);
+    m_funcs.setFunc(XType.ANYURI, GreaterThanObj);
+    m_funcs.setFunc(XType.QNAME, GreaterThanObj);
+    m_funcs.setFunc(XType.NOTATION, GreaterThanObj);
+  }
+  
+  /**
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
+   */
+  public OpFuncLookupTable getLookupTable()
+  {
+    return m_funcs;
+  }
+}
diff --git a/src/org/apache/xpath/operations/FortranLe.java b/src/org/apache/xpath/operations/FortranLe.java
new file mode 100644
index 0000000..67be31f
--- /dev/null
+++ b/src/org/apache/xpath/operations/FortranLe.java
@@ -0,0 +1,163 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.WrappedRuntimeException;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * The 'le' operation expression executer.
+ */
+public class FortranLe extends OperationNormalized
+{
+  static GenericOpFunc LessThanOrEqualObj = new GenericOpFunc()
+  {
+    /**
+     * @see org.apache.xpath.operations.opfuncs.GenericOpFunc#operate(XPathContext, XObject, XObject)
+     */
+    public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+    {
+      try
+      {
+        return lhs.lessThanOrEqual(rhs) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+      catch (TransformerException e)
+      {
+        throw new WrappedRuntimeException(e);
+      }
+    }
+  };
+
+  static OpFuncLookupTable m_funcs;
+  {
+    m_funcs = new OpFuncLookupTable();
+    m_funcs.setFunc(XType.DOUBLE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.num() <= rhs.num()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.FLOAT, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.floatVal() <= rhs.floatVal()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.INTEGER, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.integer() <= rhs.integer()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+
+    });
+    m_funcs.setFunc(XType.DECIMAL, LessThanOrEqualObj);
+
+    m_funcs.setFunc(XType.DURATION, LessThanOrEqualObj);
+    m_funcs.setFunc(XType.DAYTIMEDURATION, LessThanOrEqualObj);
+    m_funcs.setFunc(XType.YEARMONTHDURATION, LessThanOrEqualObj);
+    
+    m_funcs.setFunc(XType.DATETIME, LessThanOrEqualObj);
+    m_funcs.setFunc(XType.TIME, LessThanOrEqualObj);
+    m_funcs.setFunc(XType.DATE, LessThanOrEqualObj);
+    m_funcs.setFunc(XType.GYEARMONTH, LessThanOrEqualObj);
+    m_funcs.setFunc(XType.GYEAR, LessThanOrEqualObj);
+    m_funcs.setFunc(XType.GMONTHDAY, LessThanOrEqualObj);
+    m_funcs.setFunc(XType.GDAY, LessThanOrEqualObj);
+    m_funcs.setFunc(XType.GMONTH, LessThanOrEqualObj);
+
+    m_funcs.setFunc(XType.BOOLEAN, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+      {
+        return null;
+      }
+
+    });
+    m_funcs.setFunc(XType.STRING, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+      {
+        return null;
+      }
+
+    });
+    m_funcs.setFunc(XType.BASE64BINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.HEXBINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.ANYURI, NOTSUPPORTED);
+    m_funcs.setFunc(XType.QNAME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.NOTATION, NOTSUPPORTED);
+  }
+  
+  /**
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
+   */
+  public OpFuncLookupTable getLookupTable()
+  {
+    return m_funcs;
+  }
+}
diff --git a/src/org/apache/xpath/operations/FortranLt.java b/src/org/apache/xpath/operations/FortranLt.java
new file mode 100644
index 0000000..cf4a9cd
--- /dev/null
+++ b/src/org/apache/xpath/operations/FortranLt.java
@@ -0,0 +1,148 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.WrappedRuntimeException;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * The 'lt' operation expression executer.
+ */
+public class FortranLt extends OperationNormalized
+{
+  static GenericOpFunc LessThanObj = new GenericOpFunc()
+  {
+    /**
+     * @see org.apache.xpath.operations.opfuncs.GenericOpFunc#operate(XPathContext, XObject, XObject)
+     */
+    public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+    {
+      try
+      {
+        return lhs.lessThan(rhs) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+      catch (TransformerException e)
+      {
+        throw new WrappedRuntimeException(e);
+      }
+    }
+  };
+
+  static OpFuncLookupTable m_funcs;
+  {
+    m_funcs = new OpFuncLookupTable();
+    m_funcs.setFunc(XType.DOUBLE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.num() < rhs.num()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.FLOAT, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.floatVal() < rhs.floatVal()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.INTEGER, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.integer() < rhs.integer()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.DECIMAL, LessThanObj);
+
+    m_funcs.setFunc(XType.DURATION, LessThanObj);
+    m_funcs.setFunc(XType.DAYTIMEDURATION, LessThanObj);
+    m_funcs.setFunc(XType.YEARMONTHDURATION, LessThanObj);
+    
+    m_funcs.setFunc(XType.DATETIME, LessThanObj);
+    m_funcs.setFunc(XType.TIME, LessThanObj);
+    m_funcs.setFunc(XType.DATE, LessThanObj);
+    m_funcs.setFunc(XType.GYEARMONTH, LessThanObj);
+    m_funcs.setFunc(XType.GYEAR, LessThanObj);
+    m_funcs.setFunc(XType.GMONTHDAY, LessThanObj);
+    m_funcs.setFunc(XType.GDAY, LessThanObj);
+    m_funcs.setFunc(XType.GMONTH, LessThanObj);
+
+    m_funcs.setFunc(XType.BOOLEAN, LessThanObj);
+    m_funcs.setFunc(XType.STRING, LessThanObj);
+    m_funcs.setFunc(XType.BASE64BINARY, LessThanObj);
+    m_funcs.setFunc(XType.HEXBINARY, LessThanObj);
+    m_funcs.setFunc(XType.ANYURI, LessThanObj);
+    m_funcs.setFunc(XType.QNAME, LessThanObj);
+    m_funcs.setFunc(XType.NOTATION, LessThanObj);
+  }
+  
+  /**
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
+   */
+  public OpFuncLookupTable getLookupTable()
+  {
+    return m_funcs;
+  }
+}
diff --git a/src/org/apache/xpath/operations/FortranNe.java b/src/org/apache/xpath/operations/FortranNe.java
new file mode 100644
index 0000000..cf6b20a
--- /dev/null
+++ b/src/org/apache/xpath/operations/FortranNe.java
@@ -0,0 +1,141 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * The 'ne' operation expression executer.
+ */
+public class FortranNe extends OperationNormalized
+{
+  static GenericOpFunc IsNotEqualObj = new GenericOpFunc()
+  {
+    /**
+     * @see org.apache.xpath.operations.opfuncs.GenericOpFunc#operate(XPathContext, XObject, XObject)
+     */
+    public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+    {
+      return lhs.equals(rhs) ? XBoolean.S_FALSE : XBoolean.S_TRUE;
+    }
+
+  };
+
+  static OpFuncLookupTable m_funcs;
+  {
+    m_funcs = new OpFuncLookupTable();
+    m_funcs.setFunc(XType.DOUBLE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.num() != rhs.num()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.FLOAT, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.num() != rhs.num()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.INTEGER, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return (lhs.num() != rhs.num()) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+      }
+    });
+    m_funcs.setFunc(XType.DECIMAL, IsNotEqualObj);
+
+    m_funcs.setFunc(XType.DURATION, IsNotEqualObj);
+    m_funcs.setFunc(XType.DAYTIMEDURATION, IsNotEqualObj);
+    m_funcs.setFunc(XType.YEARMONTHDURATION, IsNotEqualObj);
+    
+    m_funcs.setFunc(XType.DATETIME, IsNotEqualObj);
+    m_funcs.setFunc(XType.TIME, IsNotEqualObj);
+    m_funcs.setFunc(XType.DATE, IsNotEqualObj);
+    m_funcs.setFunc(XType.GYEARMONTH, IsNotEqualObj);
+    m_funcs.setFunc(XType.GYEAR, IsNotEqualObj);
+    m_funcs.setFunc(XType.GMONTHDAY, IsNotEqualObj);
+    m_funcs.setFunc(XType.GDAY, IsNotEqualObj);
+    m_funcs.setFunc(XType.GMONTH, IsNotEqualObj);
+
+    m_funcs.setFunc(XType.BOOLEAN, IsNotEqualObj);
+    m_funcs.setFunc(XType.STRING, IsNotEqualObj);
+    m_funcs.setFunc(XType.BASE64BINARY, IsNotEqualObj);
+    m_funcs.setFunc(XType.HEXBINARY, IsNotEqualObj);
+    m_funcs.setFunc(XType.ANYURI, IsNotEqualObj);
+    m_funcs.setFunc(XType.QNAME, IsNotEqualObj);
+    m_funcs.setFunc(XType.NOTATION, IsNotEqualObj);
+  }
+  
+  /**
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
+   */
+  public OpFuncLookupTable getLookupTable()
+  {
+    return m_funcs;
+  }
+}
diff --git a/src/org/apache/xpath/operations/GenericOpFunc.java b/src/org/apache/xpath/operations/GenericOpFunc.java
new file mode 100644
index 0000000..28f6dc6
--- /dev/null
+++ b/src/org/apache/xpath/operations/GenericOpFunc.java
@@ -0,0 +1,115 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.utils.WrappedRuntimeException;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 29, 2002
+ * @author sboag
+ */
+public abstract class GenericOpFunc
+{
+
+  /**
+   * Constructor for GenericOpFunc.
+   */
+  public GenericOpFunc()
+  {
+    super();
+  }
+
+  /**
+   * Perform a generic operation on two operands.
+   * @param xctxt  The dynamic execution context.
+   * @param lhs The left hand side operation.
+   * @param rhs The right hand side operation.
+   * @return XObject The result object.
+   */
+  public abstract XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+          throws TransformerException;
+
+  /**
+   * Perform a generic operation on two operands, and return a boolean.
+   * @param xctxt  The dynamic execution context.
+   * @param lhs The left hand side operation.
+   * @param rhs The right hand side operation.
+   * @return boolean The result value.
+   */
+  public boolean operateToBoolean(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+  {
+    try
+    {
+      XObject xobj = operate(xctxt, lhs, rhs);
+      return xobj.bool(xctxt);
+    }
+    catch (TransformerException e)
+    {
+      throw new WrappedRuntimeException(e);
+    }
+  }
+  
+  
+
+}
diff --git a/src/org/apache/xpath/operations/Gt.java b/src/org/apache/xpath/operations/Gt.java
index a1ee4b2..2fc77d7 100644
--- a/src/org/apache/xpath/operations/Gt.java
+++ b/src/org/apache/xpath/operations/Gt.java
@@ -62,9 +62,8 @@
 /**
  * The '>' operation expression executer.
  */
-public class Gt extends Operation
+public class Gt extends OperationSimple
 {
-
   /**
    * Apply the operation to two operands, and return the result.
    *
diff --git a/src/org/apache/xpath/operations/GtGt.java b/src/org/apache/xpath/operations/GtGt.java
new file mode 100644
index 0000000..1a4b793
--- /dev/null
+++ b/src/org/apache/xpath/operations/GtGt.java
@@ -0,0 +1,83 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XBoolean;
+
+/**
+ * The '!=' operation expression executer.
+ */
+public class GtGt extends OperationSimple
+{
+  /**
+   * Apply the operation to two operands, and return the result.
+   *
+   *
+   * @param left non-null reference to the evaluated left operand.
+   * @param right non-null reference to the evaluated right operand.
+   *
+   * @return non-null reference to the XObject that represents the result of the operation.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject operate(XObject left, XObject right)
+          throws javax.xml.transform.TransformerException
+  {
+  	throw new javax.xml.transform.TransformerException("'Follows' not yet implemented!", this);
+  }
+}
diff --git a/src/org/apache/xpath/operations/Gte.java b/src/org/apache/xpath/operations/Gte.java
index 42e14be..638c34b 100644
--- a/src/org/apache/xpath/operations/Gte.java
+++ b/src/org/apache/xpath/operations/Gte.java
@@ -62,9 +62,8 @@
 /**
  * The '>=' operation expression executer.
  */
-public class Gte extends Operation
+public class Gte extends OperationSimple
 {
-
   /**
    * Apply the operation to two operands, and return the result.
    *
diff --git a/src/org/apache/xpath/operations/Idiv.java b/src/org/apache/xpath/operations/Idiv.java
new file mode 100644
index 0000000..23286a9
--- /dev/null
+++ b/src/org/apache/xpath/operations/Idiv.java
@@ -0,0 +1,122 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * The 'div' operation expression executer.
+ */
+public class Idiv extends OperationNormalized
+{
+  static GenericOpFunc IDivObj = new GenericOpFunc()
+  {
+    /**
+     * @see org.apache.xpath.operations.opfuncs.GenericOpFunc#operate(XPathContext, XObject, XObject)
+     */
+    public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+      throws TransformerException
+    {
+      return new XInteger(lhs.integer() / rhs.integer());
+    }
+
+  };
+
+  static OpFuncLookupTable m_funcs;
+  {
+    m_funcs = new OpFuncLookupTable();
+    m_funcs.setFunc(XType.DOUBLE, IDivObj);
+    m_funcs.setFunc(XType.FLOAT, IDivObj);
+    m_funcs.setFunc(XType.INTEGER, IDivObj);
+    m_funcs.setFunc(XType.DECIMAL, IDivObj);
+
+    m_funcs.setFunc(XType.DURATION, NOTSUPPORTED);
+    m_funcs.setFunc(XType.DAYTIMEDURATION, NOTSUPPORTED);
+    m_funcs.setFunc(XType.YEARMONTHDURATION, NOTSUPPORTED);
+    
+    m_funcs.setFunc(XType.DATETIME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.TIME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.DATE, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GYEARMONTH, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GYEAR, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GMONTHDAY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GDAY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GMONTH, NOTSUPPORTED);
+
+    m_funcs.setFunc(XType.BOOLEAN, NOTSUPPORTED);
+    m_funcs.setFunc(XType.STRING, NOTSUPPORTED);
+    m_funcs.setFunc(XType.BASE64BINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.HEXBINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.ANYURI, NOTSUPPORTED);
+    m_funcs.setFunc(XType.QNAME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.NOTATION, NOTSUPPORTED);
+  }
+  
+  /**
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
+   */
+  public OpFuncLookupTable getLookupTable()
+  {
+    return m_funcs;
+  }
+
+}
diff --git a/src/org/apache/xpath/operations/Is.java b/src/org/apache/xpath/operations/Is.java
new file mode 100644
index 0000000..37da637
--- /dev/null
+++ b/src/org/apache/xpath/operations/Is.java
@@ -0,0 +1,111 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * The '=' operation expression executer.
+ */
+public class Is extends OperationSimple
+{
+  /**
+   * Apply the operation to two operands, and return the result.
+   *
+   *
+   * @param left non-null reference to the evaluated left operand.
+   * @param right non-null reference to the evaluated right operand.
+   *
+   * @return non-null reference to the XObject that represents the result of the operation.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject operate(XObject left, XObject right)
+          throws javax.xml.transform.TransformerException
+  {
+  	// Might need to be more sophisticated!
+    return (left == right) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+  }
+  
+  /**
+   * Execute a binary operation by calling execute on each of the operands,
+   * and then calling the operate method on the derived class.
+   *
+   *
+   * @param xctxt The runtime execution context.
+   *
+   * @return The XObject result of the operation.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public boolean bool(XPathContext xctxt)
+          throws javax.xml.transform.TransformerException
+  {
+    XObject left = m_left.execute(xctxt, true);
+    XObject right = m_right.execute(xctxt, true);
+
+  	// Might need to be more sophisticated!
+    boolean result = (left == right) ? true : false;
+	left.detach();
+	right.detach();
+    return result;
+  }
+
+}
diff --git a/src/org/apache/xpath/operations/IsNot.java b/src/org/apache/xpath/operations/IsNot.java
new file mode 100644
index 0000000..26639a2
--- /dev/null
+++ b/src/org/apache/xpath/operations/IsNot.java
@@ -0,0 +1,84 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XBoolean;
+
+/**
+ * The '!=' operation expression executer.
+ */
+public class IsNot extends OperationSimple
+{
+  /**
+   * Apply the operation to two operands, and return the result.
+   *
+   *
+   * @param left non-null reference to the evaluated left operand.
+   * @param right non-null reference to the evaluated right operand.
+   *
+   * @return non-null reference to the XObject that represents the result of the operation.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject operate(XObject left, XObject right)
+          throws javax.xml.transform.TransformerException
+  {
+  	// Might have to be more sophisticated!
+    return (left != right) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+  }
+}
diff --git a/src/org/apache/xpath/operations/Lt.java b/src/org/apache/xpath/operations/Lt.java
index 31878ba..da5c786 100644
--- a/src/org/apache/xpath/operations/Lt.java
+++ b/src/org/apache/xpath/operations/Lt.java
@@ -62,9 +62,8 @@
 /**
  * The '<' operation expression executer.
  */
-public class Lt extends Operation
+public class Lt extends OperationSimple
 {
-
   /**
    * Apply the operation to two operands, and return the result.
    *
diff --git a/src/org/apache/xpath/operations/LtLt.java b/src/org/apache/xpath/operations/LtLt.java
new file mode 100644
index 0000000..66ed714
--- /dev/null
+++ b/src/org/apache/xpath/operations/LtLt.java
@@ -0,0 +1,83 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XBoolean;
+
+/**
+ * The '!=' operation expression executer.
+ */
+public class LtLt extends OperationSimple
+{
+  /**
+   * Apply the operation to two operands, and return the result.
+   *
+   *
+   * @param left non-null reference to the evaluated left operand.
+   * @param right non-null reference to the evaluated right operand.
+   *
+   * @return non-null reference to the XObject that represents the result of the operation.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject operate(XObject left, XObject right)
+          throws javax.xml.transform.TransformerException
+  {
+  	throw new javax.xml.transform.TransformerException("'Follows' not yet implemented!", this);
+  }
+}
diff --git a/src/org/apache/xpath/operations/Lte.java b/src/org/apache/xpath/operations/Lte.java
index 0ccf4ba..8dab46b 100644
--- a/src/org/apache/xpath/operations/Lte.java
+++ b/src/org/apache/xpath/operations/Lte.java
@@ -62,9 +62,8 @@
 /**
  * The '<=' operation expression executer.
  */
-public class Lte extends Operation
+public class Lte extends OperationSimple
 {
-
   /**
    * Apply the operation to two operands, and return the result.
    *
diff --git a/src/org/apache/xpath/operations/Mod.java b/src/org/apache/xpath/operations/Mod.java
index 36a8ea6..4ef27b5 100644
--- a/src/org/apache/xpath/operations/Mod.java
+++ b/src/org/apache/xpath/operations/Mod.java
@@ -56,47 +56,77 @@
  */
 package org.apache.xpath.operations;
 
-import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
 import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xpath.objects.XFloat;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xpath.objects.XObject;
 
 /**
  * The 'mod' operation expression executer.
  */
-public class Mod extends Operation
+public class Mod extends OperationNormalized
 {
-
-  /**
-   * Apply the operation to two operands, and return the result.
-   *
-   *
-   * @param left non-null reference to the evaluated left operand.
-   * @param right non-null reference to the evaluated right operand.
-   *
-   * @return non-null reference to the XObject that represents the result of the operation.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  public XObject operate(XObject left, XObject right)
-          throws javax.xml.transform.TransformerException
+  static OpFuncLookupTable m_funcs;
   {
-    return new XNumber(left.num() % right.num());
+    m_funcs = new OpFuncLookupTable();
+    m_funcs.setFunc(XType.DOUBLE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XDouble(lhs.num() % rhs.num());
+      }
+    });
+    m_funcs.setFunc(XType.FLOAT, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XFloat(lhs.floatVal() % rhs.floatVal());
+      }
+    });
+    m_funcs.setFunc(XType.INTEGER, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XInteger(lhs.integer() % rhs.integer());
+      }
+    });
+    m_funcs.setFunc(XType.DECIMAL, NOTSUPPORTED);
+
+    m_funcs.setFunc(XType.DURATION, NOTSUPPORTED);
+    m_funcs.setFunc(XType.DAYTIMEDURATION, NOTSUPPORTED);
+    m_funcs.setFunc(XType.YEARMONTHDURATION, NOTSUPPORTED);
+    
+    m_funcs.setFunc(XType.DATETIME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.TIME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.DATE, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GYEARMONTH, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GYEAR, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GMONTHDAY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GDAY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GMONTH, NOTSUPPORTED);
+
+    m_funcs.setFunc(XType.BOOLEAN, NOTSUPPORTED);
+    m_funcs.setFunc(XType.STRING, NOTSUPPORTED);
+    m_funcs.setFunc(XType.BASE64BINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.HEXBINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.ANYURI, NOTSUPPORTED);
+    m_funcs.setFunc(XType.QNAME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.NOTATION, NOTSUPPORTED);
   }
   
   /**
-   * Evaluate this operation directly to a double.
-   *
-   * @param xctxt The runtime execution context.
-   *
-   * @return The result of the operation as a double.
-   *
-   * @throws javax.xml.transform.TransformerException
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
    */
-  public double num(XPathContext xctxt)
-          throws javax.xml.transform.TransformerException
+  public OpFuncLookupTable getLookupTable()
   {
-
-    return (m_left.num(xctxt) % m_right.num(xctxt));
+    return m_funcs;
   }
 
 }
diff --git a/src/org/apache/xpath/operations/Mult.java b/src/org/apache/xpath/operations/Mult.java
index e5d10ee..3b911a3 100644
--- a/src/org/apache/xpath/operations/Mult.java
+++ b/src/org/apache/xpath/operations/Mult.java
@@ -56,46 +56,102 @@
  */
 package org.apache.xpath.operations;
 
-import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
 import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xpath.objects.XFloat;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XYMDuration;
+import org.apache.xpath.objects.XDTDuration;
+import org.apache.xml.utils.Duration;
 
 /**
  * The '*' operation expression executer.
  */
-public class Mult extends Operation
+public class Mult extends OperationNormalized
 {
-
-  /**
-   * Apply the operation to two operands, and return the result.
-   *
-   *
-   * @param left non-null reference to the evaluated left operand.
-   * @param right non-null reference to the evaluated right operand.
-   *
-   * @return non-null reference to the XObject that represents the result of the operation.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  public XObject operate(XObject left, XObject right)
-          throws javax.xml.transform.TransformerException
+  static OpFuncLookupTable m_funcs;
   {
-    return new XNumber(left.num() * right.num());
+    m_funcs = new OpFuncLookupTable();
+    m_funcs.setFunc(XType.DOUBLE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XDouble(lhs.num() * rhs.num());
+      }
+    });
+    m_funcs.setFunc(XType.FLOAT, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XFloat(lhs.floatVal() * rhs.floatVal());
+      }
+    });
+    m_funcs.setFunc(XType.INTEGER, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XInteger(lhs.integer() * rhs.integer());
+      }
+    });
+    m_funcs.setFunc(XType.DAYTIMEDURATION, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+      	Duration duration = lhs.duration();
+        Duration du = duration.multiplyDTDuration(rhs.num());
+        
+        return new XDTDuration(du);
+      }
+    });
+    m_funcs.setFunc(XType.YEARMONTHDURATION, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        Duration duration = lhs.duration();
+        Duration du = duration.multiplyYMDuration(rhs.num());
+        
+        return new XYMDuration(du);
+      }
+    });    
+    m_funcs.setFunc(XType.DECIMAL, NOTSUPPORTED);
+
+    m_funcs.setFunc(XType.DURATION, NOTSUPPORTED);
+    //m_funcs.setFunc(XType.DAYTIMEDURATION, NOTSUPPORTED);
+    //m_funcs.setFunc(XType.YEARMONTHDURATION, NOTSUPPORTED);
+    
+    m_funcs.setFunc(XType.DATETIME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.TIME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.DATE, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GYEARMONTH, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GYEAR, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GMONTHDAY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GDAY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GMONTH, NOTSUPPORTED);
+
+    m_funcs.setFunc(XType.BOOLEAN, NOTSUPPORTED);
+    m_funcs.setFunc(XType.STRING, NOTSUPPORTED);
+    m_funcs.setFunc(XType.BASE64BINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.HEXBINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.ANYURI, NOTSUPPORTED);
+    m_funcs.setFunc(XType.QNAME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.NOTATION, NOTSUPPORTED);
   }
   
   /**
-   * Evaluate this operation directly to a double.
-   *
-   * @param xctxt The runtime execution context.
-   *
-   * @return The result of the operation as a double.
-   *
-   * @throws javax.xml.transform.TransformerException
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
    */
-  public double num(XPathContext xctxt)
-          throws javax.xml.transform.TransformerException
+  public OpFuncLookupTable getLookupTable()
   {
-    return (m_left.num(xctxt) * m_right.num(xctxt));
+    return m_funcs;
   }
 
 }
diff --git a/src/org/apache/xpath/operations/Neg.java b/src/org/apache/xpath/operations/Neg.java
index 17fe20d..1b7c842 100644
--- a/src/org/apache/xpath/operations/Neg.java
+++ b/src/org/apache/xpath/operations/Neg.java
@@ -56,9 +56,10 @@
  */
 package org.apache.xpath.operations;
 
-import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
+import javax.xml.transform.TransformerException;
 import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xpath.objects.XObject;
 
 /**
  * The unary '-' operation expression executer.
@@ -78,7 +79,7 @@
    */
   public XObject operate(XObject right) throws javax.xml.transform.TransformerException
   {
-    return new XNumber(-right.num());
+    return new XDouble(-right.num());
   }
   
   /**
diff --git a/src/org/apache/xpath/operations/NotEquals.java b/src/org/apache/xpath/operations/NotEquals.java
index 16c4872..05c93a4 100644
--- a/src/org/apache/xpath/operations/NotEquals.java
+++ b/src/org/apache/xpath/operations/NotEquals.java
@@ -62,9 +62,8 @@
 /**
  * The '!=' operation expression executer.
  */
-public class NotEquals extends Operation
+public class NotEquals extends OperationSimple
 {
-
   /**
    * Apply the operation to two operands, and return the result.
    *
diff --git a/src/org/apache/xpath/operations/Number.java b/src/org/apache/xpath/operations/Number.java
index 32291f2..1d757aa 100644
--- a/src/org/apache/xpath/operations/Number.java
+++ b/src/org/apache/xpath/operations/Number.java
@@ -56,9 +56,10 @@
  */
 package org.apache.xpath.operations;
 
-import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
+import javax.xml.transform.TransformerException;
 import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xpath.objects.XObject;
 
 /**
  * The 'number()' operation expression executer.
@@ -82,7 +83,7 @@
     if (XObject.CLASS_NUMBER == right.getType())
       return right;
     else
-      return new XNumber(right.num());
+      return new XDouble(right.num());
   }
   
   /**
diff --git a/src/org/apache/xpath/operations/OpFuncLookupTable.java b/src/org/apache/xpath/operations/OpFuncLookupTable.java
new file mode 100644
index 0000000..518c2a5
--- /dev/null
+++ b/src/org/apache/xpath/operations/OpFuncLookupTable.java
@@ -0,0 +1,99 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import org.apache.xml.dtm.XType;
+
+/**
+ * Typed operation function.
+ * 
+ * Created Jul 29, 2002
+ * @author sboag
+ */
+public class OpFuncLookupTable
+{
+  GenericOpFunc[] m_funcs = new GenericOpFunc[XType.MAXTYPES];
+  
+  /**
+   * Constructor for OpFuncLookupTable.
+   */
+  public OpFuncLookupTable()
+  {
+    super();
+  }
+
+  /**
+   * Returns the funcs.
+   * @param type Type ID defined in XType.
+   * @return GenericOpFunc
+   */
+  public GenericOpFunc getFunc(int type)
+  {
+    return m_funcs[type];
+  }
+
+  /**
+   * Sets the funcs.
+   * @param type Type ID defined in XType.
+   * @param funcs The funcs to set
+   */
+  public void setFunc(int type, GenericOpFunc func)
+  {
+    m_funcs[type] = func;
+  }
+
+}
diff --git a/src/org/apache/xpath/operations/Operation.java b/src/org/apache/xpath/operations/Operation.java
index 9a04b4f..df9004b 100644
--- a/src/org/apache/xpath/operations/Operation.java
+++ b/src/org/apache/xpath/operations/Operation.java
@@ -56,11 +56,10 @@
  */
 package org.apache.xpath.operations;
 
-import java.util.Vector;
-
-import javax.xml.transform.TransformerException;
 import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
 import org.apache.xpath.objects.XObject;
@@ -68,7 +67,7 @@
 /**
  * The baseclass for a binary operation.
  */
-public class Operation extends Expression implements ExpressionOwner
+public abstract class Operation extends Expression implements ExpressionOwner
 {
 
   /** The left operand expression.
@@ -79,6 +78,18 @@
    *  @serial */
   protected Expression m_right;
   
+  static GenericOpFunc NOTSUPPORTED = new GenericOpFunc()
+  {
+    /**
+     * @see org.apache.xpath.operations.opfuncs.GenericOpFunc#operate(XPathContext, XObject, XObject)
+     */
+    public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+    {
+      return null;
+    }
+
+  };
+  
   /**
    * This function is used to fixup variables from QNames to stack frame 
    * indexes at stylesheet build time.
@@ -89,10 +100,10 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    m_left.fixupVariables(vars, globalsSize);
-    m_right.fixupVariables(vars, globalsSize);
+    m_left.fixupVariables(vcs);
+    m_right.fixupVariables(vcs);
   }
 
 
@@ -123,51 +134,49 @@
    */
   public void setLeftRight(Expression l, Expression r)
   {
-    m_left = l;
-    m_right = r;
-    l.exprSetParent(this);
-    r.exprSetParent(this);
+    jjtAddChild(l, 0); 
+    jjtAddChild(r, 1); 
+  }
+  
+  
+  /**
+   * Add the left or right node of the operation.
+   */
+  public void jjtAddChild(org.apache.xpath.parser.Node n, int i) 
+  {
+  	n = fixupPrimarys(n);  // yuck.
+  	if(0 == i)
+  	{
+    	m_left = (Expression)n;
+    	m_left.jjtSetParent(this);
+  	}
+  	else if(1 == i)
+  	{
+    	m_right = (Expression)n;
+    	m_right.jjtSetParent(this);
+  	}
+  	else
+  	{
+  		// assertion... should not be able to occur.
+  		throw new RuntimeException("Can't add more than two children to an operation!");
+  	}
+  }
+  
+  /** This method returns a child node.  The children are numbered
+     from zero, left to right. */
+  public ExpressionNode exprGetChild(int i)
+  {
+  	assertion(i <= 1, "Operation can only have one or two children!");
+  	return (0 == i) ? m_left : m_right;
   }
 
-  /**
-   * Execute a binary operation by calling execute on each of the operands,
-   * and then calling the operate method on the derived class.
-   *
-   *
-   * @param xctxt The runtime execution context.
-   *
-   * @return The XObject result of the operation.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  public XObject execute(XPathContext xctxt)
-          throws javax.xml.transform.TransformerException
+  /** Return the number of children the node has. */
+  public int exprGetNumChildren()
   {
-
-    XObject left = m_left.execute(xctxt, true);
-    XObject right = m_right.execute(xctxt, true);
-
-    XObject result = operate(left, right);
-    left.detach();
-    right.detach();
-    return result;
-  }
-
-  /**
-   * Apply the operation to two operands, and return the result.
-   *
-   *
-   * @param left non-null reference to the evaluated left operand.
-   * @param right non-null reference to the evaluated right operand.
-   *
-   * @return non-null reference to the XObject that represents the result of the operation.
-   *
-   * @throws javax.xml.transform.TransformerException
-   */
-  public XObject operate(XObject left, XObject right)
-          throws javax.xml.transform.TransformerException
-  {
-    return null;  // no-op
+  	int count = 1;
+   	if(null != m_right)
+  		count++;
+  	return count;
   }
 
   /** @return the left operand of binary operation, as an Expression.
@@ -247,4 +256,12 @@
   		
   	return true;
   }
+  /**
+   * Tell if this node should have it's PathExpr ancestory reduced.
+   */
+  public boolean isPathExprReduced()
+  {
+  	return true;
+  }
+
 }
diff --git a/src/org/apache/xpath/operations/OperationNormalized.java b/src/org/apache/xpath/operations/OperationNormalized.java
new file mode 100644
index 0000000..2caad81
--- /dev/null
+++ b/src/org/apache/xpath/operations/OperationNormalized.java
@@ -0,0 +1,208 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.XMLString;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XSequence;
+import org.apache.xpath.objects.XString;
+
+/**
+ * 
+ * 
+ * Created Jul 31, 2002
+ * @author sboag
+ */
+public abstract class OperationNormalized extends Operation
+{
+  public abstract OpFuncLookupTable getLookupTable();
+  
+  
+  /**
+   * Get the default value type that this operation expects.
+   * @return int one of XType.XXX being one of the simple types.
+   */
+  public int getDefaultType()
+  {
+    return XType.DOUBLE;
+  }
+  
+  /**
+   * Execute a binary operation by calling execute on each of the operands,
+   * and then calling the operate method on the derived class.
+   *
+   *
+   * @param xctxt The runtime execution context.
+   *
+   * @return The XObject result of the operation.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt)
+          throws javax.xml.transform.TransformerException
+  {
+
+    XObject left = m_left.execute(xctxt, true);
+    XObject right = m_right.execute(xctxt, true);
+
+    if(XSequence.EMPTY == left || XSequence.EMPTY == right)
+      return XSequence.EMPTY;
+    
+//    if(!left.isSingletonOrEmpty())
+//    {
+//      XSequence xseq = left.xseq();
+//      left = xseq.getCurrent();
+//      if(null == left)
+//        return XSequence.EMPTY;
+//      // Node?
+//    }
+//    if(!right.isSingletonOrEmpty())
+//    {
+//      XSequence xseq = right.xseq();
+//      right = xseq.getCurrent();
+//      if(null == right)
+//        return XSequence.EMPTY;
+//      // Node?
+//    }
+    
+    int type = left.getValueType();
+    int defaultType = getDefaultType();
+    if(type == XType.ANYTYPE || type == XType.ANYSIMPLETYPE)
+    {
+      type = getDefaultType();
+    }
+    else if(type != defaultType)
+    {
+      type = findFallbackType(type, defaultType);
+     /* if(XType.DURATION == type)
+      {
+        XObject savedLeft = left;
+        left = right;
+        right = savedLeft;
+        type = left.getValueType();
+        type = findFallbackType(type, defaultType);
+      }*/
+    }
+    
+    GenericOpFunc opfunc = getLookupTable().getFunc(type);
+    if(null == opfunc)
+      throw new TransformerException("Type Exception!", this);
+    return opfunc.operate(xctxt, left, right);
+  }
+  
+  /**
+   * Find the fallback type for this object.  
+   * Assumptions: 1) the valType and the requiredType do not match, 
+   * 2) the valType has already been checked for ANYTYPE (this is 
+   * not officially part of fallback), and 3) the valType is one of 
+   * the 19 simple types.
+   * @param valType The value type.
+   * @param requiredType  The required type.
+   * @return int Either the valType, or the required type.
+   */
+  public int findFallbackType(int valType, int requiredType)
+  {
+    switch (requiredType)
+    {
+      case XType.DOUBLE :
+      case XType.INTEGER :
+      case XType.FLOAT :
+        switch (valType)
+        {
+          case XType.ANYTYPE :
+          case XType.ANYSIMPLETYPE :
+            return requiredType;
+
+          case XType.STRING :
+          case XType.BOOLEAN :
+            return requiredType;
+            
+          case XType.DATE :
+          case XType.DATETIME :
+          case XType.TIME :
+          case XType.GYEARMONTH :
+          case XType.GYEAR :
+          case XType.GMONTHDAY :
+          case XType.GDAY :
+          case XType.GMONTH :
+            return valType;
+
+          case XType.DURATION :
+          case XType.YEARMONTHDURATION :
+          case XType.DAYTIMEDURATION :
+            // Normalize this for duration so that a quick 
+            // switch can be made in execute(XPathContext xctxt) 
+            // to make the duration the second argument.
+            return valType;//XType.DURATION;
+            }
+        break;
+
+      case XType.BOOLEAN :
+      case XType.STRING :
+      case XType.DECIMAL :
+        return requiredType;
+    }
+    return valType;
+  }
+  
+
+}
diff --git a/src/org/apache/xpath/operations/OperationSimple.java b/src/org/apache/xpath/operations/OperationSimple.java
new file mode 100644
index 0000000..7fe1558
--- /dev/null
+++ b/src/org/apache/xpath/operations/OperationSimple.java
@@ -0,0 +1,109 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * 
+ * 
+ * Created Jul 31, 2002
+ * @author sboag
+ */
+public abstract class OperationSimple extends Operation
+{
+  /**
+   * Execute a binary operation by calling execute on each of the operands,
+   * and then calling the operate method on the derived class.
+   *
+   *
+   * @param xctxt The runtime execution context.
+   *
+   * @return The XObject result of the operation.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject execute(XPathContext xctxt)
+          throws javax.xml.transform.TransformerException
+  {
+
+    XObject left = m_left.execute(xctxt, true);
+    XObject right = m_right.execute(xctxt, true);
+
+    XObject result = operate(left, right);
+    left.detach();
+    right.detach();
+    return result;
+  }
+
+  /**
+   * Apply the operation to two operands, and return the result.
+   *
+   *
+   * @param left non-null reference to the evaluated left operand.
+   * @param right non-null reference to the evaluated right operand.
+   *
+   * @return non-null reference to the XObject that represents the result of the operation.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public abstract XObject operate(XObject left, XObject right)
+          throws javax.xml.transform.TransformerException;
+
+
+}
diff --git a/src/org/apache/xpath/operations/Or.java b/src/org/apache/xpath/operations/Or.java
index ad4d756..daf188e 100644
--- a/src/org/apache/xpath/operations/Or.java
+++ b/src/org/apache/xpath/operations/Or.java
@@ -69,6 +69,13 @@
  */
 public class Or extends Operation
 {
+  /**
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
+   */
+  public OpFuncLookupTable getLookupTable()
+  {
+    return null;
+  }
 
   /**
    * OR two expressions and return the boolean result. Override
diff --git a/src/org/apache/xpath/operations/Pos.java b/src/org/apache/xpath/operations/Pos.java
new file mode 100644
index 0000000..88a3eb4
--- /dev/null
+++ b/src/org/apache/xpath/operations/Pos.java
@@ -0,0 +1,41 @@
+package org.apache.xpath.operations;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xpath.objects.XObject;
+
+public class Pos extends Neg
+{
+  /**
+   * Apply the operation to two operands, and return the result.
+   *
+   *
+   * @param right non-null reference to the evaluated right operand.
+   *
+   * @return non-null reference to the XObject that represents the result of the operation.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject operate(XObject right) throws javax.xml.transform.TransformerException
+  {
+    return new XDouble(+right.num());
+  }
+  
+  /**
+   * Evaluate this operation directly to a double.
+   *
+   * @param xctxt The runtime execution context.
+   *
+   * @return The result of the operation as a double.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public double num(XPathContext xctxt)
+          throws javax.xml.transform.TransformerException
+  {
+
+    return +(m_right.num(xctxt));
+  }
+
+}
+
diff --git a/src/org/apache/xpath/operations/Precedes.java b/src/org/apache/xpath/operations/Precedes.java
new file mode 100644
index 0000000..9c935ef
--- /dev/null
+++ b/src/org/apache/xpath/operations/Precedes.java
@@ -0,0 +1,83 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XBoolean;
+
+/**
+ * The '!=' operation expression executer.
+ */
+public class Precedes extends OperationSimple
+{
+  /**
+   * Apply the operation to two operands, and return the result.
+   *
+   *
+   * @param left non-null reference to the evaluated left operand.
+   * @param right non-null reference to the evaluated right operand.
+   *
+   * @return non-null reference to the XObject that represents the result of the operation.
+   *
+   * @throws javax.xml.transform.TransformerException
+   */
+  public XObject operate(XObject left, XObject right)
+          throws javax.xml.transform.TransformerException
+  {
+  	throw new javax.xml.transform.TransformerException("'Follows' not yet implemented!", this);
+  }
+}
diff --git a/src/org/apache/xpath/operations/Quo.java b/src/org/apache/xpath/operations/Quo.java
index 4700552..1ccc4e3 100644
--- a/src/org/apache/xpath/operations/Quo.java
+++ b/src/org/apache/xpath/operations/Quo.java
@@ -56,16 +56,16 @@
  */
 package org.apache.xpath.operations;
 
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.objects.XDouble;
 import org.apache.xpath.objects.XObject;
-import org.apache.xpath.objects.XNumber;
 
 /**
  * The 'quo' operation expression executer. (no longer supported by XPath).
  * @deprecated.
  */
-public class Quo extends Operation
+public class Quo extends OperationSimple
 {
-
   // Actually, this is no longer supported by xpath...
 
   /**
@@ -82,6 +82,6 @@
   public XObject operate(XObject left, XObject right)
           throws javax.xml.transform.TransformerException
   {
-    return new XNumber((int) (left.num() / right.num()));
+    return new XDouble((int) (left.num() / right.num()));
   }
 }
diff --git a/src/org/apache/xpath/operations/Subtract.java b/src/org/apache/xpath/operations/Subtract.java
new file mode 100644
index 0000000..d1fdee9
--- /dev/null
+++ b/src/org/apache/xpath/operations/Subtract.java
@@ -0,0 +1,258 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.operations;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.DateTimeObj;
+import org.apache.xml.utils.Duration;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XDate;
+import org.apache.xpath.objects.XDateTime;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xpath.objects.XDuration;
+import org.apache.xpath.objects.XDTDuration;
+import org.apache.xpath.objects.XYMDuration;
+import org.apache.xpath.objects.XFloat;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XTime;
+
+/**
+ * The binary '-' operation expression executer.
+ */
+public class Subtract extends OperationNormalized
+{
+  static OpFuncLookupTable m_funcs;
+  {
+    m_funcs = new OpFuncLookupTable();
+    m_funcs.setFunc(XType.DOUBLE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XDouble(lhs.num() - rhs.num());
+      }
+    });
+    m_funcs.setFunc(XType.FLOAT, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XFloat(lhs.floatVal() - rhs.floatVal());
+      }
+    });
+    m_funcs.setFunc(XType.INTEGER, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        return new XInteger(lhs.integer() - rhs.integer());
+      }
+    });
+    m_funcs.setFunc(XType.DECIMAL, NOTSUPPORTED);
+
+    m_funcs.setFunc(XType.DURATION, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        Duration duration1 = lhs.duration();
+        // The normalizer should make sure the second argument is always 
+        // a duration!
+        Duration duration2 = rhs.duration();
+        Duration du = duration1.subtractDTDuration(duration2);
+        return new XDuration(du);
+      }
+    });
+    m_funcs.setFunc(XType.DAYTIMEDURATION, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        // for now...
+        int rhsVT = rhs.getValueType();
+        if(XType.DURATION == rhsVT 
+          || XType.DAYTIMEDURATION == rhsVT)
+          {
+        Duration duration1 = lhs.duration();
+        // The normalizer should make sure the second argument is always 
+        // a duration!
+        Duration duration2 = rhs.duration();
+        Duration du = duration1.subtractDTDuration(duration2);
+        return new XDTDuration(du);
+      }
+        else
+        {
+        	throw new TransformerException("Type Exception!");
+        }
+      }
+    });
+    m_funcs.setFunc(XType.YEARMONTHDURATION, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        // for now...
+        int rhsVT = rhs.getValueType();
+        if(XType.DURATION == rhsVT 
+          || XType.YEARMONTHDURATION == rhsVT)
+          {
+        Duration duration1 = lhs.duration();
+        // The normalizer should make sure the second argument is always 
+        // a duration!
+        Duration duration2 = rhs.duration();
+        Duration du = duration1.subtractYMDuration(duration2);
+        return new XYMDuration(du);
+      }
+        else
+        {
+         throw new TransformerException("Type Exception!");
+        }
+      }
+    });
+    
+    m_funcs.setFunc(XType.DATETIME, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        DateTimeObj dt = lhs.datetime();
+        // The normalizer should
+        int rhsVT = rhs.getValueType();
+        if(XType.DURATION == rhsVT 
+          || XType.DAYTIMEDURATION == rhsVT)
+        {
+          Duration duration2 = rhs.duration();
+          DateTimeObj du = dt.subtractDTDurationFromDateTime(duration2);
+         return new XDateTime(du);
+        }
+        else //if(XType.YEARMONTHDURATION == rhsVT)
+        {
+          Duration duration2 = rhs.duration();
+          DateTimeObj du = dt.subtractYMDurationFromDateTime(duration2);
+         return new XDateTime(du);
+        }
+      }
+    });
+    m_funcs.setFunc(XType.TIME, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        DateTimeObj oldTime = lhs.time();
+        // The normalizer should
+        Duration duration2 = rhs.duration();
+        
+        DateTimeObj newTime = oldTime.subtractDTDurationFromTime(duration2);
+        return new XTime(newTime);
+      }
+    });
+    m_funcs.setFunc(XType.DATE, new GenericOpFunc()
+    {
+      public XObject operate(XPathContext xctxt, XObject lhs, XObject rhs)
+        throws TransformerException
+      {
+        DateTimeObj dt = lhs.date();
+        // The normalizer should
+        int rhsVT = rhs.getValueType();
+        if(XType.DURATION == rhsVT 
+          || XType.DAYTIMEDURATION == rhsVT)
+        {
+          Duration duration2 = rhs.duration();
+          DateTimeObj newDate = dt.subtractDTDurationFromDate(duration2);
+          return new XDate(newDate);
+        }
+       else if(XType.YEARMONTHDURATION == rhsVT)
+        {
+          Duration duration2 = rhs.duration();
+          DateTimeObj newDate = dt.subtractYMDurationFromDate(duration2);
+          return new XDate(newDate);
+        }
+        else
+        {
+          DateTimeObj dt2 = rhs.date();
+          Duration duration = dt.subtractDateFromDate(dt2);
+          return new XDuration(duration);
+        }
+      }
+    });
+    m_funcs.setFunc(XType.GYEARMONTH, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GYEAR, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GMONTHDAY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GDAY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.GMONTH, NOTSUPPORTED);
+
+    m_funcs.setFunc(XType.BOOLEAN, NOTSUPPORTED);
+    m_funcs.setFunc(XType.STRING, NOTSUPPORTED);
+    m_funcs.setFunc(XType.BASE64BINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.HEXBINARY, NOTSUPPORTED);
+    m_funcs.setFunc(XType.ANYURI, NOTSUPPORTED);
+    m_funcs.setFunc(XType.QNAME, NOTSUPPORTED);
+    m_funcs.setFunc(XType.NOTATION, NOTSUPPORTED);
+  }
+  
+  /**
+   * @see org.apache.xpath.operations.Operation#getLookupTable()
+   */
+  public OpFuncLookupTable getLookupTable()
+  {
+    return m_funcs;
+  }
+
+}
diff --git a/src/org/apache/xpath/operations/UnaryOperation.java b/src/org/apache/xpath/operations/UnaryOperation.java
index 19a67f7..a1453b5 100644
--- a/src/org/apache/xpath/operations/UnaryOperation.java
+++ b/src/org/apache/xpath/operations/UnaryOperation.java
@@ -56,13 +56,12 @@
  */
 package org.apache.xpath.operations;
 
-import java.util.Vector;
-
-import javax.xml.transform.TransformerException;
 import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
-import org.apache.xpath.ExpressionOwner;
 import org.apache.xpath.objects.XObject;
 
 /**
@@ -85,9 +84,9 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    m_right.fixupVariables(vars, globalsSize);
+    m_right.fixupVariables(vcs);
   }
   
   /**
@@ -196,6 +195,49 @@
   		
   	return true;
   }
+  
+  /**
+   * Add the left or right node of the operation.
+   */
+  public void jjtAddChild(org.apache.xpath.parser.Node n, int i) 
+  {
+  	n = fixupPrimarys(n);  // yuck.
+  	if(0 == i)
+  	{
+    	m_right = (Expression)n;
+    	m_right.exprSetParent(this);
+  	}
+  	else
+  	{
+  		// assertion... should not be able to occur.
+  		throw new RuntimeException("Can't add more than one child to an UnaryOperation!");
+  	}
+  }
+  
+  /** This method returns a child node.  The children are numbered
+     from zero, left to right. */
+  public ExpressionNode exprGetChild(int i)
+  {
+  	assertion(i == 0, "UnaryOperation can only have one child!");
+  	return m_right;
+  }
+
+  /** Return the number of children the node has. */
+  public int exprGetNumChildren()
+  {
+  	int count = 0;
+   	if(null != m_right)
+  		count++;
+  	return count;
+  }
+
+  /**
+   * Tell if this node should have it's PathExpr ancestory reduced.
+   */
+  public boolean isPathExprReduced()
+  {
+  	return true;
+  }
 
 
 }
diff --git a/src/org/apache/xpath/operations/Variable.java b/src/org/apache/xpath/operations/Variable.java
index bba942d..f15be04 100644
--- a/src/org/apache/xpath/operations/Variable.java
+++ b/src/org/apache/xpath/operations/Variable.java
@@ -59,15 +59,12 @@
 import java.util.Vector;
 
 import javax.xml.transform.TransformerException;
+
 import org.apache.xalan.res.XSLMessages;
-import org.apache.xalan.templates.ElemTemplateElement;
-import org.apache.xalan.templates.ElemVariable;
-import org.apache.xalan.templates.Stylesheet;
-import org.apache.xml.utils.PrefixResolver;
 import org.apache.xml.utils.QName;
 import org.apache.xpath.Expression;
-import org.apache.xpath.ExpressionNode;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPath;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
@@ -75,9 +72,8 @@
 import org.apache.xpath.axes.WalkerFactory;
 import org.apache.xpath.objects.XNodeSet;
 import org.apache.xpath.objects.XObject;
+import org.apache.xpath.parser.Node;
 import org.apache.xpath.res.XPATHErrorResources;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
 
 
 /**
@@ -157,9 +153,11 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
     m_fixUpWasCalled = true;
+    Vector vars = vcs.getVariableNames();
+    int globalsSize = vcs.getGlobalsSize();
     int sz = vars.size();
 
     for (int i = vars.size()-1; i >= 0; i--) 
@@ -428,5 +426,38 @@
   	return false;
   }
   
+  /**
+   * Tell if this node should have it's PathExpr ancestory reduced.
+   */
+  public boolean isPathExprReduced()
+  {
+  	// Assume that the parent of the parent is always a PathExpr when this 
+  	// method is called.
+  	Node pathOwner = jjtGetParent().jjtGetParent();
+  	return pathOwner.jjtGetNumChildren() == 1 ? true : false;
+  }
+
+  public java.lang.String toString()
+  {
+  	return "$"+m_qname;
+  }
+
+  /**
+   * Returns the fixUpWasCalled.
+   * @return boolean
+   */
+  public boolean isFixUpWasCalled()
+  {
+    return m_fixUpWasCalled;
+  }
+
+  /**
+   * Sets the fixUpWasCalled.
+   * @param fixUpWasCalled The fixUpWasCalled to set
+   */
+  public void setFixUpWasCalled(boolean fixUpWasCalled)
+  {
+    m_fixUpWasCalled = fixUpWasCalled;
+  }
 
 }
diff --git a/src/org/apache/xpath/parser/ASCII_CharStream.java b/src/org/apache/xpath/parser/ASCII_CharStream.java
new file mode 100644
index 0000000..43ae731
--- /dev/null
+++ b/src/org/apache/xpath/parser/ASCII_CharStream.java
@@ -0,0 +1,377 @@
+/* Generated By:JavaCC: Do not edit this line. ASCII_CharStream.java Version 0.7pre6 */
+/**
+ * An implementation of interface CharStream, where the stream is assumed to
+ * contain only ASCII characters (without unicode processing).
+ */
+
+package org.apache.xpath.parser;
+
+public final class ASCII_CharStream
+{
+  public static final boolean staticFlag = false;
+  int bufsize;
+  int available;
+  int tokenBegin;
+  public int bufpos = -1;
+  private int bufline[];
+  private int bufcolumn[];
+
+  private int column = 0;
+  private int line = 1;
+
+  private boolean prevCharIsCR = false;
+  private boolean prevCharIsLF = false;
+
+  private java.io.Reader inputStream;
+
+  private char[] buffer;
+  private int maxNextCharInd = 0;
+  private int inBuf = 0;
+
+  private final void ExpandBuff(boolean wrapAround)
+  {
+     char[] newbuffer = new char[bufsize + 2048];
+     int newbufline[] = new int[bufsize + 2048];
+     int newbufcolumn[] = new int[bufsize + 2048];
+
+     try
+     {
+        if (wrapAround)
+        {
+           System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+           System.arraycopy(buffer, 0, newbuffer,
+                                             bufsize - tokenBegin, bufpos);
+           buffer = newbuffer;
+
+           System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
+           System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
+           bufline = newbufline;
+
+           System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
+           System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
+           bufcolumn = newbufcolumn;
+
+           maxNextCharInd = (bufpos += (bufsize - tokenBegin));
+        }
+        else
+        {
+           System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+           buffer = newbuffer;
+
+           System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
+           bufline = newbufline;
+
+           System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
+           bufcolumn = newbufcolumn;
+
+           maxNextCharInd = (bufpos -= tokenBegin);
+        }
+     }
+     catch (Throwable t)
+     {
+        throw new Error(t.getMessage());
+     }
+
+
+     bufsize += 2048;
+     available = bufsize;
+     tokenBegin = 0;
+  }
+
+  private final void FillBuff() throws java.io.IOException
+  {
+     if (maxNextCharInd == available)
+     {
+        if (available == bufsize)
+        {
+           if (tokenBegin > 2048)
+           {
+              bufpos = maxNextCharInd = 0;
+              available = tokenBegin;
+           }
+           else if (tokenBegin < 0)
+              bufpos = maxNextCharInd = 0;
+           else
+              ExpandBuff(false);
+        }
+        else if (available > tokenBegin)
+           available = bufsize;
+        else if ((tokenBegin - available) < 2048)
+           ExpandBuff(true);
+        else
+           available = tokenBegin;
+     }
+
+     int i;
+     try {
+        if ((i = inputStream.read(buffer, maxNextCharInd,
+                                    available - maxNextCharInd)) == -1)
+        {
+           inputStream.close();
+           throw new java.io.IOException();
+        }
+        else
+           maxNextCharInd += i;
+        return;
+     }
+     catch(java.io.IOException e) {
+        --bufpos;
+        backup(0);
+        if (tokenBegin == -1)
+           tokenBegin = bufpos;
+        throw e;
+     }
+  }
+
+  public final char BeginToken() throws java.io.IOException
+  {
+     tokenBegin = -1;
+     char c = readChar();
+     tokenBegin = bufpos;
+
+     return c;
+  }
+
+  private final void UpdateLineColumn(char c)
+  {
+     column++;
+
+     if (prevCharIsLF)
+     {
+        prevCharIsLF = false;
+        line += (column = 1);
+     }
+     else if (prevCharIsCR)
+     {
+        prevCharIsCR = false;
+        if (c == '\n')
+        {
+           prevCharIsLF = true;
+        }
+        else
+           line += (column = 1);
+     }
+
+     switch (c)
+     {
+        case '\r' :
+           prevCharIsCR = true;
+           break;
+        case '\n' :
+           prevCharIsLF = true;
+           break;
+        case '\t' :
+           column--;
+           column += (8 - (column & 07));
+           break;
+        default :
+           break;
+     }
+
+     bufline[bufpos] = line;
+     bufcolumn[bufpos] = column;
+  }
+
+  public final char readChar() throws java.io.IOException
+  {
+     if (inBuf > 0)
+     {
+        --inBuf;
+        return (char)((char)0xff & buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos]);
+     }
+
+     if (++bufpos >= maxNextCharInd)
+        FillBuff();
+
+     char c = (char)((char)0xff & buffer[bufpos]);
+
+     UpdateLineColumn(c);
+     return (c);
+  }
+
+  /**
+   * @deprecated 
+   * @see #getEndColumn
+   */
+
+  public final int getColumn() {
+     return bufcolumn[bufpos];
+  }
+
+  /**
+   * @deprecated 
+   * @see #getEndLine
+   */
+
+  public final int getLine() {
+     return bufline[bufpos];
+  }
+
+  public final int getEndColumn() {
+     return bufcolumn[bufpos];
+  }
+
+  public final int getEndLine() {
+     return bufline[bufpos];
+  }
+
+  public final int getBeginColumn() {
+     return bufcolumn[tokenBegin];
+  }
+
+  public final int getBeginLine() {
+     return bufline[tokenBegin];
+  }
+
+  public final void backup(int amount) {
+
+    inBuf += amount;
+    if ((bufpos -= amount) < 0)
+       bufpos += bufsize;
+  }
+
+  public ASCII_CharStream(java.io.Reader dstream, int startline,
+  int startcolumn, int buffersize)
+  {
+    inputStream = dstream;
+    line = startline;
+    column = startcolumn - 1;
+
+    available = bufsize = buffersize;
+    buffer = new char[buffersize];
+    bufline = new int[buffersize];
+    bufcolumn = new int[buffersize];
+  }
+
+  public ASCII_CharStream(java.io.Reader dstream, int startline,
+                                                           int startcolumn)
+  {
+     this(dstream, startline, startcolumn, 4096);
+  }
+  public void ReInit(java.io.Reader dstream, int startline,
+  int startcolumn, int buffersize)
+  {
+    inputStream = dstream;
+    line = startline;
+    column = startcolumn - 1;
+
+    if (buffer == null || buffersize != buffer.length)
+    {
+      available = bufsize = buffersize;
+      buffer = new char[buffersize];
+      bufline = new int[buffersize];
+      bufcolumn = new int[buffersize];
+    }
+    prevCharIsLF = prevCharIsCR = false;
+    tokenBegin = inBuf = maxNextCharInd = 0;
+    bufpos = -1;
+  }
+
+  public void ReInit(java.io.Reader dstream, int startline,
+                                                           int startcolumn)
+  {
+     ReInit(dstream, startline, startcolumn, 4096);
+  }
+  public ASCII_CharStream(java.io.InputStream dstream, int startline,
+  int startcolumn, int buffersize)
+  {
+     this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
+  }
+
+  public ASCII_CharStream(java.io.InputStream dstream, int startline,
+                                                           int startcolumn)
+  {
+     this(dstream, startline, startcolumn, 4096);
+  }
+
+  public void ReInit(java.io.InputStream dstream, int startline,
+  int startcolumn, int buffersize)
+  {
+     ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
+  }
+  public void ReInit(java.io.InputStream dstream, int startline,
+                                                           int startcolumn)
+  {
+     ReInit(dstream, startline, startcolumn, 4096);
+  }
+  public final String GetImage()
+  {
+     if (bufpos >= tokenBegin)
+        return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
+     else
+        return new String(buffer, tokenBegin, bufsize - tokenBegin) +
+                              new String(buffer, 0, bufpos + 1);
+  }
+
+  public final char[] GetSuffix(int len)
+  {
+     char[] ret = new char[len];
+
+     if ((bufpos + 1) >= len)
+        System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
+     else
+     {
+        System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
+                                                          len - bufpos - 1);
+        System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
+     }
+
+     return ret;
+  }
+
+  public void Done()
+  {
+     buffer = null;
+     bufline = null;
+     bufcolumn = null;
+  }
+
+  /**
+   * Method to adjust line and column numbers for the start of a token.<BR>
+   */
+  public void adjustBeginLineColumn(int newLine, int newCol)
+  {
+     int start = tokenBegin;
+     int len;
+
+     if (bufpos >= tokenBegin)
+     {
+        len = bufpos - tokenBegin + inBuf + 1;
+     }
+     else
+     {
+        len = bufsize - tokenBegin + bufpos + 1 + inBuf;
+     }
+
+     int i = 0, j = 0, k = 0;
+     int nextColDiff = 0, columnDiff = 0;
+
+     while (i < len &&
+            bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
+     {
+        bufline[j] = newLine;
+        nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
+        bufcolumn[j] = newCol + columnDiff;
+        columnDiff = nextColDiff;
+        i++;
+     } 
+
+     if (i < len)
+     {
+        bufline[j] = newLine++;
+        bufcolumn[j] = newCol + columnDiff;
+
+        while (i++ < len)
+        {
+           if (bufline[j = start % bufsize] != bufline[++start % bufsize])
+              bufline[j] = newLine++;
+           else
+              bufline[j] = newLine;
+        }
+     }
+
+     line = bufline[j];
+     column = bufcolumn[j];
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/AnyKindTest.java b/src/org/apache/xpath/parser/AnyKindTest.java
new file mode 100644
index 0000000..6b81274
--- /dev/null
+++ b/src/org/apache/xpath/parser/AnyKindTest.java
@@ -0,0 +1,21 @@
+package org.apache.xpath.parser;
+
+import org.apache.xml.dtm.DTMFilter;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class AnyKindTest extends KindTest
+{
+   public AnyKindTest(XPath parser)
+   {
+  	 super(parser);
+   }
+
+   public int getWhatToShow()
+   {
+      return DTMFilter.SHOW_ALL;
+   }
+}
+
diff --git a/src/org/apache/xpath/parser/AtomicType.java b/src/org/apache/xpath/parser/AtomicType.java
new file mode 100644
index 0000000..af78f33
--- /dev/null
+++ b/src/org/apache/xpath/parser/AtomicType.java
@@ -0,0 +1,100 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.parser;
+
+import org.apache.xml.dtm.XType;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 17, 2002
+ * @author sboag
+ */
+public class AtomicType extends NonExecutableExpression
+{
+
+  /**
+   * Constructor for AtomicType.
+   * @param parser
+   * @param value
+   */
+  public AtomicType(XPath parser, String value)
+  {
+    super(parser, value);
+  }
+
+  /**
+   * Constructor for AtomicType.
+   * @param parser
+   */
+  public AtomicType(XPath parser)
+  {
+    super(parser);
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtSetParent(Node)
+   */
+  public void jjtSetParent(Node n)
+  {
+    QName qname = (QName)jjtGetChild(0);
+    int id = XType.getTypeFromQName(qname.getQName());
+    ((ItemType)n).setAtomicTypeID(id);
+    super.jjtSetParent(n);
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/CommentTest.java b/src/org/apache/xpath/parser/CommentTest.java
new file mode 100644
index 0000000..314d50e
--- /dev/null
+++ b/src/org/apache/xpath/parser/CommentTest.java
@@ -0,0 +1,21 @@
+package org.apache.xpath.parser;
+
+import org.apache.xml.dtm.DTMFilter;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class CommentTest extends KindTest
+{
+   public CommentTest(XPath parser)
+   {
+  	 super(parser);
+   }
+
+   public int getWhatToShow()
+   {
+      return DTMFilter.SHOW_COMMENT;
+   }	
+}
+
diff --git a/src/org/apache/xpath/parser/ElemOrAttrType.java b/src/org/apache/xpath/parser/ElemOrAttrType.java
new file mode 100644
index 0000000..60e5f59
--- /dev/null
+++ b/src/org/apache/xpath/parser/ElemOrAttrType.java
@@ -0,0 +1,153 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.parser;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 17, 2002
+ * @author sboag
+ */
+public class ElemOrAttrType extends NonExecutableExpression
+{
+  /** The ElemOrAttrType name, meaning the tag QName, may be null. */
+  private org.apache.xml.utils.QName m_elemOrAttrName;
+
+  /** The SchemaType name, meaning the tag QName, may be null. */
+  private org.apache.xml.utils.QName m_schemaTypeName;
+
+  /**
+   * Constructor for ElemOrAttrType.
+   * @param parser
+   * @param value
+   */
+  public ElemOrAttrType(XPath parser, String value)
+  {
+    super(parser, value);
+  }
+
+  /**
+   * Constructor for ElemOrAttrType.
+   * @param parser
+   */
+  public ElemOrAttrType(XPath parser)
+  {
+    super(parser);
+  }
+  
+  /**
+   * Returns the elemOrAttrName.
+   * @return org.apache.xml.utils.QName
+   */
+  public org.apache.xml.utils.QName getElemOrAttrName()
+  {
+    return m_elemOrAttrName;
+  }
+
+  /**
+   * Returns the schemaTypeName.
+   * @return org.apache.xml.utils.QName
+   */
+  public org.apache.xml.utils.QName getSchemaTypeName()
+  {
+    return m_schemaTypeName;
+  }
+
+  /**
+   * Sets the elemOrAttrName.
+   * @param elemOrAttrName The elemOrAttrName to set
+   */
+  public void setElemOrAttrName(org.apache.xml.utils.QName elemOrAttrName)
+  {
+    m_elemOrAttrName = elemOrAttrName;
+  }
+
+  /**
+   * Sets the schemaTypeName.
+   * @param schemaTypeName The schemaTypeName to set
+   */
+  public void setSchemaTypeName(org.apache.xml.utils.QName schemaTypeName)
+  {
+    m_schemaTypeName = schemaTypeName;
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtSetParent(Node)
+   */
+  public void jjtSetParent(Node n)
+  {
+    ItemType itype = (ItemType)n;
+    itype.setElemOrAttrName(m_elemOrAttrName);
+    
+    itype.setSchemaTypeName(m_schemaTypeName);
+    super.jjtSetParent(n);
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtAddChild(Node, int)
+   */
+  public void jjtAddChild(Node n, int i)
+  {
+    super.jjtAddChild(n, i);
+    if(n instanceof QName && !(n instanceof SchemaType))
+    {
+      QName qname = (QName)n;
+      m_elemOrAttrName = qname.getQName();
+    }
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/Empty.java b/src/org/apache/xpath/parser/Empty.java
new file mode 100644
index 0000000..cb92d16
--- /dev/null
+++ b/src/org/apache/xpath/parser/Empty.java
@@ -0,0 +1,87 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.parser;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 17, 2002
+ * @author sboag
+ */
+public class Empty extends NonExecutableExpression
+{
+
+  /**
+   * Constructor for Empty.
+   * @param parser
+   * @param value
+   */
+  public Empty(XPath parser, String value)
+  {
+    super(parser, value);
+  }
+
+  /**
+   * Constructor for Empty.
+   * @param parser
+   */
+  public Empty(XPath parser)
+  {
+    super(parser);
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/ForClause.java b/src/org/apache/xpath/parser/ForClause.java
new file mode 100644
index 0000000..c81d6dc
--- /dev/null
+++ b/src/org/apache/xpath/parser/ForClause.java
@@ -0,0 +1,64 @@
+/* Generated By:JJTree: Do not edit this line. ForClause.java */
+
+package org.apache.xpath.parser;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.operations.Variable;
+import org.apache.xpath.seqctor.Binding;
+import org.apache.xpath.seqctor.FLWRExpr;
+
+/**
+ * ForClause ::= <"for" "$"> VarName "in" 
+ *                  Expr ("," "$" VarName "in" Expr)* 
+ * 
+ * Created Jul 18, 2002
+ * @author sboag
+ */
+public class ForClause extends NonExecutableExpression
+{
+	
+  public ForClause(XPath parser) {
+    super(parser);
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtSetParent(Node)
+   */
+  public void jjtSetParent(Node n)
+  {
+    super.jjtSetParent(n);
+    FLWRExpr flwr = (FLWRExpr)n;
+    int vsize = m_exprs.size();
+    // vsize--;
+    Binding[] bindings = new Binding[vsize/3];
+    
+    int bindingIndex = 0;
+    for (int i = 0; i < vsize; i+=3)
+    {
+      Variable var = (Variable)m_exprs.elementAt(i);
+      try
+      {
+        Binding binding = new Binding();
+        binding.setVar(var);
+        bindings[bindingIndex] = binding;
+        bindingIndex++;
+        var.jjtSetParent(flwr);
+      }
+      catch (java.lang.NullPointerException e)
+      {
+        throw e;
+      }
+    }
+    bindingIndex = 0;
+    // Ignore the "in" node.  (It should really be void)
+    for (int i = 2; i < vsize; i+=3)
+    {
+      Expression expr = (Expression)m_exprs.elementAt(i);
+      expr = (Expression)fixupPrimarys(expr);
+      bindings[bindingIndex++].setExpr(expr);
+      expr.jjtSetParent(flwr);
+    }
+    flwr.setBindings(bindings);
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/IfExpr.java b/src/org/apache/xpath/parser/IfExpr.java
new file mode 100644
index 0000000..4931f6a
--- /dev/null
+++ b/src/org/apache/xpath/parser/IfExpr.java
@@ -0,0 +1,25 @@
+package org.apache.xpath.parser;
+
+
+
+public class IfExpr extends NonExecutableExpression
+{
+
+  /**
+   * Constructor for IfExpr
+   */
+  public IfExpr(XPath parser)
+  {
+    super(parser);
+  }
+
+  /**
+   * @see SimpleNode#shouldReduceIfOneChild()
+   */
+  public boolean shouldReduceIfOneChild()
+  {
+    return (jjtGetNumChildren() == 1) ? true : false;
+  }
+
+}
+
diff --git a/src/org/apache/xpath/parser/In.java b/src/org/apache/xpath/parser/In.java
new file mode 100644
index 0000000..d71cf6e
--- /dev/null
+++ b/src/org/apache/xpath/parser/In.java
@@ -0,0 +1,26 @@
+/* Generated By:JJTree: Do not edit this line. In.java */
+
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+// This node could probably be void. -sb
+public class In extends NonExecutableExpression
+{
+	
+  public In(XPath parser) {
+    super(parser);
+  }
+
+  /** Accept the visitor. **/
+  public Object jjtAccept(org.apache.xpath.parser.XPathVisitor visitor, Object data) {
+    return visitor.visit(this, data);
+  }
+  
+}
diff --git a/src/org/apache/xpath/parser/Instanceof.java b/src/org/apache/xpath/parser/Instanceof.java
new file mode 100644
index 0000000..a820572
--- /dev/null
+++ b/src/org/apache/xpath/parser/Instanceof.java
@@ -0,0 +1,14 @@
+package org.apache.xpath.parser;
+public class Instanceof extends NonExecutableExpression
+{
+
+  /**
+   * Constructor for InstanceofExpr
+   */
+  public Instanceof(XPath parser)
+  {
+    super(parser);
+  }
+
+}
+
diff --git a/src/org/apache/xpath/parser/ItemType.java b/src/org/apache/xpath/parser/ItemType.java
new file mode 100644
index 0000000..15ad2fb
--- /dev/null
+++ b/src/org/apache/xpath/parser/ItemType.java
@@ -0,0 +1,200 @@
+/* Generated By:JJTree: Do not edit this line. ItemType.java */
+
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.types.InstanceofExpr;
+
+public class ItemType extends NonExecutableExpression
+{
+  /** The sequence on which to act. **/
+  private Expression m_targetExpr;
+  
+  /** The node type value, one of DTMFilter.SHOW_ATTRIBUTE, etc. **/
+  private int m_whatToShow;
+  
+  /** The atomic type ID, one of XType.BOOLEAN, etc. **/
+  private int m_atomicTypeID;
+  
+  /** The occurance indicator ID.  One of ZERO_OR_MORE, etc. or EMPTY_SEQ **/
+  private int m_occurrenceIndicator = InstanceofExpr.ONE_OR_MORE;
+  
+  /** The ElemOrAttrType name, meaning the tag QName, may be null. */
+  private org.apache.xml.utils.QName m_elemOrAttrName;
+
+  /** The SchemaType name, meaning the tag QName, may be null. */
+  private org.apache.xml.utils.QName m_schemaTypeName;
+  
+  /** SchemaContext is not executable for the moment, so leave it 
+   * as a NEE until we figure out what we want to do with it. **/
+  private SchemaContext m_schemaContext;
+	
+
+  /**
+   * Constructor for ItemType.
+   * @param parser
+   * @param value
+   */
+  public ItemType(XPath parser, String value)
+  {
+    super(parser, value);
+  }
+
+  /**
+   * Constructor for ItemType.
+   * @param parser
+   */
+  public ItemType(XPath parser)
+  {
+    super(parser);
+  }
+
+  /**
+   * Returns the occurrenceIndicator.
+   * @return int
+   */
+  public int getOccurrenceIndicator()
+  {
+    return m_occurrenceIndicator;
+  }
+
+  /**
+   * Returns the schemaContext.
+   * @return SchemaContext
+   */
+  public SchemaContext getSchemaContext()
+  {
+    return m_schemaContext;
+  }
+
+  /**
+   * Returns the schemaTypeName.
+   * @return org.apache.xml.utils.QName
+   */
+  public org.apache.xml.utils.QName getSchemaTypeName()
+  {
+    return m_schemaTypeName;
+  }
+
+  /**
+   * Returns the targetExpr.
+   * @return Expression
+   */
+  public Expression getTargetExpr()
+  {
+    return m_targetExpr;
+  }
+
+  /**
+   * Returns the whatToShow.
+   * @return int
+   */
+  public int getWhatToShow()
+  {
+    return m_whatToShow;
+  }
+
+  /**
+   * Sets the occurrenceIndicator.
+   * @param occurrenceIndicator The occurrenceIndicator to set
+   */
+  public void setOccurrenceIndicator(int occurrenceIndicator)
+  {
+    m_occurrenceIndicator = occurrenceIndicator;
+  }
+
+  /**
+   * Sets the schemaContext.
+   * @param schemaContext The schemaContext to set
+   */
+  public void setSchemaContext(SchemaContext schemaContext)
+  {
+    m_schemaContext = schemaContext;
+  }
+
+  /**
+   * Sets the schemaTypeName.
+   * @param schemaTypeName The schemaTypeName to set
+   */
+  public void setSchemaTypeName(org.apache.xml.utils.QName schemaTypeName)
+  {
+    m_schemaTypeName = schemaTypeName;
+  }
+
+  /**
+   * Sets the targetExpr.
+   * @param targetExpr The targetExpr to set
+   */
+  public void setTargetExpr(Expression targetExpr)
+  {
+    m_targetExpr = targetExpr;
+  }
+
+  /**
+   * Sets the whatToShow.
+   * @param whatToShow The whatToShow to set
+   */
+  public void setWhatToShow(int whatToShow)
+  {
+    m_whatToShow = whatToShow;
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtSetParent(Node)
+   */
+  public void jjtSetParent(Node n)
+  {
+    SequenceType stype = (SequenceType)n;
+    stype.setAtomicTypeID(m_atomicTypeID);
+    stype.setElemOrAttrName(m_elemOrAttrName);
+    stype.setOccurrenceIndicator(m_occurrenceIndicator);
+    stype.setSchemaContext(m_schemaContext);
+    stype.setSchemaTypeName(m_schemaTypeName);
+    stype.setWhatToShow(m_whatToShow);
+    super.jjtSetParent(n);
+  }
+
+  /**
+   * Returns the atomicTypeID.
+   * @return int
+   */
+  public int getAtomicTypeID()
+  {
+    return m_atomicTypeID;
+  }
+
+  /**
+   * Returns the elemOrAttrName.
+   * @return org.apache.xml.utils.QName
+   */
+  public org.apache.xml.utils.QName getElemOrAttrName()
+  {
+    return m_elemOrAttrName;
+  }
+
+  /**
+   * Sets the atomicTypeID.
+   * @param atomicTypeID The atomicTypeID to set
+   */
+  public void setAtomicTypeID(int atomicTypeID)
+  {
+    m_atomicTypeID = atomicTypeID;
+  }
+
+  /**
+   * Sets the elemOrAttrName.
+   * @param elemOrAttrName The elemOrAttrName to set
+   */
+  public void setElemOrAttrName(org.apache.xml.utils.QName elemOrAttrName)
+  {
+    m_elemOrAttrName = elemOrAttrName;
+  }
+  
+
+}
diff --git a/src/org/apache/xpath/parser/JJTXPathState.java b/src/org/apache/xpath/parser/JJTXPathState.java
new file mode 100644
index 0000000..21a5cca
--- /dev/null
+++ b/src/org/apache/xpath/parser/JJTXPathState.java
@@ -0,0 +1,123 @@
+/* Generated By:JJTree: Do not edit this line. F:/xalan3/xml-xalan/java/xpath-src\JJTXPathState.java */
+
+package org.apache.xpath.parser;
+
+class JJTXPathState {
+  private java.util.Stack nodes;
+  private java.util.Stack marks;
+
+  private int sp;		// number of nodes on stack
+  private int mk;		// current mark
+  private boolean node_created;
+
+  JJTXPathState() {
+    nodes = new java.util.Stack();
+    marks = new java.util.Stack();
+    sp = 0;
+    mk = 0;
+  }
+
+  /* Determines whether the current node was actually closed and
+     pushed.  This should only be called in the final user action of a
+     node scope.  */
+  boolean nodeCreated() {
+    return node_created;
+  }
+
+  /* Call this to reinitialize the node stack.  It is called
+     automatically by the parser's ReInit() method. */
+  void reset() {
+    nodes.removeAllElements();
+    marks.removeAllElements();
+    sp = 0;
+    mk = 0;
+  }
+
+  /* Returns the root node of the AST.  It only makes sense to call
+     this after a successful parse. */
+  Node rootNode() {
+    return (Node)nodes.elementAt(0);
+  }
+
+  /* Pushes a node on to the stack. */
+  void pushNode(Node n) {
+    nodes.push(n);
+    ++sp;
+  }
+
+  /* Returns the node on the top of the stack, and remove it from the
+     stack.  */
+  Node popNode() {
+    if (--sp < mk) {
+      mk = ((Integer)marks.pop()).intValue();
+    }
+    return (Node)nodes.pop();
+  }
+
+  /* Returns the node currently on the top of the stack. */
+  Node peekNode() {
+    return (Node)nodes.peek();
+  }
+
+  /* Returns the number of children on the stack in the current node
+     scope. */
+  int nodeArity() {
+    return sp - mk;
+  }
+
+
+  void clearNodeScope(Node n) {
+    while (sp > mk) {
+      popNode();
+    }
+    mk = ((Integer)marks.pop()).intValue();
+  }
+
+
+  void openNodeScope(Node n) {
+    marks.push(new Integer(mk));
+    mk = sp;
+    n.jjtOpen();
+  }
+
+
+  /* A definite node is constructed from a specified number of
+     children.  That number of nodes are popped from the stack and
+     made the children of the definite node.  Then the definite node
+     is pushed on to the stack. */
+  void closeNodeScope(Node n, int num) {
+    mk = ((Integer)marks.pop()).intValue();
+    while (num-- > 0) {
+      Node c = popNode();
+      c.jjtSetParent(n);
+      n.jjtAddChild(c, num);
+    }
+    n.jjtClose();
+    pushNode(n);
+    node_created = true;
+  }
+
+
+  /* A conditional node is constructed if its condition is true.  All
+     the nodes that have been pushed since the node was opened are
+     made children of the the conditional node, which is then pushed
+     on to the stack.  If the condition is false the node is not
+     constructed and they are left on the stack. */
+  void closeNodeScope(Node n, boolean condition) {
+    if (condition) {
+      int a = nodeArity();
+      mk = ((Integer)marks.pop()).intValue();
+      while (a-- > 0) {
+	Node c = popNode();
+	c.jjtSetParent(n);
+	n.jjtAddChild(c, a);
+      }
+      n.jjtClose();
+      pushNode(n);
+      node_created = true;
+    } else {
+      mk = ((Integer)marks.pop()).intValue();
+      node_created = false;
+    }
+  }
+}
diff --git a/src/org/apache/xpath/parser/KindTest.java b/src/org/apache/xpath/parser/KindTest.java
new file mode 100644
index 0000000..a2f7011
--- /dev/null
+++ b/src/org/apache/xpath/parser/KindTest.java
@@ -0,0 +1,28 @@
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class KindTest extends NameTest
+{
+  public KindTest(XPath parser)
+  {
+  	super(parser);
+  }
+
+// Why on earth did I have this commented?
+//  public int getWhatToShow()
+//  {
+//  	return 0;
+//  }  
+}
+
diff --git a/src/org/apache/xpath/parser/LbrackOrRbrack.java b/src/org/apache/xpath/parser/LbrackOrRbrack.java
new file mode 100644
index 0000000..1d75f1d
--- /dev/null
+++ b/src/org/apache/xpath/parser/LbrackOrRbrack.java
@@ -0,0 +1,9 @@
+package org.apache.xpath.parser;
+public class LbrackOrRbrack extends NonExecutableExpression
+{
+  public LbrackOrRbrack(XPath parser)
+  {
+  	super(parser);
+  }
+}
+
diff --git a/src/org/apache/xpath/parser/NCNameColonStar.java b/src/org/apache/xpath/parser/NCNameColonStar.java
new file mode 100644
index 0000000..e5aa067
--- /dev/null
+++ b/src/org/apache/xpath/parser/NCNameColonStar.java
@@ -0,0 +1,30 @@
+package org.apache.xpath.parser;
+public class NCNameColonStar extends StarColonNCName
+{
+  NCNameColonStar(XPath parser)
+  {
+  	super(parser);
+  }
+  
+  protected String m_namespace;
+  
+  public String getNamespaceURI()
+  {
+  	return m_namespace;
+  }
+
+  public String getLocalName()
+  {
+  	return org.apache.xpath.patterns.NodeTest.WILD;
+  }  
+  
+  
+  public void processToken(Token t) 
+  { 
+  	int posOfColon = t.image.indexOf(':');
+  	String prefix = t.image.substring(0, posOfColon).trim();
+  	m_namespace = m_prefixResolver.getNamespaceForPrefix(prefix);
+  }
+
+}
+
diff --git a/src/org/apache/xpath/parser/NameTest.java b/src/org/apache/xpath/parser/NameTest.java
new file mode 100644
index 0000000..c09b080
--- /dev/null
+++ b/src/org/apache/xpath/parser/NameTest.java
@@ -0,0 +1,142 @@
+package org.apache.xpath.parser;
+
+import org.apache.xml.dtm.DTMFilter;
+import org.apache.xpath.objects.XString;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class NameTest extends NonExecutableExpression
+{  
+  public NameTest(XPath parser)
+  {
+  	super(parser);
+  }
+  
+  void processKindTest(KindTest kind)
+  {
+    if (kind instanceof AnyKindTest)
+    {
+      m_isTotallyWild = true;
+      // m_name = org.apache.xpath.patterns.NodeTest.WILD;
+      m_name = org.apache.xpath.patterns.StepPattern.PSEUDONAME_ANY;
+      m_namespace = null;
+      if (m_parser.m_predLevel == 0 && m_parser.m_isMatchPattern)
+        m_whatToShow =
+          ~DTMFilter.SHOW_ATTRIBUTE
+            & ~DTMFilter.SHOW_DOCUMENT
+            & ~DTMFilter.SHOW_DOCUMENT_FRAGMENT;
+      else
+        m_whatToShow = DTMFilter.SHOW_ALL;
+    }
+    else
+      if (kind instanceof TextTest)
+      {
+        m_isTotallyWild = false;
+        m_name = org.apache.xpath.patterns.StepPattern.PSEUDONAME_TEXT;
+        m_namespace = null;
+        m_whatToShow = DTMFilter.SHOW_TEXT;
+      }
+      else
+        if (kind instanceof CommentTest)
+        {
+          m_isTotallyWild = false;
+          m_name = org.apache.xpath.patterns.StepPattern.PSEUDONAME_COMMENT;
+          m_namespace = null;
+          m_whatToShow = DTMFilter.SHOW_COMMENT;
+        }
+        else
+          if (kind instanceof ProcessingInstructionTest)
+          {
+            m_isTotallyWild = false;
+            m_name = ((ProcessingInstructionTest)kind).getLocalName();
+            m_namespace = null;
+            m_whatToShow = DTMFilter.SHOW_PROCESSING_INSTRUCTION;
+          }
+  }
+
+  public void jjtAddChild(Node n, int i) 
+  {
+    if(n instanceof QName)
+    {
+    	QName qname = ((QName)n);
+    	m_namespace = qname.getNamespaceURI();
+    	m_name = qname.getLocalName();
+    	m_whatToShow = DTMFilter.SHOW_ELEMENT;
+    }
+    else if(n instanceof Star)
+    {
+    	m_isTotallyWild = true;
+    	m_name = org.apache.xpath.patterns.NodeTest.WILD;
+    	// m_name = null;
+    	m_namespace = null;
+    	m_whatToShow = DTMFilter.SHOW_ELEMENT;
+    }
+    else if(n instanceof KindTest)
+    {
+    	if(jjtGetNumChildren() > 0)
+    	{
+     	  processKindTest((KindTest)n.jjtGetChild(0));
+    	}
+    	else
+    	{
+    	  processKindTest((KindTest)n);
+    	}
+    	super.jjtAddChild(n, i);
+    }
+    else
+    {
+    	// Probably this is a CommentTest, TextTest, etc.
+    	// super.jjtAddChild(n, i);
+    	// Assertion, should never happen.
+    	throw new RuntimeException("node can only be a QName, Wildcard, or KindTest!");
+    }
+  }
+  
+  private boolean m_isTotallyWild = false;
+  
+  public boolean isTotallyWild()
+  {
+  	return m_isTotallyWild;
+  }
+
+  public void setIsTotallyWild(boolean b)
+  {
+  	m_isTotallyWild = b;
+  }
+
+  
+  /**
+   * The namespace to be tested for, which may be null.
+   *  @serial 
+   */
+  String m_namespace;
+
+  /**
+   * The local name to be tested for.
+   *  @serial 
+   */
+  String m_name;
+  
+  public String getNamespaceURI()
+  {
+  	return m_namespace;
+  }
+
+  public String getLocalName()
+  {
+  	return m_name;
+  }
+  
+  int m_whatToShow = DTMFilter.SHOW_ALL;
+  
+  public int getWhatToShow()
+  {
+      return m_whatToShow; // ??
+  }
+
+
+
+}
+
diff --git a/src/org/apache/xpath/parser/Node.java b/src/org/apache/xpath/parser/Node.java
new file mode 100644
index 0000000..2e17f1b
--- /dev/null
+++ b/src/org/apache/xpath/parser/Node.java
@@ -0,0 +1,37 @@
+/* Generated By:JJTree: Do not edit this line. Node.java */
+
+/* All AST nodes must implement this interface.  It provides basic
+   machinery for constructing the parent and child relationships
+   between nodes. */
+   
+package org.apache.xpath.parser;
+
+public interface Node {
+
+  /** This method is called after the node has been made the current
+    node.  It indicates that child nodes can now be added to it. */
+  public void jjtOpen();
+
+  /** This method is called after all the child nodes have been
+    added. */
+  public void jjtClose();
+
+  /** This pair of methods are used to inform the node of its
+    parent. */
+  public void jjtSetParent(Node n);
+  public Node jjtGetParent();
+
+  /** This method tells the node to add its argument to the node's
+    list of children.  */
+  public void jjtAddChild(Node n, int i);
+
+  /** This method returns a child node.  The children are numbered
+     from zero, left to right. */
+  public Node jjtGetChild(int i);
+
+  /** Return the number of children the node has. */
+  public int jjtGetNumChildren();
+
+  /** Accept the visitor. **/
+  public Object jjtAccept(XPathVisitor visitor, Object data);
+}
diff --git a/src/org/apache/xpath/parser/NodeTest.java b/src/org/apache/xpath/parser/NodeTest.java
new file mode 100644
index 0000000..0fdecbf
--- /dev/null
+++ b/src/org/apache/xpath/parser/NodeTest.java
@@ -0,0 +1,102 @@
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class NodeTest extends NonExecutableExpression
+{
+  public NodeTest(XPath parser)
+  {
+  	super(parser);
+  }
+  
+  NodeTest(int whatToShow, XPath parser)
+  {
+  	super(parser);
+  	m_whatToShow = whatToShow;
+  }
+
+  public void jjtAddChild(Node n, int i) 
+  {
+    if(n instanceof NameTest) // includes KindTest
+    {
+    	NameTest ntest = (NameTest)n;
+    	m_isTotallyWild = ntest.isTotallyWild();
+    	m_namespace = ntest.getNamespaceURI();
+    	m_name = ntest.getLocalName();
+    	m_whatToShow = ntest.getWhatToShow();
+    }
+    else
+    {
+    	// Assertion, should never happen.
+    	throw new RuntimeException("Child of NodeTest can only be a NameTest or KindTest: "+
+    		n+" "+m_parser.m_prefixResolver);
+    }
+  }
+  
+  int m_whatToShow;
+  
+  public int getWhatToShow()
+  {
+  	return m_whatToShow;
+  }
+
+  public void setWhatToShow(int wts)
+  {
+  	m_whatToShow = wts;
+  }
+
+  
+  private boolean m_isTotallyWild = false;
+  
+  public boolean isTotallyWild()
+  {
+  	return m_isTotallyWild;
+  }
+
+  public void setTotallyWild(boolean b)
+  {
+  	m_isTotallyWild = b;
+  }
+  
+  /**
+   * The namespace to be tested for, which may be null.
+   */
+  String m_namespace;
+
+  /**
+   * The local name to be tested for.
+   */
+  String m_name;
+  
+  public String getNamespaceURI()
+  {
+  	return m_namespace;
+  }
+
+  public String getLocalName()
+  {
+  	return m_name;
+  }
+  
+  public void setNamespaceURI(String n)
+  {
+  	m_namespace = n;
+  }
+
+  public void setLocalName(String n)
+  {
+  	m_name = n;
+  }
+
+}
+
diff --git a/src/org/apache/xpath/parser/NodeTestType.java b/src/org/apache/xpath/parser/NodeTestType.java
new file mode 100644
index 0000000..e3ae696
--- /dev/null
+++ b/src/org/apache/xpath/parser/NodeTestType.java
@@ -0,0 +1,111 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.parser;
+
+import org.apache.xml.dtm.DTMFilter;
+
+/**
+ * The responsibility of this node is to hold simple node tests for 
+ * the SequenceType/ItemType.
+ * 
+ * Created Jul 17, 2002
+ * @author sboag
+ */
+public class NodeTestType extends NonExecutableExpression
+{
+  int m_whatToShow;
+
+  /**
+   * Constructor for ElemOrAttrType.
+   * @param parser The parser that is producing this node.
+   * @param value  one of DTMFilter.SHOW_ATTRIBUTE, DTMFilter.SHOW_ELEMENT, etc.
+   */
+  public NodeTestType(XPath parser, int whatToShow)
+  {
+    super(parser);
+    m_whatToShow = whatToShow;
+  }
+  
+  /**
+   * Returns the whatToShow value.
+   * @return int one of DTMFilter.SHOW_ATTRIBUTE, DTMFilter.SHOW_ELEMENT, etc.
+   */
+  public int getWhatToShow()
+  {
+    return m_whatToShow;
+  }
+
+  /**
+   * Sets the whatToShow value.
+   * @param whatToShow The whatToShow value  to set, 
+   * one of DTMFilter.SHOW_ATTRIBUTE, DTMFilter.SHOW_ELEMENT, etc.
+   */
+  public void setWhatToShow(int whatToShow)
+  {
+    m_whatToShow = whatToShow;
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtSetParent(Node)
+   */
+  public void jjtSetParent(Node n)
+  {
+    ((ItemType)n).setWhatToShow(m_whatToShow);
+    super.jjtSetParent(n);
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/NonExecutableExpression.java b/src/org/apache/xpath/parser/NonExecutableExpression.java
new file mode 100644
index 0000000..7a102c1
--- /dev/null
+++ b/src/org/apache/xpath/parser/NonExecutableExpression.java
@@ -0,0 +1,132 @@
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.DTM;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class NonExecutableExpression extends Expression
+{
+  protected XPath m_parser; // I'm going to leave this for right now only.
+
+  public NonExecutableExpression(XPath parser, String value)
+  {
+  	m_parser = parser;
+  	m_value = value;
+  }
+  
+  protected NonExecutableExpression(XPath parser)
+  {
+  	m_parser = parser;
+  }
+  
+  public XPath getParser()
+  {
+  	return m_parser;
+  }
+	
+  public Vector m_exprs = new Vector();
+	
+  public void jjtAddChild(Node n, int i) 
+  {
+  	n = fixupPrimarys(n);
+    if(null == m_exprs)
+    	m_exprs  = new Vector();
+  	if(i >= m_exprs.size())
+  	{
+  		m_exprs.setSize(i+1);
+  	}
+    m_exprs.setElementAt(n, i);
+  }
+  
+  public Node jjtGetChild(int i) 
+  {
+    if(null == m_exprs)
+    	return null;
+    else
+    	return (Node)m_exprs.elementAt(i);
+  }
+
+  public int jjtGetNumChildren() 
+  {
+    if(null == m_exprs)
+    	return 0;
+    else
+    	return m_exprs.size();
+  }
+  
+  String m_value;
+  public void processToken(Token t) { m_value = t.image; }
+  
+  public String toString() 
+  { 
+  	return this.getClass().getName()+ ((null == m_value) ? "" : (" "+m_value)); 
+  }
+
+
+
+  /**
+   * @see Expression#deepEquals(Expression)
+   * Dummy stub.
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    return false;
+  }
+
+
+  /**
+   * @see Expression#fixupVariables(Vector, int)
+   * Dummy stub.
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+  }
+
+
+  /**
+   * @see Expression#execute(XPathContext)
+   * Dummy stub.
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+  	throw new RuntimeException("Can't execute a NonExecutableExpression!");
+    // return null;
+  }
+  
+  public XObject execute(XPathContext xctxt, int currentNode)
+          throws javax.xml.transform.TransformerException
+  {
+  	throw new RuntimeException("Can't execute a NonExecutableExpression!");
+  }
+  
+  public XObject execute(
+          XPathContext xctxt, int currentNode, DTM dtm, int expType)
+            throws javax.xml.transform.TransformerException
+  {
+  	throw new RuntimeException("Can't execute a NonExecutableExpression!");
+  }
+
+
+  /**
+   * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
+   * Dummy stub.
+   */
+  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
+  {
+  }
+
+
+}
+
diff --git a/src/org/apache/xpath/parser/OccurrenceIndicator.java b/src/org/apache/xpath/parser/OccurrenceIndicator.java
new file mode 100644
index 0000000..0b774ab
--- /dev/null
+++ b/src/org/apache/xpath/parser/OccurrenceIndicator.java
@@ -0,0 +1,88 @@
+/* Generated By:JJTree: Do not edit this line. OccurrenceIndicator.java */
+
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.operations.Add;
+import org.apache.xpath.types.InstanceofExpr;
+
+public class OccurrenceIndicator extends NonExecutableExpression
+{
+  int m_occuranceType;
+
+  /**
+   * Constructor for OccurrenceIndicator.
+   * @param parser
+   * @param value
+   */
+  public OccurrenceIndicator(XPath parser, String value)
+  {
+    super(parser, value);
+  }
+
+  /**
+   * Constructor for OccurrenceIndicator.
+   * @param parser
+   */
+  public OccurrenceIndicator(XPath parser)
+  {
+    super(parser);
+  }
+  
+  /**
+   * @see org.apache.xpath.parser.Node#jjtAddChild(Node, int)
+   */
+  public void jjtAddChild(Node n, int i)
+  {
+    if(n instanceof Add) // Hack... there should be a PlusOccuranceIndicator token!..
+      m_occuranceType = InstanceofExpr.ONE_OR_MORE;
+    else
+    {
+      // Assume NEE
+      char c = ((NonExecutableExpression)n).m_value.charAt(0);
+      if('*' == c)
+        m_occuranceType = InstanceofExpr.ZERO_OR_MORE;
+      else if('?' == c)
+        m_occuranceType = InstanceofExpr.ZERO_OR_ONE;
+      else
+        this.flagProblem("The occurance indicator value is unknown! Value: "+c);
+    }
+  }
+
+  /**
+   * Returns the occuranceType.
+   * @return int
+   */
+  public int getOccuranceType()
+  {
+    return m_occuranceType;
+  }
+
+  /**
+   * Sets the occuranceType.
+   * @param occuranceType The occuranceType to set
+   */
+  public void setOccuranceType(int occuranceType)
+  {
+    m_occuranceType = occuranceType;
+  }
+  
+  
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtSetParent(Node)
+   */
+  public void jjtSetParent(Node n)
+  {
+    if(n instanceof SequenceType)
+      ((SequenceType)n).setOccurrenceIndicator(m_occuranceType);
+    super.jjtSetParent(n);
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/OfType.java b/src/org/apache/xpath/parser/OfType.java
new file mode 100644
index 0000000..2255268
--- /dev/null
+++ b/src/org/apache/xpath/parser/OfType.java
@@ -0,0 +1,35 @@
+/* Generated By:JJTree: Do not edit this line. OfType.java */
+
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+public class OfType extends NonExecutableExpression
+{
+
+  /**
+   * Constructor for OfType.
+   * @param parser
+   * @param value
+   */
+  public OfType(XPath parser, String value)
+  {
+    super(parser, value);
+  }
+
+  /**
+   * Constructor for OfType.
+   * @param parser
+   */
+  public OfType(XPath parser)
+  {
+    super(parser);
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/ParseException.java b/src/org/apache/xpath/parser/ParseException.java
new file mode 100644
index 0000000..acc9236
--- /dev/null
+++ b/src/org/apache/xpath/parser/ParseException.java
@@ -0,0 +1,192 @@
+/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 0.7pre6 */
+
+package org.apache.xpath.parser;
+
+/**
+ * This exception is thrown when parse errors are encountered.
+ * You can explicitly create objects of this exception type by
+ * calling the method generateParseException in the generated
+ * parser.
+ *
+ * You can modify this class to customize your error reporting
+ * mechanisms so long as you retain the public fields.
+ */
+public class ParseException extends Exception {
+
+  /**
+   * This constructor is used by the method "generateParseException"
+   * in the generated parser.  Calling this constructor generates
+   * a new object of this type with the fields "currentToken",
+   * "expectedTokenSequences", and "tokenImage" set.  The boolean
+   * flag "specialConstructor" is also set to true to indicate that
+   * this constructor was used to create this object.
+   * This constructor calls its super class with the empty string
+   * to force the "toString" method of parent class "Throwable" to
+   * print the error message in the form:
+   *     ParseException: <result of getMessage>
+   */
+  public ParseException(Token currentTokenVal,
+                        int[][] expectedTokenSequencesVal,
+                        String[] tokenImageVal
+                       )
+  {
+    super("");
+    specialConstructor = true;
+    currentToken = currentTokenVal;
+    expectedTokenSequences = expectedTokenSequencesVal;
+    tokenImage = tokenImageVal;
+  }
+
+  /**
+   * The following constructors are for use by you for whatever
+   * purpose you can think of.  Constructing the exception in this
+   * manner makes the exception behave in the normal way - i.e., as
+   * documented in the class "Throwable".  The fields "errorToken",
+   * "expectedTokenSequences", and "tokenImage" do not contain
+   * relevant information.  The JavaCC generated code does not use
+   * these constructors.
+   */
+
+  public ParseException() {
+    super();
+    specialConstructor = false;
+  }
+
+  public ParseException(String message) {
+    super(message);
+    specialConstructor = false;
+  }
+
+  /**
+   * This variable determines which constructor was used to create
+   * this object and thereby affects the semantics of the
+   * "getMessage" method (see below).
+   */
+  protected boolean specialConstructor;
+
+  /**
+   * This is the last token that has been consumed successfully.  If
+   * this object has been created due to a parse error, the token
+   * followng this token will (therefore) be the first error token.
+   */
+  public Token currentToken;
+
+  /**
+   * Each entry in this array is an array of integers.  Each array
+   * of integers represents a sequence of tokens (by their ordinal
+   * values) that is expected at this point of the parse.
+   */
+  public int[][] expectedTokenSequences;
+
+  /**
+   * This is a reference to the "tokenImage" array of the generated
+   * parser within which the parse error occurred.  This array is
+   * defined in the generated ...Constants interface.
+   */
+  public String[] tokenImage;
+
+  /**
+   * This method has the standard behavior when this object has been
+   * created using the standard constructors.  Otherwise, it uses
+   * "currentToken" and "expectedTokenSequences" to generate a parse
+   * error message and returns it.  If this object has been created
+   * due to a parse error, and you do not catch it (it gets thrown
+   * from the parser), then this method is called during the printing
+   * of the final stack trace, and hence the correct error message
+   * gets displayed.
+   */
+  public String getMessage() {
+    if (!specialConstructor) {
+      return super.getMessage();
+    }
+    String expected = "";
+    int maxSize = 0;
+    for (int i = 0; i < expectedTokenSequences.length; i++) {
+      if (maxSize < expectedTokenSequences[i].length) {
+        maxSize = expectedTokenSequences[i].length;
+      }
+      for (int j = 0; j < expectedTokenSequences[i].length; j++) {
+        expected += tokenImage[expectedTokenSequences[i][j]] + " ";
+      }
+      if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
+        expected += "...";
+      }
+      expected += eol + "    ";
+    }
+    String retval = "Encountered \"";
+    Token tok = currentToken.next;
+    for (int i = 0; i < maxSize; i++) {
+      if (i != 0) retval += " ";
+      if (tok.kind == 0) {
+        retval += tokenImage[0];
+        break;
+      }
+      retval += add_escapes(tok.image);
+      tok = tok.next; 
+    }
+    retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn + "." + eol;
+    if (expectedTokenSequences.length == 1) {
+      retval += "Was expecting:" + eol + "    ";
+    } else {
+      retval += "Was expecting one of:" + eol + "    ";
+    }
+    retval += expected;
+    return retval;
+  }
+
+  /**
+   * The end of line string for this machine.
+   */
+  protected String eol = System.getProperty("line.separator", "\n");
+ 
+  /**
+   * Used to convert raw characters to their escaped version
+   * when these raw version cannot be used as part of an ASCII
+   * string literal.
+   */
+  protected String add_escapes(String str) {
+      StringBuffer retval = new StringBuffer();
+      char ch;
+      for (int i = 0; i < str.length(); i++) {
+        switch (str.charAt(i))
+        {
+           case 0 :
+              continue;
+           case '\b':
+              retval.append("\\b");
+              continue;
+           case '\t':
+              retval.append("\\t");
+              continue;
+           case '\n':
+              retval.append("\\n");
+              continue;
+           case '\f':
+              retval.append("\\f");
+              continue;
+           case '\r':
+              retval.append("\\r");
+              continue;
+           case '\"':
+              retval.append("\\\"");
+              continue;
+           case '\'':
+              retval.append("\\\'");
+              continue;
+           case '\\':
+              retval.append("\\\\");
+              continue;
+           default:
+              if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
+                 String s = "0000" + Integer.toString(ch, 16);
+                 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
+              } else {
+                 retval.append(ch);
+              }
+              continue;
+        }
+      }
+      return retval.toString();
+   }
+
+}
diff --git a/src/org/apache/xpath/parser/PathExpr.java b/src/org/apache/xpath/parser/PathExpr.java
new file mode 100644
index 0000000..0b9d15e
--- /dev/null
+++ b/src/org/apache/xpath/parser/PathExpr.java
@@ -0,0 +1,117 @@
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+
+import org.apache.xpath.functions.Function;
+import org.apache.xpath.operations.Variable;
+
+public class PathExpr extends NonExecutableExpression
+{
+  public PathExpr(XPath parser)
+  {
+  	super(parser);
+  }
+    
+  /**
+   * Tell if this node is part of a PathExpr chain.  For instance:
+   * <pre>
+   * 	|UnaryExpr
+   * 	|   PathExpr
+   * 	|      StepExpr
+   * 	|         AxisChild child::
+   * 	|         NodeTest
+   * 	|            NameTest
+   * 	|               QName foo
+   * 	|         Predicates   * 
+   * </pre><br/>
+   * In this example, UnaryExpr, PathExpr, and StepExpr should all return true.
+   */
+  public boolean isPathExpr()
+  {
+  	return true;
+  }
+
+	
+//  public void jjtAddChild(Node n, int i) 
+//  {
+//  	n = fixupPrimarys(n);
+//    if(null == m_exprs)
+//    	m_exprs  = new Vector();
+//  	if(i >= m_exprs.size())
+//  	{
+//  		m_exprs.setSize(i+1);
+//  	}
+//    m_exprs.setElementAt(n, i);
+//  }
+  
+  public void jjtClose() 
+  {
+  	int size = m_exprs.size();
+  	for(int i = size-1; i >= 0; i--)
+  	{
+  		SimpleNode node = (SimpleNode)m_exprs.elementAt(i);
+  		if(node instanceof SlashOrSlashSlash)
+  		{
+  			boolean isSlashSlash = ((SlashOrSlashSlash)node).getisSlashSlash();
+  			if(isSlashSlash)
+  			{
+  				node = new StepExpr(m_parser);
+  				PatternAxis patAxis = new PatternAxis(org.apache.xml.dtm.Axis.DESCENDANTORSELF, m_parser);
+  				patAxis.m_value = "descendant-or-self::"; // for diagnostics
+  				NodeTest nt = new NodeTest(org.apache.xml.dtm.DTMFilter.SHOW_ALL, m_parser);
+  				Predicates preds = new Predicates(m_parser);
+  				node.jjtAddChild(patAxis, 0);
+  				node.jjtAddChild(nt, 1);
+  				node.jjtAddChild(preds, 2);
+  				m_exprs.setElementAt(node, i);
+  			}
+  			else
+  				m_exprs.removeElementAt(i);
+  			// i--;
+  		}
+  		
+  	}
+  	Node child;
+  	if((jjtGetNumChildren() == 1) 
+  		&& (child = jjtGetChild(0)) instanceof StepExpr)
+  	{
+  		if(child.jjtGetNumChildren() == 2)
+  		{
+	  		StepExpr stepExpr = (StepExpr)child;
+	  		if(stepExpr.getPredicates().jjtGetNumChildren() == 0)
+	  		{
+	  			Node varOrFunc = stepExpr.jjtGetChild(0);
+	  			if(varOrFunc instanceof Variable 
+	  			|| varOrFunc instanceof Function
+	  			|| varOrFunc instanceof org.apache.xpath.patterns.FunctionPattern)
+	  			{
+	  				m_exprs.setElementAt(varOrFunc, 0);
+	  				varOrFunc.jjtSetParent(this); // parent will continue to reduce.
+	  			}
+	  		}
+  		}
+  	}
+  }
+  
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtAddChild(Node, int)
+   */
+  public void jjtAddChild(Node n, int i)
+  {
+    if (n instanceof StepExpr && n.jjtGetChild(0) instanceof Variable)
+    {
+      if (null == m_exprs)
+        m_exprs = new Vector();
+      if (i >= m_exprs.size())
+      {
+        m_exprs.setSize(i + 1);
+      }
+      m_exprs.setElementAt(n, i);
+    }
+    else
+      super.jjtAddChild(n, i);
+  }
+
+}
+
diff --git a/src/org/apache/xpath/parser/Pattern.java b/src/org/apache/xpath/parser/Pattern.java
new file mode 100644
index 0000000..8769a68
--- /dev/null
+++ b/src/org/apache/xpath/parser/Pattern.java
@@ -0,0 +1,86 @@
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+
+import org.apache.xerces.impl.xpath.XPath.Axis;
+import org.apache.xpath.Expression;
+import org.apache.xpath.patterns.StepPattern;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class Pattern extends NonExecutableExpression
+{
+  public Pattern(XPath parser)
+  {
+  	super(parser);
+  }
+
+  public void jjtAddChild(Node n, int i) 
+  {
+    if(null == m_exprs)
+    	m_exprs  = new Vector();
+  	if(i >= m_exprs.size())
+  	{
+  		m_exprs.setSize(i+1);
+  	}
+  	int invertedPos = (m_exprs.size()-1)-i;
+  	if(0 == invertedPos)
+  	{
+//  		if(n instanceof StepPattern)
+//  		{
+//  		 	StepPattern spat = (StepPattern)n;
+//  		 	spat.setAxis(org.apache.xml.dtm.Axis.SELF);
+//  		}
+    	m_exprs.setElementAt(n, invertedPos);
+  	}
+  	else if(n instanceof SlashOrSlashSlash)
+  	{
+  		m_exprs.setElementAt(n, invertedPos);
+  	}
+  	else
+  	{
+  		int prevNodePos = invertedPos-1;
+  		Node prevNode = (Node)m_exprs.elementAt(prevNodePos);
+  		int whichAxis;
+  		if(prevNode instanceof SlashOrSlashSlash)
+  		{
+  			m_exprs.removeElementAt(prevNodePos);
+  			whichAxis = ((SlashOrSlashSlash)prevNode).getisSlashSlash() ? 
+  					org.apache.xml.dtm.Axis.ANCESTOR : org.apache.xml.dtm.Axis.PARENT;
+  					
+	  		if(n instanceof StepPattern)
+	  		{
+	  			StepPattern spat = (StepPattern)n;
+	  			spat.setAxis(whichAxis);
+	  		}
+  		}
+  			
+  		Node head = (Node)m_exprs.elementAt(0);
+  		if(head instanceof StepPattern)
+  		{
+  			StepPattern headPat = (StepPattern)head;
+  			StepPattern tail = headPat.getRelativePathPattern();
+  			while(null != tail)
+  			{
+  					headPat = tail;
+  					tail = tail.getRelativePathPattern();
+  			}
+  			headPat.setExpression((Expression)n);
+  		}
+  			
+  	}
+  }
+
+  public void jjtClose() 
+  {
+  	if(jjtGetNumChildren() > 0)
+  	{
+  		((StepPattern)jjtGetChild(0)).calcScore();
+  		int i = 4; // debugger breakpoint
+  	}
+  }
+
+}
+
diff --git a/src/org/apache/xpath/parser/PatternAxis.java b/src/org/apache/xpath/parser/PatternAxis.java
new file mode 100644
index 0000000..81aa677
--- /dev/null
+++ b/src/org/apache/xpath/parser/PatternAxis.java
@@ -0,0 +1,54 @@
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class PatternAxis extends NonExecutableExpression
+{
+	public PatternAxis(XPath parser)
+	{
+	  super(parser);
+	}
+
+	int m_axis;
+	
+	/**
+	 * Return what axis this node represents.
+	 * @return one of org.apache.xml.dtm.Axis.DESCENDANT, etc.
+	 */
+	public int getAxis()
+	{
+		return m_axis;
+	}
+	
+	/**
+	 * Return what axis this node represents.
+	 * @return one of org.apache.xml.dtm.Axis.DESCENDANT, etc.
+	 */
+	public void setAxis(int axis)
+	{
+		m_axis = axis;
+	}
+
+	
+	/**
+	 * Construct a PatternAxis.
+	 * 
+	 * @param axis one of org.apache.xml.dtm.Axis.DESCENDANT, etc.
+	 */
+	PatternAxis(int axis, XPath parser)
+	{
+	  super(parser);
+	  m_axis = axis;
+	}
+}
+
diff --git a/src/org/apache/xpath/parser/Predicates.java b/src/org/apache/xpath/parser/Predicates.java
new file mode 100644
index 0000000..8cf8a1c
--- /dev/null
+++ b/src/org/apache/xpath/parser/Predicates.java
@@ -0,0 +1,43 @@
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class Predicates extends NonExecutableExpression
+{
+  public Predicates(XPath parser)
+  {
+	  super(parser);
+  }
+
+  public Vector getPreds()
+  {
+  	return m_exprs;
+  }
+  
+  public void jjtClose() 
+  {
+  	if(null == m_exprs)
+  		return;
+  	int count = m_exprs.size();
+  	for(int i = count-1; i >= 0; i--)
+  	{
+  		Object n = m_exprs.elementAt(i);
+  		if(n instanceof LbrackOrRbrack)
+  			m_exprs.removeElementAt(i);
+  	}
+  	super.jjtClose();
+  }
+
+	
+}
+
diff --git a/src/org/apache/xpath/parser/ProcessingInstructionTest.java b/src/org/apache/xpath/parser/ProcessingInstructionTest.java
new file mode 100644
index 0000000..6c676f3
--- /dev/null
+++ b/src/org/apache/xpath/parser/ProcessingInstructionTest.java
@@ -0,0 +1,45 @@
+package org.apache.xpath.parser;
+
+import org.apache.xml.dtm.DTMFilter;
+import org.apache.xpath.objects.XString;
+import org.apache.xpath.patterns.StepPattern;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class ProcessingInstructionTest extends KindTest
+{
+  public ProcessingInstructionTest(XPath parser)
+  {
+	  super(parser);
+    m_name = StepPattern.WILD;
+  }
+
+  public int getWhatToShow()
+  {
+      return DTMFilter.SHOW_PROCESSING_INSTRUCTION;
+  }	
+   
+   
+  public String getLocalName()
+  {
+  	return m_name;
+  }
+  
+  public void jjtAddChild(Node n, int i) 
+  {
+    if(n instanceof org.apache.xpath.objects.XString) // Includes KindTest
+    {
+    	m_name = ((XString)n).str();
+    }
+    else
+    {
+    	// Assertion, should never happen.
+    	throw new RuntimeException("node can only be a QName or Wildcard!");
+    }
+  }
+
+
+}
+
diff --git a/src/org/apache/xpath/parser/QName.java b/src/org/apache/xpath/parser/QName.java
new file mode 100644
index 0000000..d368bfc
--- /dev/null
+++ b/src/org/apache/xpath/parser/QName.java
@@ -0,0 +1,70 @@
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+
+import javax.xml.transform.TransformerException;
+import org.apache.xml.utils.PrefixResolver;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class QName extends NonExecutableExpression
+{
+  protected PrefixResolver m_prefixResolver;
+
+  QName(XPath parser)
+  {
+    super(parser);
+    m_prefixResolver = parser.m_prefixResolver;
+  }
+
+  protected org.apache.xml.utils.QName m_qname;
+
+  public org.apache.xml.utils.QName getQName()
+  {
+    return m_qname;
+  }
+
+  public String getNamespaceURI()
+  {
+    return m_qname.getNamespaceURI();
+  }
+
+  public String getLocalName()
+  {
+    return m_qname.getLocalName();
+  }
+
+  /**
+   * @see org.apache.xpath.parser.SimpleNode#processToken(Token)
+   */
+  public void processToken(Token t)
+  {
+    if (null == m_qname)
+      // We might have to call this earlier than natural, so avoid duplicate processing.
+    {
+      String qname = t.image;
+      int parenIndex = qname.lastIndexOf("(");
+      if (parenIndex > 0)
+      {
+        qname = qname.substring(0, qname.lastIndexOf("("));
+      }
+      try
+      {
+        qname = qname.trim();
+        m_qname = new org.apache.xml.utils.QName(qname, m_prefixResolver);
+      }
+      catch (RuntimeException e)
+      {
+        throw e;
+      }
+    }
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/QuantifiedExpr.java b/src/org/apache/xpath/parser/QuantifiedExpr.java
new file mode 100644
index 0000000..5904c2e
--- /dev/null
+++ b/src/org/apache/xpath/parser/QuantifiedExpr.java
@@ -0,0 +1,22 @@
+package org.apache.xpath.parser;
+public class QuantifiedExpr extends NonExecutableExpression
+{
+
+  /**
+   * Constructor for QuantifiedExpr
+   */
+  public QuantifiedExpr(XPath parser)
+  {
+    super(parser);
+  }
+
+  /**
+   * @see SimpleNode#shouldReduceIfOneChild()
+   */
+  public boolean shouldReduceIfOneChild()
+  {
+    return (jjtGetNumChildren() == 1) ? true : false;
+  }
+
+}
+
diff --git a/src/org/apache/xpath/parser/Return.java b/src/org/apache/xpath/parser/Return.java
new file mode 100644
index 0000000..2f2fce6
--- /dev/null
+++ b/src/org/apache/xpath/parser/Return.java
@@ -0,0 +1,22 @@
+/* Generated By:JJTree: Do not edit this line. Return.java */
+
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.seqctor.FLWRExpr;
+
+// The return node should probably be void
+public class Return extends NonExecutableExpression
+{
+	
+  public Return(XPath parser) 
+  {
+    super(parser);
+  }
+}
diff --git a/src/org/apache/xpath/parser/RootOfRoot.java b/src/org/apache/xpath/parser/RootOfRoot.java
new file mode 100644
index 0000000..27466c7
--- /dev/null
+++ b/src/org/apache/xpath/parser/RootOfRoot.java
@@ -0,0 +1,29 @@
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+// This is a dummy class, created because I can't seem to get the XPath2 
+// node off the top of the tree by using #void.
+public class RootOfRoot extends NonExecutableExpression
+{
+  public RootOfRoot(XPath parser)
+  {
+	  super(parser);
+  }
+  
+  public void jjtClose() 
+  {
+  	// We don't want this node to any longer be the child's parent!
+  	Node n = jjtGetChild(0);
+   	n.jjtSetParent(null);
+  	super.jjtClose();
+  }
+
+}
+
diff --git a/src/org/apache/xpath/parser/RootOfRootPattern.java b/src/org/apache/xpath/parser/RootOfRootPattern.java
new file mode 100644
index 0000000..6a18c1b
--- /dev/null
+++ b/src/org/apache/xpath/parser/RootOfRootPattern.java
@@ -0,0 +1,45 @@
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+
+import org.apache.xpath.patterns.UnionPattern;
+
+public class RootOfRootPattern extends RootOfRoot
+{
+  public RootOfRootPattern(XPath parser)
+  {
+	  super(parser);
+  }
+
+  public void jjtAddChild(Node n, int i) 
+  {
+    if(null == m_exprs)
+    	m_exprs  = new Vector();
+  	if(i >= m_exprs.size())
+  	{
+  		m_exprs.setSize(i+1);
+  	}
+  	if(n instanceof UnionPattern)
+  	{
+  		UnionPattern up = (UnionPattern)n;
+  		if(1 == up.jjtGetNumChildren())
+  		{
+  			n = up.jjtGetChild(0);
+  		}
+  	}
+    m_exprs.setElementAt(n, i);
+  }
+
+  public void jjtClose() 
+  {
+  	Node n = jjtGetChild(0);
+  	if(n instanceof Pattern)
+  	{
+  		n.jjtSetParent(null);
+  		m_exprs.setElementAt(n.jjtGetChild(0), 0);
+  	}
+  	super.jjtClose();
+  }
+
+}
+
diff --git a/src/org/apache/xpath/parser/SchemaContext.java b/src/org/apache/xpath/parser/SchemaContext.java
new file mode 100644
index 0000000..7edf261
--- /dev/null
+++ b/src/org/apache/xpath/parser/SchemaContext.java
@@ -0,0 +1,87 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.parser;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 17, 2002
+ * @author sboag
+ */
+public class SchemaContext extends NonExecutableExpression
+{
+
+  /**
+   * Constructor for SchemaContext.
+   * @param parser
+   * @param value
+   */
+  public SchemaContext(XPath parser, String value)
+  {
+    super(parser, value);
+  }
+
+  /**
+   * Constructor for SchemaContext.
+   * @param parser
+   */
+  public SchemaContext(XPath parser)
+  {
+    super(parser);
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/SchemaContextStep.java b/src/org/apache/xpath/parser/SchemaContextStep.java
new file mode 100644
index 0000000..4b1cff1
--- /dev/null
+++ b/src/org/apache/xpath/parser/SchemaContextStep.java
@@ -0,0 +1,77 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.parser;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 17, 2002
+ * @author sboag
+ */
+public class SchemaContextStep extends QName
+{
+
+  /**
+   * Constructor for SchemaContextStep.
+   * @param parser
+   */
+  public SchemaContextStep(XPath parser)
+  {
+    super(parser);
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/SchemaGlobalContext.java b/src/org/apache/xpath/parser/SchemaGlobalContext.java
new file mode 100644
index 0000000..5c1bd96
--- /dev/null
+++ b/src/org/apache/xpath/parser/SchemaGlobalContext.java
@@ -0,0 +1,87 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.parser;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 17, 2002
+ * @author sboag
+ */
+public class SchemaGlobalContext extends NonExecutableExpression
+{
+
+  /**
+   * Constructor for SchemaGlobalContext.
+   * @param parser
+   * @param value
+   */
+  public SchemaGlobalContext(XPath parser, String value)
+  {
+    super(parser, value);
+  }
+
+  /**
+   * Constructor for SchemaGlobalContext.
+   * @param parser
+   */
+  public SchemaGlobalContext(XPath parser)
+  {
+    super(parser);
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/SchemaType.java b/src/org/apache/xpath/parser/SchemaType.java
new file mode 100644
index 0000000..8da5889
--- /dev/null
+++ b/src/org/apache/xpath/parser/SchemaType.java
@@ -0,0 +1,89 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.parser;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 17, 2002
+ * @author sboag
+ */
+public class SchemaType extends QName
+{
+
+  /**
+   * Constructor for SchemaType.
+   * @param parser
+   */
+  public SchemaType(XPath parser)
+  {
+    super(parser);
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtSetParent(Node)
+   */
+  public void jjtSetParent(Node n)
+  {
+    QName qname = (QName)this.jjtGetChild(1);
+    ((ElemOrAttrType)n).setSchemaTypeName(qname.getQName());
+    super.jjtSetParent(n);
+  }
+  
+  
+
+}
diff --git a/src/org/apache/xpath/parser/SequenceType.java b/src/org/apache/xpath/parser/SequenceType.java
new file mode 100644
index 0000000..88461fa
--- /dev/null
+++ b/src/org/apache/xpath/parser/SequenceType.java
@@ -0,0 +1,187 @@
+/* Generated By:JJTree: Do not edit this line. SequenceType.java */
+
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.utils.QName;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.types.InstanceofExpr;
+
+public class SequenceType extends NonExecutableExpression
+{
+	
+  /** The sequence on which to act. **/
+  private Expression m_targetExpr;
+  
+  /** The node type value, one of DTMFilter.SHOW_ATTRIBUTE, etc. **/
+  private int m_whatToShow;
+  
+  /** The atomic type ID, one of XType.BOOLEAN, etc. **/
+  private int m_atomicTypeID;
+  
+  /** The occurance indicator ID.  One of ZERO_OR_MORE, etc. or EMPTY_SEQ **/
+  private int m_occurrenceIndicator = InstanceofExpr.ONE_OR_MORE;
+  
+  /** The ElemOrAttrType name, meaning the tag QName, may be null. */
+  private org.apache.xml.utils.QName m_elemOrAttrName;
+
+  /** The SchemaType name, meaning the tag QName, may be null. */
+  private org.apache.xml.utils.QName m_schemaTypeName;
+  
+  /** SchemaContext is not executable for the moment, so leave it 
+   * as a NEE until we figure out what we want to do with it. **/
+  private SchemaContext m_schemaContext;
+
+
+  /**
+   * Constructor for SequenceType.
+   * @param parser
+   * @param value
+   */
+  public SequenceType(XPath parser, String value)
+  {
+    super(parser, value);
+  }
+
+  /**
+   * Constructor for SequenceType.
+   * @param parser
+   */
+  public SequenceType(XPath parser)
+  {
+    super(parser);
+  }
+
+  /**
+   * Returns the occurrenceIndicator.
+   * @return int
+   */
+  public int getOccurrenceIndicator()
+  {
+    return m_occurrenceIndicator;
+  }
+
+  /**
+   * Returns the schemaContext.
+   * @return SchemaContext
+   */
+  public SchemaContext getSchemaContext()
+  {
+    return m_schemaContext;
+  }
+
+  /**
+   * Returns the schemaTypeName.
+   * @return org.apache.xml.utils.QName
+   */
+  public org.apache.xml.utils.QName getSchemaTypeName()
+  {
+    return m_schemaTypeName;
+  }
+
+  /**
+   * Returns the targetExpr.
+   * @return Expression
+   */
+  public Expression getTargetExpr()
+  {
+    return m_targetExpr;
+  }
+
+  /**
+   * Returns the whatToShow.
+   * @return int
+   */
+  public int getWhatToShow()
+  {
+    return m_whatToShow;
+  }
+
+  /**
+   * Sets the occurrenceIndicator.
+   * @param occurrenceIndicator The occurrenceIndicator to set
+   */
+  public void setOccurrenceIndicator(int occurrenceIndicator)
+  {
+    m_occurrenceIndicator = occurrenceIndicator;
+  }
+
+  /**
+   * Sets the schemaContext.
+   * @param schemaContext The schemaContext to set
+   */
+  public void setSchemaContext(SchemaContext schemaContext)
+  {
+    m_schemaContext = schemaContext;
+  }
+
+  /**
+   * Sets the schemaTypeName.
+   * @param schemaTypeName The schemaTypeName to set
+   */
+  public void setSchemaTypeName(org.apache.xml.utils.QName schemaTypeName)
+  {
+    m_schemaTypeName = schemaTypeName;
+  }
+
+  /**
+   * Sets the targetExpr.
+   * @param targetExpr The targetExpr to set
+   */
+  public void setTargetExpr(Expression targetExpr)
+  {
+    m_targetExpr = targetExpr;
+  }
+
+  /**
+   * Sets the whatToShow.
+   * @param whatToShow The whatToShow to set
+   */
+  public void setWhatToShow(int whatToShow)
+  {
+    m_whatToShow = whatToShow;
+  }
+
+  /**
+   * Returns the atomicTypeID.
+   * @return int
+   */
+  public int getAtomicTypeID()
+  {
+    return m_atomicTypeID;
+  }
+
+  /**
+   * Returns the elemOrAttrName.
+   * @return org.apache.xml.utils.QName
+   */
+  public org.apache.xml.utils.QName getElemOrAttrName()
+  {
+    return m_elemOrAttrName;
+  }
+
+  /**
+   * Sets the atomicTypeID.
+   * @param atomicTypeID The atomicTypeID to set
+   */
+  public void setAtomicTypeID(int atomicTypeID)
+  {
+    m_atomicTypeID = atomicTypeID;
+  }
+
+  /**
+   * Sets the elemOrAttrName.
+   * @param elemOrAttrName The elemOrAttrName to set
+   */
+  public void setElemOrAttrName(org.apache.xml.utils.QName elemOrAttrName)
+  {
+    m_elemOrAttrName = elemOrAttrName;
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/SimpleNode.java b/src/org/apache/xpath/parser/SimpleNode.java
new file mode 100644
index 0000000..c952f63
--- /dev/null
+++ b/src/org/apache/xpath/parser/SimpleNode.java
@@ -0,0 +1,1308 @@
+package org.apache.xpath.parser;
+
+import java.util.Hashtable;
+
+import javax.xml.transform.SourceLocator;
+
+import org.apache.xml.dtm.DTMFilter;
+import org.apache.xml.utils.QName;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
+import org.apache.xpath.axes.UnionPathIterator;
+import org.apache.xpath.axes.WalkerFactory;
+import org.apache.xpath.functions.*;
+import org.apache.xpath.objects.XDecimal;
+import org.apache.xpath.objects.XDouble;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xpath.operations.Variable;
+import org.apache.xpath.patterns.FunctionPattern;
+import org.apache.xpath.patterns.StepPattern;
+import org.apache.xpath.seqctor.ExprSequence;
+import org.apache.xpath.seqctor.FLWRExpr;
+import org.apache.xpath.types.InstanceofExpr;
+
+/**
+ * This is the most generic syntax node, which implements the JJTree 
+ * interface "Node" methods.  This class assumes that it's derived 
+ * class is org.apache.xpath.Expression, and so does a fair amount 
+ * of downcasting.  The only reason this class exists is to separate 
+ * out the jjXXX methods, to act as a more generic interface to 
+ * the JavaCC/JJTree parser, and also to act as a factory class for 
+ * the concrete implementations of the expressions.
+ * 
+ * @author sboag
+ */
+public class SimpleNode implements Node
+{
+
+  /**
+   * Construct a new SimpleNode.
+   * @see java.lang.Object#Object()
+   */
+  public SimpleNode()
+  {
+  }
+
+  public static Hashtable m_builtInFunctions;
+
+  static {
+    // For user installed functions, can we really have a single static table?
+    // Answer: no, each parser instance will need to copy the table.
+    // Then the question is, can all instances of a user Function be shared among 
+    // processes?  Answer: I think that would cause regressions.
+    m_builtInFunctions = new Hashtable();
+    m_builtInFunctions.put(new QName("current"), new FuncCurrent());
+    m_builtInFunctions.put(
+      new QName("last"),
+      new org.apache.xpath.functions.FuncLast());
+    m_builtInFunctions.put(
+      new QName("position"),
+      new org.apache.xpath.functions.FuncPosition());
+    m_builtInFunctions.put(new QName("count"), new FuncCount());
+    m_builtInFunctions.put(new QName("id"), new FuncId());
+    m_builtInFunctions.put(
+      new QName("key"),
+      new org.apache.xalan.templates.FuncKey());
+    m_builtInFunctions.put(new QName("local-name"), new FuncLocalPart());
+    m_builtInFunctions.put(new QName("namespace-uri"), new FuncNamespace());
+    m_builtInFunctions.put(new QName("name"), new FuncQname());
+    m_builtInFunctions.put(new QName("generate-id"), new FuncGenerateId());
+    m_builtInFunctions.put(new QName("not"), new FuncNot());
+    m_builtInFunctions.put(new QName("true"), new FuncTrue());
+    m_builtInFunctions.put(new QName("false"), new FuncFalse());
+    m_builtInFunctions.put(new QName("boolean"), new FuncBoolean());
+    m_builtInFunctions.put(new QName("lang"), new FuncLang());
+    m_builtInFunctions.put(new QName("number"), new FuncNumber());
+    m_builtInFunctions.put(new QName("floor"), new FuncFloor());
+    m_builtInFunctions.put(new QName("ceiling"), new FuncCeiling());
+    m_builtInFunctions.put(new QName("round"), new FuncRound());
+    m_builtInFunctions.put(new QName("sum"), new FuncSum());
+    m_builtInFunctions.put(new QName("string"), new FuncString());
+    m_builtInFunctions.put(new QName("starts-with"), new FuncStartsWith());
+    m_builtInFunctions.put(new QName("contains"), new FuncContains());
+    m_builtInFunctions.put(
+      new QName("substring-before"),
+      new FuncSubstringBefore());
+    m_builtInFunctions.put(
+      new QName("substring-after"),
+      new FuncSubstringAfter());
+    m_builtInFunctions.put(
+      new QName("normalize-space"),
+      new FuncNormalizeSpace());
+    m_builtInFunctions.put(new QName("translate"), new FuncTranslate());
+    m_builtInFunctions.put(new QName("concat"), new FuncConcat());
+    m_builtInFunctions.put(
+      new QName("system-property"),
+      new FuncSystemProperty());
+    m_builtInFunctions.put(
+      new QName("function-available"),
+      new FuncExtFunctionAvailable());
+    m_builtInFunctions.put(
+      new QName("element-available"),
+      new FuncExtElementAvailable());
+    m_builtInFunctions.put(new QName("substring"), new FuncSubstring());
+    m_builtInFunctions.put(new QName("string-length"), new FuncStringLength());
+    m_builtInFunctions.put(
+      new QName("unparsed-entity-uri"),
+      new FuncUnparsedEntityURI());
+    m_builtInFunctions.put(
+      new QName("document-location"),
+      new FuncDoclocation());
+    // Proprietary
+	// XPATH2 experimental
+    m_builtInFunctions.put(
+      new QName("data"),
+      new FuncData());    
+    m_builtInFunctions.put(
+      new QName("current-dateTime"),
+      new FuncCurrentDateTime());
+    m_builtInFunctions.put(
+      new QName("current-date"),
+      new FuncCurrentDate());
+    m_builtInFunctions.put(
+      new QName("dateTime"),
+      new FuncDateTime());
+    m_builtInFunctions.put(
+      new QName("date"),
+      new FuncDate());
+    m_builtInFunctions.put(
+      new QName("duration"),
+      new FuncDuration());
+    m_builtInFunctions.put(
+      new QName("time"),
+      new FuncTime());
+      m_builtInFunctions.put(
+      new QName("yearMonthDuration"),
+      new FuncYMDuration());
+      m_builtInFunctions.put(
+      new QName("yearMonthDuration-from-months"),
+      new FuncYMDurationFromMonths());
+      m_builtInFunctions.put(
+      new QName("dayTimeDuration"),
+      new FuncDTDuration());
+      m_builtInFunctions.put(
+      new QName("dayTimeDuration-from-seconds"),
+      new FuncDTDurationFromSecs());
+      m_builtInFunctions.put(
+      new QName("add-dayTimeDuration"),
+      new FuncAddDayTimeDuration());
+      m_builtInFunctions.put(
+      new QName("subtract-dayTimeDuration"),
+      new FuncSubDayTimeDuration());
+      m_builtInFunctions.put(
+      new QName("multiply-dayTimeDuration"),
+      new FuncMultDayTimeDuration());
+      m_builtInFunctions.put(
+      new QName("divide-dayTimeDuration"),
+      new FuncDivDayTimeDuration());
+      m_builtInFunctions.put(
+      new QName("add-yearMonthDuration"),
+      new FuncAddYearMonthDuration()); 
+      m_builtInFunctions.put(
+      new QName("subtract-yearMonthDuration"),
+      new FuncSubYearMonthDuration());
+      m_builtInFunctions.put(
+      new QName("multiply-yearMonthDuration"),
+      new FuncMultYearMonthDuration());
+      m_builtInFunctions.put(
+      new QName("divide-yearMonthDuration"),
+      new FuncDivYearMonthDuration());
+      m_builtInFunctions.put(
+      new QName("get-yearMonthDuration"),
+      new FuncGetYMDuration());
+      m_builtInFunctions.put(
+      new QName("get-dayTimeDuration"),
+      new FuncGetDTDuration());
+      m_builtInFunctions.put(
+      new QName("add-yearMonthDurationToDateTime"),
+      new FuncAddYMDurationToDT());
+      m_builtInFunctions.put(
+      new QName("subtract-yearMonthDurationFromDateTime"),
+      new FuncSubtractYMDurationFromDT());
+      m_builtInFunctions.put(
+      new QName("add-yearMonthDurationToDate"),
+      new FuncAddYMDurationToDate());
+      m_builtInFunctions.put(
+      new QName("subtract-yearMonthDurationFromDate"),
+      new FuncSubtractYMDurationFromDate());
+      m_builtInFunctions.put(
+      new QName("add-dayTimeDurationToDateTime"),
+      new FuncAddDTDurationToDT());
+      m_builtInFunctions.put(
+      new QName("subtract-dayTimeDurationFromDateTime"),
+      new FuncSubtractDTDurationFromDT());
+      m_builtInFunctions.put(
+      new QName("add-dayTimeDurationToDate"),
+      new FuncAddDTDurationToDate());
+      m_builtInFunctions.put(
+      new QName("add-dayTimeDurationToTime"),
+      new FuncAddDTDurationToTime());
+      m_builtInFunctions.put(
+      new QName("subtract-dayTimeDurationFromDate"),
+      new FuncSubtractDTDurationFromDate());
+      m_builtInFunctions.put(
+      new QName("subtract-dayTimeDurationFromTime"),
+      new FuncSubtractDTDurationFromTime());
+      m_builtInFunctions.put(
+      new QName("add-days"),
+      new FuncAddDays());
+      m_builtInFunctions.put(
+      new QName("gYearMonth"),
+      new FuncGYearMonth());
+      m_builtInFunctions.put(
+      new QName("gYear"),
+      new FuncGYear());
+      m_builtInFunctions.put(
+      new QName("gMonth"),
+      new FuncGMonth());
+      m_builtInFunctions.put(
+      new QName("gMonthDay"),
+      new FuncGMonthDay());
+      m_builtInFunctions.put(
+      new QName("gDay"),
+      new FuncGDay());
+m_builtInFunctions.put(
+      new QName("get-day-from-date"),
+      new FuncGetDFromDate());
+m_builtInFunctions.put(
+      new QName("get-day-from-dateTime"),
+      new FuncGetDFromDT());
+m_builtInFunctions.put(
+      new QName("get-days-from-dayTimeDuration"),
+      new FuncGetDFromDTDuration());
+m_builtInFunctions.put(
+      new QName("get-hours-from-dateTime"),
+      new FuncGetHFromDT());
+m_builtInFunctions.put(
+      new QName("get-hours-from-dayTimeDuration"),
+      new FuncGetHFromDTDuration());
+m_builtInFunctions.put(
+      new QName("get-hours-from-time"),
+      new FuncGetHFromTime());
+m_builtInFunctions.put(
+      new QName("get-month-from-date"),
+      new FuncGetMFromDate());
+m_builtInFunctions.put(
+      new QName("get-month-from-dateTime"),
+      new FuncGetMFromDT());
+m_builtInFunctions.put(
+      new QName("get-months-from-yearMonthDuration"),
+      new FuncGetMFromYMDuration());
+m_builtInFunctions.put(
+      new QName("get-minutes-from-dateTime"),
+      new FuncGetMnFromDT());
+m_builtInFunctions.put(
+      new QName("get-minutes-from-dayTimeDuration"),
+      new FuncGetMnFromDTDuration());
+m_builtInFunctions.put(
+      new QName("get-minutes-from-time"),
+      new FuncGetMnFromTime());
+m_builtInFunctions.put(
+      new QName("get-seconds-from-dateTime"),
+      new FuncGetSFromDT());
+m_builtInFunctions.put(
+      new QName("get-seconds-from-dayTimeDuration"),
+      new FuncGetSFromDTDuration());
+m_builtInFunctions.put(
+      new QName("get-seconds-from-time"),
+      new FuncGetSFromTime());
+m_builtInFunctions.put(
+      new QName("get-timezone-from-datetime"),
+      new FuncGetTZFromDT());
+m_builtInFunctions.put(
+      new QName("get-timezone-from-date"),
+      new FuncGetTZFromDate());
+m_builtInFunctions.put(
+      new QName("get-timezone-from-time"),
+      new FuncGetTZFromTime());
+m_builtInFunctions.put(
+      new QName("get-year-from-date"),
+      new FuncGetYFromDate());
+m_builtInFunctions.put(
+      new QName("get-year-from-dateTime"),
+      new FuncGetYFromDT());
+m_builtInFunctions.put(
+      new QName("get-years-from-yearMonthDuration"),
+      new FuncGetYFromYMDuration());
+m_builtInFunctions.put(
+      new QName("duration-equal"),
+      new FuncDurationEqual());
+m_builtInFunctions.put(
+      new QName("yearMonthDuration-equal"),
+      new FuncYMDurationEqual());
+m_builtInFunctions.put(
+      new QName("yearMonthDuration-greater-than"),
+      new FuncYMDurationGT());
+m_builtInFunctions.put(
+      new QName("yearMonthDuration-less-than"),
+      new FuncYMDurationLT());
+m_builtInFunctions.put(
+      new QName("dayTimeDuration-equal"),
+      new FuncDTDurationEqual());
+m_builtInFunctions.put(
+      new QName("dayTimeDuration-greater-than"),
+      new FuncDTDurationGT());
+m_builtInFunctions.put(
+      new QName("dayTimeDuration-less-than"),
+      new FuncDTDurationLT());
+m_builtInFunctions.put(
+      new QName("dateTime-equal"),
+      new FuncDateTimeEq());
+m_builtInFunctions.put(
+      new QName("dateTime-less-than"),
+      new FuncDateTimeLT());
+m_builtInFunctions.put(
+      new QName("dateTime-greater-than"),
+      new FuncDateTimeGT());
+  }
+
+  /**
+   * Factory method for creating parse tree nodes, which is called by 
+   * the JJTree created parser.
+   * @param p The JJTree created XPath parser.
+   * @param id The ID of the node.
+   * @return Node The new node, which may not be null.
+   */
+  public static Node jjtCreate(XPath p, int id)
+  {
+    SimpleNode newNode = null;
+    // To be done:  If function on stack, assume param.
+    switch (id)
+    {
+      case XPathTreeConstants.JJTXPATH2 :
+        // When I try to use #void to cancel out this node, 
+        // I get an error.  So I guess 
+        // the top of the tree can't be void.  So I create a dummy
+        // node.  This makes the called have to call 
+        // ((SimpleNode)tree.jjtGetChild(0)) to get the real root.
+        newNode = new RootOfRoot(p);
+        break;
+
+        // === MATCH EXPRESSIONS ===	
+      case XPathTreeConstants.JJTMATCHPATTERN :
+        // See comment above.
+        // TBD: If the pattern is a MatchPattern, then RootOfRoot should 
+        // rebuild the children according to the structure needed 
+        // by the patterns package.
+        newNode = new RootOfRootPattern(p);
+        break;
+      case XPathTreeConstants.JJTPATTERN :
+        // This should be optimized away if there is only one pattern
+        newNode = new org.apache.xpath.patterns.UnionPattern();
+        break;
+      case XPathTreeConstants.JJTPATHPATTERN :
+        // This is a temporary node, for construction purposes only,
+        // Since the patterns package constructs the StepPatterns as 
+        // a linked list.
+        newNode = new Pattern(p);
+        break;
+      case XPathTreeConstants.JJTPATTERNSTEP :
+        {
+          StepPattern spat = new StepPattern();
+          // At this point, the PatternAxis, NodeTest, and Predicates 
+          // should be already on the stack?
+          newNode = spat;
+        }
+        break;
+
+      case XPathTreeConstants.JJTROOT :
+        {
+          if (!p.m_isMatchPattern || p.m_predLevel > 0)
+          {
+            newNode = new StepExpr(p);
+            PatternAxis patAxis =
+              new PatternAxis(org.apache.xml.dtm.Axis.ROOT, p);
+            patAxis.m_value = "root::"; // for diagnostics
+            NodeTest nt =
+              new NodeTest(
+                org.apache.xml.dtm.DTMFilter.SHOW_DOCUMENT
+                  | org.apache.xml.dtm.DTMFilter.SHOW_DOCUMENT_FRAGMENT,
+                p);
+            Predicates preds = new Predicates(p);
+            newNode.jjtAddChild(patAxis, 0);
+            newNode.jjtAddChild(nt, 1);
+            newNode.jjtAddChild(preds, 2);
+          }
+          else
+          {
+            StepPattern spat = new StepPattern();
+            spat.setWhatToShow(
+              DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT);
+            spat.setAxis(org.apache.xml.dtm.Axis.PARENT);
+            // spat.setT(org.apache.xpath.patterns.StepPattern.PSEUDONAME_ROOT);
+            newNode = spat;
+          }
+        }
+        break;
+      case XPathTreeConstants.JJTROOTDESCENDANTS :
+        {
+          if (!p.m_isMatchPattern || p.m_predLevel > 0)
+          {
+            newNode = new StepExpr(p);
+            PatternAxis patAxis =
+              new PatternAxis(
+                org.apache.xml.dtm.Axis.DESCENDANTSORSELFFROMROOT,
+                p);
+            patAxis.m_value = "descendants-from-root::"; // for diagnostics
+            NodeTest nt =
+              new NodeTest(org.apache.xml.dtm.DTMFilter.SHOW_ALL, p);
+            nt.setTotallyWild(true);
+            // nt.setLocalName(org.apache.xpath.patterns.StepPattern.PSEUDONAME_ROOT);
+            Predicates preds = new Predicates(p);
+            newNode.jjtAddChild(patAxis, 0);
+            newNode.jjtAddChild(nt, 1);
+            newNode.jjtAddChild(preds, 2);
+          }
+          else
+          {
+            // see comment for JJTROOT.
+            StepPattern spat = new StepPattern();
+            spat.setWhatToShow(
+              DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT);
+            spat.setAxis(org.apache.xml.dtm.Axis.ANCESTOR);
+            newNode = spat;
+          }
+        }
+        break;
+
+      case XPathTreeConstants.JJTSLASH :
+        newNode = new SlashOrSlashSlash(false, p);
+        break;
+      case XPathTreeConstants.JJTSLASHSLASH :
+        newNode = new SlashOrSlashSlash(true, p);
+        break;
+
+        // === NODE TESTS ===	
+      case XPathTreeConstants.JJTNODETEST :
+        newNode = new NodeTest(p);
+        break;
+      case XPathTreeConstants.JJTNAMETEST :
+        newNode = new NameTest(p);
+        break;
+      case XPathTreeConstants.JJTQNAME :
+        newNode = new org.apache.xpath.parser.QName(p);
+        break;
+      case XPathTreeConstants.JJTSTAR : // Wildcard
+        newNode = new Star(p);
+        break;
+      case XPathTreeConstants.JJTNCNAMECOLONSTAR :
+        newNode = new NCNameColonStar(p);
+        break;
+      case XPathTreeConstants.JJTSTARCOLONNCNAME :
+        newNode = new StarColonNCName(p);
+        break;
+
+      case XPathTreeConstants.JJTKINDTEST :
+        newNode = new KindTest(p);
+        break;
+      case XPathTreeConstants.JJTPROCESSINGINSTRUCTIONTEST :
+        newNode = new ProcessingInstructionTest(p);
+        break;
+      case XPathTreeConstants.JJTCOMMENTTEST :
+        newNode = new CommentTest(p);
+        break;
+      case XPathTreeConstants.JJTTEXTTEST :
+        newNode = new TextTest(p);
+        break;
+      case XPathTreeConstants.JJTANYKINDTEST :
+        newNode = new AnyKindTest(p);
+        break;
+
+      case XPathTreeConstants.JJTLBRACK :
+        newNode = new LbrackOrRbrack(p);
+        p.m_predLevel++;
+        break;
+      case XPathTreeConstants.JJTRBRACK :
+        newNode = new LbrackOrRbrack(p);
+        p.m_predLevel--;
+        break;
+      case XPathTreeConstants.JJTPREDICATES :
+        newNode = new Predicates(p);
+        break;
+
+        // === AXES, ETC. ===	
+      case XPathTreeConstants.JJTAXISDESCENDANT :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.DESCENDANT, p);
+        break;
+      case XPathTreeConstants.JJTAXISSELF :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.SELF, p);
+        break;
+      case XPathTreeConstants.JJTAXISDESCENDANTORSELF :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.DESCENDANTORSELF, p);
+        break;
+      case XPathTreeConstants.JJTAXISFOLLOWINGSIBLING :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.FOLLOWINGSIBLING, p);
+        break;
+      case XPathTreeConstants.JJTAXISFOLLOWING :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.FOLLOWING, p);
+        break;
+      case XPathTreeConstants.JJTAXISNAMESPACE :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.NAMESPACE, p);
+        break;
+      case XPathTreeConstants.JJTAXISPARENT :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.PARENT, p);
+        break;
+      case XPathTreeConstants.JJTAXISANCESTOR :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.ANCESTOR, p);
+        break;
+      case XPathTreeConstants.JJTAXISPRECEDINGSIBLING :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.PRECEDINGSIBLING, p);
+        break;
+      case XPathTreeConstants.JJTAXISPRECEDING :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.PRECEDING, p);
+        break;
+      case XPathTreeConstants.JJTAXISANCESTORORSELF :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.ANCESTORORSELF, p);
+        break;
+      case XPathTreeConstants.JJTAXISCHILD :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.CHILD, p);
+        break;
+      case XPathTreeConstants.JJTAXISATTRIBUTE :
+      case XPathTreeConstants.JJTAT :
+        newNode = new PatternAxis(org.apache.xml.dtm.Axis.ATTRIBUTE, p);
+        break;
+
+      case XPathTreeConstants.JJTABBREVIATEDFORWARDSTEP :
+        {
+          PatternAxis patAxis =
+            new PatternAxis(org.apache.xml.dtm.Axis.CHILD, p);
+          patAxis.m_value = "child::"; // for diagnostics
+          newNode = patAxis;
+        }
+        break;
+      case XPathTreeConstants.JJTDOT :
+        {
+          PatternAxis patAxis =
+            new PatternAxis(org.apache.xml.dtm.Axis.SELF, p);
+          patAxis.m_value = "self::"; // for diagnostics
+          newNode = patAxis;
+          NodeTest nt = new NodeTest(org.apache.xml.dtm.DTMFilter.SHOW_ALL, p);
+          newNode.jjtAddChild(nt, 0);
+        }
+        break;
+      case XPathTreeConstants.JJTDOTDOT :
+        {
+          PatternAxis patAxis =
+            new PatternAxis(org.apache.xml.dtm.Axis.PARENT, p);
+          patAxis.m_value = "parent::"; // for diagnostics
+          newNode = patAxis;
+          NodeTest nt = new NodeTest(org.apache.xml.dtm.DTMFilter.SHOW_ALL, p);
+          newNode.jjtAddChild(nt, 0);
+        }
+        break;
+
+        // === PATH EXPRESSIONS ===	
+      case XPathTreeConstants.JJTPATHEXPR :
+        newNode = new PathExpr(p);
+        break;
+      case XPathTreeConstants.JJTSTEPEXPR :
+        newNode = new StepExpr(p);
+        break;
+
+        // === SEQUENCE UNIONS AND INTERSECTIONS ===	
+      case XPathTreeConstants.JJTUNIONEXPR :
+        newNode = new UnionPathIterator();
+        break;
+      case XPathTreeConstants.JJTINTERSECTEXCEPTEXPR :
+        newNode = new NonExecutableExpression(p, "JJTUNIONEXPR");
+        break;
+        //			case XPathTreeConstants.JJTUNION:
+        //				newNode = new SimpleNode();
+        //				break;
+        //			case XPathTreeConstants.JJTVBAR:
+        //				newNode = new SimpleNode();
+        //				break;
+        //			case XPathTreeConstants.JJTRELATIVEPATHPATTERN:
+        //				newNode = new SimpleNode();
+        //				break;
+
+        // === FUNCTIONS ===	
+      case XPathTreeConstants.JJTIDKEYPATTERN :
+        {
+          FunctionPattern fpat = new FunctionPattern();
+          p.m_matchFunc = fpat; // short lived.
+          newNode = fpat;
+        }
+        break;
+      case XPathTreeConstants.JJTFUNCTIONCALL :
+        {
+          FunctionPattern fpat = new TempFunctionHolder();
+          p.m_matchFunc = fpat; // short lived.
+          newNode = fpat;
+        }
+        break;
+      case XPathTreeConstants.JJTQNAMELPAR :
+        try
+        {
+
+          org.apache.xpath.parser.QName qname =
+            new org.apache.xpath.parser.QName(p);
+          if (null != p.m_matchFunc)
+          {
+            qname.processToken(p.getToken(0));
+            QName funcName = qname.getQName();
+            String ns = funcName.getNamespaceURI();
+            if (null != ns && ns.length() > 0)
+            {
+              String uniqueKey =
+                String.valueOf(
+                  ((SourceLocator) p.m_prefixResolver).getLineNumber())
+                  + String.valueOf(funcName.hashCode())
+                  + String.valueOf(System.currentTimeMillis());
+              Function extension =
+                new FuncExtFunction(ns, funcName.getLocalPart(), uniqueKey);
+              p.m_matchFunc.setFunctionExpression(extension);
+              p.m_matchFunc = null;
+            }
+            else
+            {
+              Expression exp = (Expression) m_builtInFunctions.get(funcName);
+              if (null != exp)
+              {
+                exp = (Expression) exp.getClass().newInstance();
+                p.m_matchFunc.setFunctionExpression(exp);
+                p.m_matchFunc = null;
+              }
+              else
+              {
+                // TBD: a proper error throw.  -sb
+                throw new RuntimeException(
+                  "Function not found: " + funcName + "!");
+              }
+            }
+          }
+          newNode = qname;
+        }
+        catch (InstantiationException iae)
+        {
+          throw new org.apache.xml.utils.WrappedRuntimeException(iae);
+        }
+        catch (IllegalAccessException iae)
+        {
+          throw new org.apache.xml.utils.WrappedRuntimeException(iae);
+        }
+
+        break;
+
+        // === BINARY OPERATORS ===	
+
+      case XPathTreeConstants.JJTOREXPR :
+        newNode = new org.apache.xpath.operations.Or();
+        break;
+      case XPathTreeConstants.JJTANDEXPR :
+        newNode = new org.apache.xpath.operations.And();
+        break;
+      case XPathTreeConstants.JJTCOMPARISONEXPR :
+        {
+          Token operator = (Token) p.binaryTokenStack.peek();
+          switch (operator.kind)
+          {
+            case XPathConstants.Equals :
+              newNode = new org.apache.xpath.operations.Equals();
+              break;
+            case XPathConstants.NotEquals :
+              newNode = new org.apache.xpath.operations.NotEquals();
+              ;
+              break;
+            case XPathConstants.Lt :
+              newNode = new org.apache.xpath.operations.Lt();
+              break;
+            case XPathConstants.LtEquals :
+              newNode = new org.apache.xpath.operations.Lte();
+              break;
+            case XPathConstants.Gt :
+              newNode = new org.apache.xpath.operations.Gt();
+              break;
+            case XPathConstants.GtEquals :
+              newNode = new org.apache.xpath.operations.Gte();
+              break;
+            case XPathConstants.FortranEq :
+              newNode = new org.apache.xpath.operations.FortranEq();
+              break;
+            case XPathConstants.FortranNe :
+              newNode = new org.apache.xpath.operations.FortranNe();
+              break;
+            case XPathConstants.FortranLt :
+              newNode = new org.apache.xpath.operations.FortranLt();
+              break;
+            case XPathConstants.FortranLe :
+              newNode = new org.apache.xpath.operations.FortranLe();
+              break;
+            case XPathConstants.FortranGt :
+              newNode = new org.apache.xpath.operations.FortranGt();
+              break;
+            case XPathConstants.FortranGe :
+              newNode = new org.apache.xpath.operations.FortranGe();
+              break;
+            case XPathConstants.Is :
+              newNode = new org.apache.xpath.operations.Is();
+              break;
+            case XPathConstants.IsNot :
+              newNode = new org.apache.xpath.operations.IsNot();
+              break;
+            case XPathConstants.LtLt :
+              newNode = new org.apache.xpath.operations.LtLt();
+              break;
+            case XPathConstants.GtGt :
+              newNode = new org.apache.xpath.operations.GtGt();
+              break;
+            case XPathConstants.Precedes :
+              newNode = new org.apache.xpath.operations.Precedes();
+              break;
+            case XPathConstants.Follows :
+              newNode = new org.apache.xpath.operations.Follows();
+              break;
+          }
+        }
+        break;
+      case XPathTreeConstants.JJTRANGEEXPR :
+        newNode = new org.apache.xpath.seqctor.RangeExpr();
+        break;
+      case XPathTreeConstants.JJTADDITIVEEXPR :
+        {
+          Token operator = (Token) p.binaryTokenStack.peek();
+          switch (operator.kind)
+          {
+            case XPathConstants.Plus :
+              newNode = new org.apache.xpath.operations.Add();
+              break;
+            case XPathConstants.Minus :
+              newNode = new org.apache.xpath.operations.Subtract();
+              ;
+              break;
+          }
+        }
+        break;
+      case XPathTreeConstants.JJTMULTIPLICATIVEEXPR :
+        {
+          Token operator = (Token) p.binaryTokenStack.peek();
+          switch (operator.kind)
+          {
+            case XPathConstants.Multiply :
+              newNode = new org.apache.xpath.operations.Mult();
+              break;
+            case XPathConstants.Div :
+              newNode = new org.apache.xpath.operations.Div();
+              ;
+              break;
+            case XPathConstants.Idiv :
+              newNode = new org.apache.xpath.operations.Idiv();
+              break;
+            case XPathConstants.Mod :
+              newNode = new org.apache.xpath.operations.Mod();
+              ;
+              break;
+          }
+        }
+        break;
+
+        // === UNARY OPERATORS ===	
+      case XPathTreeConstants.JJTUNARYEXPR :
+        newNode = new UnaryExpr(p);
+        break;
+      case XPathTreeConstants.JJTPLUS :
+        newNode = new org.apache.xpath.operations.Pos();
+        break;
+      case XPathTreeConstants.JJTMINUS :
+        newNode = new org.apache.xpath.operations.Neg();
+        break;
+
+        // === VARIABLES ===	
+      case XPathTreeConstants.JJTVARNAME :
+        {
+          // We'll have to check to make sure the node is 
+          // really on the stack.
+          Variable var = new Variable();
+          Token varToken = p.getToken(0);
+          String varName = varToken.image;
+          QName varQName = new QName(varName, p.m_prefixResolver);
+          var.setQName(varQName);
+          newNode = var;
+        }
+        break;
+
+        // === LITERALS ===	
+      case XPathTreeConstants.JJTSTRINGLITERAL :
+        newNode = new org.apache.xpath.objects.XString();
+        break;
+      case XPathTreeConstants.JJTINTEGERLITERAL :
+        if(p.getVersion() >= 2.0)
+          newNode = new XInteger();
+        else
+          newNode = new XDouble();
+        break;
+      case XPathTreeConstants.JJTDECIMALLITERAL :
+        newNode = new XDecimal();
+        break;
+      case XPathTreeConstants.JJTDOUBLELITERAL :
+        newNode = new XDouble();
+        break;
+
+        // === SEQUENCE CONSTRUCTION ===	
+      case XPathTreeConstants.JJTEXPRSEQUENCE :
+        newNode = new ExprSequence();
+        break;
+
+        // === QUANTIFIED EXPRESSIONS ===	
+      case XPathTreeConstants.JJTQUANTIFIEDEXPR :
+        newNode = new QuantifiedExpr(p);
+        break;
+      case XPathTreeConstants.JJTSOME :
+        newNode = new org.apache.xpath.quantified.Some();
+        break;
+      case XPathTreeConstants.JJTEVERY :
+        newNode = new org.apache.xpath.quantified.Every();
+        break;
+      case XPathTreeConstants.JJTSATISFIES :
+        newNode = new org.apache.xpath.quantified.Satisfies();
+        break;
+        
+      case XPathTreeConstants.JJTIN : // Both for ForClause and Quantified.
+        newNode = new In(p);
+        break;
+
+        // === CONDITIONAL EXPRESSIONS ===	
+      case XPathTreeConstants.JJTIFEXPR :
+        newNode = new IfExpr(p);
+        break;
+      case XPathTreeConstants.JJTIFLPAR :
+        newNode = new org.apache.xpath.conditional.If();
+        break;
+      case XPathTreeConstants.JJTTHEN :
+        newNode = new org.apache.xpath.conditional.Then();
+        break;
+      case XPathTreeConstants.JJTELSE :
+        newNode = new org.apache.xpath.conditional.Else();
+        break;
+
+        // === ITTERATION ===	
+      case XPathTreeConstants.JJTFLWREXPR :
+        newNode = new FLWRExpr();
+        break;
+      case XPathTreeConstants.JJTFORCLAUSE :
+        newNode = new org.apache.xpath.parser.ForClause(p);
+        break;
+      case XPathTreeConstants.JJTRETURN :
+        newNode = new org.apache.xpath.parser.Return(p);
+        break;
+
+        // === TYPE HANDLING ===	
+      case XPathTreeConstants.JJTINSTANCEOFEXPR :
+        newNode = new InstanceofExpr();
+        break;
+      case XPathTreeConstants.JJTINSTANCEOF :
+        newNode = new Instanceof(p);
+        break;
+      case XPathTreeConstants.JJTVALIDATEEXPR :
+        newNode = new NonExecutableExpression(p, "JJTVALIDATEEXPR");
+        break;
+      case XPathTreeConstants.JJTVALIDATE :
+        newNode = new NonExecutableExpression(p, "JJTVALIDATE");
+        break;
+      case XPathTreeConstants.JJTLBRACE :
+        newNode = new NonExecutableExpression(p, "JJTLBRACE");
+        break;
+      case XPathTreeConstants.JJTRBRACE :
+        newNode = new NonExecutableExpression(p, "JJTRBRACE");
+        break;
+      case XPathTreeConstants.JJTCASTEXPR :
+        newNode = new NonExecutableExpression(p, "JJTCASTEXPR");
+        break;
+      case XPathTreeConstants.JJTCASTAS :
+        newNode = new NonExecutableExpression(p, "JJTCASTAS");
+        break;
+      case XPathTreeConstants.JJTTREATAS :
+        newNode = new NonExecutableExpression(p, "JJTTREATAS");
+        break;
+      case XPathTreeConstants.JJTSCHEMACONTEXT :
+        newNode = new SchemaContext(p, "JJTSCHEMACONTEXT");
+        break;
+      case XPathTreeConstants.JJTSCHEMAGLOBALCONTEXT :
+        newNode = new SchemaGlobalContext(p, "JJTSCHEMAGLOBALCONTEXT");
+        break;
+      case XPathTreeConstants.JJTTYPE :
+        newNode = new NonExecutableExpression(p, "JJTTYPE");
+        break;
+      case XPathTreeConstants.JJTSCHEMACONTEXTSTEP :
+        newNode = new SchemaContextStep(p);
+        break;
+      case XPathTreeConstants.JJTSEQUENCETYPE :
+        newNode = new SequenceType(p, "JJTSEQUENCETYPE");
+        break;
+      case XPathTreeConstants.JJTEMPTY :
+        newNode = new Empty(p, "JJTEMPTY");
+        break;
+      case XPathTreeConstants.JJTITEMTYPE :
+        newNode = new ItemType(p, "JJTITEMTYPE");
+        break;
+      case XPathTreeConstants.JJTELEMENTTYPE :
+        newNode = new NodeTestType(p, DTMFilter.SHOW_ELEMENT);
+        break;
+      case XPathTreeConstants.JJTATTRIBUTETYPE :
+        newNode = new NodeTestType(p, DTMFilter.SHOW_ATTRIBUTE);
+        break;
+      case XPathTreeConstants.JJTNODE :
+        newNode = new NodeTestType(p, DTMFilter.SHOW_ALL);
+        break;
+      case XPathTreeConstants.JJTPROCESSINGINSTRUCTION :
+        newNode = new NodeTestType(p, DTMFilter.SHOW_PROCESSING_INSTRUCTION);
+        break;
+      case XPathTreeConstants.JJTCOMMENT :
+        newNode = new NodeTestType(p, DTMFilter.SHOW_COMMENT);
+        break;
+      case XPathTreeConstants.JJTTEXT :
+        newNode = new NodeTestType(p, DTMFilter.SHOW_TEXT);
+        break;
+      case XPathTreeConstants.JJTDOCUMENT :
+        newNode = new NodeTestType(p, DTMFilter.SHOW_DOCUMENT);
+        break;
+      case XPathTreeConstants.JJTITEM :
+        newNode = new NodeTestType(p, DTMFilter.SHOW_ITEM);
+        break;
+      case XPathTreeConstants.JJTUNTYPED :
+        newNode = new NodeTestType(p, DTMFilter.SHOW_UNTYPED);
+        break;
+//      case XPathTreeConstants.JJTATOMICVALUE :
+//        newNode = new AtomicType(p);
+//        break;
+      case XPathTreeConstants.JJTELEMORATTRTYPE :
+        newNode = new ElemOrAttrType(p, "JJTELEMORATTRTYPE");
+        break;
+      case XPathTreeConstants.JJTSCHEMATYPE :
+        newNode = new SchemaType(p);
+        break;
+      case XPathTreeConstants.JJTOFTYPE :
+        newNode = new OfType(p, "JJTOFTYPE");
+        break;
+      case XPathTreeConstants.JJTATOMICTYPE :
+        newNode = new AtomicType(p, "JJTATOMICTYPE");
+        break;
+      case XPathTreeConstants.JJTOCCURRENCEINDICATOR :
+        newNode = new OccurrenceIndicator(p, "JJTOCCURRENCEINDICATOR");
+        break;
+      case XPathTreeConstants.JJTMULTIPLY :
+        // Leave as NEE
+        newNode = new NonExecutableExpression(p, "JJTMULTIPLY");
+        break;
+      case XPathTreeConstants.JJTQMARK :
+        // Leave as NEE
+        newNode = new NonExecutableExpression(p, "JJTQMARK");
+        break;
+
+      default :
+        newNode = new NonExecutableExpression(p, "(case default: " + id + ")");
+    }
+    return newNode;
+  }
+
+  /**
+   * Tell if this node is part of a PathExpr chain.  For instance:
+   * <pre>
+   * 	|UnaryExpr
+   * 	|   PathExpr
+   * 	|      StepExpr
+   * 	|         AxisChild child::
+   * 	|         NodeTest
+   * 	|            NameTest
+   * 	|               QName foo
+   * 	|         Predicates   * 
+   * </pre><br/>
+   * In this example, UnaryExpr, PathExpr, and StepExpr should all return true.
+   */
+  public boolean isPathExpr()
+  {
+    return false;
+  }
+
+  /**
+   * Tell if this node should have it's PathExpr ancestory reduced.
+   */
+  public boolean isPathExprReduced()
+  {
+    return false;
+  }
+
+  /**
+   * Tell if this node should have it's parent reduced.
+   */
+  public boolean shouldReduceIfOneChild()
+  {
+    return false;
+  }
+
+  /**
+   * This function checks the integrity of the tree, after it has been fully built and 
+   * is ready for execution.
+   * @return boolean true if the tree has integrity, false otherwise.
+   */
+  public boolean checkTreeIntegrity()
+  {
+    return checkTreeIntegrity(0, 0, true);
+  }
+
+  /**
+   * Tell the user there is a problem with the tree.
+   * @param s The string to show the user.
+   * @return boolean false always.
+   */
+  protected boolean flagProblem(String s)
+  {
+    // System.err.println("checkTreeIntegrity failed: " + s);
+    throw new RuntimeException("checkTreeIntegrity failed: " + s);
+    // return false;
+  }
+
+  /**
+   * This function checks the integrity of the tree, after it has been fully built and 
+   * is ready for execution.  Derived classes can overload this function to check 
+   * their own assumptions.
+   * 
+   * @param levelCount The current tree level.
+   * @param childNumber The current child index.
+   * @param parentOK The parent's integrity flag.
+   * @return boolean true the node does not have integrity, otherwise 
+   *          return the parentOK value.
+   */
+  public boolean checkTreeIntegrity(
+    int levelCount,
+    int childNumber,
+    boolean parentOK)
+  {
+    boolean isOK;
+//    try
+    {
+      isOK = parentOK;
+      if (levelCount == 0)
+      {
+        if (!(null == jjtGetParent()))
+          isOK =
+            flagProblem("The root node has a parent?? parent: " + jjtGetParent());
+      }
+      else
+      {
+        Node parent = jjtGetParent();
+        if (null == parent)
+          isOK =
+            flagProblem(
+              toString() + " has a null parent and is not the root node! "+
+                this.getClass().getName());
+        else
+        {
+          if ( (childNumber >= parent.jjtGetNumChildren())
+            || (parent.jjtGetChild(childNumber) != this))
+          {
+            isOK =
+              flagProblem(
+                toString() + " has a parent that it is not a child of!");
+          }
+        }
+      
+      }
+      if (this instanceof NonExecutableExpression)
+        isOK = flagProblem(toString() + " is a NonExecutableExpression!");
+      
+      int childCount = jjtGetNumChildren();
+      for (int i = 0; i < childCount; i++)
+      {
+        Node child = jjtGetChild(i);
+        if(null == child)
+          isOK = flagProblem(toString() + " has a null child!");
+        else
+          isOK = ((SimpleNode) child).checkTreeIntegrity(levelCount + 1, i, isOK);
+      }
+    }
+//    catch (RuntimeException e)
+//    {
+//      isOK = flagProblem(toString() + e.getMessage());
+//      e.printStackTrace();
+//    }
+
+    return isOK;
+  }
+
+  /**
+   * This ugly little function strips the extranious PathExpr/RelativePathExpr/StepExpr
+   * from XObjects, recursively calling the node's child at index zero, if 
+   * the node is a path expression.  It should be called from 
+   * jjtAddChild functions.
+   * 
+   * @param n The node to fix up.
+   * @return Node The fixed up node that should be added as a child, which 
+   *               may well not be the same node that was passed in.
+   */
+  protected org.apache.xpath.parser.Node fixupPrimaryRecursive(
+    org.apache.xpath.parser.Node n)
+  {
+    if (((SimpleNode) n).isPathExpr() && n.jjtGetNumChildren() > 0)
+    {
+      SimpleNode newRoot = (SimpleNode) fixupPrimaryRecursive(n.jjtGetChild(0));
+
+      if (newRoot.isPathExprReduced() && !newRoot.isPathExpr())
+      {
+        return newRoot;
+      }
+    }
+    return n;
+  }
+
+  /**
+   * Set this to false if you don't want the PathExprs rewritten to LocationPaths.
+   * For Diagnostic purposes.
+   */
+  public static boolean m_rewritePathExprs = true;
+
+  /**
+   * This ugly little function strips the extranious PathExpr/RelativePathExpr/StepExpr
+   * from XObjects.  I'm not sure what I'm going to do with the predicates of 
+   * these expressions, or with variables, yet.  It should be called from 
+   * jjtAddChild functions.
+   * 
+   * @param n The node to fix up.
+   * @return Node The fixed up node that should be added as a child, which 
+   *               may well not be the same node that was passed in.
+   */
+  protected org.apache.xpath.parser.Node fixupPrimarys(
+    org.apache.xpath.parser.Node n)
+  {
+    if (((SimpleNode) n).shouldReduceIfOneChild())
+    {
+      n = n.jjtGetChild(0);
+      n.jjtSetParent(this);
+      return n;
+    }
+    Node orig = n;
+    if ((n instanceof NonExecutableExpression) && n.jjtGetNumChildren() > 0)
+    {
+      n = fixupPrimaryRecursive(n);
+    }
+    if (n instanceof PathExpr)
+    {
+      Node mightBeStepExprOrSomethingElse = n.jjtGetChild(0);
+      if (!(mightBeStepExprOrSomethingElse instanceof StepExpr))
+        n = mightBeStepExprOrSomethingElse; // is something else, so reduce
+    }
+    if (m_rewritePathExprs && n instanceof PathExpr)
+    {
+      boolean isTopLevel = (((PathExpr) n).m_parser.m_predLevel == 0);
+      try
+      {
+        n = (Node) WalkerFactory.newDTMIterator((PathExpr) n, isTopLevel);
+      }
+      catch (javax.xml.transform.TransformerException te)
+      {
+        throw new org.apache.xml.utils.WrappedRuntimeException(te);
+      }
+    }
+    if (n != orig)
+      n.jjtSetParent(this); // because jjtree can't!
+    return n;
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtOpen()
+   */
+  public void jjtOpen()
+  {
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtClose()
+   */
+  public void jjtClose()
+  {
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtSetParent(Node)
+   */
+  public void jjtSetParent(Node n)
+  {
+    ((Expression) this).exprSetParent((ExpressionNode) n);
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtGetParent()
+   */
+  public Node jjtGetParent()
+  {
+    return (Node) ((Expression) this).exprGetParent();
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtAddChild(Node, int)
+   */
+  public void jjtAddChild(Node n, int i)
+  {
+    n = fixupPrimarys(n);
+    ((Expression) this).exprAddChild((ExpressionNode) n, i);
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtGetChild(int)
+   */
+  public Node jjtGetChild(int i)
+  {
+    return (Node) ((Expression) this).exprGetChild(i);
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtGetNumChildren()
+   */
+  public int jjtGetNumChildren()
+  {
+    return ((Expression) this).exprGetNumChildren();
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtAccept(XPathVisitor, Object)
+   */
+  public Object jjtAccept(XPathVisitor visitor, Object data)
+  {
+    return visitor.visit(this, data);
+  }
+
+  /**
+   * Call jjtAccept for each child of the node.
+   * @param visitor The visitor that will visit the child node.
+   * @param data A data object to be handed to that visitor.
+   * @return Object The data object handed in, possibly  
+   *                 modified by jjtAccept.
+   */
+  public Object childrenAccept(XPathVisitor visitor, Object data)
+  {
+    int nChildren = jjtGetNumChildren();
+    for (int i = 0; i < nChildren; ++i)
+    {
+      jjtGetChild(i).jjtAccept(visitor, data);
+    }
+    return data;
+  }
+
+  /**
+   * @see java.lang.Object#toString()
+   */
+  public String toString()
+  {
+    return this.getClass().getName();
+  }
+
+  /**
+   * Method toString.
+   * @param prefix
+   * @return String
+   */
+  public String toString(String prefix)
+  {
+    return prefix + toString();
+  }
+
+  public void processToken(Token t)
+  {
+    // abstract
+  }
+
+  /**
+   * Dump a diagnostic representation of the node to System.out.
+   * @param prefix The prefix string to be added before the 
+   *                to each line of output.
+   */
+  public void dump(String prefix)
+  {
+    dump(prefix, System.out);
+  }
+
+  /**
+   * Method for subclasses to override to print the diagnostic 
+   * <i>value</i> of the node.
+   * @param ps The PrintStream to write the value to.
+   */
+  public void printValue(java.io.PrintStream ps)
+  {
+  }
+
+  /**
+   * Dump a diagnostic representation of the node to a PrintStream.
+   * 
+   * @param prefix The prefix string to be added before the 
+   *                to each line of output.
+  
+   * @param ps The PrintStream where the representation will 
+   *            be written.
+   */
+  public void dump(String prefix, java.io.PrintStream ps)
+  {
+    ps.print(toString(prefix));
+    printValue(ps);
+    ps.println();
+    int nChildren = jjtGetNumChildren();
+    for (int i = 0; i < nChildren; ++i)
+    {
+      SimpleNode n = (SimpleNode) jjtGetChild(i);
+      if (n != null)
+      {
+        n.dump(prefix + "   ", ps);
+      }
+    }
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/SlashOrSlashSlash.java b/src/org/apache/xpath/parser/SlashOrSlashSlash.java
new file mode 100644
index 0000000..cc8db01
--- /dev/null
+++ b/src/org/apache/xpath/parser/SlashOrSlashSlash.java
@@ -0,0 +1,65 @@
+package org.apache.xpath.parser;
+
+/**
+ * Represents a "/" or "//" node that does not appear at the head of a path expression.  This node 
+ * is not executable and exists for construction purposes only.
+ * 
+ * Created Jul 11, 2002
+ * @author sboag
+ */
+public class SlashOrSlashSlash extends NonExecutableExpression
+{
+  /** true if this is a "//" step. */
+  boolean m_isSlashSlash;
+
+  /**
+   * Construct a SlashOrSlashSlash node.
+   * @param isSlashSlash true if this is a "//" step.
+   * @see org.apache.xpath.parser.NonExecutableExpression#NonExecutableExpression(XPath)
+   */
+  public SlashOrSlashSlash(XPath parser)
+  {
+    super(parser);
+  }
+
+  /**
+   * Construct a SlashOrSlashSlash node.
+   * @param isSlashSlash true if this is a "//" step.
+   * @param parser The XPath parser that is creating this node.
+   */
+  SlashOrSlashSlash(boolean isSlashSlash, XPath parser)
+  {
+    super(parser);
+    m_isSlashSlash = isSlashSlash;
+  }
+  
+  /**
+   * Returns the isSlashSlash property.
+   * @return boolean true if this is a "//" step.
+   */
+  public boolean getisSlashSlash()
+  {
+    return m_isSlashSlash;
+  }
+
+  
+  /**
+   * Returns the isSlashSlash property.
+   * @return boolean true if this is a "//" step.
+   */
+  public boolean isSlashSlash()
+  {
+    return m_isSlashSlash;
+  }
+
+  /**
+   * Sets the isSlashSlash.
+   * @param isSlashSlash The isSlashSlash to set
+   */
+  public void setIsSlashSlash(boolean isSlashSlash)
+  {
+    m_isSlashSlash = isSlashSlash;
+  }
+
+}
+
diff --git a/src/org/apache/xpath/parser/Star.java b/src/org/apache/xpath/parser/Star.java
new file mode 100644
index 0000000..4392536
--- /dev/null
+++ b/src/org/apache/xpath/parser/Star.java
@@ -0,0 +1,22 @@
+package org.apache.xpath.parser;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class Star extends NonExecutableExpression
+{
+  public Star(XPath parser)
+  {
+	  super(parser);
+  }
+}
+
diff --git a/src/org/apache/xpath/parser/StarColonNCName.java b/src/org/apache/xpath/parser/StarColonNCName.java
new file mode 100644
index 0000000..9a9a147
--- /dev/null
+++ b/src/org/apache/xpath/parser/StarColonNCName.java
@@ -0,0 +1,29 @@
+package org.apache.xpath.parser;
+public class StarColonNCName extends QName
+{
+  StarColonNCName(XPath parser)
+  {
+  	super(parser);
+  }
+	
+  protected String m_localName;
+  
+  public String getNamespaceURI()
+  {
+  	return org.apache.xpath.patterns.NodeTest.WILD;
+  }
+
+  public String getLocalName()
+  {
+  	return m_localName;
+  }  
+  
+  
+  public void processToken(Token t) 
+  { 
+  	int posOfColon = t.image.indexOf(':');
+  	m_localName = t.image.substring(posOfColon+1).trim();
+  }
+
+}
+
diff --git a/src/org/apache/xpath/parser/StepExpr.java b/src/org/apache/xpath/parser/StepExpr.java
new file mode 100644
index 0000000..20c95dc
--- /dev/null
+++ b/src/org/apache/xpath/parser/StepExpr.java
@@ -0,0 +1,262 @@
+package org.apache.xpath.parser;
+
+import org.apache.xml.dtm.Axis;
+import org.apache.xml.dtm.DTMFilter;
+import org.apache.xpath.axes.LocPathIterator;
+
+/**
+ * The responsibility of StepExpr is to hold the axis, node test, and 
+ * predicates while the expression is being constructed.  Objects of 
+ * this class will be rewritten as DTMIterators or AxesWalkers.
+ * 
+ * Created Jul 12, 2002
+ * 
+ * @author sboag
+ * @see org.apache.xpath.parser.NonExecutableExpression#NonExecutableExpression(XPath)
+ * @see org.apache.xpath.parser.PathExpr#jjtAddChild(Node, int)
+ * @see org.apache.xpath.parser.SimpleNode#jjtAddChild(Node, int)
+ */
+public class StepExpr extends NonExecutableExpression
+{
+  /**
+   * Create a StepExpr object for construction purposes.
+   */
+  public StepExpr(XPath parser)
+  {
+    super(parser);
+  }
+
+  /**
+   * Tell if this node is part of a PathExpr chain.  For instance:
+   * <pre>
+   * 	|UnaryExpr
+   * 	|   PathExpr
+   * 	|      StepExpr
+   * 	|         AxisChild child::
+   * 	|         NodeTest
+   * 	|            NameTest
+   * 	|               QName foo
+   * 	|         Predicates   * 
+   * </pre><br/>
+   * In this example, UnaryExpr, PathExpr, and StepExpr should all return true.
+   */
+  public boolean isPathExpr()
+  {
+    // Don't reduce if there are predicates!
+    return (getNumPredicates() > 0) ? false : true;
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtClose()
+   */
+  public void jjtClose()
+  {
+    Node n = jjtGetChild(0);
+    if (n instanceof PatternAxis && n.jjtGetNumChildren() == 2)
+    {
+      Node patternAxis = n.jjtGetChild(0);
+      m_exprs.setElementAt(patternAxis, 0);
+      patternAxis.jjtSetParent(this);
+
+      NameTest nt = (NameTest) n.jjtGetChild(1);
+      NodeTest nodeTest = new NodeTest(getParser());
+      nodeTest.jjtAddChild(nt, 0);
+
+      m_exprs.insertElementAt(nodeTest, 1);
+      nodeTest.jjtSetParent(this);
+
+      ((PatternAxis) n).m_exprs.removeAllElements();
+    }
+    else
+      if (n instanceof PatternAxis && n.jjtGetNumChildren() == 1)
+      {
+        Node child = n.jjtGetChild(0);
+        if (child instanceof NodeTest)
+        {
+          NodeTest nodeTest = (NodeTest) n.jjtGetChild(0);
+          m_exprs.insertElementAt(nodeTest, 1);
+          nodeTest.jjtSetParent(this);
+        }
+        else // instanceof pattern axis
+          {
+          // occurs for "." and "..".
+          PatternAxis patAxes = (PatternAxis) n.jjtGetChild(0);
+          m_exprs.setElementAt(patAxes, 0); // replace self
+          patAxes.jjtSetParent(this);
+          NodeTest nodeTest = (NodeTest) patAxes.jjtGetChild(0);
+          m_exprs.insertElementAt(nodeTest, 1);
+          nodeTest.jjtSetParent(this);
+          patAxes.m_exprs.removeAllElements();
+        }
+
+        ((PatternAxis) n).m_exprs.removeAllElements();
+      }
+
+    // We can't tell if a "*" is an attribute until late, so we have to 
+    // wait until now, and fix up the WhatToShow value.
+    int axis = getAxis();
+
+    if (Axis.ATTRIBUTE == axis || Axis.NAMESPACE == axis)
+    {
+      NodeTest ntest = getNodeTest();
+      if (null != ntest)
+      {
+        if (org.apache.xml.dtm.Axis.ATTRIBUTE == axis)
+          ntest.setWhatToShow(org.apache.xml.dtm.DTMFilter.SHOW_ATTRIBUTE);
+        else
+          if (org.apache.xml.dtm.Axis.NAMESPACE == axis)
+          {
+            ntest.setWhatToShow(org.apache.xml.dtm.DTMFilter.SHOW_NAMESPACE);
+            org.apache.xml.utils.PrefixResolver resolver =
+              getParser().getPrefixResolver();
+            // NodeTest compares the resolved URI, so I guess this is done here.
+            // (even though I can't find it in the old code... 
+            // I guess it's in there somewhere? -sb)
+            String prefix = ntest.getLocalName();
+            if (!prefix.equals("*"))
+            {
+              String ns = resolver.getNamespaceForPrefix(prefix);
+              ntest.setLocalName(ns);
+            }
+          }
+      }
+    }
+  }
+
+  /**
+   * Get the axis ID for this step expression.
+   * @return int One of org.apache.xml.dtm.Axis.XXXX.
+   * @see org.apache.xml.dtm.Axis
+   */
+  public int getAxis()
+  {
+    Node firstChild = jjtGetChild(0);
+    if (firstChild instanceof PatternAxis)
+      return ((PatternAxis) firstChild).getAxis();
+    else
+      return org.apache.xml.dtm.Axis.ALLFROMNODE;
+  }
+
+  /**
+   * Get the axis to be traversed for this step expression.
+   * @return PatternAxis The axis expression object, or null if there isn't one.
+   */
+  public PatternAxis getAxisExpr()
+  {
+    Node firstChild = jjtGetChild(0);
+    if (firstChild instanceof PatternAxis)
+      return ((PatternAxis) firstChild);
+    else
+      return null;
+  }
+
+  /**
+   * Get the node test object owned by this step expression.
+   * @return NodeTest The node test, or null if there isn't one.
+   */
+  public NodeTest getNodeTest()
+  {
+    if (jjtGetNumChildren() > 2)
+    {
+      Node secondChild = jjtGetChild(1);
+      if (secondChild instanceof NodeTest)
+        return (NodeTest) secondChild;
+      else
+        return null;
+    }
+    else
+      return null;
+  }
+
+  /**
+   * Tell what this node should show on the given axis.
+   * @return int One of org.apache.xml.dtm.DTMFilter.SHOW_XXX.
+   * @see org.apache.xml.dtm.DTMFilter
+   */
+  public int getWhatToShow()
+  {
+    NodeTest nt = getNodeTest();
+    if (null != nt)
+      return nt.getWhatToShow();
+    else
+      return DTMFilter.SHOW_ALL;
+  }
+
+  /**
+   * Tell if this node test is a wildcard.
+   * @return boolean true if the node test should show all the nodes on the axis.
+   */
+  public boolean isTotallyWild()
+  {
+    NodeTest nt = getNodeTest();
+    if (null != nt)
+      return nt.isTotallyWild();
+    else
+      return true;
+  }
+
+  /**
+   * Get the namespace URI for the node test owned by this expression.
+   * @return String URI string, or null if none.
+   */
+  public String getNamespaceURI()
+  {
+    NodeTest nt = getNodeTest();
+    if (null != nt)
+      return nt.getNamespaceURI();
+    else
+      return null;
+  }
+
+  /**
+   * Get the local name for the node test owned by this expression.
+   * @return String local name, or null if none.
+   */
+  public String getLocalName()
+  {
+    NodeTest nt = getNodeTest();
+    if (null != nt)
+      return nt.getLocalName();
+    else
+      return null;
+  }
+
+  /**
+   * Get the number of predicates for this expression.
+   * @return int The number of predicates to apply to this expression.
+   */
+  public int getNumPredicates()
+  {
+    int lastChildIndex = jjtGetNumChildren() - 1;
+    if (lastChildIndex > 0)
+    {
+      Node lastChild = jjtGetChild(lastChildIndex);
+      if (lastChild instanceof Predicates)
+        return ((Predicates) lastChild).jjtGetNumChildren();
+      else
+        return 0;
+    }
+    else
+      return 0;
+  }
+
+  /**
+   * Get the predicates for this step expression.
+   * @return Predicates predicates if they have been added, otherwise null.
+   */
+  public Predicates getPredicates()
+  {
+    int lastChildIndex = jjtGetNumChildren() - 1;
+    if (lastChildIndex > 0)
+    {
+      Node lastChild = jjtGetChild(lastChildIndex);
+      if (lastChild instanceof Predicates)
+        return (Predicates) lastChild;
+      else
+        return null;
+    }
+    else
+      return null;
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/TempFunctionHolder.java b/src/org/apache/xpath/parser/TempFunctionHolder.java
new file mode 100644
index 0000000..6466fd0
--- /dev/null
+++ b/src/org/apache/xpath/parser/TempFunctionHolder.java
@@ -0,0 +1,38 @@
+package org.apache.xpath.parser;
+
+import org.apache.xpath.patterns.FunctionPattern;
+
+/**
+ * Temporarily holds a function while it's being built.
+ */
+public class TempFunctionHolder extends FunctionPattern
+{
+
+  /**
+   * Constructor for TempFunctionHolder
+   */
+  public TempFunctionHolder()
+  {
+    super();
+  }
+  
+  /**
+   * Tell if this node should have it's parent reduced.
+   */
+  public boolean shouldReduceIfOneChild()
+  {
+  	return true;
+  }
+
+  public Node jjtGetChild(int i) 
+  {
+    return m_functionExpr;
+  }
+
+  public int jjtGetNumChildren() {
+    return 1;
+  }
+
+
+}
+
diff --git a/src/org/apache/xpath/parser/TextTest.java b/src/org/apache/xpath/parser/TextTest.java
new file mode 100644
index 0000000..679b2a2
--- /dev/null
+++ b/src/org/apache/xpath/parser/TextTest.java
@@ -0,0 +1,21 @@
+package org.apache.xpath.parser;
+
+import org.apache.xml.dtm.DTMFilter;
+
+/**
+ * This is an expression node that only exists for construction 
+ * purposes. 
+ */
+public class TextTest extends KindTest
+{
+   public TextTest(XPath parser)
+   {
+	  super(parser);
+   }
+
+   public int getWhatToShow()
+   {
+      return DTMFilter.SHOW_TEXT;
+   }	
+}
+
diff --git a/src/org/apache/xpath/parser/Token.java b/src/org/apache/xpath/parser/Token.java
new file mode 100644
index 0000000..7016baa
--- /dev/null
+++ b/src/org/apache/xpath/parser/Token.java
@@ -0,0 +1,81 @@
+/* Generated By:JavaCC: Do not edit this line. Token.java Version 0.7pre3 */
+package org.apache.xpath.parser;
+
+/**
+ * Describes the input token stream.
+ */
+
+public class Token {
+
+  /**
+   * An integer that describes the kind of this token.  This numbering
+   * system is determined by JavaCCParser, and a table of these numbers is
+   * stored in the file ...Constants.java.
+   */
+  public int kind;
+
+  /**
+   * beginLine and beginColumn describe the position of the first character
+   * of this token; endLine and endColumn describe the position of the
+   * last character of this token.
+   */
+  public int beginLine, beginColumn, endLine, endColumn;
+
+  /**
+   * The string image of the token.
+   */
+  public String image;
+
+  /**
+   * A reference to the next regular (non-special) token from the input
+   * stream.  If this is the last token from the input stream, or if the
+   * token manager has not read tokens beyond this one, this field is
+   * set to null.  This is true only if this token is also a regular
+   * token.  Otherwise, see below for a description of the contents of
+   * this field.
+   */
+  public Token next;
+
+  /**
+   * This field is used to access special tokens that occur prior to this
+   * token, but after the immediately preceding regular (non-special) token.
+   * If there are no such special tokens, this field is set to null.
+   * When there are more than one such special token, this field refers
+   * to the last of these special tokens, which in turn refers to the next
+   * previous special token through its specialToken field, and so on
+   * until the first special token (whose specialToken field is null).
+   * The next fields of special tokens refer to other special tokens that
+   * immediately follow it (without an intervening regular token).  If there
+   * is no such token, this field is null.
+   */
+  public Token specialToken;
+
+  /**
+   * Returns the image.
+   */
+  public final String toString()
+  {
+     return image;
+  }
+
+  /**
+   * Returns a new Token object, by default. However, if you want, you
+   * can create and return subclass objects based on the value of ofKind.
+   * Simply add the cases to the switch for all those special cases.
+   * For example, if you have a subclass of Token called IDToken that
+   * you want to create if ofKind is ID, simlpy add something like :
+   *
+   *    case MyParserConstants.ID : return new IDToken();
+   *
+   * to the following switch statement. Then you can cast matchedToken
+   * variable to the appropriate type and use it in your lexical actions.
+   */
+  public static final Token newToken(int ofKind)
+  {
+     switch(ofKind)
+     {
+       default : return new Token();
+     }
+  }
+
+}
diff --git a/src/org/apache/xpath/parser/TokenMgrError.java b/src/org/apache/xpath/parser/TokenMgrError.java
new file mode 100644
index 0000000..2ee4f10
--- /dev/null
+++ b/src/org/apache/xpath/parser/TokenMgrError.java
@@ -0,0 +1,133 @@
+/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 0.7pre2 */
+package org.apache.xpath.parser;
+
+public class TokenMgrError extends Error
+{
+   /*
+    * Ordinals for various reasons why an Error of this type can be thrown.
+    */
+
+   /**
+    * Lexical error occured.
+    */
+   static final int LEXICAL_ERROR = 0;
+
+   /**
+    * An attempt wass made to create a second instance of a static token manager.
+    */
+   static final int STATIC_LEXER_ERROR = 1;
+
+   /**
+    * Tried to change to an invalid lexical state.
+    */
+   static final int INVALID_LEXICAL_STATE = 2;
+
+   /**
+    * Detected (and bailed out of) an infinite loop in the token manager.
+    */
+   static final int LOOP_DETECTED = 3;
+
+   /**
+    * Indicates the reason why the exception is thrown. It will have
+    * one of the above 4 values.
+    */
+   int errorCode;
+
+   /**
+    * Replaces unprintable characters by their espaced (or unicode escaped)
+    * equivalents in the given string
+    */
+   protected static final String addEscapes(String str) {
+      StringBuffer retval = new StringBuffer();
+      char ch;
+      for (int i = 0; i < str.length(); i++) {
+        switch (str.charAt(i))
+        {
+           case 0 :
+              continue;
+           case '\b':
+              retval.append("\\b");
+              continue;
+           case '\t':
+              retval.append("\\t");
+              continue;
+           case '\n':
+              retval.append("\\n");
+              continue;
+           case '\f':
+              retval.append("\\f");
+              continue;
+           case '\r':
+              retval.append("\\r");
+              continue;
+           case '\"':
+              retval.append("\\\"");
+              continue;
+           case '\'':
+              retval.append("\\\'");
+              continue;
+           case '\\':
+              retval.append("\\\\");
+              continue;
+           default:
+              if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
+                 String s = "0000" + Integer.toString(ch, 16);
+                 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
+              } else {
+                 retval.append(ch);
+              }
+              continue;
+        }
+      }
+      return retval.toString();
+   }
+
+   /**
+    * Returns a detailed message for the Error when it is thrown by the
+    * token manager to indicate a lexical error.
+    * Parameters : 
+    *    EOFSeen     : indicates if EOF caused the lexicl error
+    *    curLexState : lexical state in which this error occured
+    *    errorLine   : line number when the error occured
+    *    errorColumn : column number when the error occured
+    *    errorAfter  : prefix that was seen before this error occured
+    *    curchar     : the offending character
+    * Note: You can customize the lexical error message by modifying this method.
+    */
+   private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
+      return("Lexical error at line " +
+           errorLine + ", column " +
+           errorColumn + ".  Encountered: " +
+           (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
+           "after : \"" + addEscapes(errorAfter) + "\"");
+   }
+
+   /**
+    * You can also modify the body of this method to customize your error messages.
+    * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
+    * of end-users concern, so you can return something like : 
+    *
+    *     "Internal Error : Please file a bug report .... "
+    *
+    * from this method for such cases in the release version of your parser.
+    */
+   public String getMessage() {
+      return super.getMessage();
+   }
+
+   /*
+    * Constructors of various flavors follow.
+    */
+
+   public TokenMgrError() {
+   }
+
+   public TokenMgrError(String message, int reason) {
+      super(message);
+      errorCode = reason;
+   }
+
+   public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
+      this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
+   }
+}
diff --git a/src/org/apache/xpath/parser/UnaryExpr.java b/src/org/apache/xpath/parser/UnaryExpr.java
new file mode 100644
index 0000000..efb9824
--- /dev/null
+++ b/src/org/apache/xpath/parser/UnaryExpr.java
@@ -0,0 +1,54 @@
+package org.apache.xpath.parser;
+public class UnaryExpr extends NonExecutableExpression
+{
+  public UnaryExpr(XPath parser)
+  {
+	  super(parser);
+  }
+
+  public void jjtClose() 
+  {
+  	int n = jjtGetNumChildren();
+  	if(n > 1)
+  	{
+  		Node head = jjtGetChild(0);
+  		for(int i = 1; i < n; i++)
+  		{
+  			Node next = jjtGetChild(i);
+  			head.jjtAddChild(next, 0);
+  			head = next;
+  		}
+  		m_exprs.setSize(1);
+  	}
+  }
+  
+  /**
+   * Tell if this node is part of a PathExpr chain.  For instance:
+   * <pre>
+   * 	|UnaryExpr
+   * 	|   PathExpr
+   * 	|      StepExpr
+   * 	|         AxisChild child::
+   * 	|         NodeTest
+   * 	|            NameTest
+   * 	|               QName foo
+   * 	|         Predicates   * 
+   * </pre><br/>
+   * In this example, UnaryExpr, PathExpr, and StepExpr should all return true.
+   */
+  public boolean isPathExpr()
+  {
+  	return true;
+  }
+ 
+  /**
+   * @see SimpleNode#shouldReduceIfOneChild()
+   */
+  public boolean shouldReduceIfOneChild()
+  {
+    return (jjtGetNumChildren() == 1) ? true : false;
+  }
+
+
+}
+
diff --git a/src/org/apache/xpath/parser/XPath.java b/src/org/apache/xpath/parser/XPath.java
new file mode 100644
index 0000000..0aa239b
--- /dev/null
+++ b/src/org/apache/xpath/parser/XPath.java
@@ -0,0 +1,3909 @@
+/* Generated By:JJTree&JavaCC: Do not edit this line. XPath.java */
+package org.apache.xpath.parser;
+
+
+import java.util.Stack;
+
+public class XPath/*@bgen(jjtree)*/implements XPathTreeConstants, XPathConstants {/*@bgen(jjtree)*/
+  protected JJTXPathState jjtree = new JJTXPathState();
+      org.apache.xml.utils.PrefixResolver m_prefixResolver;
+      org.apache.xpath.patterns.FunctionPattern m_matchFunc = null; // short lived.
+
+      int m_predLevel = 0;
+
+      public void setPrefixResolver(org.apache.xml.utils.PrefixResolver resolver)
+      {
+        m_prefixResolver = resolver;
+      }
+
+      public org.apache.xml.utils.PrefixResolver getPrefixResolver()
+      {
+        return m_prefixResolver;
+      }
+
+          /**
+	   * The "version" property.
+	   * @serial
+	   */
+          private double m_version;
+
+          /**
+	   * Set the "version" property for XPath.
+	   *
+	   * @param v Value for the "version" property.
+	   */
+          public void setVersion(double v)
+          {
+            m_version = v;
+          }
+
+          /**
+	   * Get the "version" property of XPath.
+	   *
+	   * @return The value of the "version" property.
+	   */
+          public double getVersion()
+          {
+            return m_version;
+          }
+
+
+
+      boolean m_isMatchPattern = false;
+
+                  Stack binaryTokenStack = new Stack();
+                  public static void main(String args[])
+                     throws Exception
+                  {
+         int numberArgsLeft = args.length;
+         int argsStart = 0;
+         boolean isMatchParser = false;
+         if(numberArgsLeft > 0)
+         {
+           if(args[argsStart].equals("-match"))
+           {
+             isMatchParser = true;
+             System.out.println("Match Pattern Parser");
+             argsStart++;
+             numberArgsLeft--;
+           }
+         }
+                     if(numberArgsLeft > 0)
+                    {
+                        try
+                        {
+                                for(int i = argsStart; i < args.length; i++)
+                                {
+                                        System.out.println();
+                                        System.out.println("Test["+i+"]: "+args[i]);
+                                        XPath parser = new XPath(new java.io.StringBufferInputStream(args[i]));
+          SimpleNode tree;
+          if(isMatchParser)
+          {
+                                        tree = parser.MatchPattern();
+          }
+          else
+          {
+                                        tree = parser.XPath2();
+          }
+                                        ((SimpleNode)tree.jjtGetChild(0)).dump("|") ;
+                                }
+                                System.out.println("Success!!!!");
+                        }
+                        catch(ParseException pe)
+                        {
+                                System.err.println(pe.getMessage());
+                        }
+                        return;
+                   }
+                    java.io.DataInputStream dinput = new java.io.DataInputStream(System.in);
+                    while(true)
+                    {
+                          try
+                          {
+                              System.err.println("Type Expression: ");
+                              String input =  dinput.readLine();
+                              if(null == input || input.trim().length() == 0)
+                                break;
+                              XPath parser = new XPath(new java.io.StringBufferInputStream(input));
+          SimpleNode tree;
+          if(isMatchParser)
+          {
+                                        tree = parser.MatchPattern();
+          }
+          else
+          {
+                                        tree = parser.XPath2();
+          }
+                              ((SimpleNode)tree.jjtGetChild(0)).dump("|") ;
+                          }
+                          catch(ParseException pe)
+                          {
+                                System.err.println(pe.getMessage());
+                          }
+                          catch(Exception e)
+                          {
+                                System.err.println(e.getMessage());
+                          }
+                    }
+                  }
+
+  final public SimpleNode XPath2() throws ParseException {
+                 /*@bgen(jjtree) XPath2 */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTXPATH2);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      Expr();
+      jj_consume_token(0);
+                    jjtree.closeNodeScope(jjtn000, true);
+                    jjtc000 = false;
+                    {if (true) return jjtn000 ;}
+    } catch (Throwable jjte000) {
+                    if (jjtc000) {
+                      jjtree.clearNodeScope(jjtn000);
+                      jjtc000 = false;
+                    } else {
+                      jjtree.popNode();
+                    }
+                    if (jjte000 instanceof RuntimeException) {
+                      {if (true) throw (RuntimeException)jjte000;}
+                    }
+                    if (jjte000 instanceof ParseException) {
+                      {if (true) throw (ParseException)jjte000;}
+                    }
+                    {if (true) throw (Error)jjte000;}
+    } finally {
+                    if (jjtc000) {
+                      jjtree.closeNodeScope(jjtn000, true);
+                    }
+    }
+    throw new Error("Missing return statement in function");
+  }
+
+  final public SimpleNode MatchPattern() throws ParseException {
+                 /*@bgen(jjtree) MatchPattern */
+                 SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTMATCHPATTERN);
+                 boolean jjtc000 = true;
+                 jjtree.openNodeScope(jjtn000);m_isMatchPattern = true;
+    try {
+      Pattern();
+      jj_consume_token(0);
+                    jjtree.closeNodeScope(jjtn000, true);
+                    jjtc000 = false;
+                    {if (true) return jjtn000 ;}
+    } catch (Throwable jjte000) {
+                    if (jjtc000) {
+                      jjtree.clearNodeScope(jjtn000);
+                      jjtc000 = false;
+                    } else {
+                      jjtree.popNode();
+                    }
+                    if (jjte000 instanceof RuntimeException) {
+                      {if (true) throw (RuntimeException)jjte000;}
+                    }
+                    if (jjte000 instanceof ParseException) {
+                      {if (true) throw (ParseException)jjte000;}
+                    }
+                    {if (true) throw (Error)jjte000;}
+    } finally {
+                    if (jjtc000) {
+                      jjtree.closeNodeScope(jjtn000, true);
+                    }
+    }
+    throw new Error("Missing return statement in function");
+  }
+
+  final public void ExprSequence() throws ParseException {
+ /*@bgen(jjtree) ExprSequence */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTEXPRSEQUENCE);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      Expr();
+      label_1:
+      while (true) {
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case Comma:
+          ;
+          break;
+        default:
+          jj_la1[0] = jj_gen;
+          break label_1;
+        }
+        jj_consume_token(Comma);
+        Expr();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void Pattern() throws ParseException {
+ /*@bgen(jjtree) Pattern */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTPATTERN);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      PathPattern();
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Union:
+      case Vbar:
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case Union:
+          jj_consume_token(Union);
+          break;
+        case Vbar:
+          jj_consume_token(Vbar);
+          break;
+        default:
+          jj_la1[1] = jj_gen;
+          jj_consume_token(-1);
+          throw new ParseException();
+        }
+        Pattern();
+        break;
+      default:
+        jj_la1[2] = jj_gen;
+        ;
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void PathPattern() throws ParseException {
+ /*@bgen(jjtree) PathPattern */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTPATHPATTERN);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Root:
+        jj_consume_token(Root);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTROOT);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case AxisChild:
+        case AxisAttribute:
+        case Star:
+        case NCNameColonStar:
+        case StarColonNCName:
+        case At:
+        case NodeLpar:
+        case CommentLpar:
+        case TextLpar:
+        case ProcessingInstructionLpar:
+        case QName:
+          RelativePathPattern();
+          break;
+        default:
+          jj_la1[3] = jj_gen;
+          ;
+        }
+        break;
+      case RootDescendants:
+        jj_consume_token(RootDescendants);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTROOTDESCENDANTS);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+        try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+        } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+        }
+        RelativePathPattern();
+        break;
+      case QNameLpar:
+        IdKeyPattern();
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case Slash:
+        case SlashSlash:
+          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+          case Slash:
+            jj_consume_token(Slash);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSLASH);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+            try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+            } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+            }
+            break;
+          case SlashSlash:
+            jj_consume_token(SlashSlash);
+                SimpleNode jjtn004 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSLASHSLASH);
+                boolean jjtc004 = true;
+                jjtree.openNodeScope(jjtn004);
+            try {
+                jjtree.closeNodeScope(jjtn004,  true);
+                jjtc004 = false;
+               jjtn004.processToken(token);
+            } finally {
+                if (jjtc004) {
+                  jjtree.closeNodeScope(jjtn004,  true);
+                }
+            }
+            break;
+          default:
+            jj_la1[4] = jj_gen;
+            jj_consume_token(-1);
+            throw new ParseException();
+          }
+          RelativePathPattern();
+          break;
+        default:
+          jj_la1[5] = jj_gen;
+          ;
+        }
+        break;
+      case AxisChild:
+      case AxisAttribute:
+      case Star:
+      case NCNameColonStar:
+      case StarColonNCName:
+      case At:
+      case NodeLpar:
+      case CommentLpar:
+      case TextLpar:
+      case ProcessingInstructionLpar:
+      case QName:
+        RelativePathPattern();
+        break;
+      default:
+        jj_la1[6] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void RelativePathPattern() throws ParseException {
+    PatternStep();
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case Slash:
+    case SlashSlash:
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Slash:
+        jj_consume_token(Slash);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSLASH);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        break;
+      case SlashSlash:
+        jj_consume_token(SlashSlash);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSLASHSLASH);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+        try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+        } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+        }
+        break;
+      default:
+        jj_la1[7] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+      RelativePathPattern();
+      break;
+    default:
+      jj_la1[8] = jj_gen;
+      ;
+    }
+  }
+
+  final public void PatternStep() throws ParseException {
+ /*@bgen(jjtree) PatternStep */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTPATTERNSTEP);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case AxisChild:
+      case AxisAttribute:
+      case At:
+        PatternAxis();
+        break;
+      default:
+        jj_la1[9] = jj_gen;
+        ;
+      }
+      NodeTest();
+      Predicates();
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void PatternAxis() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case AxisChild:
+      jj_consume_token(AxisChild);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISCHILD);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      break;
+    case AxisAttribute:
+      jj_consume_token(AxisAttribute);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISATTRIBUTE);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+      try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+      } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+      }
+      break;
+    case At:
+      jj_consume_token(At);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAT);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+      try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+      } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+      }
+      break;
+    default:
+      jj_la1[10] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void IdKeyPattern() throws ParseException {
+ /*@bgen(jjtree) IdKeyPattern */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTIDKEYPATTERN);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      jj_consume_token(QNameLpar);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTQNAMELPAR);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      IdKeyValue();
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Comma:
+        jj_consume_token(Comma);
+        IdKeyValue();
+        break;
+      default:
+        jj_la1[11] = jj_gen;
+        ;
+      }
+      jj_consume_token(Rpar);
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void IdKeyValue() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case IntegerLiteral:
+    case DecimalLiteral:
+    case DoubleLiteral:
+    case StringLiteral:
+      Literal();
+      break;
+    case VariableIndicator:
+      jj_consume_token(VariableIndicator);
+      jj_consume_token(VarName);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTVARNAME);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      break;
+    default:
+      jj_la1[12] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void Expr() throws ParseException {
+    OrExpr();
+  }
+
+  final public void OrExpr() throws ParseException {
+    AndExpr();
+    label_2:
+    while (true) {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Or:
+        ;
+        break;
+      default:
+        jj_la1[13] = jj_gen;
+        break label_2;
+      }
+      jj_consume_token(Or);
+          binaryTokenStack.push(token);
+      AndExpr();
+                  SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTOREXPR);
+                  boolean jjtc001 = true;
+                  jjtree.openNodeScope(jjtn001);
+      try {
+                  jjtree.closeNodeScope(jjtn001,  2);
+                  jjtc001 = false;
+         try
+         {
+                       jjtn001.processToken((Token)binaryTokenStack.pop());
+         }
+         catch(java.util.EmptyStackException e)
+         {
+           token_source.printLinePos();
+           e.printStackTrace();
+           {if (true) throw e;}
+         }
+      } finally {
+                  if (jjtc001) {
+                    jjtree.closeNodeScope(jjtn001,  2);
+                  }
+      }
+    }
+  }
+
+  final public void AndExpr() throws ParseException {
+    FLWRExpr();
+    label_3:
+    while (true) {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case And:
+        ;
+        break;
+      default:
+        jj_la1[14] = jj_gen;
+        break label_3;
+      }
+      jj_consume_token(And);
+          binaryTokenStack.push(token);
+      FLWRExpr();
+                  SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTANDEXPR);
+                  boolean jjtc001 = true;
+                  jjtree.openNodeScope(jjtn001);
+      try {
+                  jjtree.closeNodeScope(jjtn001,  2);
+                  jjtc001 = false;
+         try
+         {
+                       jjtn001.processToken((Token)binaryTokenStack.pop());
+         }
+         catch(java.util.EmptyStackException e)
+         {
+           token_source.printLinePos();
+           e.printStackTrace();
+           {if (true) throw e;}
+         }
+      } finally {
+                  if (jjtc001) {
+                    jjtree.closeNodeScope(jjtn001,  2);
+                  }
+      }
+    }
+  }
+
+  final public void FLWRExpr() throws ParseException {
+ /*@bgen(jjtree) FLWRExpr */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTFLWREXPR);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      label_4:
+      while (true) {
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case ForVariable:
+          ;
+          break;
+        default:
+          jj_la1[15] = jj_gen;
+          break label_4;
+        }
+        ForClause();
+        jj_consume_token(Return);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTRETURN);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+      }
+      QuantifiedExpr();
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void QuantifiedExpr() throws ParseException {
+ /*@bgen(jjtree) QuantifiedExpr */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTQUANTIFIEDEXPR);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      label_5:
+      while (true) {
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case Some:
+        case Every:
+          ;
+          break;
+        default:
+          jj_la1[16] = jj_gen;
+          break label_5;
+        }
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case Some:
+          jj_consume_token(Some);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSOME);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+          try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+          } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+          }
+          break;
+        case Every:
+          jj_consume_token(Every);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTEVERY);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+          try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+          } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+          }
+          break;
+        default:
+          jj_la1[17] = jj_gen;
+          jj_consume_token(-1);
+          throw new ParseException();
+        }
+        jj_consume_token(VarName);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTVARNAME);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+        try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+        } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+        }
+        jj_consume_token(In);
+                SimpleNode jjtn004 = (SimpleNode)SimpleNode.jjtCreate(this, JJTIN);
+                boolean jjtc004 = true;
+                jjtree.openNodeScope(jjtn004);
+        try {
+                jjtree.closeNodeScope(jjtn004,  true);
+                jjtc004 = false;
+               jjtn004.processToken(token);
+        } finally {
+                if (jjtc004) {
+                  jjtree.closeNodeScope(jjtn004,  true);
+                }
+        }
+        Expr();
+        label_6:
+        while (true) {
+          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+          case Comma:
+            ;
+            break;
+          default:
+            jj_la1[18] = jj_gen;
+            break label_6;
+          }
+          jj_consume_token(Comma);
+          jj_consume_token(VariableIndicator);
+          jj_consume_token(VarName);
+                SimpleNode jjtn005 = (SimpleNode)SimpleNode.jjtCreate(this, JJTVARNAME);
+                boolean jjtc005 = true;
+                jjtree.openNodeScope(jjtn005);
+          try {
+                jjtree.closeNodeScope(jjtn005,  true);
+                jjtc005 = false;
+               jjtn005.processToken(token);
+          } finally {
+                if (jjtc005) {
+                  jjtree.closeNodeScope(jjtn005,  true);
+                }
+          }
+          jj_consume_token(In);
+                SimpleNode jjtn006 = (SimpleNode)SimpleNode.jjtCreate(this, JJTIN);
+                boolean jjtc006 = true;
+                jjtree.openNodeScope(jjtn006);
+          try {
+                jjtree.closeNodeScope(jjtn006,  true);
+                jjtc006 = false;
+               jjtn006.processToken(token);
+          } finally {
+                if (jjtc006) {
+                  jjtree.closeNodeScope(jjtn006,  true);
+                }
+          }
+          Expr();
+        }
+        jj_consume_token(Satisfies);
+                SimpleNode jjtn007 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSATISFIES);
+                boolean jjtc007 = true;
+                jjtree.openNodeScope(jjtn007);
+        try {
+                jjtree.closeNodeScope(jjtn007,  true);
+                jjtc007 = false;
+               jjtn007.processToken(token);
+        } finally {
+                if (jjtc007) {
+                  jjtree.closeNodeScope(jjtn007,  true);
+                }
+        }
+      }
+      IfExpr();
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void IfExpr() throws ParseException {
+ /*@bgen(jjtree) IfExpr */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTIFEXPR);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      label_7:
+      while (true) {
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case IfLpar:
+          ;
+          break;
+        default:
+          jj_la1[19] = jj_gen;
+          break label_7;
+        }
+        jj_consume_token(IfLpar);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTIFLPAR);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        Expr();
+        jj_consume_token(Rpar);
+        jj_consume_token(Then);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTTHEN);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+        try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+        } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+        }
+        Expr();
+        jj_consume_token(Else);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTELSE);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+        try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+        } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+        }
+      }
+      InstanceofExpr();
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void InstanceofExpr() throws ParseException {
+ /*@bgen(jjtree) InstanceofExpr */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTINSTANCEOFEXPR);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      ComparisonExpr();
+      label_8:
+      while (true) {
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case Instanceof:
+          ;
+          break;
+        default:
+          jj_la1[20] = jj_gen;
+          break label_8;
+        }
+        jj_consume_token(Instanceof);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTINSTANCEOF);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        SequenceType();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void ComparisonExpr() throws ParseException {
+    RangeExpr();
+    label_9:
+    while (true) {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Precedes:
+      case Follows:
+      case Equals:
+      case Is:
+      case NotEquals:
+      case IsNot:
+      case LtEquals:
+      case LtLt:
+      case GtEquals:
+      case GtGt:
+      case FortranEq:
+      case FortranNe:
+      case FortranGt:
+      case FortranGe:
+      case FortranLt:
+      case FortranLe:
+      case Lt:
+      case Gt:
+        ;
+        break;
+      default:
+        jj_la1[21] = jj_gen;
+        break label_9;
+      }
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case FortranEq:
+      case FortranNe:
+      case FortranGt:
+      case FortranGe:
+      case FortranLt:
+      case FortranLe:
+        ValueComp();
+        break;
+      case Equals:
+      case NotEquals:
+      case LtEquals:
+      case GtEquals:
+      case Lt:
+      case Gt:
+        GeneralComp();
+        break;
+      case Is:
+      case IsNot:
+        NodeComp();
+        break;
+      case Precedes:
+      case Follows:
+      case LtLt:
+      case GtGt:
+        OrderComp();
+        break;
+      default:
+        jj_la1[22] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+      RangeExpr();
+                  SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTCOMPARISONEXPR);
+                  boolean jjtc001 = true;
+                  jjtree.openNodeScope(jjtn001);
+      try {
+                  jjtree.closeNodeScope(jjtn001,  2);
+                  jjtc001 = false;
+         try
+         {
+                       jjtn001.processToken((Token)binaryTokenStack.pop());
+         }
+         catch(java.util.EmptyStackException e)
+         {
+           token_source.printLinePos();
+           e.printStackTrace();
+           {if (true) throw e;}
+         }
+      } finally {
+                  if (jjtc001) {
+                    jjtree.closeNodeScope(jjtn001,  2);
+                  }
+      }
+    }
+  }
+
+  final public void RangeExpr() throws ParseException {
+    AdditiveExpr();
+    label_10:
+    while (true) {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case To:
+        ;
+        break;
+      default:
+        jj_la1[23] = jj_gen;
+        break label_10;
+      }
+      jj_consume_token(To);
+          binaryTokenStack.push(token);
+      AdditiveExpr();
+                  SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTRANGEEXPR);
+                  boolean jjtc001 = true;
+                  jjtree.openNodeScope(jjtn001);
+      try {
+                  jjtree.closeNodeScope(jjtn001,  2);
+                  jjtc001 = false;
+         try
+         {
+                       jjtn001.processToken((Token)binaryTokenStack.pop());
+         }
+         catch(java.util.EmptyStackException e)
+         {
+           token_source.printLinePos();
+           e.printStackTrace();
+           {if (true) throw e;}
+         }
+      } finally {
+                  if (jjtc001) {
+                    jjtree.closeNodeScope(jjtn001,  2);
+                  }
+      }
+    }
+  }
+
+  final public void AdditiveExpr() throws ParseException {
+    MultiplicativeExpr();
+    label_11:
+    while (true) {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Minus:
+      case Plus:
+        ;
+        break;
+      default:
+        jj_la1[24] = jj_gen;
+        break label_11;
+      }
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Plus:
+        jj_consume_token(Plus);
+          binaryTokenStack.push(token);
+        break;
+      case Minus:
+        jj_consume_token(Minus);
+          binaryTokenStack.push(token);
+        break;
+      default:
+        jj_la1[25] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+      MultiplicativeExpr();
+                  SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTADDITIVEEXPR);
+                  boolean jjtc001 = true;
+                  jjtree.openNodeScope(jjtn001);
+      try {
+                  jjtree.closeNodeScope(jjtn001,  2);
+                  jjtc001 = false;
+         try
+         {
+                       jjtn001.processToken((Token)binaryTokenStack.pop());
+         }
+         catch(java.util.EmptyStackException e)
+         {
+           token_source.printLinePos();
+           e.printStackTrace();
+           {if (true) throw e;}
+         }
+      } finally {
+                  if (jjtc001) {
+                    jjtree.closeNodeScope(jjtn001,  2);
+                  }
+      }
+    }
+  }
+
+  final public void MultiplicativeExpr() throws ParseException {
+    UnionExpr();
+    label_12:
+    while (true) {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Div:
+      case Idiv:
+      case Mod:
+      case Multiply:
+        ;
+        break;
+      default:
+        jj_la1[26] = jj_gen;
+        break label_12;
+      }
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Multiply:
+        jj_consume_token(Multiply);
+          binaryTokenStack.push(token);
+        break;
+      case Div:
+        jj_consume_token(Div);
+          binaryTokenStack.push(token);
+        break;
+      case Idiv:
+        jj_consume_token(Idiv);
+          binaryTokenStack.push(token);
+        break;
+      case Mod:
+        jj_consume_token(Mod);
+          binaryTokenStack.push(token);
+        break;
+      default:
+        jj_la1[27] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+      UnionExpr();
+                  SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTMULTIPLICATIVEEXPR);
+                  boolean jjtc001 = true;
+                  jjtree.openNodeScope(jjtn001);
+      try {
+                  jjtree.closeNodeScope(jjtn001,  2);
+                  jjtc001 = false;
+         try
+         {
+                       jjtn001.processToken((Token)binaryTokenStack.pop());
+         }
+         catch(java.util.EmptyStackException e)
+         {
+           token_source.printLinePos();
+           e.printStackTrace();
+           {if (true) throw e;}
+         }
+      } finally {
+                  if (jjtc001) {
+                    jjtree.closeNodeScope(jjtn001,  2);
+                  }
+      }
+    }
+  }
+
+  final public void UnionExpr() throws ParseException {
+    IntersectExceptExpr();
+    label_13:
+    while (true) {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Union:
+      case Vbar:
+        ;
+        break;
+      default:
+        jj_la1[28] = jj_gen;
+        break label_13;
+      }
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Union:
+        jj_consume_token(Union);
+          binaryTokenStack.push(token);
+        break;
+      case Vbar:
+        jj_consume_token(Vbar);
+          binaryTokenStack.push(token);
+        break;
+      default:
+        jj_la1[29] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+      IntersectExceptExpr();
+                  SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTUNIONEXPR);
+                  boolean jjtc001 = true;
+                  jjtree.openNodeScope(jjtn001);
+      try {
+                  jjtree.closeNodeScope(jjtn001,  2);
+                  jjtc001 = false;
+         try
+         {
+                       jjtn001.processToken((Token)binaryTokenStack.pop());
+         }
+         catch(java.util.EmptyStackException e)
+         {
+           token_source.printLinePos();
+           e.printStackTrace();
+           {if (true) throw e;}
+         }
+      } finally {
+                  if (jjtc001) {
+                    jjtree.closeNodeScope(jjtn001,  2);
+                  }
+      }
+    }
+  }
+
+  final public void IntersectExceptExpr() throws ParseException {
+    UnaryExpr();
+    label_14:
+    while (true) {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Intersect:
+      case Except:
+        ;
+        break;
+      default:
+        jj_la1[30] = jj_gen;
+        break label_14;
+      }
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Intersect:
+        jj_consume_token(Intersect);
+          binaryTokenStack.push(token);
+        break;
+      case Except:
+        jj_consume_token(Except);
+          binaryTokenStack.push(token);
+        break;
+      default:
+        jj_la1[31] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+      UnaryExpr();
+                  SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTINTERSECTEXCEPTEXPR);
+                  boolean jjtc001 = true;
+                  jjtree.openNodeScope(jjtn001);
+      try {
+                  jjtree.closeNodeScope(jjtn001,  2);
+                  jjtc001 = false;
+         try
+         {
+                       jjtn001.processToken((Token)binaryTokenStack.pop());
+         }
+         catch(java.util.EmptyStackException e)
+         {
+           token_source.printLinePos();
+           e.printStackTrace();
+           {if (true) throw e;}
+         }
+      } finally {
+                  if (jjtc001) {
+                    jjtree.closeNodeScope(jjtn001,  2);
+                  }
+      }
+    }
+  }
+
+  final public void UnaryExpr() throws ParseException {
+ /*@bgen(jjtree) UnaryExpr */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTUNARYEXPR);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      label_15:
+      while (true) {
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case Minus:
+        case Plus:
+          ;
+          break;
+        default:
+          jj_la1[32] = jj_gen;
+          break label_15;
+        }
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case Minus:
+          jj_consume_token(Minus);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTMINUS);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+          try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+          } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+          }
+          break;
+        case Plus:
+          jj_consume_token(Plus);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTPLUS);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+          try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+          } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+          }
+          break;
+        default:
+          jj_la1[33] = jj_gen;
+          jj_consume_token(-1);
+          throw new ParseException();
+        }
+      }
+      ValueExpr();
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void ValueExpr() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case Validate:
+      ValidateExpr();
+      break;
+    case CastAs:
+    case TreatAs:
+      CastExpr();
+      break;
+    case AxisChild:
+    case AxisDescendant:
+    case AxisParent:
+    case AxisAttribute:
+    case AxisSelf:
+    case AxisDescendantOrSelf:
+    case AxisAncestor:
+    case AxisFollowingSibling:
+    case AxisPrecedingSibling:
+    case AxisFollowing:
+    case AxisPreceding:
+    case AxisNamespace:
+    case AxisAncestorOrSelf:
+    case Star:
+    case NCNameColonStar:
+    case StarColonNCName:
+    case Root:
+    case RootDescendants:
+    case Lpar:
+    case At:
+    case IntegerLiteral:
+    case DecimalLiteral:
+    case DoubleLiteral:
+    case NodeLpar:
+    case CommentLpar:
+    case TextLpar:
+    case ProcessingInstructionLpar:
+    case StringLiteral:
+    case Dot:
+    case DotDot:
+    case VariableIndicator:
+    case QName:
+    case QNameLpar:
+      PathExpr();
+      break;
+    default:
+      jj_la1[34] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void PathExpr() throws ParseException {
+ /*@bgen(jjtree) PathExpr */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTPATHEXPR);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Root:
+        jj_consume_token(Root);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTROOT);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case AxisChild:
+        case AxisDescendant:
+        case AxisParent:
+        case AxisAttribute:
+        case AxisSelf:
+        case AxisDescendantOrSelf:
+        case AxisAncestor:
+        case AxisFollowingSibling:
+        case AxisPrecedingSibling:
+        case AxisFollowing:
+        case AxisPreceding:
+        case AxisNamespace:
+        case AxisAncestorOrSelf:
+        case Star:
+        case NCNameColonStar:
+        case StarColonNCName:
+        case Lpar:
+        case At:
+        case IntegerLiteral:
+        case DecimalLiteral:
+        case DoubleLiteral:
+        case NodeLpar:
+        case CommentLpar:
+        case TextLpar:
+        case ProcessingInstructionLpar:
+        case StringLiteral:
+        case Dot:
+        case DotDot:
+        case VariableIndicator:
+        case QName:
+        case QNameLpar:
+          RelativePathExpr();
+          break;
+        default:
+          jj_la1[35] = jj_gen;
+          ;
+        }
+        break;
+      case RootDescendants:
+        jj_consume_token(RootDescendants);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTROOTDESCENDANTS);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+        try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+        } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+        }
+        RelativePathExpr();
+        break;
+      case AxisChild:
+      case AxisDescendant:
+      case AxisParent:
+      case AxisAttribute:
+      case AxisSelf:
+      case AxisDescendantOrSelf:
+      case AxisAncestor:
+      case AxisFollowingSibling:
+      case AxisPrecedingSibling:
+      case AxisFollowing:
+      case AxisPreceding:
+      case AxisNamespace:
+      case AxisAncestorOrSelf:
+      case Star:
+      case NCNameColonStar:
+      case StarColonNCName:
+      case Lpar:
+      case At:
+      case IntegerLiteral:
+      case DecimalLiteral:
+      case DoubleLiteral:
+      case NodeLpar:
+      case CommentLpar:
+      case TextLpar:
+      case ProcessingInstructionLpar:
+      case StringLiteral:
+      case Dot:
+      case DotDot:
+      case VariableIndicator:
+      case QName:
+      case QNameLpar:
+        RelativePathExpr();
+        break;
+      default:
+        jj_la1[36] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void RelativePathExpr() throws ParseException {
+    StepExpr();
+    label_16:
+    while (true) {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Slash:
+      case SlashSlash:
+        ;
+        break;
+      default:
+        jj_la1[37] = jj_gen;
+        break label_16;
+      }
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Slash:
+        jj_consume_token(Slash);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSLASH);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        break;
+      case SlashSlash:
+        jj_consume_token(SlashSlash);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSLASHSLASH);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+        try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+        } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+        }
+        break;
+      default:
+        jj_la1[38] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+      StepExpr();
+    }
+  }
+
+  final public void StepExpr() throws ParseException {
+ /*@bgen(jjtree) StepExpr */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSTEPEXPR);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case AxisChild:
+      case AxisDescendant:
+      case AxisAttribute:
+      case AxisSelf:
+      case AxisDescendantOrSelf:
+      case AxisFollowingSibling:
+      case AxisFollowing:
+      case AxisNamespace:
+      case Star:
+      case NCNameColonStar:
+      case StarColonNCName:
+      case At:
+      case NodeLpar:
+      case CommentLpar:
+      case TextLpar:
+      case ProcessingInstructionLpar:
+      case Dot:
+      case QName:
+        ForwardStep();
+        break;
+      case AxisParent:
+      case AxisAncestor:
+      case AxisPrecedingSibling:
+      case AxisPreceding:
+      case AxisAncestorOrSelf:
+      case DotDot:
+        ReverseStep();
+        break;
+      case Lpar:
+      case IntegerLiteral:
+      case DecimalLiteral:
+      case DoubleLiteral:
+      case StringLiteral:
+      case VariableIndicator:
+      case QNameLpar:
+        PrimaryExpr();
+        break;
+      default:
+        jj_la1[39] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+      Predicates();
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void ForClause() throws ParseException {
+ /*@bgen(jjtree) ForClause */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTFORCLAUSE);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      jj_consume_token(ForVariable);
+      jj_consume_token(VarName);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTVARNAME);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      jj_consume_token(In);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTIN);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+      try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+      } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+      }
+      Expr();
+      label_17:
+      while (true) {
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case Comma:
+          ;
+          break;
+        default:
+          jj_la1[40] = jj_gen;
+          break label_17;
+        }
+        jj_consume_token(Comma);
+        jj_consume_token(VariableIndicator);
+        jj_consume_token(VarName);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTVARNAME);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+        try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+        } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+        }
+        jj_consume_token(In);
+                SimpleNode jjtn004 = (SimpleNode)SimpleNode.jjtCreate(this, JJTIN);
+                boolean jjtc004 = true;
+                jjtree.openNodeScope(jjtn004);
+        try {
+                jjtree.closeNodeScope(jjtn004,  true);
+                jjtc004 = false;
+               jjtn004.processToken(token);
+        } finally {
+                if (jjtc004) {
+                  jjtree.closeNodeScope(jjtn004,  true);
+                }
+        }
+        Expr();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void ValidateExpr() throws ParseException {
+ /*@bgen(jjtree) ValidateExpr */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTVALIDATEEXPR);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      jj_consume_token(Validate);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTVALIDATE);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case In:
+        SchemaContext();
+        break;
+      default:
+        jj_la1[41] = jj_gen;
+        ;
+      }
+      jj_consume_token(Lbrace);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTLBRACE);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+      try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+      } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+      }
+      Expr();
+      jj_consume_token(Rbrace);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTRBRACE);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+      try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+      } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void CastExpr() throws ParseException {
+ /*@bgen(jjtree) CastExpr */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTCASTEXPR);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case CastAs:
+        jj_consume_token(CastAs);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTCASTAS);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        break;
+      case TreatAs:
+        jj_consume_token(TreatAs);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTTREATAS);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+        try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+        } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+        }
+        break;
+      default:
+        jj_la1[42] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+      SequenceType();
+      ParenthesizedExpr();
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void GeneralComp() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case Equals:
+      jj_consume_token(Equals);
+          binaryTokenStack.push(token);
+      break;
+    case NotEquals:
+      jj_consume_token(NotEquals);
+          binaryTokenStack.push(token);
+      break;
+    case Lt:
+      jj_consume_token(Lt);
+          binaryTokenStack.push(token);
+      break;
+    case LtEquals:
+      jj_consume_token(LtEquals);
+          binaryTokenStack.push(token);
+      break;
+    case Gt:
+      jj_consume_token(Gt);
+          binaryTokenStack.push(token);
+      break;
+    case GtEquals:
+      jj_consume_token(GtEquals);
+          binaryTokenStack.push(token);
+      break;
+    default:
+      jj_la1[43] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void ValueComp() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case FortranEq:
+      jj_consume_token(FortranEq);
+          binaryTokenStack.push(token);
+      break;
+    case FortranNe:
+      jj_consume_token(FortranNe);
+          binaryTokenStack.push(token);
+      break;
+    case FortranLt:
+      jj_consume_token(FortranLt);
+          binaryTokenStack.push(token);
+      break;
+    case FortranLe:
+      jj_consume_token(FortranLe);
+          binaryTokenStack.push(token);
+      break;
+    case FortranGt:
+      jj_consume_token(FortranGt);
+          binaryTokenStack.push(token);
+      break;
+    case FortranGe:
+      jj_consume_token(FortranGe);
+          binaryTokenStack.push(token);
+      break;
+    default:
+      jj_la1[44] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void NodeComp() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case Is:
+      jj_consume_token(Is);
+          binaryTokenStack.push(token);
+      break;
+    case IsNot:
+      jj_consume_token(IsNot);
+          binaryTokenStack.push(token);
+      break;
+    default:
+      jj_la1[45] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void OrderComp() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case LtLt:
+      jj_consume_token(LtLt);
+          binaryTokenStack.push(token);
+      break;
+    case GtGt:
+      jj_consume_token(GtGt);
+          binaryTokenStack.push(token);
+      break;
+    case Precedes:
+      jj_consume_token(Precedes);
+          binaryTokenStack.push(token);
+      break;
+    case Follows:
+      jj_consume_token(Follows);
+          binaryTokenStack.push(token);
+      break;
+    default:
+      jj_la1[46] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void PrimaryExpr() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case IntegerLiteral:
+    case DecimalLiteral:
+    case DoubleLiteral:
+    case StringLiteral:
+      Literal();
+      break;
+    case QNameLpar:
+      FunctionCall();
+      break;
+    case VariableIndicator:
+      jj_consume_token(VariableIndicator);
+      jj_consume_token(VarName);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTVARNAME);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      break;
+    case Lpar:
+      ParenthesizedExpr();
+      break;
+    default:
+      jj_la1[47] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void ForwardAxis() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case AxisChild:
+      jj_consume_token(AxisChild);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISCHILD);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      break;
+    case AxisDescendant:
+      jj_consume_token(AxisDescendant);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISDESCENDANT);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+      try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+      } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+      }
+      break;
+    case AxisAttribute:
+      jj_consume_token(AxisAttribute);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISATTRIBUTE);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+      try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+      } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+      }
+      break;
+    case AxisSelf:
+      jj_consume_token(AxisSelf);
+                SimpleNode jjtn004 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISSELF);
+                boolean jjtc004 = true;
+                jjtree.openNodeScope(jjtn004);
+      try {
+                jjtree.closeNodeScope(jjtn004,  true);
+                jjtc004 = false;
+               jjtn004.processToken(token);
+      } finally {
+                if (jjtc004) {
+                  jjtree.closeNodeScope(jjtn004,  true);
+                }
+      }
+      break;
+    case AxisDescendantOrSelf:
+      jj_consume_token(AxisDescendantOrSelf);
+                SimpleNode jjtn005 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISDESCENDANTORSELF);
+                boolean jjtc005 = true;
+                jjtree.openNodeScope(jjtn005);
+      try {
+                jjtree.closeNodeScope(jjtn005,  true);
+                jjtc005 = false;
+               jjtn005.processToken(token);
+      } finally {
+                if (jjtc005) {
+                  jjtree.closeNodeScope(jjtn005,  true);
+                }
+      }
+      break;
+    case AxisFollowingSibling:
+      jj_consume_token(AxisFollowingSibling);
+                SimpleNode jjtn006 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISFOLLOWINGSIBLING);
+                boolean jjtc006 = true;
+                jjtree.openNodeScope(jjtn006);
+      try {
+                jjtree.closeNodeScope(jjtn006,  true);
+                jjtc006 = false;
+               jjtn006.processToken(token);
+      } finally {
+                if (jjtc006) {
+                  jjtree.closeNodeScope(jjtn006,  true);
+                }
+      }
+      break;
+    case AxisFollowing:
+      jj_consume_token(AxisFollowing);
+                SimpleNode jjtn007 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISFOLLOWING);
+                boolean jjtc007 = true;
+                jjtree.openNodeScope(jjtn007);
+      try {
+                jjtree.closeNodeScope(jjtn007,  true);
+                jjtc007 = false;
+               jjtn007.processToken(token);
+      } finally {
+                if (jjtc007) {
+                  jjtree.closeNodeScope(jjtn007,  true);
+                }
+      }
+      break;
+    case AxisNamespace:
+      jj_consume_token(AxisNamespace);
+                SimpleNode jjtn008 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISNAMESPACE);
+                boolean jjtc008 = true;
+                jjtree.openNodeScope(jjtn008);
+      try {
+                jjtree.closeNodeScope(jjtn008,  true);
+                jjtc008 = false;
+               jjtn008.processToken(token);
+      } finally {
+                if (jjtc008) {
+                  jjtree.closeNodeScope(jjtn008,  true);
+                }
+      }
+      break;
+    default:
+      jj_la1[48] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void ReverseAxis() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case AxisParent:
+      jj_consume_token(AxisParent);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISPARENT);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      break;
+    case AxisAncestor:
+      jj_consume_token(AxisAncestor);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISANCESTOR);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+      try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+      } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+      }
+      break;
+    case AxisPrecedingSibling:
+      jj_consume_token(AxisPrecedingSibling);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISPRECEDINGSIBLING);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+      try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+      } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+      }
+      break;
+    case AxisPreceding:
+      jj_consume_token(AxisPreceding);
+                SimpleNode jjtn004 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISPRECEDING);
+                boolean jjtc004 = true;
+                jjtree.openNodeScope(jjtn004);
+      try {
+                jjtree.closeNodeScope(jjtn004,  true);
+                jjtc004 = false;
+               jjtn004.processToken(token);
+      } finally {
+                if (jjtc004) {
+                  jjtree.closeNodeScope(jjtn004,  true);
+                }
+      }
+      break;
+    case AxisAncestorOrSelf:
+      jj_consume_token(AxisAncestorOrSelf);
+                SimpleNode jjtn005 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAXISANCESTORORSELF);
+                boolean jjtc005 = true;
+                jjtree.openNodeScope(jjtn005);
+      try {
+                jjtree.closeNodeScope(jjtn005,  true);
+                jjtc005 = false;
+               jjtn005.processToken(token);
+      } finally {
+                if (jjtc005) {
+                  jjtree.closeNodeScope(jjtn005,  true);
+                }
+      }
+      break;
+    default:
+      jj_la1[49] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void NodeTest() throws ParseException {
+ /*@bgen(jjtree) NodeTest */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTNODETEST);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case NodeLpar:
+      case CommentLpar:
+      case TextLpar:
+      case ProcessingInstructionLpar:
+        KindTest();
+        break;
+      case Star:
+      case NCNameColonStar:
+      case StarColonNCName:
+      case QName:
+        NameTest();
+        break;
+      default:
+        jj_la1[50] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void NameTest() throws ParseException {
+ /*@bgen(jjtree) NameTest */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTNAMETEST);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case QName:
+        jj_consume_token(QName);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTQNAME);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        break;
+      case Star:
+      case NCNameColonStar:
+      case StarColonNCName:
+        Wildcard();
+        break;
+      default:
+        jj_la1[51] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void Wildcard() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case Star:
+      jj_consume_token(Star);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSTAR);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      break;
+    case NCNameColonStar:
+      jj_consume_token(NCNameColonStar);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTNCNAMECOLONSTAR);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+      try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+      } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+      }
+      break;
+    case StarColonNCName:
+      jj_consume_token(StarColonNCName);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSTARCOLONNCNAME);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+      try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+      } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+      }
+      break;
+    default:
+      jj_la1[52] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void KindTest() throws ParseException {
+ /*@bgen(jjtree) KindTest */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTKINDTEST);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case ProcessingInstructionLpar:
+        ProcessingInstructionTest();
+        break;
+      case CommentLpar:
+        CommentTest();
+        break;
+      case TextLpar:
+        TextTest();
+        break;
+      case NodeLpar:
+        AnyKindTest();
+        break;
+      default:
+        jj_la1[53] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void ProcessingInstructionTest() throws ParseException {
+ /*@bgen(jjtree) ProcessingInstructionTest */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTPROCESSINGINSTRUCTIONTEST);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      jj_consume_token(ProcessingInstructionLpar);
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case StringLiteral:
+        jj_consume_token(StringLiteral);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSTRINGLITERAL);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        break;
+      default:
+        jj_la1[54] = jj_gen;
+        ;
+      }
+      jj_consume_token(Rpar);
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void CommentTest() throws ParseException {
+ /*@bgen(jjtree) CommentTest */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTCOMMENTTEST);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      jj_consume_token(CommentLpar);
+      jj_consume_token(Rpar);
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void TextTest() throws ParseException {
+ /*@bgen(jjtree) TextTest */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTTEXTTEST);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      jj_consume_token(TextLpar);
+      jj_consume_token(Rpar);
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void AnyKindTest() throws ParseException {
+ /*@bgen(jjtree) AnyKindTest */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTANYKINDTEST);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      jj_consume_token(NodeLpar);
+      jj_consume_token(Rpar);
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void ForwardStep() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case AxisChild:
+    case AxisDescendant:
+    case AxisAttribute:
+    case AxisSelf:
+    case AxisDescendantOrSelf:
+    case AxisFollowingSibling:
+    case AxisFollowing:
+    case AxisNamespace:
+      ForwardAxis();
+      NodeTest();
+      break;
+    case Star:
+    case NCNameColonStar:
+    case StarColonNCName:
+    case At:
+    case NodeLpar:
+    case CommentLpar:
+    case TextLpar:
+    case ProcessingInstructionLpar:
+    case Dot:
+    case QName:
+      AbbreviatedForwardStep();
+      break;
+    default:
+      jj_la1[55] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void ReverseStep() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case AxisParent:
+    case AxisAncestor:
+    case AxisPrecedingSibling:
+    case AxisPreceding:
+    case AxisAncestorOrSelf:
+      ReverseAxis();
+      NodeTest();
+      break;
+    case DotDot:
+      AbbreviatedReverseStep();
+      break;
+    default:
+      jj_la1[56] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void AbbreviatedForwardStep() throws ParseException {
+ /*@bgen(jjtree) AbbreviatedForwardStep */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTABBREVIATEDFORWARDSTEP);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Dot:
+        jj_consume_token(Dot);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTDOT);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        break;
+      case At:
+        jj_consume_token(At);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTAT);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+        try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+        } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+        }
+        NameTest();
+        break;
+      case Star:
+      case NCNameColonStar:
+      case StarColonNCName:
+      case NodeLpar:
+      case CommentLpar:
+      case TextLpar:
+      case ProcessingInstructionLpar:
+      case QName:
+        NodeTest();
+        break;
+      default:
+        jj_la1[57] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void AbbreviatedReverseStep() throws ParseException {
+    jj_consume_token(DotDot);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTDOTDOT);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+    try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+    } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+    }
+  }
+
+  final public void Predicates() throws ParseException {
+ /*@bgen(jjtree) Predicates */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTPREDICATES);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      label_18:
+      while (true) {
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case Lbrack:
+          ;
+          break;
+        default:
+          jj_la1[58] = jj_gen;
+          break label_18;
+        }
+        jj_consume_token(Lbrack);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTLBRACK);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        Expr();
+        jj_consume_token(Rbrack);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTRBRACK);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+        try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+        } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+        }
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void NumericLiteral() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case IntegerLiteral:
+      jj_consume_token(IntegerLiteral);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTINTEGERLITERAL);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      break;
+    case DecimalLiteral:
+      jj_consume_token(DecimalLiteral);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTDECIMALLITERAL);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+      try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+      } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+      }
+      break;
+    case DoubleLiteral:
+      jj_consume_token(DoubleLiteral);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTDOUBLELITERAL);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+      try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+      } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+      }
+      break;
+    default:
+      jj_la1[59] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void Literal() throws ParseException {
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case IntegerLiteral:
+    case DecimalLiteral:
+    case DoubleLiteral:
+      NumericLiteral();
+      break;
+    case StringLiteral:
+      jj_consume_token(StringLiteral);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSTRINGLITERAL);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      break;
+    default:
+      jj_la1[60] = jj_gen;
+      jj_consume_token(-1);
+      throw new ParseException();
+    }
+  }
+
+  final public void ParenthesizedExpr() throws ParseException {
+    jj_consume_token(Lpar);
+    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+    case AxisChild:
+    case AxisDescendant:
+    case AxisParent:
+    case AxisAttribute:
+    case AxisSelf:
+    case AxisDescendantOrSelf:
+    case AxisAncestor:
+    case AxisFollowingSibling:
+    case AxisPrecedingSibling:
+    case AxisFollowing:
+    case AxisPreceding:
+    case AxisNamespace:
+    case AxisAncestorOrSelf:
+    case Star:
+    case NCNameColonStar:
+    case StarColonNCName:
+    case Root:
+    case RootDescendants:
+    case Minus:
+    case Plus:
+    case Lpar:
+    case At:
+    case Some:
+    case Every:
+    case ForVariable:
+    case CastAs:
+    case TreatAs:
+    case Validate:
+    case IntegerLiteral:
+    case DecimalLiteral:
+    case DoubleLiteral:
+    case NodeLpar:
+    case CommentLpar:
+    case TextLpar:
+    case ProcessingInstructionLpar:
+    case IfLpar:
+    case StringLiteral:
+    case Dot:
+    case DotDot:
+    case VariableIndicator:
+    case QName:
+    case QNameLpar:
+      ExprSequence();
+      break;
+    default:
+      jj_la1[61] = jj_gen;
+      ;
+    }
+    jj_consume_token(Rpar);
+  }
+
+  final public void FunctionCall() throws ParseException {
+ /*@bgen(jjtree) FunctionCall */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTFUNCTIONCALL);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      jj_consume_token(QNameLpar);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTQNAMELPAR);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case AxisChild:
+      case AxisDescendant:
+      case AxisParent:
+      case AxisAttribute:
+      case AxisSelf:
+      case AxisDescendantOrSelf:
+      case AxisAncestor:
+      case AxisFollowingSibling:
+      case AxisPrecedingSibling:
+      case AxisFollowing:
+      case AxisPreceding:
+      case AxisNamespace:
+      case AxisAncestorOrSelf:
+      case Star:
+      case NCNameColonStar:
+      case StarColonNCName:
+      case Root:
+      case RootDescendants:
+      case Minus:
+      case Plus:
+      case Lpar:
+      case At:
+      case Some:
+      case Every:
+      case ForVariable:
+      case CastAs:
+      case TreatAs:
+      case Validate:
+      case IntegerLiteral:
+      case DecimalLiteral:
+      case DoubleLiteral:
+      case NodeLpar:
+      case CommentLpar:
+      case TextLpar:
+      case ProcessingInstructionLpar:
+      case IfLpar:
+      case StringLiteral:
+      case Dot:
+      case DotDot:
+      case VariableIndicator:
+      case QName:
+      case QNameLpar:
+        Expr();
+        label_19:
+        while (true) {
+          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+          case Comma:
+            ;
+            break;
+          default:
+            jj_la1[62] = jj_gen;
+            break label_19;
+          }
+          jj_consume_token(Comma);
+          Expr();
+        }
+        break;
+      default:
+        jj_la1[63] = jj_gen;
+        ;
+      }
+      jj_consume_token(Rpar);
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void SchemaContext() throws ParseException {
+ /*@bgen(jjtree) SchemaContext */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSCHEMACONTEXT);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      jj_consume_token(In);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTIN);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      SchemaGlobalContext();
+      label_20:
+      while (true) {
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case Slash:
+          ;
+          break;
+        default:
+          jj_la1[64] = jj_gen;
+          break label_20;
+        }
+        jj_consume_token(Slash);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSLASH);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+        try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+        } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+        }
+        SchemaContextStep();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void SchemaGlobalContext() throws ParseException {
+ /*@bgen(jjtree) SchemaGlobalContext */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSCHEMAGLOBALCONTEXT);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case QName:
+        jj_consume_token(QName);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTQNAME);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        break;
+      case Type:
+        jj_consume_token(Type);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTTYPE);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+        try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+        } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+        }
+        jj_consume_token(QName);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTQNAME);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+        try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+        } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+        }
+        break;
+      default:
+        jj_la1[65] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void SchemaContextStep() throws ParseException {
+ /*@bgen(jjtree) SchemaContextStep */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSCHEMACONTEXTSTEP);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      jj_consume_token(QName);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTQNAME);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void SequenceType() throws ParseException {
+ /*@bgen(jjtree) SequenceType */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSEQUENCETYPE);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Item:
+      case ElementType:
+      case AttributeType:
+      case AtomicValue:
+      case Node:
+      case Comment:
+      case Document:
+      case Text:
+      case Untyped:
+      case ProcessingInstruction:
+      case QName:
+        ItemType();
+        OccurrenceIndicator();
+        break;
+      case Empty:
+        jj_consume_token(Empty);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTEMPTY);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        break;
+      default:
+        jj_la1[66] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void ItemType() throws ParseException {
+ /*@bgen(jjtree) ItemType */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTITEMTYPE);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case ElementType:
+      case AttributeType:
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case ElementType:
+          jj_consume_token(ElementType);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTELEMENTTYPE);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+          try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+          } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+          }
+          break;
+        case AttributeType:
+          jj_consume_token(AttributeType);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTATTRIBUTETYPE);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+          try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+          } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+          }
+          break;
+        default:
+          jj_la1[67] = jj_gen;
+          jj_consume_token(-1);
+          throw new ParseException();
+        }
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case OfType:
+        case QName:
+          ElemOrAttrType();
+          break;
+        default:
+          jj_la1[68] = jj_gen;
+          ;
+        }
+        break;
+      case Node:
+        jj_consume_token(Node);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTNODE);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+        try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+        } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+        }
+        break;
+      case ProcessingInstruction:
+        jj_consume_token(ProcessingInstruction);
+                SimpleNode jjtn004 = (SimpleNode)SimpleNode.jjtCreate(this, JJTPROCESSINGINSTRUCTION);
+                boolean jjtc004 = true;
+                jjtree.openNodeScope(jjtn004);
+        try {
+                jjtree.closeNodeScope(jjtn004,  true);
+                jjtc004 = false;
+               jjtn004.processToken(token);
+        } finally {
+                if (jjtc004) {
+                  jjtree.closeNodeScope(jjtn004,  true);
+                }
+        }
+        break;
+      case Comment:
+        jj_consume_token(Comment);
+                SimpleNode jjtn005 = (SimpleNode)SimpleNode.jjtCreate(this, JJTCOMMENT);
+                boolean jjtc005 = true;
+                jjtree.openNodeScope(jjtn005);
+        try {
+                jjtree.closeNodeScope(jjtn005,  true);
+                jjtc005 = false;
+               jjtn005.processToken(token);
+        } finally {
+                if (jjtc005) {
+                  jjtree.closeNodeScope(jjtn005,  true);
+                }
+        }
+        break;
+      case Text:
+        jj_consume_token(Text);
+                SimpleNode jjtn006 = (SimpleNode)SimpleNode.jjtCreate(this, JJTTEXT);
+                boolean jjtc006 = true;
+                jjtree.openNodeScope(jjtn006);
+        try {
+                jjtree.closeNodeScope(jjtn006,  true);
+                jjtc006 = false;
+               jjtn006.processToken(token);
+        } finally {
+                if (jjtc006) {
+                  jjtree.closeNodeScope(jjtn006,  true);
+                }
+        }
+        break;
+      case Document:
+        jj_consume_token(Document);
+                SimpleNode jjtn007 = (SimpleNode)SimpleNode.jjtCreate(this, JJTDOCUMENT);
+                boolean jjtc007 = true;
+                jjtree.openNodeScope(jjtn007);
+        try {
+                jjtree.closeNodeScope(jjtn007,  true);
+                jjtc007 = false;
+               jjtn007.processToken(token);
+        } finally {
+                if (jjtc007) {
+                  jjtree.closeNodeScope(jjtn007,  true);
+                }
+        }
+        break;
+      case Item:
+        jj_consume_token(Item);
+                SimpleNode jjtn008 = (SimpleNode)SimpleNode.jjtCreate(this, JJTITEM);
+                boolean jjtc008 = true;
+                jjtree.openNodeScope(jjtn008);
+        try {
+                jjtree.closeNodeScope(jjtn008,  true);
+                jjtc008 = false;
+               jjtn008.processToken(token);
+        } finally {
+                if (jjtc008) {
+                  jjtree.closeNodeScope(jjtn008,  true);
+                }
+        }
+        break;
+      case QName:
+        AtomicType();
+        break;
+      case Untyped:
+        jj_consume_token(Untyped);
+                SimpleNode jjtn009 = (SimpleNode)SimpleNode.jjtCreate(this, JJTUNTYPED);
+                boolean jjtc009 = true;
+                jjtree.openNodeScope(jjtn009);
+        try {
+                jjtree.closeNodeScope(jjtn009,  true);
+                jjtc009 = false;
+               jjtn009.processToken(token);
+        } finally {
+                if (jjtc009) {
+                  jjtree.closeNodeScope(jjtn009,  true);
+                }
+        }
+        break;
+      case AtomicValue:
+        jj_consume_token(AtomicValue);
+                SimpleNode jjtn010 = (SimpleNode)SimpleNode.jjtCreate(this, JJTATOMICVALUE);
+                boolean jjtc010 = true;
+                jjtree.openNodeScope(jjtn010);
+        try {
+                jjtree.closeNodeScope(jjtn010,  true);
+                jjtc010 = false;
+               jjtn010.processToken(token);
+        } finally {
+                if (jjtc010) {
+                  jjtree.closeNodeScope(jjtn010,  true);
+                }
+        }
+        break;
+      default:
+        jj_la1[69] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void ElemOrAttrType() throws ParseException {
+ /*@bgen(jjtree) ElemOrAttrType */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTELEMORATTRTYPE);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case QName:
+        jj_consume_token(QName);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTQNAME);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+        try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+        } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+        }
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case OfType:
+          SchemaType();
+          break;
+        default:
+          jj_la1[71] = jj_gen;
+          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+          case In:
+            SchemaContext();
+            break;
+          default:
+            jj_la1[70] = jj_gen;
+            ;
+          }
+        }
+        break;
+      case OfType:
+        SchemaType();
+        break;
+      default:
+        jj_la1[72] = jj_gen;
+        jj_consume_token(-1);
+        throw new ParseException();
+      }
+    } catch (Throwable jjte000) {
+    if (jjtc000) {
+      jjtree.clearNodeScope(jjtn000);
+      jjtc000 = false;
+    } else {
+      jjtree.popNode();
+    }
+    if (jjte000 instanceof RuntimeException) {
+      {if (true) throw (RuntimeException)jjte000;}
+    }
+    if (jjte000 instanceof ParseException) {
+      {if (true) throw (ParseException)jjte000;}
+    }
+    {if (true) throw (Error)jjte000;}
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void SchemaType() throws ParseException {
+ /*@bgen(jjtree) SchemaType */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTSCHEMATYPE);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      jj_consume_token(OfType);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTOFTYPE);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+      jj_consume_token(QName);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTQNAME);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+      try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+      } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+      }
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void AtomicType() throws ParseException {
+ /*@bgen(jjtree) AtomicType */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTATOMICTYPE);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      jj_consume_token(QName);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTQNAME);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+      try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+      } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+      }
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  final public void OccurrenceIndicator() throws ParseException {
+ /*@bgen(jjtree) OccurrenceIndicator */
+  SimpleNode jjtn000 = (SimpleNode)SimpleNode.jjtCreate(this, JJTOCCURRENCEINDICATOR);
+  boolean jjtc000 = true;
+  jjtree.openNodeScope(jjtn000);
+    try {
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+      case Multiply:
+      case Plus:
+      case QMark:
+        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+        case Multiply:
+          jj_consume_token(Multiply);
+                SimpleNode jjtn001 = (SimpleNode)SimpleNode.jjtCreate(this, JJTMULTIPLY);
+                boolean jjtc001 = true;
+                jjtree.openNodeScope(jjtn001);
+          try {
+                jjtree.closeNodeScope(jjtn001,  true);
+                jjtc001 = false;
+               jjtn001.processToken(token);
+          } finally {
+                if (jjtc001) {
+                  jjtree.closeNodeScope(jjtn001,  true);
+                }
+          }
+          break;
+        case Plus:
+          jj_consume_token(Plus);
+                SimpleNode jjtn002 = (SimpleNode)SimpleNode.jjtCreate(this, JJTPLUS);
+                boolean jjtc002 = true;
+                jjtree.openNodeScope(jjtn002);
+          try {
+                jjtree.closeNodeScope(jjtn002,  true);
+                jjtc002 = false;
+               jjtn002.processToken(token);
+          } finally {
+                if (jjtc002) {
+                  jjtree.closeNodeScope(jjtn002,  true);
+                }
+          }
+          break;
+        case QMark:
+          jj_consume_token(QMark);
+                SimpleNode jjtn003 = (SimpleNode)SimpleNode.jjtCreate(this, JJTQMARK);
+                boolean jjtc003 = true;
+                jjtree.openNodeScope(jjtn003);
+          try {
+                jjtree.closeNodeScope(jjtn003,  true);
+                jjtc003 = false;
+               jjtn003.processToken(token);
+          } finally {
+                if (jjtc003) {
+                  jjtree.closeNodeScope(jjtn003,  true);
+                }
+          }
+          break;
+        default:
+          jj_la1[73] = jj_gen;
+          jj_consume_token(-1);
+          throw new ParseException();
+        }
+        break;
+      default:
+        jj_la1[74] = jj_gen;
+        ;
+      }
+    } finally {
+    if (jjtc000) {
+      jjtree.closeNodeScope(jjtn000, true);
+    }
+    }
+  }
+
+  public XPathTokenManager token_source;
+  ASCII_CharStream jj_input_stream;
+  public Token token, jj_nt;
+  private int jj_ntk;
+  private int jj_gen;
+  final private int[] jj_la1 = new int[75];
+  final private int[] jj_la1_0 = {0x0,0x80000000,0x80000000,0x120,0x0,0x0,0x120,0x0,0x0,0x120,0x120,0x0,0x0,0x40000,0x80000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20000000,0x0,0x0,0xf00000,0xf00000,0x80000000,0x80000000,0x40000000,0x40000000,0x0,0x0,0x3ffe0,0x3ffe0,0x3ffe0,0x0,0x0,0x3ffe0,0x0,0x1000000,0x0,0x0,0x0,0x0,0x0,0x0,0x15760,0x2a880,0x0,0x0,0x0,0x0,0x0,0x15760,0x2a880,0x0,0x0,0x0,0x0,0x3ffe0,0x0,0x3ffe0,0x0,0x0,0x0,0x0,0x0,0x0,0x1000000,0x0,0x0,0x800000,0x800000,};
+  final private int[] jj_la1_1 = {0x0,0x0,0x0,0x700000,0x6000000,0x6000000,0x1f00000,0x6000000,0x6000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0xf8000006,0xf8000006,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x1f00000,0x700000,0x1f00000,0x6000000,0x6000000,0x700000,0x0,0x0,0x0,0xa8000000,0x0,0x50000000,0x6,0x0,0x0,0x0,0x700000,0x700000,0x700000,0x0,0x0,0x700000,0x0,0x700000,0x0,0x0,0x0,0x1f00000,0x0,0x1f00000,0x2000000,0x8000,0x34070,0x60,0x2000,0x14070,0x0,0x2000,0x2000,0x0,0x0,};
+  final private int[] jj_la1_2 = {0x0,0x4000,0x4000,0x10000,0x0,0x0,0x10000,0x0,0x0,0x10000,0x10000,0x0,0x38000000,0x0,0x0,0x400000,0x300000,0x300000,0x0,0x0,0x0,0x7ff,0x7ff,0x0,0x1800,0x1800,0x0,0x0,0x4000,0x4000,0x0,0x0,0x1800,0x1800,0x3b818000,0x38018000,0x38018000,0x0,0x0,0x38018000,0x0,0x0,0x1800000,0x602,0x1f8,0x0,0x5,0x38008000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10000,0x0,0x10000,0x20000,0x38000000,0x38000000,0x3bf19800,0x0,0x3bf19800,0x0,0x0,0xc0000000,0x0,0x0,0xc0000000,0x0,0x0,0x0,0x3000,0x3000,};
+  final private int[] jj_la1_3 = {0x200,0x0,0x0,0x800f0,0x0,0x0,0x4800f0,0x0,0x0,0x0,0x0,0x200,0x20400,0x0,0x0,0x0,0x0,0x0,0x200,0x100,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x4a34f0,0x4a34f0,0x4a34f0,0x0,0x0,0x4a34f0,0x200,0x0,0x0,0x0,0x0,0x0,0x0,0x420400,0x0,0x0,0x800f0,0x80000,0x0,0xf0,0x400,0x810f0,0x2000,0x810f0,0x0,0x0,0x400,0x4a35f0,0x200,0x4a35f0,0x0,0x80000,0x8000e,0x0,0x80000,0x8000e,0x0,0x0,0x80000,0x0,0x0,};
+  final private int[] jj_la1_4 = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,};
+
+  public XPath(java.io.InputStream stream) {
+    jj_input_stream = new ASCII_CharStream(stream, 1, 1);
+    token_source = new XPathTokenManager(jj_input_stream);
+    token = new Token();
+    jj_ntk = -1;
+    jj_gen = 0;
+    for (int i = 0; i < 75; i++) jj_la1[i] = -1;
+  }
+
+  public void ReInit(java.io.InputStream stream) {
+    jj_input_stream.ReInit(stream, 1, 1);
+    token_source.ReInit(jj_input_stream);
+    token = new Token();
+    jj_ntk = -1;
+    jjtree.reset();
+    jj_gen = 0;
+    for (int i = 0; i < 75; i++) jj_la1[i] = -1;
+  }
+
+  public XPath(java.io.Reader stream) {
+    jj_input_stream = new ASCII_CharStream(stream, 1, 1);
+    token_source = new XPathTokenManager(jj_input_stream);
+    token = new Token();
+    jj_ntk = -1;
+    jj_gen = 0;
+    for (int i = 0; i < 75; i++) jj_la1[i] = -1;
+  }
+
+  public void ReInit(java.io.Reader stream) {
+    jj_input_stream.ReInit(stream, 1, 1);
+    token_source.ReInit(jj_input_stream);
+    token = new Token();
+    jj_ntk = -1;
+    jjtree.reset();
+    jj_gen = 0;
+    for (int i = 0; i < 75; i++) jj_la1[i] = -1;
+  }
+
+  public XPath(XPathTokenManager tm) {
+    token_source = tm;
+    token = new Token();
+    jj_ntk = -1;
+    jj_gen = 0;
+    for (int i = 0; i < 75; i++) jj_la1[i] = -1;
+  }
+
+  public void ReInit(XPathTokenManager tm) {
+    token_source = tm;
+    token = new Token();
+    jj_ntk = -1;
+    jjtree.reset();
+    jj_gen = 0;
+    for (int i = 0; i < 75; i++) jj_la1[i] = -1;
+  }
+
+  final private Token jj_consume_token(int kind) throws ParseException {
+    Token oldToken;
+    if ((oldToken = token).next != null) token = token.next;
+    else token = token.next = token_source.getNextToken();
+    jj_ntk = -1;
+    if (token.kind == kind) {
+      jj_gen++;
+      return token;
+    }
+    token = oldToken;
+    jj_kind = kind;
+    throw generateParseException();
+  }
+
+  final public Token getNextToken() {
+    if (token.next != null) token = token.next;
+    else token = token.next = token_source.getNextToken();
+    jj_ntk = -1;
+    jj_gen++;
+    return token;
+  }
+
+  final public Token getToken(int index) {
+    Token t = token;
+    for (int i = 0; i < index; i++) {
+      if (t.next != null) t = t.next;
+      else t = t.next = token_source.getNextToken();
+    }
+    return t;
+  }
+
+  final private int jj_ntk() {
+    if ((jj_nt=token.next) == null)
+      return (jj_ntk = (token.next=token_source.getNextToken()).kind);
+    else
+      return (jj_ntk = jj_nt.kind);
+  }
+
+  private java.util.Vector jj_expentries = new java.util.Vector();
+  private int[] jj_expentry;
+  private int jj_kind = -1;
+
+  final public ParseException generateParseException() {
+    jj_expentries.removeAllElements();
+    boolean[] la1tokens = new boolean[129];
+    for (int i = 0; i < 129; i++) {
+      la1tokens[i] = false;
+    }
+    if (jj_kind >= 0) {
+      la1tokens[jj_kind] = true;
+      jj_kind = -1;
+    }
+    for (int i = 0; i < 75; i++) {
+      if (jj_la1[i] == jj_gen) {
+        for (int j = 0; j < 32; j++) {
+          if ((jj_la1_0[i] & (1<<j)) != 0) {
+            la1tokens[j] = true;
+          }
+          if ((jj_la1_1[i] & (1<<j)) != 0) {
+            la1tokens[32+j] = true;
+          }
+          if ((jj_la1_2[i] & (1<<j)) != 0) {
+            la1tokens[64+j] = true;
+          }
+          if ((jj_la1_3[i] & (1<<j)) != 0) {
+            la1tokens[96+j] = true;
+          }
+          if ((jj_la1_4[i] & (1<<j)) != 0) {
+            la1tokens[128+j] = true;
+          }
+        }
+      }
+    }
+    for (int i = 0; i < 129; i++) {
+      if (la1tokens[i]) {
+        jj_expentry = new int[1];
+        jj_expentry[0] = i;
+        jj_expentries.addElement(jj_expentry);
+      }
+    }
+    int[][] exptokseq = new int[jj_expentries.size()][];
+    for (int i = 0; i < jj_expentries.size(); i++) {
+      exptokseq[i] = (int[])jj_expentries.elementAt(i);
+    }
+    return new ParseException(token, exptokseq, tokenImage);
+  }
+
+  final public void enable_tracing() {
+  }
+
+  final public void disable_tracing() {
+  }
+
+                }
diff --git a/src/org/apache/xpath/parser/XPathConstants.java b/src/org/apache/xpath/parser/XPathConstants.java
new file mode 100644
index 0000000..7d2f6df
--- /dev/null
+++ b/src/org/apache/xpath/parser/XPathConstants.java
@@ -0,0 +1,286 @@
+/* Generated By:JJTree&JavaCC: Do not edit this line. XPathConstants.java */
+package org.apache.xpath.parser;
+
+public interface XPathConstants {
+
+  int EOF = 0;
+  int ExprComment = 1;
+  int skip_ = 3;
+  int S = 4;
+  int AxisChild = 5;
+  int AxisDescendant = 6;
+  int AxisParent = 7;
+  int AxisAttribute = 8;
+  int AxisSelf = 9;
+  int AxisDescendantOrSelf = 10;
+  int AxisAncestor = 11;
+  int AxisFollowingSibling = 12;
+  int AxisPrecedingSibling = 13;
+  int AxisFollowing = 14;
+  int AxisPreceding = 15;
+  int AxisNamespace = 16;
+  int AxisAncestorOrSelf = 17;
+  int Or = 18;
+  int And = 19;
+  int Div = 20;
+  int Idiv = 21;
+  int Mod = 22;
+  int Multiply = 23;
+  int In = 24;
+  int Satisfies = 25;
+  int Return = 26;
+  int Then = 27;
+  int Else = 28;
+  int To = 29;
+  int Intersect = 30;
+  int Union = 31;
+  int Except = 32;
+  int Precedes = 33;
+  int Follows = 34;
+  int Instanceof = 35;
+  int Item = 36;
+  int ElementType = 37;
+  int AttributeType = 38;
+  int ElementQNameLbrace = 39;
+  int AttributeQNameLbrace = 40;
+  int ElementLbrace = 41;
+  int AttributeLbrace = 42;
+  int DefaultElement = 43;
+  int DefaultFunction = 44;
+  int OfType = 45;
+  int AtomicValue = 46;
+  int Type = 47;
+  int Node = 48;
+  int Empty = 49;
+  int Nmstart = 50;
+  int Nmchar = 51;
+  int Star = 52;
+  int NCNameColonStar = 53;
+  int StarColonNCName = 54;
+  int Root = 55;
+  int RootDescendants = 56;
+  int Slash = 57;
+  int SlashSlash = 58;
+  int Equals = 59;
+  int Is = 60;
+  int NotEquals = 61;
+  int IsNot = 62;
+  int LtEquals = 63;
+  int LtLt = 64;
+  int GtEquals = 65;
+  int GtGt = 66;
+  int FortranEq = 67;
+  int FortranNe = 68;
+  int FortranGt = 69;
+  int FortranGe = 70;
+  int FortranLt = 71;
+  int FortranLe = 72;
+  int Lt = 73;
+  int Gt = 74;
+  int Minus = 75;
+  int Plus = 76;
+  int QMark = 77;
+  int Vbar = 78;
+  int Lpar = 79;
+  int At = 80;
+  int Lbrack = 81;
+  int Rbrack = 82;
+  int Rpar = 83;
+  int Some = 84;
+  int Every = 85;
+  int ForVariable = 86;
+  int CastAs = 87;
+  int TreatAs = 88;
+  int Validate = 89;
+  int Digits = 90;
+  int IntegerLiteral = 91;
+  int DecimalLiteral = 92;
+  int DoubleLiteral = 93;
+  int Comment = 94;
+  int Document = 95;
+  int DocumentLbrace = 96;
+  int Text = 97;
+  int Untyped = 98;
+  int ProcessingInstruction = 99;
+  int NodeLpar = 100;
+  int CommentLpar = 101;
+  int TextLpar = 102;
+  int ProcessingInstructionLpar = 103;
+  int IfLpar = 104;
+  int Comma = 105;
+  int StringLiteral = 106;
+  int NamespaceURLLiteral = 107;
+  int Dot = 108;
+  int DotDot = 109;
+  int NCName = 110;
+  int Prefix = 111;
+  int LocalPart = 112;
+  int VariableIndicator = 113;
+  int VarName = 114;
+  int QName = 115;
+  int FuncName = 116;
+  int FuncPListOpen = 117;
+  int QNameLpar = 118;
+  int Lbrace = 119;
+  int Rbrace = 120;
+  int Char = 121;
+  int WhitespaceChar = 122;
+  int Letter = 123;
+  int BaseChar = 124;
+  int Ideographic = 125;
+  int CombiningChar = 126;
+  int Digit = 127;
+  int Extender = 128;
+
+  int DEFAULT = 0;
+  int ELEMENT_CONTENT = 1;
+  int OPERATOR = 2;
+  int QNAME = 3;
+  int NAMESPACEDECL = 4;
+  int XMLSPACE_DECL = 5;
+  int ITEMTYPE = 6;
+  int FUNCDEF = 7;
+  int NAMESPACEKEYWORD = 8;
+  int START_TAG = 9;
+  int END_TAG = 10;
+  int VARNAME = 11;
+  int QUOT_ATTRIBUTE_CONTENT = 12;
+  int APOS_ATTRIBUTE_CONTENT = 13;
+  int CDATA_SECTION = 14;
+  int PROCESSING_INSTRUCTION = 15;
+  int XML_COMMENT = 16;
+  int XQUERY_COMMENT = 17;
+
+  String[] tokenImage = {
+    "<EOF>",
+    "<ExprComment>",
+    "<token of kind 2>",
+    "<skip_>",
+    "<S>",
+    "<AxisChild>",
+    "<AxisDescendant>",
+    "<AxisParent>",
+    "<AxisAttribute>",
+    "<AxisSelf>",
+    "<AxisDescendantOrSelf>",
+    "<AxisAncestor>",
+    "<AxisFollowingSibling>",
+    "<AxisPrecedingSibling>",
+    "<AxisFollowing>",
+    "<AxisPreceding>",
+    "<AxisNamespace>",
+    "<AxisAncestorOrSelf>",
+    "\"or\"",
+    "\"and\"",
+    "\"div\"",
+    "\"idiv\"",
+    "\"mod\"",
+    "\"*\"",
+    "\"in\"",
+    "\"satisfies\"",
+    "\"return\"",
+    "\"then\"",
+    "\"else\"",
+    "\"to\"",
+    "\"intersect\"",
+    "\"union\"",
+    "\"except\"",
+    "\"precedes\"",
+    "\"follows\"",
+    "<Instanceof>",
+    "\"item\"",
+    "\"element\"",
+    "\"attribute\"",
+    "<ElementQNameLbrace>",
+    "<AttributeQNameLbrace>",
+    "<ElementLbrace>",
+    "<AttributeLbrace>",
+    "<DefaultElement>",
+    "<DefaultFunction>",
+    "<OfType>",
+    "<AtomicValue>",
+    "\"type\"",
+    "\"node\"",
+    "\"empty\"",
+    "<Nmstart>",
+    "<Nmchar>",
+    "\"*\"",
+    "<NCNameColonStar>",
+    "<StarColonNCName>",
+    "\"/\"",
+    "\"//\"",
+    "\"/\"",
+    "\"//\"",
+    "\"=\"",
+    "\"is\"",
+    "\"!=\"",
+    "\"isnot\"",
+    "\"<=\"",
+    "\"<<\"",
+    "\">=\"",
+    "\">>\"",
+    "\"eq\"",
+    "\"ne\"",
+    "\"gt\"",
+    "\"ge\"",
+    "\"lt\"",
+    "\"le\"",
+    "\"<\"",
+    "\">\"",
+    "\"-\"",
+    "\"+\"",
+    "\"?\"",
+    "\"|\"",
+    "\"(\"",
+    "\"@\"",
+    "\"[\"",
+    "\"]\"",
+    "\")\"",
+    "<Some>",
+    "<Every>",
+    "<ForVariable>",
+    "<CastAs>",
+    "<TreatAs>",
+    "\"validate\"",
+    "<Digits>",
+    "<IntegerLiteral>",
+    "<DecimalLiteral>",
+    "<DoubleLiteral>",
+    "\"comment\"",
+    "\"document\"",
+    "<DocumentLbrace>",
+    "\"text\"",
+    "\"untyped\"",
+    "\"processing-instruction\"",
+    "<NodeLpar>",
+    "<CommentLpar>",
+    "<TextLpar>",
+    "<ProcessingInstructionLpar>",
+    "<IfLpar>",
+    "\",\"",
+    "<StringLiteral>",
+    "<NamespaceURLLiteral>",
+    "\".\"",
+    "\"..\"",
+    "<NCName>",
+    "<Prefix>",
+    "<LocalPart>",
+    "\"$\"",
+    "<VarName>",
+    "<QName>",
+    "<FuncName>",
+    "\"(\"",
+    "<QNameLpar>",
+    "\"{\"",
+    "\"}\"",
+    "<Char>",
+    "<WhitespaceChar>",
+    "<Letter>",
+    "<BaseChar>",
+    "<Ideographic>",
+    "<CombiningChar>",
+    "<Digit>",
+    "<Extender>",
+  };
+
+}
diff --git a/src/org/apache/xpath/parser/XPathTokenManager.java b/src/org/apache/xpath/parser/XPathTokenManager.java
new file mode 100644
index 0000000..98b550c
--- /dev/null
+++ b/src/org/apache/xpath/parser/XPathTokenManager.java
@@ -0,0 +1,7912 @@
+/* Generated By:JJTree&JavaCC: Do not edit this line. XPathTokenManager.java */
+package org.apache.xpath.parser;
+
+import java.util.Stack;
+
+
+public class XPathTokenManager implements XPathConstants
+{
+  private java.util.Vector stateStack = new java.util.Vector();
+  private void pushState() {
+    stateStack.addElement(new Integer(curLexState));
+  }
+  private void pushState(int state) {
+    stateStack.addElement(new Integer(state));
+  }
+  private void popState() {
+    if(stateStack.size() == 0)
+    {
+      printLinePos();
+    }
+
+    int nextState = ((Integer)stateStack.lastElement()).intValue();
+
+    stateStack.setSize(stateStack.size() - 1);
+    SwitchTo(nextState);
+  }
+
+  public void printLinePos()
+  {
+    System.err.println("Line: "+input_stream.getEndLine());
+  }
+
+private final int jjMoveStringLiteralDfa0_15()
+{
+   return jjMoveNfa_15(0, 0);
+}
+private final void jjCheckNAdd(int state)
+{
+   if (jjrounds[state] != jjround)
+   {
+      jjstateSet[jjnewStateCnt++] = state;
+      jjrounds[state] = jjround;
+   }
+}
+private final void jjAddStates(int start, int end)
+{
+   do {
+      jjstateSet[jjnewStateCnt++] = jjnextStates[start];
+   } while (start++ != end);
+}
+private final void jjCheckNAddTwoStates(int state1, int state2)
+{
+   jjCheckNAdd(state1);
+   jjCheckNAdd(state2);
+}
+private final void jjCheckNAddStates(int start, int end)
+{
+   do {
+      jjCheckNAdd(jjnextStates[start]);
+   } while (start++ != end);
+}
+private final void jjCheckNAddStates(int start)
+{
+   jjCheckNAdd(jjnextStates[start]);
+   jjCheckNAdd(jjnextStates[start + 1]);
+}
+static final long[] jjbitVec0 = {
+   0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0x7fffffffffffffffL
+};
+static final long[] jjbitVec2 = {
+   0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
+};
+static final long[] jjbitVec3 = {
+   0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0x3fffffffffffffffL
+};
+private final int jjMoveNfa_15(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 1;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((0xffffffff00002600L & l) != 0L)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((jjbitVec2[i2] & l2) != 0L && kind > 121)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjStopStringLiteralDfa_10(int pos, long active0, long active1)
+{
+   switch (pos)
+   {
+      default :
+         return -1;
+   }
+}
+private final int jjStartNfa_10(int pos, long active0, long active1)
+{
+   return jjMoveNfa_10(jjStopStringLiteralDfa_10(pos, active0, active1), pos + 1);
+}
+private final int jjStopAtPos(int pos, int kind)
+{
+   jjmatchedKind = kind;
+   jjmatchedPos = pos;
+   return pos + 1;
+}
+private final int jjStartNfaWithStates_10(int pos, int kind, int state)
+{
+   jjmatchedKind = kind;
+   jjmatchedPos = pos;
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) { return pos + 1; }
+   return jjMoveNfa_10(state, pos + 1);
+}
+private final int jjMoveStringLiteralDfa0_10()
+{
+   switch(curChar)
+   {
+      case 123:
+         return jjStopAtPos(0, 119);
+      default :
+         return jjMoveNfa_10(0, 0);
+   }
+}
+private final int jjMoveNfa_10(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 1;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  kind = 4;
+                  jjstateSet[jjnewStateCnt++] = 0;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjMoveStringLiteralDfa0_16()
+{
+   return jjMoveNfa_16(0, 0);
+}
+private final int jjMoveNfa_16(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 1;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((0xffffffff00002600L & l) != 0L)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((jjbitVec2[i2] & l2) != 0L && kind > 121)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjStopStringLiteralDfa_3(int pos, long active0, long active1)
+{
+   switch (pos)
+   {
+      case 0:
+         if ((active0 & 0x10000000000000L) != 0L)
+            return 8;
+         return -1;
+      default :
+         return -1;
+   }
+}
+private final int jjStartNfa_3(int pos, long active0, long active1)
+{
+   return jjMoveNfa_3(jjStopStringLiteralDfa_3(pos, active0, active1), pos + 1);
+}
+private final int jjStartNfaWithStates_3(int pos, int kind, int state)
+{
+   jjmatchedKind = kind;
+   jjmatchedPos = pos;
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) { return pos + 1; }
+   return jjMoveNfa_3(state, pos + 1);
+}
+private final int jjMoveStringLiteralDfa0_3()
+{
+   switch(curChar)
+   {
+      case 36:
+         return jjStopAtPos(0, 113);
+      case 40:
+         return jjStopAtPos(0, 79);
+      case 41:
+         return jjStopAtPos(0, 83);
+      case 42:
+         return jjStartNfaWithStates_3(0, 52, 8);
+      case 46:
+         jjmatchedKind = 108;
+         return jjMoveStringLiteralDfa1_3(0x0L, 0x200000000000L);
+      case 47:
+         jjmatchedKind = 55;
+         return jjMoveStringLiteralDfa1_3(0x100000000000000L, 0x0L);
+      case 64:
+         return jjStopAtPos(0, 80);
+      default :
+         return jjMoveNfa_3(6, 0);
+   }
+}
+private final int jjMoveStringLiteralDfa1_3(long active0, long active1)
+{
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_3(0, active0, active1);
+      return 1;
+   }
+   switch(curChar)
+   {
+      case 46:
+         if ((active1 & 0x200000000000L) != 0L)
+            return jjStopAtPos(1, 109);
+         break;
+      case 47:
+         if ((active0 & 0x100000000000000L) != 0L)
+            return jjStopAtPos(1, 56);
+         break;
+      default :
+         break;
+   }
+   return jjStartNfa_3(0, active0, active1);
+}
+static final long[] jjbitVec4 = {
+   0x0L, 0xffffffffffffc000L, 0xfffff0007fffffffL, 0x7fffffL
+};
+static final long[] jjbitVec5 = {
+   0x0L, 0x0L, 0x0L, 0xff7fffffff7fffffL
+};
+static final long[] jjbitVec6 = {
+   0x7ff3ffffffffffffL, 0x7ffffffffffffdfeL, 0xffffffffffffffffL, 0xfc31ffffffffe00fL
+};
+static final long[] jjbitVec7 = {
+   0xffffffL, 0xffffffffffff0000L, 0xf80001ffffffffffL, 0x3L
+};
+static final long[] jjbitVec8 = {
+   0x0L, 0x0L, 0xfffffffbffffd740L, 0xffffd547f7fffL
+};
+static final long[] jjbitVec9 = {
+   0xffffffffffffdffeL, 0xffffffffdffeffffL, 0xffffffffffff0003L, 0x33fcfffffff199fL
+};
+static final long[] jjbitVec10 = {
+   0xfffe000000000000L, 0xfffffffe027fffffL, 0x7fL, 0x707ffffff0000L
+};
+static final long[] jjbitVec11 = {
+   0x7fffffe00000000L, 0xfffe0000000007feL, 0x7cffffffffffffffL, 0x60002f7fffL
+};
+static final long[] jjbitVec12 = {
+   0x23ffffffffffffe0L, 0x3ff000000L, 0x3c5fdfffff99fe0L, 0x30003b0000000L
+};
+static final long[] jjbitVec13 = {
+   0x36dfdfffff987e0L, 0x1c00005e000000L, 0x23edfdfffffbafe0L, 0x100000000L
+};
+static final long[] jjbitVec14 = {
+   0x23cdfdfffff99fe0L, 0x3b0000000L, 0x3bfc718d63dc7e0L, 0x0L
+};
+static final long[] jjbitVec15 = {
+   0x3effdfffffddfe0L, 0x300000000L, 0x3effdfffffddfe0L, 0x340000000L
+};
+static final long[] jjbitVec16 = {
+   0x3fffdfffffddfe0L, 0x300000000L, 0x0L, 0x0L
+};
+static final long[] jjbitVec17 = {
+   0xd7ffffffffffeL, 0x3fL, 0x200d6caefef02596L, 0x1fL
+};
+static final long[] jjbitVec18 = {
+   0x0L, 0x3fffffffeffL, 0x0L, 0x0L
+};
+static final long[] jjbitVec19 = {
+   0x0L, 0x0L, 0xffffffff00000000L, 0x7fffffffff003fL
+};
+static final long[] jjbitVec20 = {
+   0x500000000007daedL, 0x2c62ab82315001L, 0xf580c90040000000L, 0x201080000000007L
+};
+static final long[] jjbitVec21 = {
+   0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffff0fffffffL, 0x3ffffffffffffffL
+};
+static final long[] jjbitVec22 = {
+   0xffffffff3f3fffffL, 0x3fffffffaaff3f3fL, 0x5fdfffffffffffffL, 0x1fdc1fff0fcf1fdcL
+};
+static final long[] jjbitVec23 = {
+   0x4c4000000000L, 0x0L, 0x7L, 0x0L
+};
+static final long[] jjbitVec24 = {
+   0x3fe00000080L, 0xfffffffffffffffeL, 0xfffffffe001fffffL, 0x7ffffffffffffffL
+};
+static final long[] jjbitVec25 = {
+   0x1fffffffffe0L, 0x0L, 0x0L, 0x0L
+};
+static final long[] jjbitVec26 = {
+   0xffffffffffffffffL, 0xffffffffffffffffL, 0x3fffffffffL, 0x0L
+};
+static final long[] jjbitVec27 = {
+   0xffffffffffffffffL, 0xffffffffffffffffL, 0xfffffffffL, 0x0L
+};
+static final long[] jjbitVec28 = {
+   0x0L, 0x0L, 0x80000000000000L, 0xff7fffffff7fffffL
+};
+static final long[] jjbitVec29 = {
+   0xffffffL, 0xffffffffffff0000L, 0xf80001ffffffffffL, 0x30003L
+};
+static final long[] jjbitVec30 = {
+   0xffffffffffffffffL, 0x30000003fL, 0xfffffffbffffd7c0L, 0xffffd547f7fffL
+};
+static final long[] jjbitVec31 = {
+   0xffffffffffffdffeL, 0xffffffffdffeffffL, 0xffffffffffff007bL, 0x33fcfffffff199fL
+};
+static final long[] jjbitVec32 = {
+   0xfffe000000000000L, 0xfffffffe027fffffL, 0xbbfffffbfffe007fL, 0x707ffffff0016L
+};
+static final long[] jjbitVec33 = {
+   0x7fffffe00000000L, 0xffff03ff0007ffffL, 0x7cffffffffffffffL, 0x3ff3dffffef7fffL
+};
+static final long[] jjbitVec34 = {
+   0xf3ffffffffffffeeL, 0xffcfff1e3fffL, 0xd3c5fdfffff99feeL, 0x3ffcfb080399fL
+};
+static final long[] jjbitVec35 = {
+   0xd36dfdfffff987e4L, 0x1fffc05e003987L, 0xf3edfdfffffbafeeL, 0xffc100003bbfL
+};
+static final long[] jjbitVec36 = {
+   0xf3cdfdfffff99feeL, 0xffc3b0c0398fL, 0xc3bfc718d63dc7ecL, 0xff8000803dc7L
+};
+static final long[] jjbitVec37 = {
+   0xc3effdfffffddfeeL, 0xffc300603ddfL, 0xc3effdfffffddfecL, 0xffc340603ddfL
+};
+static final long[] jjbitVec38 = {
+   0xc3fffdfffffddfecL, 0xffc300803dcfL, 0x0L, 0x0L
+};
+static final long[] jjbitVec39 = {
+   0x7ff7ffffffffffeL, 0x3ff7fffL, 0x3bff6caefef02596L, 0x3ff3f5fL
+};
+static final long[] jjbitVec40 = {
+   0xc2a003ff03000000L, 0xfffe03fffffffeffL, 0x2fe3ffffebf0fdfL, 0x0L
+};
+static final long[] jjbitVec41 = {
+   0x0L, 0x0L, 0x0L, 0x21fff0000L
+};
+static final long[] jjbitVec42 = {
+   0x3efffe000000a0L, 0xfffffffffffffffeL, 0xfffffffe661fffffL, 0x77ffffffffffffffL
+};
+private final int jjMoveNfa_3(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 227;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 6:
+                  if ((0x100002600L & l) != 0L)
+                  {
+                     if (kind > 2)
+                        kind = 2;
+                     jjCheckNAddTwoStates(18, 19);
+                  }
+                  else if (curChar == 42)
+                     jjstateSet[jjnewStateCnt++] = 8;
+                  break;
+               case 1:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(0, 1);
+                  break;
+               case 2:
+                  if (curChar == 58 && kind > 9)
+                     kind = 9;
+                  break;
+               case 3:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 2;
+                  break;
+               case 7:
+                  if (curChar == 42)
+                     jjstateSet[jjnewStateCnt++] = 8;
+                  break;
+               case 8:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 9;
+                  break;
+               case 10:
+                  if ((0x3ff600000000000L & l) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjstateSet[jjnewStateCnt++] = 10;
+                  break;
+               case 12:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(2, 3);
+                  break;
+               case 13:
+                  if (curChar == 40 && kind > 102)
+                     kind = 102;
+                  break;
+               case 17:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 2)
+                     kind = 2;
+                  jjCheckNAddTwoStates(18, 19);
+                  break;
+               case 18:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 2)
+                     kind = 2;
+                  jjCheckNAdd(18);
+                  break;
+               case 19:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 4)
+                     kind = 4;
+                  jjCheckNAdd(19);
+                  break;
+               case 22:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(4, 5);
+                  break;
+               case 23:
+                  if (curChar == 58 && kind > 5)
+                     kind = 5;
+                  break;
+               case 24:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 23;
+                  break;
+               case 29:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(6, 7);
+                  break;
+               case 30:
+                  if (curChar == 40 && kind > 101)
+                     kind = 101;
+                  break;
+               case 38:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(8, 9);
+                  break;
+               case 39:
+                  if (curChar == 58 && kind > 6)
+                     kind = 6;
+                  break;
+               case 40:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 39;
+                  break;
+               case 50:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(10, 11);
+                  break;
+               case 51:
+                  if (curChar == 58 && kind > 10)
+                     kind = 10;
+                  break;
+               case 52:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 51;
+                  break;
+               case 56:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 55;
+                  break;
+               case 59:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 58;
+                  break;
+               case 71:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(12, 13);
+                  break;
+               case 72:
+                  if (curChar == 58 && kind > 7)
+                     kind = 7;
+                  break;
+               case 73:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 72;
+                  break;
+               case 79:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(14, 15);
+                  break;
+               case 80:
+                  if (curChar == 58 && kind > 13)
+                     kind = 13;
+                  break;
+               case 81:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 80;
+                  break;
+               case 88:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 87;
+                  break;
+               case 98:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(16, 17);
+                  break;
+               case 99:
+                  if (curChar == 58 && kind > 15)
+                     kind = 15;
+                  break;
+               case 100:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 99;
+                  break;
+               case 109:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(18, 19);
+                  break;
+               case 110:
+                  if (curChar == 40 && kind > 103)
+                     kind = 103;
+                  break;
+               case 121:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 120;
+                  break;
+               case 133:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(20, 21);
+                  break;
+               case 134:
+                  if (curChar == 58 && kind > 8)
+                     kind = 8;
+                  break;
+               case 135:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 134;
+                  break;
+               case 144:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(22, 23);
+                  break;
+               case 145:
+                  if (curChar == 58 && kind > 11)
+                     kind = 11;
+                  break;
+               case 146:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 145;
+                  break;
+               case 154:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(24, 25);
+                  break;
+               case 155:
+                  if (curChar == 58 && kind > 17)
+                     kind = 17;
+                  break;
+               case 156:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 155;
+                  break;
+               case 160:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 159;
+                  break;
+               case 163:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 162;
+                  break;
+               case 173:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(26, 27);
+                  break;
+               case 174:
+                  if (curChar == 58 && kind > 12)
+                     kind = 12;
+                  break;
+               case 175:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 174;
+                  break;
+               case 182:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 181;
+                  break;
+               case 192:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(28, 29);
+                  break;
+               case 193:
+                  if (curChar == 58 && kind > 14)
+                     kind = 14;
+                  break;
+               case 194:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 193;
+                  break;
+               case 204:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(30, 31);
+                  break;
+               case 205:
+                  if (curChar == 58 && kind > 16)
+                     kind = 16;
+                  break;
+               case 206:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 205;
+                  break;
+               case 215:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(32, 33);
+                  break;
+               case 216:
+                  if (curChar == 40 && kind > 100)
+                     kind = 100;
+                  break;
+               case 220:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjAddStates(34, 35);
+                  break;
+               case 221:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 222;
+                  break;
+               case 222:
+                  if (curChar == 42 && kind > 53)
+                     kind = 53;
+                  break;
+               case 223:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjAddStates(36, 37);
+                  break;
+               case 224:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 225;
+                  break;
+               case 226:
+                  if ((0x3ff600000000000L & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjstateSet[jjnewStateCnt++] = 226;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 6:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAddStates(38, 42);
+                  }
+                  if (curChar == 110)
+                     jjAddStates(43, 44);
+                  else if (curChar == 102)
+                     jjAddStates(45, 46);
+                  else if (curChar == 97)
+                     jjAddStates(47, 49);
+                  else if (curChar == 112)
+                     jjAddStates(50, 53);
+                  else if (curChar == 100)
+                     jjAddStates(54, 55);
+                  else if (curChar == 99)
+                     jjAddStates(56, 57);
+                  else if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 15;
+                  else if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 5;
+                  break;
+               case 0:
+                  if (curChar == 102)
+                     jjAddStates(0, 1);
+                  break;
+               case 4:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 0;
+                  break;
+               case 5:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 4;
+                  break;
+               case 9:
+               case 10:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjCheckNAdd(10);
+                  break;
+               case 11:
+                  if (curChar == 116)
+                     jjAddStates(2, 3);
+                  break;
+               case 14:
+                  if (curChar == 120)
+                     jjstateSet[jjnewStateCnt++] = 11;
+                  break;
+               case 15:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 14;
+                  break;
+               case 16:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 15;
+                  break;
+               case 20:
+                  if (curChar == 99)
+                     jjAddStates(56, 57);
+                  break;
+               case 21:
+                  if (curChar == 100)
+                     jjAddStates(4, 5);
+                  break;
+               case 25:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 21;
+                  break;
+               case 26:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 25;
+                  break;
+               case 27:
+                  if (curChar == 104)
+                     jjstateSet[jjnewStateCnt++] = 26;
+                  break;
+               case 28:
+                  if (curChar == 116)
+                     jjAddStates(6, 7);
+                  break;
+               case 31:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 28;
+                  break;
+               case 32:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 31;
+                  break;
+               case 33:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 32;
+                  break;
+               case 34:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 33;
+                  break;
+               case 35:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 34;
+                  break;
+               case 36:
+                  if (curChar == 100)
+                     jjAddStates(54, 55);
+                  break;
+               case 37:
+                  if (curChar == 116)
+                     jjAddStates(8, 9);
+                  break;
+               case 41:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 37;
+                  break;
+               case 42:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 41;
+                  break;
+               case 43:
+                  if (curChar == 100)
+                     jjstateSet[jjnewStateCnt++] = 42;
+                  break;
+               case 44:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 43;
+                  break;
+               case 45:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 44;
+                  break;
+               case 46:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 45;
+                  break;
+               case 47:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 46;
+                  break;
+               case 48:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 47;
+                  break;
+               case 49:
+                  if (curChar == 102)
+                     jjAddStates(10, 11);
+                  break;
+               case 53:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 49;
+                  break;
+               case 54:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 53;
+                  break;
+               case 55:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 54;
+                  break;
+               case 57:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 56;
+                  break;
+               case 58:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 57;
+                  break;
+               case 60:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 59;
+                  break;
+               case 61:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 60;
+                  break;
+               case 62:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 61;
+                  break;
+               case 63:
+                  if (curChar == 100)
+                     jjstateSet[jjnewStateCnt++] = 62;
+                  break;
+               case 64:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 63;
+                  break;
+               case 65:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 64;
+                  break;
+               case 66:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 65;
+                  break;
+               case 67:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 66;
+                  break;
+               case 68:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 67;
+                  break;
+               case 69:
+                  if (curChar == 112)
+                     jjAddStates(50, 53);
+                  break;
+               case 70:
+                  if (curChar == 116)
+                     jjAddStates(12, 13);
+                  break;
+               case 74:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 70;
+                  break;
+               case 75:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 74;
+                  break;
+               case 76:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 75;
+                  break;
+               case 77:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 76;
+                  break;
+               case 78:
+                  if (curChar == 103)
+                     jjAddStates(14, 15);
+                  break;
+               case 82:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 78;
+                  break;
+               case 83:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 82;
+                  break;
+               case 84:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 83;
+                  break;
+               case 85:
+                  if (curChar == 98)
+                     jjstateSet[jjnewStateCnt++] = 84;
+                  break;
+               case 86:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 85;
+                  break;
+               case 87:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 86;
+                  break;
+               case 89:
+                  if (curChar == 103)
+                     jjstateSet[jjnewStateCnt++] = 88;
+                  break;
+               case 90:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 89;
+                  break;
+               case 91:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 90;
+                  break;
+               case 92:
+                  if (curChar == 100)
+                     jjstateSet[jjnewStateCnt++] = 91;
+                  break;
+               case 93:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 92;
+                  break;
+               case 94:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 93;
+                  break;
+               case 95:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 94;
+                  break;
+               case 96:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 95;
+                  break;
+               case 97:
+                  if (curChar == 103)
+                     jjAddStates(16, 17);
+                  break;
+               case 101:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 97;
+                  break;
+               case 102:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 101;
+                  break;
+               case 103:
+                  if (curChar == 100)
+                     jjstateSet[jjnewStateCnt++] = 102;
+                  break;
+               case 104:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 103;
+                  break;
+               case 105:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 104;
+                  break;
+               case 106:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 105;
+                  break;
+               case 107:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 106;
+                  break;
+               case 108:
+                  if (curChar == 110)
+                     jjAddStates(18, 19);
+                  break;
+               case 111:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 108;
+                  break;
+               case 112:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 111;
+                  break;
+               case 113:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 112;
+                  break;
+               case 114:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 113;
+                  break;
+               case 115:
+                  if (curChar == 117)
+                     jjstateSet[jjnewStateCnt++] = 114;
+                  break;
+               case 116:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 115;
+                  break;
+               case 117:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 116;
+                  break;
+               case 118:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 117;
+                  break;
+               case 119:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 118;
+                  break;
+               case 120:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 119;
+                  break;
+               case 122:
+                  if (curChar == 103)
+                     jjstateSet[jjnewStateCnt++] = 121;
+                  break;
+               case 123:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 122;
+                  break;
+               case 124:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 123;
+                  break;
+               case 125:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 124;
+                  break;
+               case 126:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 125;
+                  break;
+               case 127:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 126;
+                  break;
+               case 128:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 127;
+                  break;
+               case 129:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 128;
+                  break;
+               case 130:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 129;
+                  break;
+               case 131:
+                  if (curChar == 97)
+                     jjAddStates(47, 49);
+                  break;
+               case 132:
+                  if (curChar == 101)
+                     jjAddStates(20, 21);
+                  break;
+               case 136:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 132;
+                  break;
+               case 137:
+                  if (curChar == 117)
+                     jjstateSet[jjnewStateCnt++] = 136;
+                  break;
+               case 138:
+                  if (curChar == 98)
+                     jjstateSet[jjnewStateCnt++] = 137;
+                  break;
+               case 139:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 138;
+                  break;
+               case 140:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 139;
+                  break;
+               case 141:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 140;
+                  break;
+               case 142:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 141;
+                  break;
+               case 143:
+                  if (curChar == 114)
+                     jjAddStates(22, 23);
+                  break;
+               case 147:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 143;
+                  break;
+               case 148:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 147;
+                  break;
+               case 149:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 148;
+                  break;
+               case 150:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 149;
+                  break;
+               case 151:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 150;
+                  break;
+               case 152:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 151;
+                  break;
+               case 153:
+                  if (curChar == 102)
+                     jjAddStates(24, 25);
+                  break;
+               case 157:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 153;
+                  break;
+               case 158:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 157;
+                  break;
+               case 159:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 158;
+                  break;
+               case 161:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 160;
+                  break;
+               case 162:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 161;
+                  break;
+               case 164:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 163;
+                  break;
+               case 165:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 164;
+                  break;
+               case 166:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 165;
+                  break;
+               case 167:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 166;
+                  break;
+               case 168:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 167;
+                  break;
+               case 169:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 168;
+                  break;
+               case 170:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 169;
+                  break;
+               case 171:
+                  if (curChar == 102)
+                     jjAddStates(45, 46);
+                  break;
+               case 172:
+                  if (curChar == 103)
+                     jjAddStates(26, 27);
+                  break;
+               case 176:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 172;
+                  break;
+               case 177:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 176;
+                  break;
+               case 178:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 177;
+                  break;
+               case 179:
+                  if (curChar == 98)
+                     jjstateSet[jjnewStateCnt++] = 178;
+                  break;
+               case 180:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 179;
+                  break;
+               case 181:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 180;
+                  break;
+               case 183:
+                  if (curChar == 103)
+                     jjstateSet[jjnewStateCnt++] = 182;
+                  break;
+               case 184:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 183;
+                  break;
+               case 185:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 184;
+                  break;
+               case 186:
+                  if (curChar == 119)
+                     jjstateSet[jjnewStateCnt++] = 185;
+                  break;
+               case 187:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 186;
+                  break;
+               case 188:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 187;
+                  break;
+               case 189:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 188;
+                  break;
+               case 190:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 189;
+                  break;
+               case 191:
+                  if (curChar == 103)
+                     jjAddStates(28, 29);
+                  break;
+               case 195:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 191;
+                  break;
+               case 196:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 195;
+                  break;
+               case 197:
+                  if (curChar == 119)
+                     jjstateSet[jjnewStateCnt++] = 196;
+                  break;
+               case 198:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 197;
+                  break;
+               case 199:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 198;
+                  break;
+               case 200:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 199;
+                  break;
+               case 201:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 200;
+                  break;
+               case 202:
+                  if (curChar == 110)
+                     jjAddStates(43, 44);
+                  break;
+               case 203:
+                  if (curChar == 101)
+                     jjAddStates(30, 31);
+                  break;
+               case 207:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 203;
+                  break;
+               case 208:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 207;
+                  break;
+               case 209:
+                  if (curChar == 112)
+                     jjstateSet[jjnewStateCnt++] = 208;
+                  break;
+               case 210:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 209;
+                  break;
+               case 211:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 210;
+                  break;
+               case 212:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 211;
+                  break;
+               case 213:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 212;
+                  break;
+               case 214:
+                  if (curChar == 101)
+                     jjAddStates(32, 33);
+                  break;
+               case 217:
+                  if (curChar == 100)
+                     jjstateSet[jjnewStateCnt++] = 214;
+                  break;
+               case 218:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 217;
+                  break;
+               case 219:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAddStates(38, 42);
+                  break;
+               case 220:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(220, 221);
+                  break;
+               case 223:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(223, 224);
+                  break;
+               case 225:
+               case 226:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(226);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 6:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAddStates(38, 42);
+                  break;
+               case 9:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjCheckNAdd(10);
+                  break;
+               case 10:
+                  if ((jjbitVec28[i2] & l2) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjCheckNAdd(10);
+                  break;
+               case 220:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(220, 221);
+                  break;
+               case 223:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(223, 224);
+                  break;
+               case 225:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(226);
+                  break;
+               case 226:
+                  if ((jjbitVec28[i2] & l2) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(226);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 227 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjStopStringLiteralDfa_6(int pos, long active0, long active1)
+{
+   switch (pos)
+   {
+      case 0:
+         if ((active0 & 0x4000000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            return 10;
+         }
+         if ((active0 & 0x1003000000000L) != 0L || (active1 & 0xec0000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            return 27;
+         }
+         return -1;
+      case 1:
+         if ((active0 & 0x1003000000000L) != 0L || (active1 & 0xec0000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 1;
+            return 27;
+         }
+         if ((active0 & 0x4000000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 1;
+            return 9;
+         }
+         return -1;
+      case 2:
+         if ((active0 & 0x1007000000000L) != 0L || (active1 & 0xec0000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 2;
+            return 27;
+         }
+         return -1;
+      case 3:
+         if ((active0 & 0x1001000000000L) != 0L || (active1 & 0x200000000L) != 0L)
+            return 27;
+         if ((active0 & 0x6000000000L) != 0L || (active1 & 0xcc0000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 3;
+            return 27;
+         }
+         return -1;
+      case 4:
+         if ((active0 & 0x6000000000L) != 0L || (active1 & 0xcc0000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 4;
+            return 27;
+         }
+         return -1;
+      case 5:
+         if ((active0 & 0x6000000000L) != 0L || (active1 & 0xcc0000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 5;
+            return 27;
+         }
+         return -1;
+      case 6:
+         if ((active0 & 0x4000000000L) != 0L || (active1 & 0x880000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 6;
+            return 27;
+         }
+         if ((active0 & 0x2000000000L) != 0L || (active1 & 0x440000000L) != 0L)
+            return 27;
+         return -1;
+      case 7:
+         if ((active1 & 0x80000000L) != 0L)
+            return 27;
+         if ((active0 & 0x4000000000L) != 0L || (active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 7;
+            return 27;
+         }
+         return -1;
+      case 8:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 8;
+            return 27;
+         }
+         if ((active0 & 0x4000000000L) != 0L)
+            return 27;
+         return -1;
+      case 9:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 9;
+            return 27;
+         }
+         return -1;
+      case 10:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 10;
+            return 27;
+         }
+         return -1;
+      case 11:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 11;
+            return 27;
+         }
+         return -1;
+      case 12:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 12;
+            return 27;
+         }
+         return -1;
+      case 13:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 13;
+            return 27;
+         }
+         return -1;
+      case 14:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 14;
+            return 27;
+         }
+         return -1;
+      case 15:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 15;
+            return 27;
+         }
+         return -1;
+      case 16:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 16;
+            return 27;
+         }
+         return -1;
+      case 17:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 17;
+            return 27;
+         }
+         return -1;
+      case 18:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 18;
+            return 27;
+         }
+         return -1;
+      case 19:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 19;
+            return 27;
+         }
+         return -1;
+      case 20:
+         if ((active1 & 0x800000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 20;
+            return 27;
+         }
+         return -1;
+      default :
+         return -1;
+   }
+}
+private final int jjStartNfa_6(int pos, long active0, long active1)
+{
+   return jjMoveNfa_6(jjStopStringLiteralDfa_6(pos, active0, active1), pos + 1);
+}
+private final int jjStartNfaWithStates_6(int pos, int kind, int state)
+{
+   jjmatchedKind = kind;
+   jjmatchedPos = pos;
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) { return pos + 1; }
+   return jjMoveNfa_6(state, pos + 1);
+}
+private final int jjMoveStringLiteralDfa0_6()
+{
+   switch(curChar)
+   {
+      case 36:
+         return jjStopAtPos(0, 113);
+      case 41:
+         return jjStopAtPos(0, 83);
+      case 46:
+         jjmatchedKind = 108;
+         return jjMoveStringLiteralDfa1_6(0x0L, 0x200000000000L);
+      case 97:
+         return jjMoveStringLiteralDfa1_6(0x4000000000L, 0x0L);
+      case 99:
+         return jjMoveStringLiteralDfa1_6(0x0L, 0x40000000L);
+      case 100:
+         return jjMoveStringLiteralDfa1_6(0x0L, 0x80000000L);
+      case 101:
+         return jjMoveStringLiteralDfa1_6(0x2000000000L, 0x0L);
+      case 105:
+         return jjMoveStringLiteralDfa1_6(0x1000000000L, 0x0L);
+      case 110:
+         return jjMoveStringLiteralDfa1_6(0x1000000000000L, 0x0L);
+      case 112:
+         return jjMoveStringLiteralDfa1_6(0x0L, 0x800000000L);
+      case 116:
+         return jjMoveStringLiteralDfa1_6(0x0L, 0x200000000L);
+      case 117:
+         return jjMoveStringLiteralDfa1_6(0x0L, 0x400000000L);
+      default :
+         return jjMoveNfa_6(11, 0);
+   }
+}
+private final int jjMoveStringLiteralDfa1_6(long active0, long active1)
+{
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(0, active0, active1);
+      return 1;
+   }
+   switch(curChar)
+   {
+      case 46:
+         if ((active1 & 0x200000000000L) != 0L)
+            return jjStopAtPos(1, 109);
+         break;
+      case 101:
+         return jjMoveStringLiteralDfa2_6(active0, 0L, active1, 0x200000000L);
+      case 108:
+         return jjMoveStringLiteralDfa2_6(active0, 0x2000000000L, active1, 0L);
+      case 110:
+         return jjMoveStringLiteralDfa2_6(active0, 0L, active1, 0x400000000L);
+      case 111:
+         return jjMoveStringLiteralDfa2_6(active0, 0x1000000000000L, active1, 0xc0000000L);
+      case 114:
+         return jjMoveStringLiteralDfa2_6(active0, 0L, active1, 0x800000000L);
+      case 116:
+         return jjMoveStringLiteralDfa2_6(active0, 0x5000000000L, active1, 0L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(0, active0, active1);
+}
+private final int jjMoveStringLiteralDfa2_6(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_6(0, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(1, active0, active1);
+      return 2;
+   }
+   switch(curChar)
+   {
+      case 99:
+         return jjMoveStringLiteralDfa3_6(active0, 0L, active1, 0x80000000L);
+      case 100:
+         return jjMoveStringLiteralDfa3_6(active0, 0x1000000000000L, active1, 0L);
+      case 101:
+         return jjMoveStringLiteralDfa3_6(active0, 0x3000000000L, active1, 0L);
+      case 109:
+         return jjMoveStringLiteralDfa3_6(active0, 0L, active1, 0x40000000L);
+      case 111:
+         return jjMoveStringLiteralDfa3_6(active0, 0L, active1, 0x800000000L);
+      case 116:
+         return jjMoveStringLiteralDfa3_6(active0, 0x4000000000L, active1, 0x400000000L);
+      case 120:
+         return jjMoveStringLiteralDfa3_6(active0, 0L, active1, 0x200000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(1, active0, active1);
+}
+private final int jjMoveStringLiteralDfa3_6(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_6(1, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(2, active0, active1);
+      return 3;
+   }
+   switch(curChar)
+   {
+      case 99:
+         return jjMoveStringLiteralDfa4_6(active0, 0L, active1, 0x800000000L);
+      case 101:
+         if ((active0 & 0x1000000000000L) != 0L)
+            return jjStartNfaWithStates_6(3, 48, 27);
+         break;
+      case 109:
+         if ((active0 & 0x1000000000L) != 0L)
+            return jjStartNfaWithStates_6(3, 36, 27);
+         return jjMoveStringLiteralDfa4_6(active0, 0x2000000000L, active1, 0x40000000L);
+      case 114:
+         return jjMoveStringLiteralDfa4_6(active0, 0x4000000000L, active1, 0L);
+      case 116:
+         if ((active1 & 0x200000000L) != 0L)
+            return jjStartNfaWithStates_6(3, 97, 27);
+         break;
+      case 117:
+         return jjMoveStringLiteralDfa4_6(active0, 0L, active1, 0x80000000L);
+      case 121:
+         return jjMoveStringLiteralDfa4_6(active0, 0L, active1, 0x400000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(2, active0, active1);
+}
+private final int jjMoveStringLiteralDfa4_6(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_6(2, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(3, active0, active1);
+      return 4;
+   }
+   switch(curChar)
+   {
+      case 101:
+         return jjMoveStringLiteralDfa5_6(active0, 0x2000000000L, active1, 0x840000000L);
+      case 105:
+         return jjMoveStringLiteralDfa5_6(active0, 0x4000000000L, active1, 0L);
+      case 109:
+         return jjMoveStringLiteralDfa5_6(active0, 0L, active1, 0x80000000L);
+      case 112:
+         return jjMoveStringLiteralDfa5_6(active0, 0L, active1, 0x400000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(3, active0, active1);
+}
+private final int jjMoveStringLiteralDfa5_6(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_6(3, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(4, active0, active1);
+      return 5;
+   }
+   switch(curChar)
+   {
+      case 98:
+         return jjMoveStringLiteralDfa6_6(active0, 0x4000000000L, active1, 0L);
+      case 101:
+         return jjMoveStringLiteralDfa6_6(active0, 0L, active1, 0x480000000L);
+      case 110:
+         return jjMoveStringLiteralDfa6_6(active0, 0x2000000000L, active1, 0x40000000L);
+      case 115:
+         return jjMoveStringLiteralDfa6_6(active0, 0L, active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(4, active0, active1);
+}
+private final int jjMoveStringLiteralDfa6_6(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_6(4, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(5, active0, active1);
+      return 6;
+   }
+   switch(curChar)
+   {
+      case 100:
+         if ((active1 & 0x400000000L) != 0L)
+            return jjStartNfaWithStates_6(6, 98, 27);
+         break;
+      case 110:
+         return jjMoveStringLiteralDfa7_6(active0, 0L, active1, 0x80000000L);
+      case 115:
+         return jjMoveStringLiteralDfa7_6(active0, 0L, active1, 0x800000000L);
+      case 116:
+         if ((active0 & 0x2000000000L) != 0L)
+            return jjStartNfaWithStates_6(6, 37, 27);
+         else if ((active1 & 0x40000000L) != 0L)
+            return jjStartNfaWithStates_6(6, 94, 27);
+         break;
+      case 117:
+         return jjMoveStringLiteralDfa7_6(active0, 0x4000000000L, active1, 0L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(5, active0, active1);
+}
+private final int jjMoveStringLiteralDfa7_6(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_6(5, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(6, active0, active1);
+      return 7;
+   }
+   switch(curChar)
+   {
+      case 105:
+         return jjMoveStringLiteralDfa8_6(active0, 0L, active1, 0x800000000L);
+      case 116:
+         if ((active1 & 0x80000000L) != 0L)
+            return jjStartNfaWithStates_6(7, 95, 27);
+         return jjMoveStringLiteralDfa8_6(active0, 0x4000000000L, active1, 0L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(6, active0, active1);
+}
+private final int jjMoveStringLiteralDfa8_6(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_6(6, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(7, active0, active1);
+      return 8;
+   }
+   switch(curChar)
+   {
+      case 101:
+         if ((active0 & 0x4000000000L) != 0L)
+            return jjStartNfaWithStates_6(8, 38, 27);
+         break;
+      case 110:
+         return jjMoveStringLiteralDfa9_6(active0, 0L, active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(7, active0, active1);
+}
+private final int jjMoveStringLiteralDfa9_6(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_6(7, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(8, 0L, active1);
+      return 9;
+   }
+   switch(curChar)
+   {
+      case 103:
+         return jjMoveStringLiteralDfa10_6(active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(8, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa10_6(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_6(8, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(9, 0L, active1);
+      return 10;
+   }
+   switch(curChar)
+   {
+      case 45:
+         return jjMoveStringLiteralDfa11_6(active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(9, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa11_6(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_6(9, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(10, 0L, active1);
+      return 11;
+   }
+   switch(curChar)
+   {
+      case 105:
+         return jjMoveStringLiteralDfa12_6(active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(10, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa12_6(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_6(10, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(11, 0L, active1);
+      return 12;
+   }
+   switch(curChar)
+   {
+      case 110:
+         return jjMoveStringLiteralDfa13_6(active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(11, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa13_6(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_6(11, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(12, 0L, active1);
+      return 13;
+   }
+   switch(curChar)
+   {
+      case 115:
+         return jjMoveStringLiteralDfa14_6(active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(12, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa14_6(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_6(12, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(13, 0L, active1);
+      return 14;
+   }
+   switch(curChar)
+   {
+      case 116:
+         return jjMoveStringLiteralDfa15_6(active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(13, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa15_6(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_6(13, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(14, 0L, active1);
+      return 15;
+   }
+   switch(curChar)
+   {
+      case 114:
+         return jjMoveStringLiteralDfa16_6(active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(14, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa16_6(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_6(14, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(15, 0L, active1);
+      return 16;
+   }
+   switch(curChar)
+   {
+      case 117:
+         return jjMoveStringLiteralDfa17_6(active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(15, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa17_6(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_6(15, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(16, 0L, active1);
+      return 17;
+   }
+   switch(curChar)
+   {
+      case 99:
+         return jjMoveStringLiteralDfa18_6(active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(16, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa18_6(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_6(16, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(17, 0L, active1);
+      return 18;
+   }
+   switch(curChar)
+   {
+      case 116:
+         return jjMoveStringLiteralDfa19_6(active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(17, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa19_6(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_6(17, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(18, 0L, active1);
+      return 19;
+   }
+   switch(curChar)
+   {
+      case 105:
+         return jjMoveStringLiteralDfa20_6(active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(18, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa20_6(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_6(18, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(19, 0L, active1);
+      return 20;
+   }
+   switch(curChar)
+   {
+      case 111:
+         return jjMoveStringLiteralDfa21_6(active1, 0x800000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_6(19, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa21_6(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_6(19, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_6(20, 0L, active1);
+      return 21;
+   }
+   switch(curChar)
+   {
+      case 110:
+         if ((active1 & 0x800000000L) != 0L)
+            return jjStartNfaWithStates_6(21, 99, 27);
+         break;
+      default :
+         break;
+   }
+   return jjStartNfa_6(20, 0L, active1);
+}
+private final int jjMoveNfa_6(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 27;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 9:
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(26);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 25;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 22;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(20, 21);
+                  break;
+               case 11:
+                  if ((0x100002600L & l) != 0L)
+                  {
+                     if (kind > 2)
+                        kind = 2;
+                     jjCheckNAddTwoStates(17, 18);
+                  }
+                  else if (curChar == 42)
+                     jjstateSet[jjnewStateCnt++] = 13;
+                  break;
+               case 27:
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(26);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 25;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 22;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(20, 21);
+                  break;
+               case 10:
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(26);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 25;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 22;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(20, 21);
+                  break;
+               case 1:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(58, 59);
+                  break;
+               case 12:
+                  if (curChar == 42)
+                     jjstateSet[jjnewStateCnt++] = 13;
+                  break;
+               case 13:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 14;
+                  break;
+               case 15:
+                  if ((0x3ff600000000000L & l) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjstateSet[jjnewStateCnt++] = 15;
+                  break;
+               case 16:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 2)
+                     kind = 2;
+                  jjCheckNAddTwoStates(17, 18);
+                  break;
+               case 17:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 2)
+                     kind = 2;
+                  jjCheckNAdd(17);
+                  break;
+               case 18:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 4)
+                     kind = 4;
+                  jjCheckNAdd(18);
+                  break;
+               case 20:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(20, 21);
+                  break;
+               case 21:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 22;
+                  break;
+               case 22:
+                  if (curChar == 42 && kind > 53)
+                     kind = 53;
+                  break;
+               case 23:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  break;
+               case 24:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 25;
+                  break;
+               case 26:
+                  if ((0x3ff600000000000L & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(26);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 9:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(26);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(20, 21);
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 8;
+                  break;
+               case 11:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAddStates(60, 64);
+                  }
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 10;
+                  break;
+               case 27:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(26);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(20, 21);
+                  break;
+               case 10:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(26);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(20, 21);
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 9;
+                  break;
+               case 0:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 1;
+                  break;
+               case 2:
+                  if (curChar == 101 && kind > 46)
+                     kind = 46;
+                  break;
+               case 3:
+                  if (curChar == 117)
+                     jjstateSet[jjnewStateCnt++] = 2;
+                  break;
+               case 4:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 3;
+                  break;
+               case 5:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 4;
+                  break;
+               case 6:
+                  if (curChar == 118)
+                     jjstateSet[jjnewStateCnt++] = 5;
+                  break;
+               case 7:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 0;
+                  break;
+               case 8:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 7;
+                  break;
+               case 14:
+               case 15:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjCheckNAdd(15);
+                  break;
+               case 19:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAddStates(60, 64);
+                  break;
+               case 20:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(20, 21);
+                  break;
+               case 23:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  break;
+               case 25:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(26);
+                  break;
+               case 26:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(26);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 9:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(20, 21);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(26);
+                  }
+                  break;
+               case 11:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAddStates(60, 64);
+                  break;
+               case 27:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(20, 21);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(26);
+                  }
+                  break;
+               case 10:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(20, 21);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(26);
+                  }
+                  break;
+               case 14:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjCheckNAdd(15);
+                  break;
+               case 15:
+                  if ((jjbitVec28[i2] & l2) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjCheckNAdd(15);
+                  break;
+               case 20:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(20, 21);
+                  break;
+               case 23:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  break;
+               case 25:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(26);
+                  break;
+               case 26:
+                  if ((jjbitVec28[i2] & l2) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(26);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 27 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjStopStringLiteralDfa_1(int pos, long active0, long active1)
+{
+   switch (pos)
+   {
+      default :
+         return -1;
+   }
+}
+private final int jjStartNfa_1(int pos, long active0, long active1)
+{
+   return jjMoveNfa_1(jjStopStringLiteralDfa_1(pos, active0, active1), pos + 1);
+}
+private final int jjStartNfaWithStates_1(int pos, int kind, int state)
+{
+   jjmatchedKind = kind;
+   jjmatchedPos = pos;
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) { return pos + 1; }
+   return jjMoveNfa_1(state, pos + 1);
+}
+private final int jjMoveStringLiteralDfa0_1()
+{
+   switch(curChar)
+   {
+      case 123:
+         return jjStartNfaWithStates_1(0, 119, 5);
+      default :
+         return jjMoveNfa_1(6, 0);
+   }
+}
+private final int jjMoveNfa_1(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 8;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 6:
+                  if ((0xffffffff00002600L & l) != 0L && kind > 121)
+                     kind = 121;
+                  break;
+               case 0:
+                  if (curChar == 45)
+                     jjCheckNAddTwoStates(1, 4);
+                  break;
+               case 1:
+                  jjCheckNAddTwoStates(1, 4);
+                  break;
+               case 3:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 2;
+                  break;
+               case 4:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 3;
+                  break;
+               case 5:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 0;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 6:
+                  if (kind > 121)
+                     kind = 121;
+                  if (curChar == 123)
+                     jjstateSet[jjnewStateCnt++] = 5;
+                  break;
+               case 1:
+                  if ((0xdfffffffffffffffL & l) != 0L)
+                     jjAddStates(65, 66);
+                  break;
+               case 2:
+                  if (curChar == 125 && kind > 1)
+                     kind = 1;
+                  break;
+               case 7:
+                  if (kind > 121)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 6:
+                  if ((jjbitVec2[i2] & l2) != 0L && kind > 121)
+                     kind = 121;
+                  break;
+               case 1:
+                  if ((jjbitVec2[i2] & l2) != 0L)
+                     jjAddStates(65, 66);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 8 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjStopStringLiteralDfa_2(int pos, long active0, long active1)
+{
+   switch (pos)
+   {
+      case 0:
+         if ((active0 & 0x800000L) != 0L)
+            return 19;
+         if ((active0 & 0x5000000041200000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            return 9;
+         }
+         if ((active0 & 0x100000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            return 48;
+         }
+         if ((active0 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            return 26;
+         }
+         if ((active0 & 0x400000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            return 38;
+         }
+         if ((active1 & 0x300000000000L) != 0L)
+            return 81;
+         if ((active0 & 0x40000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            return 11;
+         }
+         if ((active0 & 0x8002ac480000L) != 0L || (active1 & 0x20001f0L) != 0L)
+         {
+            jjmatchedKind = 115;
+            return 82;
+         }
+         if ((active0 & 0x110000000L) != 0L || (active1 & 0x8L) != 0L)
+         {
+            jjmatchedKind = 115;
+            return 33;
+         }
+         return -1;
+      case 1:
+         if ((active0 & 0x41000000L) != 0L)
+            return 8;
+         if ((active0 & 0x400000000L) != 0L)
+         {
+            if (jjmatchedPos != 1)
+            {
+               jjmatchedKind = 115;
+               jjmatchedPos = 1;
+            }
+            return 35;
+         }
+         if ((active0 & 0x5000000020040000L) != 0L || (active1 & 0x1f8L) != 0L)
+            return 82;
+         if ((active0 & 0x80039e780000L) != 0L || (active1 & 0x2000000L) != 0L)
+         {
+            if (jjmatchedPos != 1)
+            {
+               jjmatchedKind = 115;
+               jjmatchedPos = 1;
+            }
+            return 82;
+         }
+         return -1;
+      case 2:
+         if ((active0 & 0x40008007de200000L) != 0L || (active1 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 2;
+            return 82;
+         }
+         if ((active0 & 0x580000L) != 0L)
+            return 82;
+         return -1;
+      case 3:
+         if ((active0 & 0x800018200000L) != 0L)
+            return 82;
+         if ((active0 & 0x40000007c6000000L) != 0L || (active1 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 3;
+            return 82;
+         }
+         return -1;
+      case 4:
+         if ((active0 & 0x4000000080000000L) != 0L)
+            return 82;
+         if ((active0 & 0x746000000L) != 0L || (active1 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 4;
+            return 82;
+         }
+         return -1;
+      case 5:
+         if ((active0 & 0x104000000L) != 0L)
+            return 82;
+         if ((active0 & 0x642000000L) != 0L || (active1 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 5;
+            return 82;
+         }
+         return -1;
+      case 6:
+         if ((active0 & 0x400000000L) != 0L)
+            return 82;
+         if ((active0 & 0x242000000L) != 0L || (active1 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 6;
+            return 82;
+         }
+         return -1;
+      case 7:
+         if ((active0 & 0x200000000L) != 0L || (active1 & 0x2000000L) != 0L)
+            return 82;
+         if ((active0 & 0x42000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 7;
+            return 82;
+         }
+         return -1;
+      default :
+         return -1;
+   }
+}
+private final int jjStartNfa_2(int pos, long active0, long active1)
+{
+   return jjMoveNfa_2(jjStopStringLiteralDfa_2(pos, active0, active1), pos + 1);
+}
+private final int jjStartNfaWithStates_2(int pos, int kind, int state)
+{
+   jjmatchedKind = kind;
+   jjmatchedPos = pos;
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) { return pos + 1; }
+   return jjMoveNfa_2(state, pos + 1);
+}
+private final int jjMoveStringLiteralDfa0_2()
+{
+   switch(curChar)
+   {
+      case 33:
+         return jjMoveStringLiteralDfa1_2(0x2000000000000000L, 0x0L);
+      case 36:
+         return jjStopAtPos(0, 113);
+      case 40:
+         return jjStopAtPos(0, 79);
+      case 41:
+         return jjStopAtPos(0, 83);
+      case 42:
+         return jjStartNfaWithStates_2(0, 23, 19);
+      case 43:
+         return jjStopAtPos(0, 76);
+      case 44:
+         return jjStopAtPos(0, 105);
+      case 45:
+         return jjStopAtPos(0, 75);
+      case 46:
+         jjmatchedKind = 108;
+         return jjMoveStringLiteralDfa1_2(0x0L, 0x200000000000L);
+      case 47:
+         jjmatchedKind = 57;
+         return jjMoveStringLiteralDfa1_2(0x400000000000000L, 0x0L);
+      case 60:
+         jjmatchedKind = 73;
+         return jjMoveStringLiteralDfa1_2(0x8000000000000000L, 0x1L);
+      case 61:
+         return jjStopAtPos(0, 59);
+      case 62:
+         jjmatchedKind = 74;
+         return jjMoveStringLiteralDfa1_2(0x0L, 0x6L);
+      case 63:
+         return jjStopAtPos(0, 77);
+      case 91:
+         return jjStopAtPos(0, 81);
+      case 93:
+         return jjStopAtPos(0, 82);
+      case 97:
+         return jjMoveStringLiteralDfa1_2(0x80000L, 0x0L);
+      case 100:
+         return jjMoveStringLiteralDfa1_2(0x100000L, 0x0L);
+      case 101:
+         return jjMoveStringLiteralDfa1_2(0x110000000L, 0x8L);
+      case 102:
+         return jjMoveStringLiteralDfa1_2(0x400000000L, 0x0L);
+      case 103:
+         return jjMoveStringLiteralDfa1_2(0x0L, 0x60L);
+      case 105:
+         return jjMoveStringLiteralDfa1_2(0x5000000041200000L, 0x0L);
+      case 108:
+         return jjMoveStringLiteralDfa1_2(0x0L, 0x180L);
+      case 109:
+         return jjMoveStringLiteralDfa1_2(0x400000L, 0x0L);
+      case 110:
+         return jjMoveStringLiteralDfa1_2(0x0L, 0x10L);
+      case 111:
+         return jjMoveStringLiteralDfa1_2(0x40000L, 0x0L);
+      case 112:
+         return jjMoveStringLiteralDfa1_2(0x200000000L, 0x0L);
+      case 114:
+         return jjMoveStringLiteralDfa1_2(0x4000000L, 0x0L);
+      case 115:
+         return jjMoveStringLiteralDfa1_2(0x2000000L, 0x0L);
+      case 116:
+         return jjMoveStringLiteralDfa1_2(0x800028000000L, 0x0L);
+      case 117:
+         return jjMoveStringLiteralDfa1_2(0x80000000L, 0x0L);
+      case 118:
+         return jjMoveStringLiteralDfa1_2(0x0L, 0x2000000L);
+      case 124:
+         return jjStopAtPos(0, 78);
+      case 125:
+         return jjStopAtPos(0, 120);
+      default :
+         return jjMoveNfa_2(10, 0);
+   }
+}
+private final int jjMoveStringLiteralDfa1_2(long active0, long active1)
+{
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_2(0, active0, active1);
+      return 1;
+   }
+   switch(curChar)
+   {
+      case 46:
+         if ((active1 & 0x200000000000L) != 0L)
+            return jjStopAtPos(1, 109);
+         break;
+      case 47:
+         if ((active0 & 0x400000000000000L) != 0L)
+            return jjStopAtPos(1, 58);
+         break;
+      case 60:
+         if ((active1 & 0x1L) != 0L)
+            return jjStopAtPos(1, 64);
+         break;
+      case 61:
+         if ((active0 & 0x2000000000000000L) != 0L)
+            return jjStopAtPos(1, 61);
+         else if ((active0 & 0x8000000000000000L) != 0L)
+            return jjStopAtPos(1, 63);
+         else if ((active1 & 0x2L) != 0L)
+            return jjStopAtPos(1, 65);
+         break;
+      case 62:
+         if ((active1 & 0x4L) != 0L)
+            return jjStopAtPos(1, 66);
+         break;
+      case 97:
+         return jjMoveStringLiteralDfa2_2(active0, 0x2000000L, active1, 0x2000000L);
+      case 100:
+         return jjMoveStringLiteralDfa2_2(active0, 0x200000L, active1, 0L);
+      case 101:
+         if ((active1 & 0x10L) != 0L)
+            return jjStartNfaWithStates_2(1, 68, 82);
+         else if ((active1 & 0x40L) != 0L)
+            return jjStartNfaWithStates_2(1, 70, 82);
+         else if ((active1 & 0x100L) != 0L)
+            return jjStartNfaWithStates_2(1, 72, 82);
+         return jjMoveStringLiteralDfa2_2(active0, 0x4000000L, active1, 0L);
+      case 104:
+         return jjMoveStringLiteralDfa2_2(active0, 0x8000000L, active1, 0L);
+      case 105:
+         return jjMoveStringLiteralDfa2_2(active0, 0x100000L, active1, 0L);
+      case 108:
+         return jjMoveStringLiteralDfa2_2(active0, 0x10000000L, active1, 0L);
+      case 110:
+         if ((active0 & 0x1000000L) != 0L)
+         {
+            jjmatchedKind = 24;
+            jjmatchedPos = 1;
+         }
+         return jjMoveStringLiteralDfa2_2(active0, 0xc0080000L, active1, 0L);
+      case 111:
+         if ((active0 & 0x20000000L) != 0L)
+            return jjStartNfaWithStates_2(1, 29, 82);
+         return jjMoveStringLiteralDfa2_2(active0, 0x400400000L, active1, 0L);
+      case 113:
+         if ((active1 & 0x8L) != 0L)
+            return jjStartNfaWithStates_2(1, 67, 82);
+         break;
+      case 114:
+         if ((active0 & 0x40000L) != 0L)
+            return jjStartNfaWithStates_2(1, 18, 82);
+         return jjMoveStringLiteralDfa2_2(active0, 0x200000000L, active1, 0L);
+      case 115:
+         if ((active0 & 0x1000000000000000L) != 0L)
+         {
+            jjmatchedKind = 60;
+            jjmatchedPos = 1;
+         }
+         return jjMoveStringLiteralDfa2_2(active0, 0x4000000000000000L, active1, 0L);
+      case 116:
+         if ((active1 & 0x20L) != 0L)
+            return jjStartNfaWithStates_2(1, 69, 82);
+         else if ((active1 & 0x80L) != 0L)
+            return jjStartNfaWithStates_2(1, 71, 82);
+         break;
+      case 120:
+         return jjMoveStringLiteralDfa2_2(active0, 0x100000000L, active1, 0L);
+      case 121:
+         return jjMoveStringLiteralDfa2_2(active0, 0x800000000000L, active1, 0L);
+      default :
+         break;
+   }
+   return jjStartNfa_2(0, active0, active1);
+}
+private final int jjMoveStringLiteralDfa2_2(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_2(0, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_2(1, active0, active1);
+      return 2;
+   }
+   switch(curChar)
+   {
+      case 99:
+         return jjMoveStringLiteralDfa3_2(active0, 0x100000000L, active1, 0L);
+      case 100:
+         if ((active0 & 0x80000L) != 0L)
+            return jjStartNfaWithStates_2(2, 19, 82);
+         else if ((active0 & 0x400000L) != 0L)
+            return jjStartNfaWithStates_2(2, 22, 82);
+         break;
+      case 101:
+         return jjMoveStringLiteralDfa3_2(active0, 0x208000000L, active1, 0L);
+      case 105:
+         return jjMoveStringLiteralDfa3_2(active0, 0x80200000L, active1, 0L);
+      case 108:
+         return jjMoveStringLiteralDfa3_2(active0, 0x400000000L, active1, 0x2000000L);
+      case 110:
+         return jjMoveStringLiteralDfa3_2(active0, 0x4000000000000000L, active1, 0L);
+      case 112:
+         return jjMoveStringLiteralDfa3_2(active0, 0x800000000000L, active1, 0L);
+      case 115:
+         return jjMoveStringLiteralDfa3_2(active0, 0x10000000L, active1, 0L);
+      case 116:
+         return jjMoveStringLiteralDfa3_2(active0, 0x46000000L, active1, 0L);
+      case 118:
+         if ((active0 & 0x100000L) != 0L)
+            return jjStartNfaWithStates_2(2, 20, 82);
+         break;
+      default :
+         break;
+   }
+   return jjStartNfa_2(1, active0, active1);
+}
+private final int jjMoveStringLiteralDfa3_2(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_2(1, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_2(2, active0, active1);
+      return 3;
+   }
+   switch(curChar)
+   {
+      case 99:
+         return jjMoveStringLiteralDfa4_2(active0, 0x200000000L, active1, 0L);
+      case 101:
+         if ((active0 & 0x10000000L) != 0L)
+            return jjStartNfaWithStates_2(3, 28, 82);
+         else if ((active0 & 0x800000000000L) != 0L)
+            return jjStartNfaWithStates_2(3, 47, 82);
+         return jjMoveStringLiteralDfa4_2(active0, 0x140000000L, active1, 0L);
+      case 105:
+         return jjMoveStringLiteralDfa4_2(active0, 0x2000000L, active1, 0x2000000L);
+      case 108:
+         return jjMoveStringLiteralDfa4_2(active0, 0x400000000L, active1, 0L);
+      case 110:
+         if ((active0 & 0x8000000L) != 0L)
+            return jjStartNfaWithStates_2(3, 27, 82);
+         break;
+      case 111:
+         return jjMoveStringLiteralDfa4_2(active0, 0x4000000080000000L, active1, 0L);
+      case 117:
+         return jjMoveStringLiteralDfa4_2(active0, 0x4000000L, active1, 0L);
+      case 118:
+         if ((active0 & 0x200000L) != 0L)
+            return jjStartNfaWithStates_2(3, 21, 82);
+         break;
+      default :
+         break;
+   }
+   return jjStartNfa_2(2, active0, active1);
+}
+private final int jjMoveStringLiteralDfa4_2(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_2(2, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_2(3, active0, active1);
+      return 4;
+   }
+   switch(curChar)
+   {
+      case 100:
+         return jjMoveStringLiteralDfa5_2(active0, 0L, active1, 0x2000000L);
+      case 101:
+         return jjMoveStringLiteralDfa5_2(active0, 0x200000000L, active1, 0L);
+      case 110:
+         if ((active0 & 0x80000000L) != 0L)
+            return jjStartNfaWithStates_2(4, 31, 82);
+         break;
+      case 111:
+         return jjMoveStringLiteralDfa5_2(active0, 0x400000000L, active1, 0L);
+      case 112:
+         return jjMoveStringLiteralDfa5_2(active0, 0x100000000L, active1, 0L);
+      case 114:
+         return jjMoveStringLiteralDfa5_2(active0, 0x44000000L, active1, 0L);
+      case 115:
+         return jjMoveStringLiteralDfa5_2(active0, 0x2000000L, active1, 0L);
+      case 116:
+         if ((active0 & 0x4000000000000000L) != 0L)
+            return jjStartNfaWithStates_2(4, 62, 82);
+         break;
+      default :
+         break;
+   }
+   return jjStartNfa_2(3, active0, active1);
+}
+private final int jjMoveStringLiteralDfa5_2(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_2(3, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_2(4, active0, active1);
+      return 5;
+   }
+   switch(curChar)
+   {
+      case 97:
+         return jjMoveStringLiteralDfa6_2(active0, 0L, active1, 0x2000000L);
+      case 100:
+         return jjMoveStringLiteralDfa6_2(active0, 0x200000000L, active1, 0L);
+      case 102:
+         return jjMoveStringLiteralDfa6_2(active0, 0x2000000L, active1, 0L);
+      case 110:
+         if ((active0 & 0x4000000L) != 0L)
+            return jjStartNfaWithStates_2(5, 26, 82);
+         break;
+      case 115:
+         return jjMoveStringLiteralDfa6_2(active0, 0x40000000L, active1, 0L);
+      case 116:
+         if ((active0 & 0x100000000L) != 0L)
+            return jjStartNfaWithStates_2(5, 32, 82);
+         break;
+      case 119:
+         return jjMoveStringLiteralDfa6_2(active0, 0x400000000L, active1, 0L);
+      default :
+         break;
+   }
+   return jjStartNfa_2(4, active0, active1);
+}
+private final int jjMoveStringLiteralDfa6_2(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_2(4, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_2(5, active0, active1);
+      return 6;
+   }
+   switch(curChar)
+   {
+      case 101:
+         return jjMoveStringLiteralDfa7_2(active0, 0x240000000L, active1, 0L);
+      case 105:
+         return jjMoveStringLiteralDfa7_2(active0, 0x2000000L, active1, 0L);
+      case 115:
+         if ((active0 & 0x400000000L) != 0L)
+            return jjStartNfaWithStates_2(6, 34, 82);
+         break;
+      case 116:
+         return jjMoveStringLiteralDfa7_2(active0, 0L, active1, 0x2000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_2(5, active0, active1);
+}
+private final int jjMoveStringLiteralDfa7_2(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_2(5, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_2(6, active0, active1);
+      return 7;
+   }
+   switch(curChar)
+   {
+      case 99:
+         return jjMoveStringLiteralDfa8_2(active0, 0x40000000L, active1, 0L);
+      case 101:
+         if ((active1 & 0x2000000L) != 0L)
+            return jjStartNfaWithStates_2(7, 89, 82);
+         return jjMoveStringLiteralDfa8_2(active0, 0x2000000L, active1, 0L);
+      case 115:
+         if ((active0 & 0x200000000L) != 0L)
+            return jjStartNfaWithStates_2(7, 33, 82);
+         break;
+      default :
+         break;
+   }
+   return jjStartNfa_2(6, active0, active1);
+}
+private final int jjMoveStringLiteralDfa8_2(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_2(6, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_2(7, active0, 0L);
+      return 8;
+   }
+   switch(curChar)
+   {
+      case 115:
+         if ((active0 & 0x2000000L) != 0L)
+            return jjStartNfaWithStates_2(8, 25, 82);
+         break;
+      case 116:
+         if ((active0 & 0x40000000L) != 0L)
+            return jjStartNfaWithStates_2(8, 30, 82);
+         break;
+      default :
+         break;
+   }
+   return jjStartNfa_2(7, active0, 0L);
+}
+private final int jjMoveNfa_2(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 81;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 38:
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 65;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 62;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 9:
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 65;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 62;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 11:
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 65;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 62;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 33:
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 65;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 62;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 10:
+                  if ((0x3ff000000000000L & l) != 0L)
+                  {
+                     if (kind > 91)
+                        kind = 91;
+                     jjCheckNAddStates(67, 72);
+                  }
+                  else if ((0x100002600L & l) != 0L)
+                  {
+                     if (kind > 2)
+                        kind = 2;
+                     jjCheckNAddTwoStates(57, 58);
+                  }
+                  else if (curChar == 46)
+                     jjCheckNAddTwoStates(79, 80);
+                  else if (curChar == 39)
+                     jjCheckNAddTwoStates(54, 55);
+                  else if (curChar == 34)
+                     jjCheckNAddTwoStates(51, 52);
+                  else if (curChar == 42)
+                     jjstateSet[jjnewStateCnt++] = 19;
+                  break;
+               case 35:
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 65;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 62;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 81:
+                  if ((0x3ff000000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(80, 75);
+                  if ((0x3ff000000000000L & l) != 0L)
+                  {
+                     if (kind > 92)
+                        kind = 92;
+                     jjCheckNAdd(79);
+                  }
+                  break;
+               case 82:
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 65;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 62;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 8:
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 65;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 62;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 48:
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 65;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 62;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 26:
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 65;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 62;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 1:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(0, 1);
+                  break;
+               case 12:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(73, 74);
+                  break;
+               case 18:
+                  if (curChar == 42)
+                     jjstateSet[jjnewStateCnt++] = 19;
+                  break;
+               case 19:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 20;
+                  break;
+               case 21:
+                  if ((0x3ff600000000000L & l) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjstateSet[jjnewStateCnt++] = 21;
+                  break;
+               case 23:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(75, 76);
+                  break;
+               case 24:
+                  if (curChar == 36 && kind > 84)
+                     kind = 84;
+                  break;
+               case 29:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(6, 7);
+                  break;
+               case 30:
+                  if (curChar == 36 && kind > 85)
+                     kind = 85;
+                  break;
+               case 36:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(77, 78);
+                  break;
+               case 37:
+                  if (curChar == 36 && kind > 86)
+                     kind = 86;
+                  break;
+               case 41:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(79, 80);
+                  break;
+               case 50:
+                  if (curChar == 34)
+                     jjCheckNAddTwoStates(51, 52);
+                  break;
+               case 51:
+                  if ((0xfffffffbffffffffL & l) != 0L)
+                     jjCheckNAddTwoStates(51, 52);
+                  break;
+               case 52:
+                  if (curChar != 34)
+                     break;
+                  if (kind > 106)
+                     kind = 106;
+                  jjstateSet[jjnewStateCnt++] = 50;
+                  break;
+               case 53:
+                  if (curChar == 39)
+                     jjCheckNAddTwoStates(54, 55);
+                  break;
+               case 54:
+                  if ((0xffffff7fffffffffL & l) != 0L)
+                     jjCheckNAddTwoStates(54, 55);
+                  break;
+               case 55:
+                  if (curChar != 39)
+                     break;
+                  if (kind > 106)
+                     kind = 106;
+                  jjstateSet[jjnewStateCnt++] = 53;
+                  break;
+               case 56:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 2)
+                     kind = 2;
+                  jjCheckNAddTwoStates(57, 58);
+                  break;
+               case 57:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 2)
+                     kind = 2;
+                  jjCheckNAdd(57);
+                  break;
+               case 58:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 4)
+                     kind = 4;
+                  jjCheckNAdd(58);
+                  break;
+               case 60:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 61:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 62;
+                  break;
+               case 62:
+                  if (curChar == 42 && kind > 53)
+                     kind = 53;
+                  break;
+               case 63:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  break;
+               case 64:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 65;
+                  break;
+               case 66:
+                  if ((0x3ff600000000000L & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(66);
+                  break;
+               case 67:
+                  if ((0x3ff000000000000L & l) == 0L)
+                     break;
+                  if (kind > 91)
+                     kind = 91;
+                  jjCheckNAddStates(67, 72);
+                  break;
+               case 68:
+                  if ((0x3ff000000000000L & l) == 0L)
+                     break;
+                  if (kind > 91)
+                     kind = 91;
+                  jjCheckNAdd(68);
+                  break;
+               case 69:
+                  if ((0x3ff000000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(69, 70);
+                  break;
+               case 70:
+                  if (curChar != 46)
+                     break;
+                  if (kind > 92)
+                     kind = 92;
+                  jjCheckNAdd(71);
+                  break;
+               case 71:
+                  if ((0x3ff000000000000L & l) == 0L)
+                     break;
+                  if (kind > 92)
+                     kind = 92;
+                  jjCheckNAdd(71);
+                  break;
+               case 72:
+                  if ((0x3ff000000000000L & l) != 0L)
+                     jjCheckNAddStates(81, 83);
+                  break;
+               case 73:
+                  if (curChar == 46)
+                     jjCheckNAddTwoStates(74, 75);
+                  break;
+               case 74:
+                  if ((0x3ff000000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(74, 75);
+                  break;
+               case 76:
+                  if ((0x280000000000L & l) != 0L)
+                     jjCheckNAdd(77);
+                  break;
+               case 77:
+                  if ((0x3ff000000000000L & l) == 0L)
+                     break;
+                  if (kind > 93)
+                     kind = 93;
+                  jjCheckNAdd(77);
+                  break;
+               case 78:
+                  if (curChar == 46)
+                     jjCheckNAddTwoStates(79, 80);
+                  break;
+               case 79:
+                  if ((0x3ff000000000000L & l) == 0L)
+                     break;
+                  if (kind > 92)
+                     kind = 92;
+                  jjCheckNAdd(79);
+                  break;
+               case 80:
+                  if ((0x3ff000000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(80, 75);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 38:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 35;
+                  break;
+               case 9:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 8;
+                  break;
+               case 11:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if (curChar == 102)
+                     jjstateSet[jjnewStateCnt++] = 12;
+                  break;
+               case 33:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if (curChar == 118)
+                     jjstateSet[jjnewStateCnt++] = 32;
+                  break;
+               case 10:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAddStates(84, 88);
+                  }
+                  if (curChar == 100)
+                     jjstateSet[jjnewStateCnt++] = 48;
+                  else if (curChar == 102)
+                     jjstateSet[jjnewStateCnt++] = 38;
+                  else if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 33;
+                  else if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 26;
+                  else if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 11;
+                  else if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 9;
+                  break;
+               case 35:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if (curChar == 114)
+                     jjAddStates(77, 78);
+                  break;
+               case 82:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 8:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 7;
+                  break;
+               case 48:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 47;
+                  break;
+               case 26:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 25;
+                  break;
+               case 0:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 1;
+                  break;
+               case 2:
+                  if (curChar == 102 && kind > 35)
+                     kind = 35;
+                  break;
+               case 3:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 2;
+                  break;
+               case 4:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 0;
+                  break;
+               case 5:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 4;
+                  break;
+               case 6:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 5;
+                  break;
+               case 7:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 6;
+                  break;
+               case 13:
+                  if (curChar == 101 && kind > 45)
+                     kind = 45;
+                  break;
+               case 14:
+                  if (curChar == 112)
+                     jjstateSet[jjnewStateCnt++] = 13;
+                  break;
+               case 15:
+                  if (curChar == 121)
+                     jjstateSet[jjnewStateCnt++] = 14;
+                  break;
+               case 16:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 15;
+                  break;
+               case 17:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 11;
+                  break;
+               case 20:
+               case 21:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjCheckNAdd(21);
+                  break;
+               case 22:
+                  if (curChar == 101)
+                     jjAddStates(75, 76);
+                  break;
+               case 25:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 22;
+                  break;
+               case 27:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 26;
+                  break;
+               case 28:
+                  if (curChar == 121)
+                     jjAddStates(6, 7);
+                  break;
+               case 31:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 28;
+                  break;
+               case 32:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 31;
+                  break;
+               case 34:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 33;
+                  break;
+               case 39:
+                  if (curChar == 102)
+                     jjstateSet[jjnewStateCnt++] = 38;
+                  break;
+               case 40:
+                  if (curChar == 116)
+                     jjAddStates(79, 80);
+                  break;
+               case 42:
+                  if (curChar == 123 && kind > 96)
+                     kind = 96;
+                  break;
+               case 43:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 40;
+                  break;
+               case 44:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 43;
+                  break;
+               case 45:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 44;
+                  break;
+               case 46:
+                  if (curChar == 117)
+                     jjstateSet[jjnewStateCnt++] = 45;
+                  break;
+               case 47:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 46;
+                  break;
+               case 49:
+                  if (curChar == 100)
+                     jjstateSet[jjnewStateCnt++] = 48;
+                  break;
+               case 51:
+                  jjAddStates(89, 90);
+                  break;
+               case 54:
+                  jjAddStates(91, 92);
+                  break;
+               case 59:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAddStates(84, 88);
+                  break;
+               case 60:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 63:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  break;
+               case 65:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(66);
+                  break;
+               case 66:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(66);
+                  break;
+               case 75:
+                  if ((0x2000000020L & l) != 0L)
+                     jjAddStates(93, 94);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 38:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  break;
+               case 9:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  break;
+               case 11:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  break;
+               case 33:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  break;
+               case 10:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAddStates(84, 88);
+                  break;
+               case 35:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  break;
+               case 82:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  break;
+               case 8:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  break;
+               case 48:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  break;
+               case 26:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(66);
+                  }
+                  break;
+               case 20:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjCheckNAdd(21);
+                  break;
+               case 21:
+                  if ((jjbitVec28[i2] & l2) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjCheckNAdd(21);
+                  break;
+               case 51:
+                  if ((jjbitVec2[i2] & l2) != 0L)
+                     jjAddStates(89, 90);
+                  break;
+               case 54:
+                  if ((jjbitVec2[i2] & l2) != 0L)
+                     jjAddStates(91, 92);
+                  break;
+               case 60:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(60, 61);
+                  break;
+               case 63:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(63, 64);
+                  break;
+               case 65:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(66);
+                  break;
+               case 66:
+                  if ((jjbitVec28[i2] & l2) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(66);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 81 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjMoveStringLiteralDfa0_14()
+{
+   return jjMoveNfa_14(0, 0);
+}
+private final int jjMoveNfa_14(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 1;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((0xffffffff00002600L & l) != 0L)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((jjbitVec2[i2] & l2) != 0L && kind > 121)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjMoveStringLiteralDfa0_8()
+{
+   return jjMoveNfa_8(6, 0);
+}
+private final int jjMoveNfa_8(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 9;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 6:
+                  if ((0x100002600L & l) != 0L)
+                  {
+                     if (kind > 2)
+                        kind = 2;
+                     jjCheckNAddTwoStates(7, 8);
+                  }
+                  else if (curChar == 39)
+                     jjCheckNAddTwoStates(4, 5);
+                  else if (curChar == 34)
+                     jjCheckNAddTwoStates(1, 2);
+                  break;
+               case 0:
+                  if (curChar == 34)
+                     jjCheckNAddTwoStates(1, 2);
+                  break;
+               case 1:
+                  if ((0xfffffffbffffffffL & l) != 0L)
+                     jjCheckNAddTwoStates(1, 2);
+                  break;
+               case 2:
+                  if (curChar != 34)
+                     break;
+                  if (kind > 106)
+                     kind = 106;
+                  jjstateSet[jjnewStateCnt++] = 0;
+                  break;
+               case 3:
+                  if (curChar == 39)
+                     jjCheckNAddTwoStates(4, 5);
+                  break;
+               case 4:
+                  if ((0xffffff7fffffffffL & l) != 0L)
+                     jjCheckNAddTwoStates(4, 5);
+                  break;
+               case 5:
+                  if (curChar != 39)
+                     break;
+                  if (kind > 106)
+                     kind = 106;
+                  jjstateSet[jjnewStateCnt++] = 3;
+                  break;
+               case 7:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 2)
+                     kind = 2;
+                  jjCheckNAdd(7);
+                  break;
+               case 8:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 4)
+                     kind = 4;
+                  jjCheckNAdd(8);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 1:
+                  jjAddStates(95, 96);
+                  break;
+               case 4:
+                  jjAddStates(97, 98);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 1:
+                  if ((jjbitVec2[i2] & l2) != 0L)
+                     jjAddStates(95, 96);
+                  break;
+               case 4:
+                  if ((jjbitVec2[i2] & l2) != 0L)
+                     jjAddStates(97, 98);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 9 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjMoveStringLiteralDfa0_11()
+{
+   return jjMoveNfa_11(0, 0);
+}
+private final int jjMoveNfa_11(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 5;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 1:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjAddStates(95, 96);
+                  break;
+               case 2:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 3;
+                  break;
+               case 4:
+                  if ((0x3ff600000000000L & l) == 0L)
+                     break;
+                  if (kind > 114)
+                     kind = 114;
+                  jjstateSet[jjnewStateCnt++] = 4;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 114)
+                     kind = 114;
+                  jjCheckNAddStates(99, 101);
+                  break;
+               case 1:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(1, 2);
+                  break;
+               case 3:
+               case 4:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 114)
+                     kind = 114;
+                  jjCheckNAdd(4);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 114)
+                     kind = 114;
+                  jjCheckNAddStates(99, 101);
+                  break;
+               case 1:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(1, 2);
+                  break;
+               case 3:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 114)
+                     kind = 114;
+                  jjCheckNAdd(4);
+                  break;
+               case 4:
+                  if ((jjbitVec28[i2] & l2) == 0L)
+                     break;
+                  if (kind > 114)
+                     kind = 114;
+                  jjCheckNAdd(4);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 5 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjStopStringLiteralDfa_9(int pos, long active0, long active1)
+{
+   switch (pos)
+   {
+      default :
+         return -1;
+   }
+}
+private final int jjStartNfa_9(int pos, long active0, long active1)
+{
+   return jjMoveNfa_9(jjStopStringLiteralDfa_9(pos, active0, active1), pos + 1);
+}
+private final int jjStartNfaWithStates_9(int pos, int kind, int state)
+{
+   jjmatchedKind = kind;
+   jjmatchedPos = pos;
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) { return pos + 1; }
+   return jjMoveNfa_9(state, pos + 1);
+}
+private final int jjMoveStringLiteralDfa0_9()
+{
+   switch(curChar)
+   {
+      case 123:
+         return jjStopAtPos(0, 119);
+      default :
+         return jjMoveNfa_9(0, 0);
+   }
+}
+private final int jjMoveNfa_9(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 1;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  kind = 4;
+                  jjstateSet[jjnewStateCnt++] = 0;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjMoveStringLiteralDfa0_17()
+{
+   return jjMoveNfa_17(0, 0);
+}
+private final int jjMoveNfa_17(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 1;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((0xffffffff00002600L & l) != 0L)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((jjbitVec2[i2] & l2) != 0L && kind > 121)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjMoveStringLiteralDfa0_4()
+{
+   return jjMoveNfa_4(6, 0);
+}
+private final int jjMoveNfa_4(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 9;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 6:
+                  if ((0x100002600L & l) != 0L)
+                  {
+                     if (kind > 2)
+                        kind = 2;
+                     jjCheckNAddTwoStates(7, 8);
+                  }
+                  else if (curChar == 39)
+                     jjCheckNAddTwoStates(4, 5);
+                  else if (curChar == 34)
+                     jjCheckNAddTwoStates(1, 2);
+                  break;
+               case 0:
+                  if (curChar == 34)
+                     jjCheckNAddTwoStates(1, 2);
+                  break;
+               case 1:
+                  if ((0xfffffffbffffffffL & l) != 0L)
+                     jjCheckNAddTwoStates(1, 2);
+                  break;
+               case 2:
+                  if (curChar != 34)
+                     break;
+                  if (kind > 107)
+                     kind = 107;
+                  jjstateSet[jjnewStateCnt++] = 0;
+                  break;
+               case 3:
+                  if (curChar == 39)
+                     jjCheckNAddTwoStates(4, 5);
+                  break;
+               case 4:
+                  if ((0xffffff7fffffffffL & l) != 0L)
+                     jjCheckNAddTwoStates(4, 5);
+                  break;
+               case 5:
+                  if (curChar != 39)
+                     break;
+                  if (kind > 107)
+                     kind = 107;
+                  jjstateSet[jjnewStateCnt++] = 3;
+                  break;
+               case 7:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 2)
+                     kind = 2;
+                  jjCheckNAdd(7);
+                  break;
+               case 8:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 4)
+                     kind = 4;
+                  jjCheckNAdd(8);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 1:
+                  jjAddStates(95, 96);
+                  break;
+               case 4:
+                  jjAddStates(97, 98);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 1:
+                  if ((jjbitVec2[i2] & l2) != 0L)
+                     jjAddStates(95, 96);
+                  break;
+               case 4:
+                  if ((jjbitVec2[i2] & l2) != 0L)
+                     jjAddStates(97, 98);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 9 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjMoveStringLiteralDfa0_5()
+{
+   return jjMoveNfa_5(0, 0);
+}
+private final int jjMoveNfa_5(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 1;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  kind = 2;
+                  jjstateSet[jjnewStateCnt++] = 0;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1)
+{
+   switch (pos)
+   {
+      case 0:
+         if ((active1 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            return 386;
+         }
+         if ((active0 & 0x10000000000000L) != 0L)
+            return 15;
+         if ((active0 & 0x2000000000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            return 330;
+         }
+         if ((active1 & 0x300000000000L) != 0L)
+            return 387;
+         return -1;
+      case 1:
+         if ((active0 & 0x2000000000000L) != 0L || (active1 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 1;
+            return 386;
+         }
+         return -1;
+      case 2:
+         if ((active0 & 0x2000000000000L) != 0L || (active1 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 2;
+            return 386;
+         }
+         return -1;
+      case 3:
+         if ((active0 & 0x2000000000000L) != 0L || (active1 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 3;
+            return 386;
+         }
+         return -1;
+      case 4:
+         if ((active0 & 0x2000000000000L) != 0L)
+            return 386;
+         if ((active1 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 4;
+            return 386;
+         }
+         return -1;
+      case 5:
+         if ((active1 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 5;
+            return 386;
+         }
+         return -1;
+      case 6:
+         if ((active1 & 0x2000000L) != 0L)
+         {
+            jjmatchedKind = 115;
+            jjmatchedPos = 6;
+            return 386;
+         }
+         return -1;
+      default :
+         return -1;
+   }
+}
+private final int jjStartNfa_0(int pos, long active0, long active1)
+{
+   return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0, active1), pos + 1);
+}
+private final int jjStartNfaWithStates_0(int pos, int kind, int state)
+{
+   jjmatchedKind = kind;
+   jjmatchedPos = pos;
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) { return pos + 1; }
+   return jjMoveNfa_0(state, pos + 1);
+}
+private final int jjMoveStringLiteralDfa0_0()
+{
+   switch(curChar)
+   {
+      case 36:
+         return jjStopAtPos(0, 113);
+      case 40:
+         return jjStopAtPos(0, 79);
+      case 41:
+         return jjStopAtPos(0, 83);
+      case 42:
+         return jjStartNfaWithStates_0(0, 52, 15);
+      case 43:
+         return jjStopAtPos(0, 76);
+      case 44:
+         return jjStopAtPos(0, 105);
+      case 45:
+         return jjStopAtPos(0, 75);
+      case 46:
+         jjmatchedKind = 108;
+         return jjMoveStringLiteralDfa1_0(0x0L, 0x200000000000L);
+      case 47:
+         jjmatchedKind = 55;
+         return jjMoveStringLiteralDfa1_0(0x100000000000000L, 0x0L);
+      case 64:
+         return jjStopAtPos(0, 80);
+      case 91:
+         return jjStopAtPos(0, 81);
+      case 93:
+         return jjStopAtPos(0, 82);
+      case 101:
+         return jjMoveStringLiteralDfa1_0(0x2000000000000L, 0x0L);
+      case 118:
+         return jjMoveStringLiteralDfa1_0(0x0L, 0x2000000L);
+      case 125:
+         return jjStopAtPos(0, 120);
+      default :
+         return jjMoveNfa_0(6, 0);
+   }
+}
+private final int jjMoveStringLiteralDfa1_0(long active0, long active1)
+{
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_0(0, active0, active1);
+      return 1;
+   }
+   switch(curChar)
+   {
+      case 46:
+         if ((active1 & 0x200000000000L) != 0L)
+            return jjStopAtPos(1, 109);
+         break;
+      case 47:
+         if ((active0 & 0x100000000000000L) != 0L)
+            return jjStopAtPos(1, 56);
+         break;
+      case 97:
+         return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0x2000000L);
+      case 109:
+         return jjMoveStringLiteralDfa2_0(active0, 0x2000000000000L, active1, 0L);
+      default :
+         break;
+   }
+   return jjStartNfa_0(0, active0, active1);
+}
+private final int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_0(0, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_0(1, active0, active1);
+      return 2;
+   }
+   switch(curChar)
+   {
+      case 108:
+         return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0x2000000L);
+      case 112:
+         return jjMoveStringLiteralDfa3_0(active0, 0x2000000000000L, active1, 0L);
+      default :
+         break;
+   }
+   return jjStartNfa_0(1, active0, active1);
+}
+private final int jjMoveStringLiteralDfa3_0(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_0(1, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_0(2, active0, active1);
+      return 3;
+   }
+   switch(curChar)
+   {
+      case 105:
+         return jjMoveStringLiteralDfa4_0(active0, 0L, active1, 0x2000000L);
+      case 116:
+         return jjMoveStringLiteralDfa4_0(active0, 0x2000000000000L, active1, 0L);
+      default :
+         break;
+   }
+   return jjStartNfa_0(2, active0, active1);
+}
+private final int jjMoveStringLiteralDfa4_0(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_0(2, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_0(3, active0, active1);
+      return 4;
+   }
+   switch(curChar)
+   {
+      case 100:
+         return jjMoveStringLiteralDfa5_0(active0, 0L, active1, 0x2000000L);
+      case 121:
+         if ((active0 & 0x2000000000000L) != 0L)
+            return jjStartNfaWithStates_0(4, 49, 386);
+         break;
+      default :
+         break;
+   }
+   return jjStartNfa_0(3, active0, active1);
+}
+private final int jjMoveStringLiteralDfa5_0(long old0, long active0, long old1, long active1)
+{
+   if (((active0 &= old0) | (active1 &= old1)) == 0L)
+      return jjStartNfa_0(3, old0, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_0(4, 0L, active1);
+      return 5;
+   }
+   switch(curChar)
+   {
+      case 97:
+         return jjMoveStringLiteralDfa6_0(active1, 0x2000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_0(4, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa6_0(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_0(4, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_0(5, 0L, active1);
+      return 6;
+   }
+   switch(curChar)
+   {
+      case 116:
+         return jjMoveStringLiteralDfa7_0(active1, 0x2000000L);
+      default :
+         break;
+   }
+   return jjStartNfa_0(5, 0L, active1);
+}
+private final int jjMoveStringLiteralDfa7_0(long old1, long active1)
+{
+   if (((active1 &= old1)) == 0L)
+      return jjStartNfa_0(5, 0L, old1); 
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) {
+      jjStopStringLiteralDfa_0(6, 0L, active1);
+      return 7;
+   }
+   switch(curChar)
+   {
+      case 101:
+         if ((active1 & 0x2000000L) != 0L)
+            return jjStartNfaWithStates_0(7, 89, 386);
+         break;
+      default :
+         break;
+   }
+   return jjStartNfa_0(6, 0L, active1);
+}
+private final int jjMoveNfa_0(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 386;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 330:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddStates(102, 104);
+                  else if ((0x100002600L & l) != 0L)
+                     jjCheckNAddTwoStates(357, 358);
+                  else if (curChar == 40)
+                  {
+                     if (kind > 118)
+                        kind = 118;
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 355;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(353, 354);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 351;
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(352);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 348;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(349, 350);
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(346, 347);
+                  break;
+               case 6:
+                  if ((0x3ff000000000000L & l) != 0L)
+                  {
+                     if (kind > 91)
+                        kind = 91;
+                     jjCheckNAddStates(105, 110);
+                  }
+                  else if ((0x100002600L & l) != 0L)
+                  {
+                     if (kind > 2)
+                        kind = 2;
+                     jjCheckNAddTwoStates(29, 30);
+                  }
+                  else if (curChar == 46)
+                     jjCheckNAddTwoStates(384, 385);
+                  else if (curChar == 39)
+                     jjCheckNAddTwoStates(26, 27);
+                  else if (curChar == 34)
+                     jjCheckNAddTwoStates(23, 24);
+                  else if (curChar == 42)
+                     jjstateSet[jjnewStateCnt++] = 15;
+                  break;
+               case 387:
+                  if ((0x3ff000000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(385, 380);
+                  if ((0x3ff000000000000L & l) != 0L)
+                  {
+                     if (kind > 92)
+                        kind = 92;
+                     jjCheckNAdd(384);
+                  }
+                  break;
+               case 386:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddStates(102, 104);
+                  else if ((0x100002600L & l) != 0L)
+                     jjCheckNAddTwoStates(357, 358);
+                  else if (curChar == 40)
+                  {
+                     if (kind > 118)
+                        kind = 118;
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 355;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(353, 354);
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 351;
+                  if ((0x3ff600000000000L & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(352);
+                  }
+                  else if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 348;
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(349, 350);
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(346, 347);
+                  break;
+               case 0:
+                  if (curChar == 45)
+                     jjCheckNAddTwoStates(1, 4);
+                  break;
+               case 1:
+                  jjCheckNAddTwoStates(1, 4);
+                  break;
+               case 3:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 2;
+                  break;
+               case 4:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 3;
+                  break;
+               case 5:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 0;
+                  break;
+               case 8:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(111, 112);
+                  break;
+               case 14:
+                  if (curChar == 42)
+                     jjstateSet[jjnewStateCnt++] = 15;
+                  break;
+               case 15:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 16;
+                  break;
+               case 17:
+                  if ((0x3ff600000000000L & l) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjstateSet[jjnewStateCnt++] = 17;
+                  break;
+               case 19:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(113, 114);
+                  break;
+               case 20:
+                  if (curChar == 40 && kind > 104)
+                     kind = 104;
+                  break;
+               case 22:
+                  if (curChar == 34)
+                     jjCheckNAddTwoStates(23, 24);
+                  break;
+               case 23:
+                  if ((0xfffffffbffffffffL & l) != 0L)
+                     jjCheckNAddTwoStates(23, 24);
+                  break;
+               case 24:
+                  if (curChar != 34)
+                     break;
+                  if (kind > 106)
+                     kind = 106;
+                  jjstateSet[jjnewStateCnt++] = 22;
+                  break;
+               case 25:
+                  if (curChar == 39)
+                     jjCheckNAddTwoStates(26, 27);
+                  break;
+               case 26:
+                  if ((0xffffff7fffffffffL & l) != 0L)
+                     jjCheckNAddTwoStates(26, 27);
+                  break;
+               case 27:
+                  if (curChar != 39)
+                     break;
+                  if (kind > 106)
+                     kind = 106;
+                  jjstateSet[jjnewStateCnt++] = 25;
+                  break;
+               case 28:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 2)
+                     kind = 2;
+                  jjCheckNAddTwoStates(29, 30);
+                  break;
+               case 29:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 2)
+                     kind = 2;
+                  jjCheckNAdd(29);
+                  break;
+               case 30:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 4)
+                     kind = 4;
+                  jjCheckNAdd(30);
+                  break;
+               case 33:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(115, 116);
+                  break;
+               case 34:
+                  if (curChar == 58 && kind > 5)
+                     kind = 5;
+                  break;
+               case 35:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 34;
+                  break;
+               case 40:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(117, 118);
+                  break;
+               case 46:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(119, 120);
+                  break;
+               case 47:
+                  if (curChar == 40 && kind > 101)
+                     kind = 101;
+                  break;
+               case 55:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(121, 122);
+                  break;
+               case 56:
+                  if (curChar == 58 && kind > 6)
+                     kind = 6;
+                  break;
+               case 57:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 56;
+                  break;
+               case 67:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(123, 124);
+                  break;
+               case 68:
+                  if (curChar == 58 && kind > 10)
+                     kind = 10;
+                  break;
+               case 69:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 68;
+                  break;
+               case 73:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 72;
+                  break;
+               case 76:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 75;
+                  break;
+               case 87:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(125, 126);
+                  break;
+               case 101:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(127, 128);
+                  break;
+               case 116:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(129, 130);
+                  break;
+               case 126:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(131, 132);
+                  break;
+               case 127:
+                  if (curChar == 58 && kind > 7)
+                     kind = 7;
+                  break;
+               case 128:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 127;
+                  break;
+               case 134:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(133, 134);
+                  break;
+               case 135:
+                  if (curChar == 58 && kind > 13)
+                     kind = 13;
+                  break;
+               case 136:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 135;
+                  break;
+               case 143:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 142;
+                  break;
+               case 153:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(135, 136);
+                  break;
+               case 154:
+                  if (curChar == 58 && kind > 15)
+                     kind = 15;
+                  break;
+               case 155:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 154;
+                  break;
+               case 164:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(137, 138);
+                  break;
+               case 165:
+                  if (curChar == 40 && kind > 103)
+                     kind = 103;
+                  break;
+               case 176:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 175;
+                  break;
+               case 188:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(139, 140);
+                  break;
+               case 189:
+                  if (curChar == 58 && kind > 8)
+                     kind = 8;
+                  break;
+               case 190:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 189;
+                  break;
+               case 199:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(141, 142);
+                  break;
+               case 200:
+                  if (curChar == 58 && kind > 11)
+                     kind = 11;
+                  break;
+               case 201:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 200;
+                  break;
+               case 209:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(143, 144);
+                  break;
+               case 210:
+                  if (curChar == 58 && kind > 17)
+                     kind = 17;
+                  break;
+               case 211:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 210;
+                  break;
+               case 215:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 214;
+                  break;
+               case 218:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 217;
+                  break;
+               case 227:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(145, 146);
+                  break;
+               case 229:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjAddStates(147, 148);
+                  break;
+               case 230:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 231;
+                  break;
+               case 232:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(232, 233);
+                  break;
+               case 233:
+                  if ((0x100002600L & l) != 0L)
+                     jjCheckNAddTwoStates(233, 234);
+                  break;
+               case 243:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(149, 150);
+                  break;
+               case 254:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(151, 152);
+                  break;
+               case 255:
+                  if (curChar == 58 && kind > 9)
+                     kind = 9;
+                  break;
+               case 256:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 255;
+                  break;
+               case 260:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(153, 154);
+                  break;
+               case 261:
+                  if (curChar == 36 && kind > 84)
+                     kind = 84;
+                  break;
+               case 266:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(155, 156);
+                  break;
+               case 267:
+                  if (curChar == 58 && kind > 12)
+                     kind = 12;
+                  break;
+               case 268:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 267;
+                  break;
+               case 275:
+                  if (curChar == 45)
+                     jjstateSet[jjnewStateCnt++] = 274;
+                  break;
+               case 285:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(157, 158);
+                  break;
+               case 286:
+                  if (curChar == 58 && kind > 14)
+                     kind = 14;
+                  break;
+               case 287:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 286;
+                  break;
+               case 296:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(159, 160);
+                  break;
+               case 297:
+                  if (curChar == 36 && kind > 86)
+                     kind = 86;
+                  break;
+               case 301:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(161, 162);
+                  break;
+               case 302:
+                  if (curChar == 58 && kind > 16)
+                     kind = 16;
+                  break;
+               case 303:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 302;
+                  break;
+               case 312:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(163, 164);
+                  break;
+               case 313:
+                  if (curChar == 40 && kind > 100)
+                     kind = 100;
+                  break;
+               case 318:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(165, 166);
+                  break;
+               case 320:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjAddStates(167, 168);
+                  break;
+               case 321:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 322;
+                  break;
+               case 323:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(323, 324);
+                  break;
+               case 324:
+                  if ((0x100002600L & l) != 0L)
+                     jjCheckNAddTwoStates(324, 325);
+                  break;
+               case 332:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(169, 170);
+                  break;
+               case 340:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(171, 172);
+                  break;
+               case 341:
+                  if (curChar == 36 && kind > 85)
+                     kind = 85;
+                  break;
+               case 346:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(346, 347);
+                  break;
+               case 347:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 348;
+                  break;
+               case 348:
+                  if (curChar == 42 && kind > 53)
+                     kind = 53;
+                  break;
+               case 349:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(349, 350);
+                  break;
+               case 350:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 351;
+                  break;
+               case 352:
+                  if ((0x3ff600000000000L & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(352);
+                  break;
+               case 353:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(353, 354);
+                  break;
+               case 354:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 355;
+                  break;
+               case 356:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjCheckNAddStates(102, 104);
+                  break;
+               case 357:
+                  if ((0x100002600L & l) != 0L)
+                     jjCheckNAddTwoStates(357, 358);
+                  break;
+               case 358:
+                  if (curChar == 40 && kind > 118)
+                     kind = 118;
+                  break;
+               case 361:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(173, 174);
+                  break;
+               case 368:
+                  if ((0x100002600L & l) != 0L)
+                     jjAddStates(175, 176);
+                  break;
+               case 369:
+                  if (curChar == 40 && kind > 102)
+                     kind = 102;
+                  break;
+               case 372:
+                  if ((0x3ff000000000000L & l) == 0L)
+                     break;
+                  if (kind > 91)
+                     kind = 91;
+                  jjCheckNAddStates(105, 110);
+                  break;
+               case 373:
+                  if ((0x3ff000000000000L & l) == 0L)
+                     break;
+                  if (kind > 91)
+                     kind = 91;
+                  jjCheckNAdd(373);
+                  break;
+               case 374:
+                  if ((0x3ff000000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(374, 375);
+                  break;
+               case 375:
+                  if (curChar != 46)
+                     break;
+                  if (kind > 92)
+                     kind = 92;
+                  jjCheckNAdd(376);
+                  break;
+               case 376:
+                  if ((0x3ff000000000000L & l) == 0L)
+                     break;
+                  if (kind > 92)
+                     kind = 92;
+                  jjCheckNAdd(376);
+                  break;
+               case 377:
+                  if ((0x3ff000000000000L & l) != 0L)
+                     jjCheckNAddStates(177, 179);
+                  break;
+               case 378:
+                  if (curChar == 46)
+                     jjCheckNAddTwoStates(379, 380);
+                  break;
+               case 379:
+                  if ((0x3ff000000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(379, 380);
+                  break;
+               case 381:
+                  if ((0x280000000000L & l) != 0L)
+                     jjCheckNAdd(382);
+                  break;
+               case 382:
+                  if ((0x3ff000000000000L & l) == 0L)
+                     break;
+                  if (kind > 93)
+                     kind = 93;
+                  jjCheckNAdd(382);
+                  break;
+               case 383:
+                  if (curChar == 46)
+                     jjCheckNAddTwoStates(384, 385);
+                  break;
+               case 384:
+                  if ((0x3ff000000000000L & l) == 0L)
+                     break;
+                  if (kind > 92)
+                     kind = 92;
+                  jjCheckNAdd(384);
+                  break;
+               case 385:
+                  if ((0x3ff000000000000L & l) != 0L)
+                     jjCheckNAddTwoStates(385, 380);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 330:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddStates(102, 104);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(353, 354);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(352);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(349, 350);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(346, 347);
+                  if (curChar == 118)
+                     jjstateSet[jjnewStateCnt++] = 343;
+                  else if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 337;
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 329;
+                  break;
+               case 6:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAddStates(180, 189);
+                  }
+                  else if (curChar == 123)
+                     jjstateSet[jjnewStateCnt++] = 5;
+                  if (curChar == 116)
+                     jjAddStates(190, 191);
+                  else if (curChar == 101)
+                     jjAddStates(192, 194);
+                  else if (curChar == 110)
+                     jjAddStates(195, 196);
+                  else if (curChar == 102)
+                     jjAddStates(197, 199);
+                  else if (curChar == 115)
+                     jjAddStates(200, 201);
+                  else if (curChar == 97)
+                     jjAddStates(202, 206);
+                  else if (curChar == 112)
+                     jjAddStates(207, 210);
+                  else if (curChar == 100)
+                     jjAddStates(211, 215);
+                  else if (curChar == 99)
+                     jjAddStates(216, 218);
+                  else if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 18;
+                  else if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 7;
+                  break;
+               case 386:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddStates(102, 104);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(353, 354);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(352);
+                  }
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(349, 350);
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(346, 347);
+                  break;
+               case 1:
+                  if ((0xdfffffffffffffffL & l) != 0L)
+                     jjAddStates(65, 66);
+                  break;
+               case 2:
+                  if (curChar == 125 && kind > 1)
+                     kind = 1;
+                  break;
+               case 7:
+                  if (curChar == 102)
+                     jjstateSet[jjnewStateCnt++] = 8;
+                  break;
+               case 9:
+                  if (curChar == 101 && kind > 45)
+                     kind = 45;
+                  break;
+               case 10:
+                  if (curChar == 112)
+                     jjstateSet[jjnewStateCnt++] = 9;
+                  break;
+               case 11:
+                  if (curChar == 121)
+                     jjstateSet[jjnewStateCnt++] = 10;
+                  break;
+               case 12:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 11;
+                  break;
+               case 13:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 7;
+                  break;
+               case 16:
+               case 17:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjCheckNAdd(17);
+                  break;
+               case 18:
+                  if (curChar == 102)
+                     jjAddStates(113, 114);
+                  break;
+               case 21:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 18;
+                  break;
+               case 23:
+                  jjAddStates(75, 76);
+                  break;
+               case 26:
+                  jjAddStates(219, 220);
+                  break;
+               case 31:
+                  if (curChar == 99)
+                     jjAddStates(216, 218);
+                  break;
+               case 32:
+                  if (curChar == 100)
+                     jjAddStates(115, 116);
+                  break;
+               case 36:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 32;
+                  break;
+               case 37:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 36;
+                  break;
+               case 38:
+                  if (curChar == 104)
+                     jjstateSet[jjnewStateCnt++] = 37;
+                  break;
+               case 39:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 40;
+                  break;
+               case 41:
+                  if (curChar == 115 && kind > 87)
+                     kind = 87;
+                  break;
+               case 42:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 41;
+                  break;
+               case 43:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 39;
+                  break;
+               case 44:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 43;
+                  break;
+               case 45:
+                  if (curChar == 116)
+                     jjAddStates(119, 120);
+                  break;
+               case 48:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 45;
+                  break;
+               case 49:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 48;
+                  break;
+               case 50:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 49;
+                  break;
+               case 51:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 50;
+                  break;
+               case 52:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 51;
+                  break;
+               case 53:
+                  if (curChar == 100)
+                     jjAddStates(211, 215);
+                  break;
+               case 54:
+                  if (curChar == 116)
+                     jjAddStates(121, 122);
+                  break;
+               case 58:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 54;
+                  break;
+               case 59:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 58;
+                  break;
+               case 60:
+                  if (curChar == 100)
+                     jjstateSet[jjnewStateCnt++] = 59;
+                  break;
+               case 61:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 60;
+                  break;
+               case 62:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 61;
+                  break;
+               case 63:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 62;
+                  break;
+               case 64:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 63;
+                  break;
+               case 65:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 64;
+                  break;
+               case 66:
+                  if (curChar == 102)
+                     jjAddStates(123, 124);
+                  break;
+               case 70:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 66;
+                  break;
+               case 71:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 70;
+                  break;
+               case 72:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 71;
+                  break;
+               case 74:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 73;
+                  break;
+               case 75:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 74;
+                  break;
+               case 77:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 76;
+                  break;
+               case 78:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 77;
+                  break;
+               case 79:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 78;
+                  break;
+               case 80:
+                  if (curChar == 100)
+                     jjstateSet[jjnewStateCnt++] = 79;
+                  break;
+               case 81:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 80;
+                  break;
+               case 82:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 81;
+                  break;
+               case 83:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 82;
+                  break;
+               case 84:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 83;
+                  break;
+               case 85:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 84;
+                  break;
+               case 86:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 87;
+                  break;
+               case 88:
+                  if (curChar == 116 && kind > 43)
+                     kind = 43;
+                  break;
+               case 89:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 88;
+                  break;
+               case 90:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 89;
+                  break;
+               case 91:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 90;
+                  break;
+               case 92:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 91;
+                  break;
+               case 93:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 92;
+                  break;
+               case 94:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 93;
+                  break;
+               case 95:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 86;
+                  break;
+               case 96:
+                  if (curChar == 117)
+                     jjstateSet[jjnewStateCnt++] = 95;
+                  break;
+               case 97:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 96;
+                  break;
+               case 98:
+                  if (curChar == 102)
+                     jjstateSet[jjnewStateCnt++] = 97;
+                  break;
+               case 99:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 98;
+                  break;
+               case 100:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 101;
+                  break;
+               case 102:
+                  if (curChar == 110 && kind > 44)
+                     kind = 44;
+                  break;
+               case 103:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 102;
+                  break;
+               case 104:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 103;
+                  break;
+               case 105:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 104;
+                  break;
+               case 106:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 105;
+                  break;
+               case 107:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 106;
+                  break;
+               case 108:
+                  if (curChar == 117)
+                     jjstateSet[jjnewStateCnt++] = 107;
+                  break;
+               case 109:
+                  if (curChar == 102)
+                     jjstateSet[jjnewStateCnt++] = 108;
+                  break;
+               case 110:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 100;
+                  break;
+               case 111:
+                  if (curChar == 117)
+                     jjstateSet[jjnewStateCnt++] = 110;
+                  break;
+               case 112:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 111;
+                  break;
+               case 113:
+                  if (curChar == 102)
+                     jjstateSet[jjnewStateCnt++] = 112;
+                  break;
+               case 114:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 113;
+                  break;
+               case 115:
+                  if (curChar == 116)
+                     jjAddStates(129, 130);
+                  break;
+               case 117:
+                  if (curChar == 123 && kind > 96)
+                     kind = 96;
+                  break;
+               case 118:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 115;
+                  break;
+               case 119:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 118;
+                  break;
+               case 120:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 119;
+                  break;
+               case 121:
+                  if (curChar == 117)
+                     jjstateSet[jjnewStateCnt++] = 120;
+                  break;
+               case 122:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 121;
+                  break;
+               case 123:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 122;
+                  break;
+               case 124:
+                  if (curChar == 112)
+                     jjAddStates(207, 210);
+                  break;
+               case 125:
+                  if (curChar == 116)
+                     jjAddStates(131, 132);
+                  break;
+               case 129:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 125;
+                  break;
+               case 130:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 129;
+                  break;
+               case 131:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 130;
+                  break;
+               case 132:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 131;
+                  break;
+               case 133:
+                  if (curChar == 103)
+                     jjAddStates(133, 134);
+                  break;
+               case 137:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 133;
+                  break;
+               case 138:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 137;
+                  break;
+               case 139:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 138;
+                  break;
+               case 140:
+                  if (curChar == 98)
+                     jjstateSet[jjnewStateCnt++] = 139;
+                  break;
+               case 141:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 140;
+                  break;
+               case 142:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 141;
+                  break;
+               case 144:
+                  if (curChar == 103)
+                     jjstateSet[jjnewStateCnt++] = 143;
+                  break;
+               case 145:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 144;
+                  break;
+               case 146:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 145;
+                  break;
+               case 147:
+                  if (curChar == 100)
+                     jjstateSet[jjnewStateCnt++] = 146;
+                  break;
+               case 148:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 147;
+                  break;
+               case 149:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 148;
+                  break;
+               case 150:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 149;
+                  break;
+               case 151:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 150;
+                  break;
+               case 152:
+                  if (curChar == 103)
+                     jjAddStates(135, 136);
+                  break;
+               case 156:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 152;
+                  break;
+               case 157:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 156;
+                  break;
+               case 158:
+                  if (curChar == 100)
+                     jjstateSet[jjnewStateCnt++] = 157;
+                  break;
+               case 159:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 158;
+                  break;
+               case 160:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 159;
+                  break;
+               case 161:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 160;
+                  break;
+               case 162:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 161;
+                  break;
+               case 163:
+                  if (curChar == 110)
+                     jjAddStates(137, 138);
+                  break;
+               case 166:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 163;
+                  break;
+               case 167:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 166;
+                  break;
+               case 168:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 167;
+                  break;
+               case 169:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 168;
+                  break;
+               case 170:
+                  if (curChar == 117)
+                     jjstateSet[jjnewStateCnt++] = 169;
+                  break;
+               case 171:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 170;
+                  break;
+               case 172:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 171;
+                  break;
+               case 173:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 172;
+                  break;
+               case 174:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 173;
+                  break;
+               case 175:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 174;
+                  break;
+               case 177:
+                  if (curChar == 103)
+                     jjstateSet[jjnewStateCnt++] = 176;
+                  break;
+               case 178:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 177;
+                  break;
+               case 179:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 178;
+                  break;
+               case 180:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 179;
+                  break;
+               case 181:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 180;
+                  break;
+               case 182:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 181;
+                  break;
+               case 183:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 182;
+                  break;
+               case 184:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 183;
+                  break;
+               case 185:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 184;
+                  break;
+               case 186:
+                  if (curChar == 97)
+                     jjAddStates(202, 206);
+                  break;
+               case 187:
+                  if (curChar == 101)
+                     jjAddStates(139, 140);
+                  break;
+               case 191:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 187;
+                  break;
+               case 192:
+                  if (curChar == 117)
+                     jjstateSet[jjnewStateCnt++] = 191;
+                  break;
+               case 193:
+                  if (curChar == 98)
+                     jjstateSet[jjnewStateCnt++] = 192;
+                  break;
+               case 194:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 193;
+                  break;
+               case 195:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 194;
+                  break;
+               case 196:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 195;
+                  break;
+               case 197:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 196;
+                  break;
+               case 198:
+                  if (curChar == 114)
+                     jjAddStates(141, 142);
+                  break;
+               case 202:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 198;
+                  break;
+               case 203:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 202;
+                  break;
+               case 204:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 203;
+                  break;
+               case 205:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 204;
+                  break;
+               case 206:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 205;
+                  break;
+               case 207:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 206;
+                  break;
+               case 208:
+                  if (curChar == 102)
+                     jjAddStates(143, 144);
+                  break;
+               case 212:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 208;
+                  break;
+               case 213:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 212;
+                  break;
+               case 214:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 213;
+                  break;
+               case 216:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 215;
+                  break;
+               case 217:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 216;
+                  break;
+               case 219:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 218;
+                  break;
+               case 220:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 219;
+                  break;
+               case 221:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 220;
+                  break;
+               case 222:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 221;
+                  break;
+               case 223:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 222;
+                  break;
+               case 224:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 223;
+                  break;
+               case 225:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 224;
+                  break;
+               case 226:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 227;
+                  break;
+               case 228:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddStates(221, 224);
+                  break;
+               case 229:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(229, 230);
+                  break;
+               case 231:
+               case 232:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(232, 233);
+                  break;
+               case 234:
+                  if (curChar == 123 && kind > 40)
+                     kind = 40;
+                  break;
+               case 235:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 226;
+                  break;
+               case 236:
+                  if (curChar == 117)
+                     jjstateSet[jjnewStateCnt++] = 235;
+                  break;
+               case 237:
+                  if (curChar == 98)
+                     jjstateSet[jjnewStateCnt++] = 236;
+                  break;
+               case 238:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 237;
+                  break;
+               case 239:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 238;
+                  break;
+               case 240:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 239;
+                  break;
+               case 241:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 240;
+                  break;
+               case 242:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 243;
+                  break;
+               case 244:
+                  if (curChar == 123 && kind > 42)
+                     kind = 42;
+                  break;
+               case 245:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 242;
+                  break;
+               case 246:
+                  if (curChar == 117)
+                     jjstateSet[jjnewStateCnt++] = 245;
+                  break;
+               case 247:
+                  if (curChar == 98)
+                     jjstateSet[jjnewStateCnt++] = 246;
+                  break;
+               case 248:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 247;
+                  break;
+               case 249:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 248;
+                  break;
+               case 250:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 249;
+                  break;
+               case 251:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 250;
+                  break;
+               case 252:
+                  if (curChar == 115)
+                     jjAddStates(200, 201);
+                  break;
+               case 253:
+                  if (curChar == 102)
+                     jjAddStates(151, 152);
+                  break;
+               case 257:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 253;
+                  break;
+               case 258:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 257;
+                  break;
+               case 259:
+                  if (curChar == 101)
+                     jjAddStates(153, 154);
+                  break;
+               case 262:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 259;
+                  break;
+               case 263:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 262;
+                  break;
+               case 264:
+                  if (curChar == 102)
+                     jjAddStates(197, 199);
+                  break;
+               case 265:
+                  if (curChar == 103)
+                     jjAddStates(155, 156);
+                  break;
+               case 269:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 265;
+                  break;
+               case 270:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 269;
+                  break;
+               case 271:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 270;
+                  break;
+               case 272:
+                  if (curChar == 98)
+                     jjstateSet[jjnewStateCnt++] = 271;
+                  break;
+               case 273:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 272;
+                  break;
+               case 274:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 273;
+                  break;
+               case 276:
+                  if (curChar == 103)
+                     jjstateSet[jjnewStateCnt++] = 275;
+                  break;
+               case 277:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 276;
+                  break;
+               case 278:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 277;
+                  break;
+               case 279:
+                  if (curChar == 119)
+                     jjstateSet[jjnewStateCnt++] = 278;
+                  break;
+               case 280:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 279;
+                  break;
+               case 281:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 280;
+                  break;
+               case 282:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 281;
+                  break;
+               case 283:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 282;
+                  break;
+               case 284:
+                  if (curChar == 103)
+                     jjAddStates(157, 158);
+                  break;
+               case 288:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 284;
+                  break;
+               case 289:
+                  if (curChar == 105)
+                     jjstateSet[jjnewStateCnt++] = 288;
+                  break;
+               case 290:
+                  if (curChar == 119)
+                     jjstateSet[jjnewStateCnt++] = 289;
+                  break;
+               case 291:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 290;
+                  break;
+               case 292:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 291;
+                  break;
+               case 293:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 292;
+                  break;
+               case 294:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 293;
+                  break;
+               case 295:
+                  if (curChar == 114)
+                     jjAddStates(159, 160);
+                  break;
+               case 298:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 295;
+                  break;
+               case 299:
+                  if (curChar == 110)
+                     jjAddStates(195, 196);
+                  break;
+               case 300:
+                  if (curChar == 101)
+                     jjAddStates(161, 162);
+                  break;
+               case 304:
+                  if (curChar == 99)
+                     jjstateSet[jjnewStateCnt++] = 300;
+                  break;
+               case 305:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 304;
+                  break;
+               case 306:
+                  if (curChar == 112)
+                     jjstateSet[jjnewStateCnt++] = 305;
+                  break;
+               case 307:
+                  if (curChar == 115)
+                     jjstateSet[jjnewStateCnt++] = 306;
+                  break;
+               case 308:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 307;
+                  break;
+               case 309:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 308;
+                  break;
+               case 310:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 309;
+                  break;
+               case 311:
+                  if (curChar == 101)
+                     jjAddStates(163, 164);
+                  break;
+               case 314:
+                  if (curChar == 100)
+                     jjstateSet[jjnewStateCnt++] = 311;
+                  break;
+               case 315:
+                  if (curChar == 111)
+                     jjstateSet[jjnewStateCnt++] = 314;
+                  break;
+               case 316:
+                  if (curChar == 101)
+                     jjAddStates(192, 194);
+                  break;
+               case 317:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 318;
+                  break;
+               case 319:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddStates(225, 228);
+                  break;
+               case 320:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(320, 321);
+                  break;
+               case 322:
+               case 323:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(323, 324);
+                  break;
+               case 325:
+                  if (curChar == 123 && kind > 39)
+                     kind = 39;
+                  break;
+               case 326:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 317;
+                  break;
+               case 327:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 326;
+                  break;
+               case 328:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 327;
+                  break;
+               case 329:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 328;
+                  break;
+               case 331:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 332;
+                  break;
+               case 333:
+                  if (curChar == 123 && kind > 41)
+                     kind = 41;
+                  break;
+               case 334:
+                  if (curChar == 110)
+                     jjstateSet[jjnewStateCnt++] = 331;
+                  break;
+               case 335:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 334;
+                  break;
+               case 336:
+                  if (curChar == 109)
+                     jjstateSet[jjnewStateCnt++] = 335;
+                  break;
+               case 337:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 336;
+                  break;
+               case 338:
+                  if (curChar == 108)
+                     jjstateSet[jjnewStateCnt++] = 337;
+                  break;
+               case 339:
+                  if (curChar == 121)
+                     jjAddStates(171, 172);
+                  break;
+               case 342:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 339;
+                  break;
+               case 343:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 342;
+                  break;
+               case 344:
+                  if (curChar == 118)
+                     jjstateSet[jjnewStateCnt++] = 343;
+                  break;
+               case 345:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAddStates(180, 189);
+                  break;
+               case 346:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(346, 347);
+                  break;
+               case 349:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(349, 350);
+                  break;
+               case 351:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(352);
+                  break;
+               case 352:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(352);
+                  break;
+               case 353:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(353, 354);
+                  break;
+               case 355:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddStates(102, 104);
+                  break;
+               case 356:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddStates(102, 104);
+                  break;
+               case 359:
+                  if (curChar == 116)
+                     jjAddStates(190, 191);
+                  break;
+               case 360:
+                  if (curChar == 116)
+                     jjstateSet[jjnewStateCnt++] = 361;
+                  break;
+               case 362:
+                  if (curChar == 115 && kind > 88)
+                     kind = 88;
+                  break;
+               case 363:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 362;
+                  break;
+               case 364:
+                  if (curChar == 97)
+                     jjstateSet[jjnewStateCnt++] = 360;
+                  break;
+               case 365:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 364;
+                  break;
+               case 366:
+                  if (curChar == 114)
+                     jjstateSet[jjnewStateCnt++] = 365;
+                  break;
+               case 367:
+                  if (curChar == 116)
+                     jjAddStates(175, 176);
+                  break;
+               case 370:
+                  if (curChar == 120)
+                     jjstateSet[jjnewStateCnt++] = 367;
+                  break;
+               case 371:
+                  if (curChar == 101)
+                     jjstateSet[jjnewStateCnt++] = 370;
+                  break;
+               case 380:
+                  if ((0x2000000020L & l) != 0L)
+                     jjAddStates(229, 230);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 330:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(346, 347);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(349, 350);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(352);
+                  }
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(353, 354);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddStates(102, 104);
+                  break;
+               case 6:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAddStates(180, 189);
+                  break;
+               case 386:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(346, 347);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(349, 350);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                  {
+                     if (kind > 115)
+                        kind = 115;
+                     jjCheckNAdd(352);
+                  }
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(353, 354);
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddStates(102, 104);
+                  break;
+               case 1:
+                  if ((jjbitVec2[i2] & l2) != 0L)
+                     jjAddStates(65, 66);
+                  break;
+               case 16:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjCheckNAdd(17);
+                  break;
+               case 17:
+                  if ((jjbitVec28[i2] & l2) == 0L)
+                     break;
+                  if (kind > 54)
+                     kind = 54;
+                  jjCheckNAdd(17);
+                  break;
+               case 23:
+                  if ((jjbitVec2[i2] & l2) != 0L)
+                     jjAddStates(75, 76);
+                  break;
+               case 26:
+                  if ((jjbitVec2[i2] & l2) != 0L)
+                     jjAddStates(219, 220);
+                  break;
+               case 228:
+                  if ((jjbitVec5[i2] & l2) != 0L)
+                     jjCheckNAddStates(221, 224);
+                  break;
+               case 229:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(229, 230);
+                  break;
+               case 231:
+                  if ((jjbitVec5[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(232, 233);
+                  break;
+               case 232:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(232, 233);
+                  break;
+               case 319:
+                  if ((jjbitVec5[i2] & l2) != 0L)
+                     jjCheckNAddStates(225, 228);
+                  break;
+               case 320:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(320, 321);
+                  break;
+               case 322:
+                  if ((jjbitVec5[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(323, 324);
+                  break;
+               case 323:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(323, 324);
+                  break;
+               case 346:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(346, 347);
+                  break;
+               case 349:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(349, 350);
+                  break;
+               case 351:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(352);
+                  break;
+               case 352:
+                  if ((jjbitVec28[i2] & l2) == 0L)
+                     break;
+                  if (kind > 115)
+                     kind = 115;
+                  jjCheckNAdd(352);
+                  break;
+               case 353:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(353, 354);
+                  break;
+               case 355:
+                  if ((jjbitVec5[i2] & l2) != 0L)
+                     jjCheckNAddStates(102, 104);
+                  break;
+               case 356:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddStates(102, 104);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 386 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjStopStringLiteralDfa_13(int pos, long active0, long active1)
+{
+   switch (pos)
+   {
+      default :
+         return -1;
+   }
+}
+private final int jjStartNfa_13(int pos, long active0, long active1)
+{
+   return jjMoveNfa_13(jjStopStringLiteralDfa_13(pos, active0, active1), pos + 1);
+}
+private final int jjStartNfaWithStates_13(int pos, int kind, int state)
+{
+   jjmatchedKind = kind;
+   jjmatchedPos = pos;
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) { return pos + 1; }
+   return jjMoveNfa_13(state, pos + 1);
+}
+private final int jjMoveStringLiteralDfa0_13()
+{
+   switch(curChar)
+   {
+      case 123:
+         return jjStopAtPos(0, 119);
+      default :
+         return jjMoveNfa_13(0, 0);
+   }
+}
+private final int jjMoveNfa_13(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 1;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((0xffffffff00002600L & l) != 0L)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((jjbitVec2[i2] & l2) != 0L && kind > 121)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjStopStringLiteralDfa_12(int pos, long active0, long active1)
+{
+   switch (pos)
+   {
+      default :
+         return -1;
+   }
+}
+private final int jjStartNfa_12(int pos, long active0, long active1)
+{
+   return jjMoveNfa_12(jjStopStringLiteralDfa_12(pos, active0, active1), pos + 1);
+}
+private final int jjStartNfaWithStates_12(int pos, int kind, int state)
+{
+   jjmatchedKind = kind;
+   jjmatchedPos = pos;
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) { return pos + 1; }
+   return jjMoveNfa_12(state, pos + 1);
+}
+private final int jjMoveStringLiteralDfa0_12()
+{
+   switch(curChar)
+   {
+      case 123:
+         return jjStopAtPos(0, 119);
+      default :
+         return jjMoveNfa_12(0, 0);
+   }
+}
+private final int jjMoveNfa_12(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 1;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((0xffffffff00002600L & l) != 0L)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((jjbitVec2[i2] & l2) != 0L && kind > 121)
+                     kind = 121;
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+private final int jjStopStringLiteralDfa_7(int pos, long active0, long active1)
+{
+   switch (pos)
+   {
+      default :
+         return -1;
+   }
+}
+private final int jjStartNfa_7(int pos, long active0, long active1)
+{
+   return jjMoveNfa_7(jjStopStringLiteralDfa_7(pos, active0, active1), pos + 1);
+}
+private final int jjStartNfaWithStates_7(int pos, int kind, int state)
+{
+   jjmatchedKind = kind;
+   jjmatchedPos = pos;
+   try { curChar = input_stream.readChar(); }
+   catch(java.io.IOException e) { return pos + 1; }
+   return jjMoveNfa_7(state, pos + 1);
+}
+private final int jjMoveStringLiteralDfa0_7()
+{
+   switch(curChar)
+   {
+      case 40:
+         return jjStopAtPos(0, 117);
+      default :
+         return jjMoveNfa_7(0, 0);
+   }
+}
+private final int jjMoveNfa_7(int startState, int curPos)
+{
+   int[] nextStates;
+   int startsAt = 0;
+   jjnewStateCnt = 8;
+   int i = 1;
+   jjstateSet[0] = startState;
+   int j, kind = 0x7fffffff;
+   for (;;)
+   {
+      if (++jjround == 0x7fffffff)
+         ReInitRounds();
+      if (curChar < 64)
+      {
+         long l = 1L << curChar;
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 2)
+                     kind = 2;
+                  jjCheckNAddTwoStates(6, 7);
+                  break;
+               case 1:
+                  if ((0x3ff600000000000L & l) != 0L)
+                     jjAddStates(95, 96);
+                  break;
+               case 2:
+                  if (curChar == 58)
+                     jjstateSet[jjnewStateCnt++] = 3;
+                  break;
+               case 4:
+                  if ((0x3ff600000000000L & l) == 0L)
+                     break;
+                  if (kind > 116)
+                     kind = 116;
+                  jjstateSet[jjnewStateCnt++] = 4;
+                  break;
+               case 6:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 2)
+                     kind = 2;
+                  jjCheckNAdd(6);
+                  break;
+               case 7:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 4)
+                     kind = 4;
+                  jjCheckNAdd(7);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else if (curChar < 128)
+      {
+         long l = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 116)
+                     kind = 116;
+                  jjCheckNAddStates(99, 101);
+                  break;
+               case 1:
+                  if ((0x7fffffe87fffffeL & l) != 0L)
+                     jjCheckNAddTwoStates(1, 2);
+                  break;
+               case 3:
+               case 4:
+                  if ((0x7fffffe87fffffeL & l) == 0L)
+                     break;
+                  if (kind > 116)
+                     kind = 116;
+                  jjCheckNAdd(4);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      else
+      {
+         int i2 = (curChar & 0xff) >> 6;
+         long l2 = 1L << (curChar & 077);
+         MatchLoop: do
+         {
+            switch(jjstateSet[--i])
+            {
+               case 0:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 116)
+                     kind = 116;
+                  jjCheckNAddStates(99, 101);
+                  break;
+               case 1:
+                  if ((jjbitVec28[i2] & l2) != 0L)
+                     jjCheckNAddTwoStates(1, 2);
+                  break;
+               case 3:
+                  if ((jjbitVec5[i2] & l2) == 0L)
+                     break;
+                  if (kind > 116)
+                     kind = 116;
+                  jjCheckNAdd(4);
+                  break;
+               case 4:
+                  if ((jjbitVec28[i2] & l2) == 0L)
+                     break;
+                  if (kind > 116)
+                     kind = 116;
+                  jjCheckNAdd(4);
+                  break;
+               default : break;
+            }
+         } while(i != startsAt);
+      }
+      if (kind != 0x7fffffff)
+      {
+         jjmatchedKind = kind;
+         jjmatchedPos = curPos;
+         kind = 0x7fffffff;
+      }
+      ++curPos;
+      if ((i = jjnewStateCnt) == (startsAt = 8 - (jjnewStateCnt = startsAt)))
+         return curPos;
+      try { curChar = input_stream.readChar(); }
+      catch(java.io.IOException e) { return curPos; }
+   }
+}
+static final int[] jjnextStates = {
+   1, 3, 12, 13, 22, 24, 29, 30, 38, 40, 50, 52, 71, 73, 79, 81, 
+   98, 100, 109, 110, 133, 135, 144, 146, 154, 156, 173, 175, 192, 194, 204, 206, 
+   215, 216, 220, 221, 223, 224, 220, 221, 223, 224, 226, 213, 218, 190, 201, 142, 
+   152, 170, 77, 96, 107, 130, 48, 68, 27, 35, 1, 6, 20, 21, 23, 24, 
+   26, 1, 4, 68, 69, 70, 72, 73, 75, 12, 16, 23, 24, 36, 37, 41, 
+   42, 72, 73, 75, 60, 61, 63, 64, 66, 51, 52, 54, 55, 76, 77, 1, 
+   2, 4, 5, 1, 2, 4, 356, 357, 358, 373, 374, 375, 377, 378, 380, 8, 
+   12, 19, 20, 33, 35, 40, 42, 46, 47, 55, 57, 67, 69, 87, 94, 101, 
+   109, 116, 117, 126, 128, 134, 136, 153, 155, 164, 165, 188, 190, 199, 201, 209, 
+   211, 227, 228, 229, 230, 243, 244, 254, 256, 260, 261, 266, 268, 285, 287, 296, 
+   297, 301, 303, 312, 313, 318, 319, 320, 321, 332, 333, 340, 341, 361, 363, 368, 
+   369, 377, 378, 380, 346, 347, 349, 350, 352, 353, 354, 356, 357, 358, 366, 371, 
+   330, 338, 344, 310, 315, 283, 294, 298, 258, 263, 197, 207, 225, 241, 251, 132, 
+   151, 162, 185, 65, 85, 99, 114, 123, 38, 44, 52, 26, 27, 229, 230, 232, 
+   233, 320, 321, 323, 324, 381, 382, 
+};
+public static final String[] jjstrLiteralImages = {
+"", null, null, null, null, null, null, null, null, null, null, null, null, 
+null, null, null, null, null, "\157\162", "\141\156\144", "\144\151\166", 
+"\151\144\151\166", "\155\157\144", "\52", "\151\156", "\163\141\164\151\163\146\151\145\163", 
+"\162\145\164\165\162\156", "\164\150\145\156", "\145\154\163\145", "\164\157", 
+"\151\156\164\145\162\163\145\143\164", "\165\156\151\157\156", "\145\170\143\145\160\164", 
+"\160\162\145\143\145\144\145\163", "\146\157\154\154\157\167\163", null, "\151\164\145\155", 
+"\145\154\145\155\145\156\164", "\141\164\164\162\151\142\165\164\145", null, null, null, null, null, null, 
+null, null, "\164\171\160\145", "\156\157\144\145", "\145\155\160\164\171", null, 
+null, "\52", null, null, "\57", "\57\57", "\57", "\57\57", "\75", "\151\163", 
+"\41\75", "\151\163\156\157\164", "\74\75", "\74\74", "\76\75", "\76\76", "\145\161", 
+"\156\145", "\147\164", "\147\145", "\154\164", "\154\145", "\74", "\76", "\55", "\53", 
+"\77", "\174", "\50", "\100", "\133", "\135", "\51", null, null, null, null, null, 
+"\166\141\154\151\144\141\164\145", null, null, null, null, "\143\157\155\155\145\156\164", 
+"\144\157\143\165\155\145\156\164", null, "\164\145\170\164", "\165\156\164\171\160\145\144", 
+"\160\162\157\143\145\163\163\151\156\147\55\151\156\163\164\162\165\143\164\151\157\156", null, null, null, null, null, "\54", null, null, "\56", "\56\56", null, null, 
+null, "\44", null, null, null, "\50", null, "\173", "\175", null, null, null, null, 
+null, null, null, null, };
+public static final String[] lexStateNames = {
+   "DEFAULT", 
+   "ELEMENT_CONTENT", 
+   "OPERATOR", 
+   "QNAME", 
+   "NAMESPACEDECL", 
+   "XMLSPACE_DECL", 
+   "ITEMTYPE", 
+   "FUNCDEF", 
+   "NAMESPACEKEYWORD", 
+   "START_TAG", 
+   "END_TAG", 
+   "VARNAME", 
+   "QUOT_ATTRIBUTE_CONTENT", 
+   "APOS_ATTRIBUTE_CONTENT", 
+   "CDATA_SECTION", 
+   "PROCESSING_INSTRUCTION", 
+   "XML_COMMENT", 
+   "XQUERY_COMMENT", 
+};
+public static final int[] jjnewLexState = {
+   -1, -1, -1, -1, -1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 
+   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, -1, -1, -1, -1, 8, 8, 3, 0, 0, 0, -1, 
+   -1, -1, 2, 2, 2, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+   0, 0, 0, 0, 0, 3, 0, 2, 2, 11, 11, 11, 6, 6, 2, -1, 2, 2, 2, 0, 0, 2, 0, 0, 0, 
+   0, 0, 0, 0, -1, 0, 2, 0, 2, 2, -1, -1, -1, 11, 2, 2, -1, 6, -1, 0, -1, -1, -1, -1, -1, 
+   -1, -1, -1, -1, 
+};
+static final long[] jjtoToken = {
+   0xfff3fffffffffff1L, 0x3fe3ffffbffffffL, 0x0L, 
+};
+static final long[] jjtoSkip = {
+   0x6L, 0x0L, 0x0L, 
+};
+static final long[] jjtoSpecial = {
+   0x2L, 0x0L, 0x0L, 
+};
+private ASCII_CharStream input_stream;
+private final int[] jjrounds = new int[386];
+private final int[] jjstateSet = new int[772];
+StringBuffer image;
+int jjimageLen;
+int lengthOfMatch;
+protected char curChar;
+public XPathTokenManager(ASCII_CharStream stream)
+{
+   if (ASCII_CharStream.staticFlag)
+      throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.");
+   input_stream = stream;
+}
+public XPathTokenManager(ASCII_CharStream stream, int lexState)
+{
+   this(stream);
+   SwitchTo(lexState);
+}
+public void ReInit(ASCII_CharStream stream)
+{
+   jjmatchedPos = jjnewStateCnt = 0;
+   curLexState = defaultLexState;
+   input_stream = stream;
+   ReInitRounds();
+}
+private final void ReInitRounds()
+{
+   int i;
+   jjround = 0x80000001;
+   for (i = 386; i-- > 0;)
+      jjrounds[i] = 0x80000000;
+}
+public void ReInit(ASCII_CharStream stream, int lexState)
+{
+   ReInit(stream);
+   SwitchTo(lexState);
+}
+public void SwitchTo(int lexState)
+{
+   if (lexState >= 18 || lexState < 0)
+      throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
+   else
+      curLexState = lexState;
+}
+
+private final Token jjFillToken()
+{
+   Token t = Token.newToken(jjmatchedKind);
+   t.kind = jjmatchedKind;
+   String im = jjstrLiteralImages[jjmatchedKind];
+   t.image = (im == null) ? input_stream.GetImage() : im;
+   t.beginLine = input_stream.getBeginLine();
+   t.beginColumn = input_stream.getBeginColumn();
+   t.endLine = input_stream.getEndLine();
+   t.endColumn = input_stream.getEndColumn();
+   return t;
+}
+
+int curLexState = 0;
+int defaultLexState = 0;
+int jjnewStateCnt;
+int jjround;
+int jjmatchedPos;
+int jjmatchedKind;
+
+public final Token getNextToken() 
+{
+  int kind;
+  Token specialToken = null;
+  Token matchedToken;
+  int curPos = 0;
+
+  EOFLoop :
+  for (;;)
+  {   
+   try   
+   {     
+      curChar = input_stream.BeginToken();
+   }     
+   catch(java.io.IOException e)
+   {        
+      jjmatchedKind = 0;
+      matchedToken = jjFillToken();
+      matchedToken.specialToken = specialToken;
+      return matchedToken;
+   }
+   image = null;
+   jjimageLen = 0;
+
+   switch(curLexState)
+   {
+     case 0:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_0();
+       break;
+     case 1:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_1();
+       break;
+     case 2:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_2();
+       break;
+     case 3:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_3();
+       break;
+     case 4:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_4();
+       break;
+     case 5:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_5();
+       break;
+     case 6:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_6();
+       break;
+     case 7:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_7();
+       break;
+     case 8:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_8();
+       break;
+     case 9:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_9();
+       break;
+     case 10:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_10();
+       break;
+     case 11:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_11();
+       break;
+     case 12:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_12();
+       break;
+     case 13:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_13();
+       break;
+     case 14:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_14();
+       break;
+     case 15:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_15();
+       break;
+     case 16:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_16();
+       break;
+     case 17:
+       jjmatchedKind = 0x7fffffff;
+       jjmatchedPos = 0;
+       curPos = jjMoveStringLiteralDfa0_17();
+       break;
+   }
+     if (jjmatchedKind != 0x7fffffff)
+     {
+        if (jjmatchedPos + 1 < curPos)
+           input_stream.backup(curPos - jjmatchedPos - 1);
+        if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+        {
+           matchedToken = jjFillToken();
+           matchedToken.specialToken = specialToken;
+           TokenLexicalActions(matchedToken);
+       if (jjnewLexState[jjmatchedKind] != -1)
+         curLexState = jjnewLexState[jjmatchedKind];
+           return matchedToken;
+        }
+        else
+        {
+           if ((jjtoSpecial[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+           {
+              matchedToken = jjFillToken();
+              if (specialToken == null)
+                 specialToken = matchedToken;
+              else
+              {
+                 matchedToken.specialToken = specialToken;
+                 specialToken = (specialToken.next = matchedToken);
+              }
+           }
+         if (jjnewLexState[jjmatchedKind] != -1)
+           curLexState = jjnewLexState[jjmatchedKind];
+           continue EOFLoop;
+        }
+     }
+     int error_line = input_stream.getEndLine();
+     int error_column = input_stream.getEndColumn();
+     String error_after = null;
+     boolean EOFSeen = false;
+     try { input_stream.readChar(); input_stream.backup(1); }
+     catch (java.io.IOException e1) {
+        EOFSeen = true;
+        error_after = curPos <= 1 ? "" : input_stream.GetImage();
+        if (curChar == '\n' || curChar == '\r') {
+           error_line++;
+           error_column = 0;
+        }
+        else
+           error_column++;
+     }
+     if (!EOFSeen) {
+        input_stream.backup(1);
+        error_after = curPos <= 1 ? "" : input_stream.GetImage();
+     }
+     throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
+  }
+}
+
+final void TokenLexicalActions(Token matchedToken)
+{
+   switch(jjmatchedKind)
+   {
+      case 39 :
+        if (image == null)
+            image = new StringBuffer(new String(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))));
+         else
+            image.append(new String(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))));
+                                                                         pushState(DEFAULT);
+         break;
+      case 40 :
+        if (image == null)
+            image = new StringBuffer(new String(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))));
+         else
+            image.append(new String(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))));
+                                                                             pushState(DEFAULT);
+         break;
+      case 41 :
+        if (image == null)
+            image = new StringBuffer(new String(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))));
+         else
+            image.append(new String(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))));
+                                                 pushState(DEFAULT);
+         break;
+      case 42 :
+        if (image == null)
+            image = new StringBuffer(new String(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))));
+         else
+            image.append(new String(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))));
+                                                     pushState(DEFAULT);
+         break;
+      case 119 :
+        if (image == null)
+            image = new StringBuffer(jjstrLiteralImages[119]);
+         else
+            image.append(jjstrLiteralImages[119]);
+                     pushState();
+         break;
+      case 120 :
+        if (image == null)
+            image = new StringBuffer(jjstrLiteralImages[120]);
+         else
+            image.append(jjstrLiteralImages[120]);
+                     popState();
+         break;
+      default : 
+         break;
+   }
+}
+}
diff --git a/src/org/apache/xpath/parser/XPathTreeConstants.java b/src/org/apache/xpath/parser/XPathTreeConstants.java
new file mode 100644
index 0000000..dd8b4b4
--- /dev/null
+++ b/src/org/apache/xpath/parser/XPathTreeConstants.java
@@ -0,0 +1,227 @@
+/* Generated By:JJTree: Do not edit this line. F:/xalan3/xml-xalan/java/xpath-src\XPathTreeConstants.java */
+
+package org.apache.xpath.parser;
+
+public interface XPathTreeConstants
+{
+  public int JJTXPATH2 = 0;
+  public int JJTMATCHPATTERN = 1;
+  public int JJTEXPRSEQUENCE = 2;
+  public int JJTPATTERN = 3;
+  public int JJTPATHPATTERN = 4;
+  public int JJTROOT = 5;
+  public int JJTROOTDESCENDANTS = 6;
+  public int JJTSLASH = 7;
+  public int JJTSLASHSLASH = 8;
+  public int JJTVOID = 9;
+  public int JJTPATTERNSTEP = 10;
+  public int JJTAXISCHILD = 11;
+  public int JJTAXISATTRIBUTE = 12;
+  public int JJTAT = 13;
+  public int JJTIDKEYPATTERN = 14;
+  public int JJTQNAMELPAR = 15;
+  public int JJTVARNAME = 16;
+  public int JJTOREXPR = 17;
+  public int JJTANDEXPR = 18;
+  public int JJTFLWREXPR = 19;
+  public int JJTRETURN = 20;
+  public int JJTQUANTIFIEDEXPR = 21;
+  public int JJTSOME = 22;
+  public int JJTEVERY = 23;
+  public int JJTIN = 24;
+  public int JJTSATISFIES = 25;
+  public int JJTIFEXPR = 26;
+  public int JJTIFLPAR = 27;
+  public int JJTTHEN = 28;
+  public int JJTELSE = 29;
+  public int JJTINSTANCEOFEXPR = 30;
+  public int JJTINSTANCEOF = 31;
+  public int JJTCOMPARISONEXPR = 32;
+  public int JJTRANGEEXPR = 33;
+  public int JJTADDITIVEEXPR = 34;
+  public int JJTMULTIPLICATIVEEXPR = 35;
+  public int JJTUNIONEXPR = 36;
+  public int JJTINTERSECTEXCEPTEXPR = 37;
+  public int JJTUNARYEXPR = 38;
+  public int JJTMINUS = 39;
+  public int JJTPLUS = 40;
+  public int JJTPATHEXPR = 41;
+  public int JJTSTEPEXPR = 42;
+  public int JJTFORCLAUSE = 43;
+  public int JJTVALIDATEEXPR = 44;
+  public int JJTVALIDATE = 45;
+  public int JJTLBRACE = 46;
+  public int JJTRBRACE = 47;
+  public int JJTCASTEXPR = 48;
+  public int JJTCASTAS = 49;
+  public int JJTTREATAS = 50;
+  public int JJTAXISDESCENDANT = 51;
+  public int JJTAXISSELF = 52;
+  public int JJTAXISDESCENDANTORSELF = 53;
+  public int JJTAXISFOLLOWINGSIBLING = 54;
+  public int JJTAXISFOLLOWING = 55;
+  public int JJTAXISNAMESPACE = 56;
+  public int JJTAXISPARENT = 57;
+  public int JJTAXISANCESTOR = 58;
+  public int JJTAXISPRECEDINGSIBLING = 59;
+  public int JJTAXISPRECEDING = 60;
+  public int JJTAXISANCESTORORSELF = 61;
+  public int JJTNODETEST = 62;
+  public int JJTNAMETEST = 63;
+  public int JJTQNAME = 64;
+  public int JJTSTAR = 65;
+  public int JJTNCNAMECOLONSTAR = 66;
+  public int JJTSTARCOLONNCNAME = 67;
+  public int JJTKINDTEST = 68;
+  public int JJTPROCESSINGINSTRUCTIONTEST = 69;
+  public int JJTSTRINGLITERAL = 70;
+  public int JJTCOMMENTTEST = 71;
+  public int JJTTEXTTEST = 72;
+  public int JJTANYKINDTEST = 73;
+  public int JJTABBREVIATEDFORWARDSTEP = 74;
+  public int JJTDOT = 75;
+  public int JJTDOTDOT = 76;
+  public int JJTPREDICATES = 77;
+  public int JJTLBRACK = 78;
+  public int JJTRBRACK = 79;
+  public int JJTINTEGERLITERAL = 80;
+  public int JJTDECIMALLITERAL = 81;
+  public int JJTDOUBLELITERAL = 82;
+  public int JJTFUNCTIONCALL = 83;
+  public int JJTSCHEMACONTEXT = 84;
+  public int JJTSCHEMAGLOBALCONTEXT = 85;
+  public int JJTTYPE = 86;
+  public int JJTSCHEMACONTEXTSTEP = 87;
+  public int JJTSEQUENCETYPE = 88;
+  public int JJTEMPTY = 89;
+  public int JJTITEMTYPE = 90;
+  public int JJTELEMENTTYPE = 91;
+  public int JJTATTRIBUTETYPE = 92;
+  public int JJTNODE = 93;
+  public int JJTPROCESSINGINSTRUCTION = 94;
+  public int JJTCOMMENT = 95;
+  public int JJTTEXT = 96;
+  public int JJTDOCUMENT = 97;
+  public int JJTITEM = 98;
+  public int JJTUNTYPED = 99;
+  public int JJTATOMICVALUE = 100;
+  public int JJTELEMORATTRTYPE = 101;
+  public int JJTSCHEMATYPE = 102;
+  public int JJTOFTYPE = 103;
+  public int JJTATOMICTYPE = 104;
+  public int JJTOCCURRENCEINDICATOR = 105;
+  public int JJTMULTIPLY = 106;
+  public int JJTQMARK = 107;
+
+
+  public String[] jjtNodeName = {
+    "XPath2",
+    "MatchPattern",
+    "ExprSequence",
+    "Pattern",
+    "PathPattern",
+    "Root",
+    "RootDescendants",
+    "Slash",
+    "SlashSlash",
+    "void",
+    "PatternStep",
+    "AxisChild",
+    "AxisAttribute",
+    "At",
+    "IdKeyPattern",
+    "QNameLpar",
+    "VarName",
+    "OrExpr",
+    "AndExpr",
+    "FLWRExpr",
+    "Return",
+    "QuantifiedExpr",
+    "Some",
+    "Every",
+    "In",
+    "Satisfies",
+    "IfExpr",
+    "IfLpar",
+    "Then",
+    "Else",
+    "InstanceofExpr",
+    "Instanceof",
+    "ComparisonExpr",
+    "RangeExpr",
+    "AdditiveExpr",
+    "MultiplicativeExpr",
+    "UnionExpr",
+    "IntersectExceptExpr",
+    "UnaryExpr",
+    "Minus",
+    "Plus",
+    "PathExpr",
+    "StepExpr",
+    "ForClause",
+    "ValidateExpr",
+    "Validate",
+    "Lbrace",
+    "Rbrace",
+    "CastExpr",
+    "CastAs",
+    "TreatAs",
+    "AxisDescendant",
+    "AxisSelf",
+    "AxisDescendantOrSelf",
+    "AxisFollowingSibling",
+    "AxisFollowing",
+    "AxisNamespace",
+    "AxisParent",
+    "AxisAncestor",
+    "AxisPrecedingSibling",
+    "AxisPreceding",
+    "AxisAncestorOrSelf",
+    "NodeTest",
+    "NameTest",
+    "QName",
+    "Star",
+    "NCNameColonStar",
+    "StarColonNCName",
+    "KindTest",
+    "ProcessingInstructionTest",
+    "StringLiteral",
+    "CommentTest",
+    "TextTest",
+    "AnyKindTest",
+    "AbbreviatedForwardStep",
+    "Dot",
+    "DotDot",
+    "Predicates",
+    "Lbrack",
+    "Rbrack",
+    "IntegerLiteral",
+    "DecimalLiteral",
+    "DoubleLiteral",
+    "FunctionCall",
+    "SchemaContext",
+    "SchemaGlobalContext",
+    "Type",
+    "SchemaContextStep",
+    "SequenceType",
+    "Empty",
+    "ItemType",
+    "ElementType",
+    "AttributeType",
+    "Node",
+    "ProcessingInstruction",
+    "Comment",
+    "Text",
+    "Document",
+    "Item",
+    "Untyped",
+    "AtomicValue",
+    "ElemOrAttrType",
+    "SchemaType",
+    "OfType",
+    "AtomicType",
+    "OccurrenceIndicator",
+    "Multiply",
+    "QMark",
+  };
+}
diff --git a/src/org/apache/xpath/parser/XPathVisitor.java b/src/org/apache/xpath/parser/XPathVisitor.java
new file mode 100644
index 0000000..b126a57
--- /dev/null
+++ b/src/org/apache/xpath/parser/XPathVisitor.java
@@ -0,0 +1,8 @@
+/* Generated By:JJTree: Do not edit this line. F:/xalan3/xml-xalan/java/xpath-src\XPathVisitor.java */
+
+package org.apache.xpath.parser;
+
+public interface XPathVisitor
+{
+  public Object visit(SimpleNode node, Object data);
+}
diff --git a/src/org/apache/xpath/patterns/ContextMatchStepPattern.java b/src/org/apache/xpath/patterns/ContextMatchStepPattern.java
index 8e0c93e..5d22abf 100644
--- a/src/org/apache/xpath/patterns/ContextMatchStepPattern.java
+++ b/src/org/apache/xpath/patterns/ContextMatchStepPattern.java
@@ -71,16 +71,24 @@
 public class ContextMatchStepPattern extends StepPattern
 {
 
+//  /**
+//   * Construct a ContextMatchStepPattern.
+//   *
+//   * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
+//   */
+//  public ContextMatchStepPattern(int axis, int paxis)
+//  {
+//    super(DTMFilter.SHOW_ALL, axis, paxis);
+//  }
+  
   /**
    * Construct a ContextMatchStepPattern.
-   *
-   * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
    */
-  public ContextMatchStepPattern(int axis, int paxis)
+  public ContextMatchStepPattern()
   {
-    super(DTMFilter.SHOW_ALL, axis, paxis);
   }
 
+
   /**
    * Execute this pattern step, including predicates.
    *
diff --git a/src/org/apache/xpath/patterns/FunctionPattern.java b/src/org/apache/xpath/patterns/FunctionPattern.java
index ffbffba..4ff02ba 100644
--- a/src/org/apache/xpath/patterns/FunctionPattern.java
+++ b/src/org/apache/xpath/patterns/FunctionPattern.java
@@ -61,13 +61,15 @@
 import javax.xml.transform.TransformerException;
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMIterator;
+import org.apache.xml.utils.QName;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
 import org.apache.xpath.objects.XNumber;
 import org.apache.xpath.objects.XObject;
-import org.apache.xpath.patterns.StepPattern.PredOwner;
+import org.apache.xpath.parser.Node;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -76,22 +78,30 @@
 public class FunctionPattern extends StepPattern
 {
 
+//  /**
+//   * Construct a FunctionPattern from a
+//   * {@link org.apache.xpath.functions.Function expression}.
+//   *
+//   *
+//   * @param a should be a {@link org.apache.xpath.functions.Function expression}.
+//   *
+//   * NEEDSDOC @param expr
+//   */
+//  public FunctionPattern(Expression expr, int axis, int predaxis)
+//  {
+//
+//    super(0, null, null, axis, predaxis);
+//
+//    m_functionExpr = expr;
+//  }
+
   /**
-   * Construct a FunctionPattern from a
-   * {@link org.apache.xpath.functions.Function expression}.
-   *
-   *
-   * @param a should be a {@link org.apache.xpath.functions.Function expression}.
-   *
-   * NEEDSDOC @param expr
+   * Construct a FunctionPattern.
    */
-  public FunctionPattern(Expression expr, int axis, int predaxis)
+  public FunctionPattern()
   {
-
-    super(0, null, null, axis, predaxis);
-
-    m_functionExpr = expr;
   }
+  
 
   /**
    * Static calc of match score.
@@ -109,7 +119,41 @@
    * Should be a {@link org.apache.xpath.functions.Function expression}.
    *  @serial   
    */
-  Expression m_functionExpr;
+  protected Expression m_functionExpr;
+  
+  /**
+   * @see ExpressionOwner#setExpression(Expression)
+   */
+  public void setFunctionExpression(Expression exp)
+  {
+    exp.exprSetParent(this);
+  	m_functionExpr = exp;
+  }
+  
+  /**
+   * Add parameters to the function expression.
+   */
+  public void jjtAddChild(Node n, int i) 
+  {
+  	if(!(n instanceof org.apache.xpath.parser.QName))
+  	{
+  		m_functionExpr.jjtAddChild(n, i-1);
+  	}
+  }
+
+//  public void jjtClose() 
+//  {
+//  	if(
+//  }
+
+  public Node jjtGetChild(int i) 
+  {
+    return m_functionExpr.jjtGetChild(i);
+  }
+
+  public int jjtGetNumChildren() {
+    return m_functionExpr.jjtGetNumChildren();
+  }
   
   /**
    * This function is used to fixup variables from QNames to stack frame 
@@ -121,10 +165,10 @@
    * in the stack frame (but variables above the globalsTop value will need 
    * to be offset to the current stack frame).
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
-    super.fixupVariables(vars, globalsSize);
-    m_functionExpr.fixupVariables(vars, globalsSize);
+    super.fixupVariables(vcs);
+    m_functionExpr.fixupVariables(vcs);
   }
 
   
@@ -286,5 +330,18 @@
     m_functionExpr.callVisitors(new FunctionOwner(), visitor);
     super.callSubtreeVisitors(visitor);
   }
+  
+  /**
+   * Get the string represenentation of this step for diagnostic purposes.
+   *
+   *
+   * @return A string representation of this step, built by reverse-engineering 
+   * the contained info.
+   */
+  public String toString()
+  {
+  	return m_functionExpr.toString();
+  }
+
 
 }
diff --git a/src/org/apache/xpath/patterns/NodeTest.java b/src/org/apache/xpath/patterns/NodeTest.java
index c18a072..31a5b64 100644
--- a/src/org/apache/xpath/patterns/NodeTest.java
+++ b/src/org/apache/xpath/patterns/NodeTest.java
@@ -61,13 +61,13 @@
 import javax.xml.transform.TransformerException;
 import org.apache.xml.dtm.DTM;
 import org.apache.xml.dtm.DTMFilter;
-import org.apache.xml.dtm.ref.ExpandedNameTable;
 import org.apache.xpath.Expression;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPath;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
-import org.apache.xpath.objects.XNumber;
+import org.apache.xpath.objects.XDouble;
 import org.apache.xpath.objects.XObject;
 
 /**
@@ -188,68 +188,68 @@
    *  {@link #SCORE_OTHER}.
    *  @serial
    */
-  XNumber m_score;
+  XDouble m_score;
 
   /**
    * The match score if the pattern consists of just a NodeTest.
    *  @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a> 
    */
-  public static final XNumber SCORE_NODETEST =
-    new XNumber(XPath.MATCH_SCORE_NODETEST);
+  public static final XDouble SCORE_NODETEST =
+    new XDouble(XPath.MATCH_SCORE_NODETEST);
 
   /**
    * The match score if the pattern pattern has the form NCName:*.
    *  @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a> 
    */
-  public static final XNumber SCORE_NSWILD =
-    new XNumber(XPath.MATCH_SCORE_NSWILD);
+  public static final XDouble SCORE_NSWILD =
+    new XDouble(XPath.MATCH_SCORE_NSWILD);
 
   /**
    * The match score if the pattern has the form
    * of a QName optionally preceded by an @ character.
    *  @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a> 
    */
-  public static final XNumber SCORE_QNAME =
-    new XNumber(XPath.MATCH_SCORE_QNAME);
+  public static final XDouble SCORE_QNAME =
+    new XDouble(XPath.MATCH_SCORE_QNAME);
 
   /**
    * The match score if the pattern consists of something
    * other than just a NodeTest or just a qname.
    *  @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a> 
    */
-  public static final XNumber SCORE_OTHER =
-    new XNumber(XPath.MATCH_SCORE_OTHER);
+  public static final XDouble SCORE_OTHER =
+    new XDouble(XPath.MATCH_SCORE_OTHER);
 
   /**
    * The match score if no match is made.
    *  @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification - 5.5 Conflict Resolution for Template Rules</a> 
    */
-  public static final XNumber SCORE_NONE =
-    new XNumber(XPath.MATCH_SCORE_NONE);
+  public static final XDouble SCORE_NONE =
+    new XDouble(XPath.MATCH_SCORE_NONE);
 
-  /**
-   * Construct an NodeTest that tests for namespaces and node names.
-   *
-   *
-   * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
-   * @param namespace The namespace to be tested.
-   * @param name The local name to be tested.
-   */
-  public NodeTest(int whatToShow, String namespace, String name)
-  {
-    initNodeTest(whatToShow, namespace, name);
-  }
-
-  /**
-   * Construct an NodeTest that doesn't test for node names.
-   *
-   *
-   * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
-   */
-  public NodeTest(int whatToShow)
-  {
-    initNodeTest(whatToShow);
-  }
+//  /**
+//   * Construct an NodeTest that tests for namespaces and node names.
+//   *
+//   *
+//   * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
+//   * @param namespace The namespace to be tested.
+//   * @param name The local name to be tested.
+//   */
+//  public NodeTest(int whatToShow, String namespace, String name)
+//  {
+//    initNodeTest(whatToShow, namespace, name);
+//  }
+//
+//  /**
+//   * Construct an NodeTest that doesn't test for node names.
+//   *
+//   *
+//   * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
+//   */
+//  public NodeTest(int whatToShow)
+//  {
+//    initNodeTest(whatToShow);
+//  }
   
   /**
    * @see Expression#deepEquals(Expression)
@@ -334,13 +334,13 @@
    * True if this test has a null namespace and a local name of {@link #WILD}.
    *  @serial 
    */
-  private boolean m_isTotallyWild;
+  boolean m_isTotallyWild;
   
   /**
    * Get the static score for this node test.
    * @return Should be one of the SCORE_XXX constants.
    */
-  public XNumber getStaticScore()
+  public XDouble getStaticScore()
   {
     return m_score;
   }
@@ -349,7 +349,7 @@
    * Set the static score for this node test.
    * @param score Should be one of the SCORE_XXX constants.
    */
-  public void setStaticScore(XNumber score)
+  public void setStaticScore(XDouble score)
   {
     m_score = score;
   }
@@ -715,7 +715,7 @@
   /**
    * Node tests by themselves do not need to fix up variables.
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
     // no-op
   }
diff --git a/src/org/apache/xpath/patterns/StepPattern.java b/src/org/apache/xpath/patterns/StepPattern.java
index 6dc4244..b055eaf 100644
--- a/src/org/apache/xpath/patterns/StepPattern.java
+++ b/src/org/apache/xpath/patterns/StepPattern.java
@@ -56,6 +56,11 @@
  */
 package org.apache.xpath.patterns;
 
+import java.io.ByteArrayOutputStream;
+import java.io.CharArrayWriter;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
 import java.util.Vector;
 
 import javax.xml.transform.TransformerException;
@@ -64,12 +69,16 @@
 import org.apache.xml.dtm.DTMAxisTraverser;
 import org.apache.xml.dtm.DTMFilter;
 import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
 import org.apache.xpath.axes.SubContextList;
-import org.apache.xpath.compiler.PsuedoNames;
 import org.apache.xpath.objects.XObject;
+import org.apache.xpath.parser.Node;
+import org.apache.xpath.parser.PatternAxis;
+import org.apache.xpath.parser.Predicates;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -79,48 +88,86 @@
 {
 
   /** The axis for this test. */
-  protected int m_axis;
+  protected int m_axis = org.apache.xml.dtm.Axis.SELF;
+
+//  /**
+//   * Construct a StepPattern that tests for namespaces and node names.
+//   *
+//   *
+//   * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
+//   * @param namespace The namespace to be tested.
+//   * @param name The local name to be tested.
+//   * @param axis The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
+//   * @param axisForPredicate No longer used.
+//   */
+//  public StepPattern(int whatToShow, String namespace, String name, int axis,
+//                     int axisForPredicate)
+//  {
+//
+//    super(whatToShow, namespace, name);
+//
+//    m_axis = axis;
+//  }
+//
+//  /**
+//   * Construct a StepPattern that doesn't test for node names.
+//   *
+//   *
+//   * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
+//   * @param axis The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
+//   * @param axisForPredicate No longer used.
+//   */
+//  public StepPattern(int whatToShow, int axis, int axisForPredicate)
+//  {
+//
+//    super(whatToShow);
+//
+//    m_axis = axis;
+//  }
 
   /**
-   * Construct a StepPattern that tests for namespaces and node names.
-   *
-   *
-   * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
-   * @param namespace The namespace to be tested.
-   * @param name The local name to be tested.
-   * @param axis The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
-   * @param axisForPredicate No longer used.
+   * Construct a StepPattern.
    */
-  public StepPattern(int whatToShow, String namespace, String name, int axis,
-                     int axisForPredicate)
+  public StepPattern()
   {
-
-    super(whatToShow, namespace, name);
-
-    m_axis = axis;
   }
 
-  /**
-   * Construct a StepPattern that doesn't test for node names.
-   *
-   *
-   * @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
-   * @param axis The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
-   * @param axisForPredicate No longer used.
-   */
-  public StepPattern(int whatToShow, int axis, int axisForPredicate)
-  {
-
-    super(whatToShow);
-
-    m_axis = axis;
-  }
 
   /**
    * The target local name or psuedo name, for hash table lookup optimization.
    *  @serial
    */
   String m_targetString;  // only calculate on head
+  
+  /**
+   * Psuedo name for a wild card pattern ('*').
+   */
+  public static final String PSEUDONAME_ANY = "*";
+
+  /**
+   * Psuedo name for the root node.
+   */
+  public static final String PSEUDONAME_ROOT = "/";
+
+  /**
+   * Psuedo name for a text node.
+   */
+  public static final String PSEUDONAME_TEXT = "#text";
+
+  /**
+   * Psuedo name for a comment node.
+   */
+  public static final String PSEUDONAME_COMMENT = "#comment";
+
+  /**
+   * Psuedo name for a processing instruction node.
+   */
+  public static final String PSEUDONAME_PI = "#pi";
+
+  /**
+   * Psuedo name for an unknown type value.
+   */
+  public static final String PSEUDONAME_OTHER = "*";
 
   /**
    * Calculate the local name or psuedo name of the node that this pattern will test,
@@ -136,28 +183,28 @@
     switch (whatToShow)
     {
     case DTMFilter.SHOW_COMMENT :
-      m_targetString = PsuedoNames.PSEUDONAME_COMMENT;
+      m_targetString = PSEUDONAME_COMMENT;
       break;
     case DTMFilter.SHOW_TEXT :
     case DTMFilter.SHOW_CDATA_SECTION :
     case (DTMFilter.SHOW_TEXT | DTMFilter.SHOW_CDATA_SECTION) :
-      m_targetString = PsuedoNames.PSEUDONAME_TEXT;
+      m_targetString = PSEUDONAME_TEXT;
       break;
     case DTMFilter.SHOW_ALL :
-      m_targetString = PsuedoNames.PSEUDONAME_ANY;
+      m_targetString = PSEUDONAME_ANY;
       break;
     case DTMFilter.SHOW_DOCUMENT :
     case DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT :
-      m_targetString = PsuedoNames.PSEUDONAME_ROOT;
+      m_targetString = PSEUDONAME_ROOT;
       break;
     case DTMFilter.SHOW_ELEMENT :
       if (this.WILD == m_name)
-        m_targetString = PsuedoNames.PSEUDONAME_ANY;
+        m_targetString = PSEUDONAME_ANY;
       else
         m_targetString = m_name;
       break;
     default :
-      m_targetString = PsuedoNames.PSEUDONAME_ANY;
+      m_targetString = PSEUDONAME_ANY;
       break;
     }
   }
@@ -193,22 +240,22 @@
    * to be offset to the current stack frame).
    * @param globalsSize The number of variables in the global variable area.
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
 
-    super.fixupVariables(vars, globalsSize);
+    super.fixupVariables(vcs);
 
     if (null != m_predicates)
     {
       for (int i = 0; i < m_predicates.length; i++)
       {
-        m_predicates[i].fixupVariables(vars, globalsSize);
+        m_predicates[i].fixupVariables(vcs);
       }
     }
 
     if (null != m_relativePathPattern)
     {
-      m_relativePathPattern.fixupVariables(vars, globalsSize);
+      m_relativePathPattern.fixupVariables(vcs);
     }
   }
 
@@ -345,6 +392,9 @@
     }
     else
       super.calcScore();
+      
+    if(null != m_relativePathPattern)
+      m_relativePathPattern.calcScore();
 
     if (null == m_targetString)
       calcTargetString();
@@ -814,11 +864,24 @@
 
     return result;
   }
+  
+  /** This method returns a child node.  The children are numbered
+     from zero, left to right. */
+  public ExpressionNode exprGetChild(int i)
+  {
+  	assertion(i == 0, "StepPattern can only have one child!");
+  	return m_relativePathPattern;
+  }
+
+  /** Return the number of children the node has. */
+  public int exprGetNumChildren()
+  {
+  	return (null == m_relativePathPattern) ? 0 : 1;
+  }
 
   /**
    * Get the string represenentation of this step for diagnostic purposes.
    *
-   *
    * @return A string representation of this step, built by reverse-engineering 
    * the contained info.
    */
@@ -826,8 +889,9 @@
   {
 
     StringBuffer buf = new StringBuffer();
-
-    for (StepPattern pat = this; pat != null; pat = pat.m_relativePathPattern)
+	
+	  StepPattern pat = this;
+    // for (StepPattern pat = this; pat != null; pat = pat.m_relativePathPattern)
     {
       if (pat != this)
         buf.append("/");
@@ -901,7 +965,11 @@
         for (int i = 0; i < pat.m_predicates.length; i++)
         {
           buf.append("[");
-          buf.append(pat.m_predicates[i]);
+          ByteArrayOutputStream baos = new ByteArrayOutputStream();
+          PrintStream ps = new PrintStream(baos);
+          pat.m_predicates[i].dump("  ", ps);
+          ps.close();
+          buf.append(baos.toString());
           buf.append("]");
         }
       }
@@ -1053,6 +1121,56 @@
   }
   
   /**
+   * This method is called by the parser to add the PatternAxis, 
+   * NodeTest, and Predicates.  We only use the node the populate 
+   * the fields of this class.
+   */
+  public void jjtAddChild(org.apache.xpath.parser.Node n, int index) 
+  {
+    if(n instanceof org.apache.xpath.parser.PatternAxis)
+    {
+    	m_axis = ((org.apache.xpath.parser.PatternAxis)n).getAxis();
+    	if(Axis.ATTRIBUTE == m_axis)
+    	{
+    		m_whatToShow = DTMFilter.SHOW_ATTRIBUTE;
+    		if(0 == index)
+    			m_axis = Axis.SELF;
+    	}
+    } 
+    else if(n instanceof org.apache.xpath.parser.NodeTest)
+    {
+    	org.apache.xpath.parser.NodeTest ntest = (org.apache.xpath.parser.NodeTest)n;
+    	m_isTotallyWild = ntest.isTotallyWild();
+    	m_namespace = ntest.getNamespaceURI();
+    	m_name = ntest.getLocalName();
+    	if(Axis.ATTRIBUTE == m_axis)
+    		m_whatToShow = DTMFilter.SHOW_ATTRIBUTE;
+    	else
+    		m_whatToShow = ntest.getWhatToShow();
+    }
+    else if(n instanceof org.apache.xpath.parser.Predicates)
+    {
+    	Vector preds = ((org.apache.xpath.parser.Predicates)n).getPreds();
+    	if(null != preds)
+    	{
+    		int nPreds = preds.size();
+    		m_predicates = new Expression[nPreds];
+    		for(int i = 0; i < nPreds; i++)
+    		{
+    			m_predicates[i] = (Expression)preds.elementAt(i);
+    		}
+    		
+    	}
+    }
+    else
+    {
+    	// Assertion, should never happen.
+    	throw new RuntimeException("node can only be a QName or Wildcard!");
+    }
+  }
+
+  
+  /**
    * @see Expression#deepEquals(Expression)
    */
   public boolean deepEquals(Expression expr)
@@ -1088,4 +1206,12 @@
   }
 
 
+  /**
+   * @see org.apache.xpath.parser.Node#jjtClose()
+   */
+  public void jjtClose()
+  {
+    super.jjtClose();
+  }
+
 }
diff --git a/src/org/apache/xpath/patterns/UnionPattern.java b/src/org/apache/xpath/patterns/UnionPattern.java
index dac9456..6c838d9 100644
--- a/src/org/apache/xpath/patterns/UnionPattern.java
+++ b/src/org/apache/xpath/patterns/UnionPattern.java
@@ -60,10 +60,14 @@
 
 import javax.xml.transform.TransformerException;
 import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
 import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
 import org.apache.xpath.XPathContext;
 import org.apache.xpath.XPathVisitor;
 import org.apache.xpath.objects.XObject;
+import org.apache.xpath.parser.Node;
+import org.apache.xpath.parser.Pattern;
 
 /**
  * <meta name="usage" content="advanced"/>
@@ -75,16 +79,16 @@
 
   /** Array of the contained step patterns to be tested.
    *  @serial  */
-  private StepPattern[] m_patterns;
+  private ExpressionNode[] m_patterns;
   
   /**
    * No arguments to process, so this does nothing.
    */
-  public void fixupVariables(java.util.Vector vars, int globalsSize)
+  public void fixupVariables(VariableComposeState vcs)
   {
     for (int i = 0; i < m_patterns.length; i++) 
     {
-      m_patterns[i].fixupVariables(vars, globalsSize);
+      ((Expression)m_patterns[i]).fixupVariables(vcs);
     }
   }
 
@@ -102,7 +106,7 @@
       int n = m_patterns.length;
       for (int i = 0; i < n; i++) 
       {
-        if(m_patterns[i].canTraverseOutsideSubtree())
+        if(((StepPattern)m_patterns[i]).canTraverseOutsideSubtree())
           return true;
       }
      }
@@ -127,6 +131,88 @@
     }
     
   }
+  
+  /** This method tells the node to add its argument to the node's
+    list of children.  */
+  public void exprAddChild(ExpressionNode n, int i)
+  {
+  	
+  	if(null == m_patterns)
+  	{
+  		m_patterns = new ExpressionNode[i+1];
+  	}
+  	if(i >= m_patterns.length)
+  	{
+   		ExpressionNode newPats[] = new ExpressionNode[i+1];
+  		System.arraycopy(m_patterns, 0, newPats, 0, m_patterns.length);
+  		m_patterns = newPats;
+  		
+  	}
+    m_patterns[i] = n;
+  }
+  
+  public void jjtAddChild(org.apache.xpath.parser.Node n, int i) 
+  {
+  	if(n instanceof UnionPattern)
+  	{
+  		// Undo the work of having the unions as binary operators.
+  		// Certainly, this makes no sense for match patters.
+  		UnionPattern up = (UnionPattern)n;
+  		int count = up.jjtGetNumChildren();
+  		for(int j = 0; j < count; j++)
+  		{
+  			n = up.jjtGetChild(j);
+  			if(n instanceof Pattern)
+		  	{
+		  		n = n.jjtGetChild(0);
+		  		// n.jjtSetParent(this);  // Called in jjtClose
+		  	}
+
+  			exprAddChild((ExpressionNode)n, i+j);
+  		}
+  	}
+  	else
+  	{
+  		if(n instanceof Pattern)
+		{
+		  	n = n.jjtGetChild(0);
+		  	// n.jjtSetParent(this); // Called in jjtClose
+		}
+    	exprAddChild((ExpressionNode)n, i);
+  	}
+  }
+    
+  /** This method returns a child node.  The children are numbered
+     from zero, left to right. */
+  public ExpressionNode exprGetChild(int i)
+  {
+  	return m_patterns[i];
+  }
+
+  /** Return the number of children the node has. */
+  public int exprGetNumChildren()
+  {
+  	if(null == m_patterns)
+  	{
+  		return 0;
+  	}
+  	else 
+  	{
+  		return m_patterns.length;
+  	}
+  }
+  
+  public void jjtClose() 
+  {
+  	super.jjtClose();
+  	int childCount = jjtGetNumChildren();
+  	for(int i = 0; i < childCount; i++)
+  	{
+  		Node child = jjtGetChild(i);
+  		child.jjtSetParent(this);
+  	}
+  }
+
 
   /**
    * Get the contained step patterns to be tested. 
@@ -134,9 +220,9 @@
    *
    * @return an array of the contained step patterns to be tested. 
    */
-  public StepPattern[] getPatterns()
+  public ExpressionNode[] getPatterns()
   {
-    return m_patterns;
+    return (ExpressionNode[])m_patterns;
   }
 
   /**
@@ -160,7 +246,7 @@
 
     for (int i = 0; i < n; i++)
     {
-      XObject score = m_patterns[i].execute(xctxt);
+      XObject score = ((Expression)m_patterns[i]).execute(xctxt);
 
       if (score != NodeTest.SCORE_NONE)
       {
@@ -193,7 +279,7 @@
      */
     public Expression getExpression()
     {
-      return m_patterns[m_index];
+      return (Expression)m_patterns[m_index];
     }
 
 
@@ -218,7 +304,7 @@
   		int n = m_patterns.length;
   		for(int i = 0; i < n; i++)
   		{
-  			m_patterns[i].callVisitors(new UnionPathPartOwner(i), visitor);
+  			((Expression)m_patterns[i]).callVisitors(new UnionPathPartOwner(i), visitor);
   		}
   	}
   }
@@ -241,7 +327,7 @@
   			
   		for(int i = 0; i < n; i++)
   		{
-  			if(!m_patterns[i].deepEquals(up.m_patterns[i]))
+  			if(!((Expression)m_patterns[i]).deepEquals((Expression)up.m_patterns[i]))
   				return false;
   		}
   	}
diff --git a/src/org/apache/xpath/quantified/Every.java b/src/org/apache/xpath/quantified/Every.java
new file mode 100644
index 0000000..4686cbe
--- /dev/null
+++ b/src/org/apache/xpath/quantified/Every.java
@@ -0,0 +1,77 @@
+/* Generated By:JJTree: Do not edit this line. Every.java */
+
+package org.apache.xpath.quantified;
+
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.parser.XPath;
+
+public class Every extends Expression implements ExpressionOwner
+{
+	
+  public Every() {
+    super();
+  }
+
+  /** Accept the visitor. **/
+  public Object jjtAccept(org.apache.xpath.parser.XPathVisitor visitor, Object data) {
+    return visitor.visit(this, data);
+  }
+  
+  /**
+   * @see Expression#deepEquals(Expression)
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    return false;
+  }
+
+  /**
+   * @see Expression#fixupVariables(Vector, int)
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+  }
+
+
+  /**
+   * @see Expression#execute(XPathContext)
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+    return null;
+  }
+
+
+  /**
+   * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
+   */
+  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
+  {
+  }
+
+
+  /**
+   * @see ExpressionOwner#getExpression()
+   */
+  public Expression getExpression()
+  {
+    return null;
+  }
+
+
+  /**
+   * @see ExpressionOwner#setExpression(Expression)
+   */
+  public void setExpression(Expression exp)
+  {
+  }
+
+
+}
diff --git a/src/org/apache/xpath/quantified/In.java b/src/org/apache/xpath/quantified/In.java
new file mode 100644
index 0000000..3455c9e
--- /dev/null
+++ b/src/org/apache/xpath/quantified/In.java
@@ -0,0 +1,76 @@
+/* Generated By:JJTree: Do not edit this line. In.java */
+
+package org.apache.xpath.quantified;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+public class In extends Expression implements ExpressionOwner
+{
+	
+  public In() {
+    super();
+  }
+
+  /** Accept the visitor. **/
+  public Object jjtAccept(org.apache.xpath.parser.XPathVisitor visitor, Object data) {
+    return visitor.visit(this, data);
+  }
+  
+  /**
+   * @see Expression#deepEquals(Expression)
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    return false;
+  }
+
+  /**
+   * @see Expression#fixupVariables(Vector, int)
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+  }
+
+
+  /**
+   * @see Expression#execute(XPathContext)
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+    return null;
+  }
+
+
+  /**
+   * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
+   */
+  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
+  {
+  }
+
+
+  /**
+   * @see ExpressionOwner#getExpression()
+   */
+  public Expression getExpression()
+  {
+    return null;
+  }
+
+
+  /**
+   * @see ExpressionOwner#setExpression(Expression)
+   */
+  public void setExpression(Expression exp)
+  {
+  }
+
+
+}
diff --git a/src/org/apache/xpath/quantified/Satisfies.java b/src/org/apache/xpath/quantified/Satisfies.java
new file mode 100644
index 0000000..2cec42c
--- /dev/null
+++ b/src/org/apache/xpath/quantified/Satisfies.java
@@ -0,0 +1,76 @@
+/* Generated By:JJTree: Do not edit this line. Satisfies.java */
+
+package org.apache.xpath.quantified;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+public class Satisfies extends Expression implements ExpressionOwner
+{
+	
+  public Satisfies() {
+    super();
+  }
+
+  /** Accept the visitor. **/
+  public Object jjtAccept(org.apache.xpath.parser.XPathVisitor visitor, Object data) {
+    return visitor.visit(this, data);
+  }
+  
+  /**
+   * @see Expression#deepEquals(Expression)
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    return false;
+  }
+
+  /**
+   * @see Expression#fixupVariables(Vector, int)
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+  }
+
+
+  /**
+   * @see Expression#execute(XPathContext)
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+    return null;
+  }
+
+
+  /**
+   * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
+   */
+  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
+  {
+  }
+
+
+  /**
+   * @see ExpressionOwner#getExpression()
+   */
+  public Expression getExpression()
+  {
+    return null;
+  }
+
+
+  /**
+   * @see ExpressionOwner#setExpression(Expression)
+   */
+  public void setExpression(Expression exp)
+  {
+  }
+
+
+}
diff --git a/src/org/apache/xpath/quantified/Some.java b/src/org/apache/xpath/quantified/Some.java
new file mode 100644
index 0000000..c9761e8
--- /dev/null
+++ b/src/org/apache/xpath/quantified/Some.java
@@ -0,0 +1,70 @@
+/* Generated By:JJTree: Do not edit this line. Some.java */
+
+package org.apache.xpath.quantified;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+
+public class Some extends Expression implements ExpressionOwner
+{
+	
+  public Some() {
+    super();
+  }
+
+  /** Accept the visitor. **/
+  public Object jjtAccept(org.apache.xpath.parser.XPathVisitor visitor, Object data) {
+    return visitor.visit(this, data);
+  }
+  
+  /**
+   * @see Expression#deepEquals(Expression)
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    return false;
+  }
+  /**
+   * @see Expression#fixupVariables(Vector, int)
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+  }
+
+  /**
+   * @see Expression#execute(XPathContext)
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+    return null;
+  }
+
+  /**
+   * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
+   */
+  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
+  {
+  }
+
+  /**
+   * @see ExpressionOwner#getExpression()
+   */
+  public Expression getExpression()
+  {
+    return null;
+  }
+
+  /**
+   * @see ExpressionOwner#setExpression(Expression)
+   */
+  public void setExpression(Expression exp)
+  {
+  }
+
+}
diff --git a/src/org/apache/xpath/res/XPATHErrorResources.java b/src/org/apache/xpath/res/XPATHErrorResources.java
index 7084ad9..2cff2e9 100644
--- a/src/org/apache/xpath/res/XPATHErrorResources.java
+++ b/src/org/apache/xpath/res/XPATHErrorResources.java
@@ -464,68 +464,7 @@
   
 // Variable accessed before it is bound!
   public static final int ER_VARIABLE_ACCESSED_BEFORE_BIND = 85;
-  
-  // XStringForFSB can not take a string for an argument!
-  public static final int ER_FSB_CANNOT_TAKE_STRING = 86;
-  
-  // Error! Setting the root of a walker to null!
-  public static final int ER_SETTING_WALKER_ROOT_TO_NULL = 87;
-  
-  // This NodeSetDTM can not iterate to a previous node!
-  public static final int ER_NODESETDTM_CANNOT_ITERATE = 88;
-  
-  // This NodeSet can not iterate to a previous node!
-  public static final int ER_NODESET_CANNOT_ITERATE = 89;
 
-  // This NodeSetDTM can not do indexing or counting functions!
-  public static final int ER_NODESETDTM_CANNOT_INDEX = 90;
-  
-  // This NodeSet can not do indexing or counting functions!
-  public static final int ER_NODESET_CANNOT_INDEX = 91;
-
-  // Can not call setShouldCacheNodes after nextNode has been called!
-  public static final int ER_CANNOT_CALL_SETSHOULDCACHENODE = 92;
-  
-  // {0} only allows {1} arguments
-  public static final int ER_ONLY_ALLOWS = 93;
-  
-  // Programmer's assertion in getNextStepPos: unknown stepType: {0}
-  public static final int ER_UNKNOWN_STEP = 94;
-  
-  /** Problem with RelativeLocationPath */
-  public static final int ER_EXPECTED_REL_LOC_PATH = 95;
-
-
-   /** Problem with LocationPath */
-  public static final int ER_EXPECTED_LOC_PATH = 96;
-
-
-   /** Problem with Step */
-  public static final int ER_EXPECTED_LOC_STEP = 97;
-
-
-   /** Problem with NodeTest */
-  public static final int ER_EXPECTED_NODE_TEST = 98;
-
-
-   /** Expected step pattern */
-  public static final int ER_EXPECTED_STEP_PATTERN = 99;
-
-  
-   /** Expected relative path pattern */
-  public static final int ER_EXPECTED_REL_PATH_PATTERN = 100;
-  
-  /** localname in QNAME should be a valid NCName */  
-  public static final int ER_ARG_LOCALNAME_INVALID = 101;
-
-  /** prefix in QNAME should be a valid NCName */
-  public static final int ER_ARG_PREFIX_INVALID = 102;
-
- 
-
-
-
-  
   // Warnings...
 
   /** Field WG_LOCALE_NAME_NOT_HANDLED          */
diff --git a/src/org/apache/xpath/res/XPATHErrorResources.properties b/src/org/apache/xpath/res/XPATHErrorResources.properties
index bafeda2..b749e7a 100644
--- a/src/org/apache/xpath/res/XPATHErrorResources.properties
+++ b/src/org/apache/xpath/res/XPATHErrorResources.properties
@@ -176,41 +176,6 @@
 ER0084=2 or 3
 # ER_VARIABLE_ACCESSED_BEFORE_BIND
 ER0085=Variable accessed before it is bound!
-# ER_FSB_CANNOT_TAKE_STRING 
-ER0086=XStringForFSB can not take a string for an argument!
-# ER_SETTING_WALKER_ROOT_T)_NULL 
-ER0087=\n !!!! Error! Setting the root of a walker to null!!!
-# ER_NODESETDTM_CANNOT_ITERATE
-ER0088=This NodeSetDTM can not iterate to a previous node!
-# ER_NODESET_CANNOT_ITERATE
-ER0089=This NodeSet can not iterate to a previous node!
-# ER_NODESETDTM_CANNOT_INDEX
-ER0090=This NodeSetDTM can not do indexing or counting functions!
-# ER_NODESET_CANNOT_INDEX
-ER0091=This NodeSet can not do indexing or counting functions!
-# ER_CANNOT_CALL_SETSHOULDCACHENODE
-ER0092=Can not call setShouldCacheNodes after nextNode has been called!
-# ER_ONLY_ALLOWS
-ER0093={0} only allows {1} arguments
-# ER_UNKNOWN_STEP
-ER0094=Programmer's assertion in getNextStepPos: unknown stepType: {0}
-# ER_EXPECTED_REL_LOC_PATH
-ER0095=A relative location path was expected following the '/' or '//' token.
-# ER_EXPECTED_LOC_PATH
-ER0096=A location path was expected, but the following token was encountered\u003a  {0}
-# ER_EXPECTED_LOC_STEP
-ER0097=A location step was expected following the '/' or '//' token.
-# ER_EXPECTED_NODE_TEST
-ER0098=A node test that matches either NCName:* or QName was expected.
-# ER_EXPECTED_STEP_PATTERN
-ER0099=A step pattern was expected, but '/' was encountered.
-# ER_EXPECTED_REL_PATH_PATTERN
-ER0100=A relative path pattern was expected.
-# ER_ARG_LOCALNAME_INVALID
-ER0101= Localname in QNAME should be a valid NCName   
-# ER_ARG_PREFIX_INVALID
-ER0102=Prefix in QNAME should be a valid NCName 
-
 
 # WG_LOCALE_NAME_NOT_HANDLED 
 WR0001=locale name in the format-number function not yet handled!
diff --git a/src/org/apache/xpath/seqctor/Binding.java b/src/org/apache/xpath/seqctor/Binding.java
new file mode 100644
index 0000000..3b1f36b
--- /dev/null
+++ b/src/org/apache/xpath/seqctor/Binding.java
@@ -0,0 +1,117 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.seqctor;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.operations.Variable;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 19, 2002
+ * @author sboag
+ */
+public class Binding
+{
+  private Variable m_var;
+  private Expression m_expr;
+
+  /**
+   * Constructor for Binding.
+   */
+  public Binding()
+  {
+    super();
+  }
+
+  /**
+   * Returns the expr.
+   * @return Expression
+   */
+  public Expression getExpr()
+  {
+    return m_expr;
+  }
+
+  /**
+   * Returns the var.
+   * @return Variable
+   */
+  public Variable getVar()
+  {
+    return m_var;
+  }
+
+  /**
+   * Sets the expr.
+   * @param expr The expr to set
+   */
+  public void setExpr(Expression expr)
+  {
+    m_expr = expr;
+  }
+
+  /**
+   * Sets the var.
+   * @param var The var to set
+   */
+  public void setVar(Variable var)
+  {
+    m_var = var;
+  }
+
+}
diff --git a/src/org/apache/xpath/seqctor/ExprSequence.java b/src/org/apache/xpath/seqctor/ExprSequence.java
new file mode 100644
index 0000000..3940c21
--- /dev/null
+++ b/src/org/apache/xpath/seqctor/ExprSequence.java
@@ -0,0 +1,126 @@
+/* Generated By:JJTree: Do not edit this line. ExprSequence.java */
+
+package org.apache.xpath.seqctor;
+
+import java.util.Vector;
+
+import javax.xml.transform.TransformerException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.parser.Node;
+import org.apache.xpath.parser.Token;
+
+public class ExprSequence extends Expression implements ExpressionOwner
+{
+	
+  Vector m_exprs = new Vector();
+	
+  public void jjtAddChild(Node n, int i) 
+  {
+  	n = fixupPrimarys(n);
+    if(null == m_exprs)
+    	m_exprs  = new Vector();
+  	if(i >= m_exprs.size())
+  	{
+  		m_exprs.setSize(i+1);
+  	}
+    m_exprs.setElementAt(n, i);
+  }
+  
+  public Node jjtGetChild(int i) 
+  {
+    if(null == m_exprs)
+    	return null;
+    else
+    	return (Node)m_exprs.elementAt(i);
+  }
+
+  public int jjtGetNumChildren() 
+  {
+    if(null == m_exprs)
+    	return 0;
+    else
+    	return m_exprs.size();
+  }
+  
+
+  /**
+   * @see Expression#deepEquals(Expression)
+   * Dummy stub.
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    return false;
+  }
+
+
+  /**
+   * @see Expression#fixupVariables(Vector, int)
+   * Dummy stub.
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+    Vector exprs = m_exprs;
+    int vsize = exprs.size();
+    for (int i = 0; i < vsize; i++)
+    {
+      Expression val = (Expression)exprs.elementAt(i);
+      val.fixupVariables(vcs);
+    }
+  }
+
+
+  /**
+   * @see Expression#execute(XPathContext)
+   * Dummy stub.
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+    return new ExprSequenceIter(m_exprs, xctxt);
+  }
+
+
+  /**
+   * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
+   * Dummy stub.
+   */
+  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
+  {
+  }
+
+
+  /**
+   * @see ExpressionOwner#getExpression()
+   */
+  public Expression getExpression()
+  {
+    return null;
+  }
+
+  /**
+   * @see ExpressionOwner#setExpression(Expression)
+   */
+  public void setExpression(Expression exp)
+  {
+  }
+  
+  /**
+   * @see SimpleNode#shouldReduceIfOneChild()
+   */
+  public boolean shouldReduceIfOneChild()
+  {
+    return (jjtGetNumChildren() == 1) ? true : false;
+  }
+  /**
+   * @see org.apache.xpath.parser.SimpleNode#isPathExprReduced()
+   */
+  public boolean isPathExprReduced()
+  {
+    return (null == m_exprs) ? false : true;
+  }
+
+}
diff --git a/src/org/apache/xpath/seqctor/ExprSequenceIter.java b/src/org/apache/xpath/seqctor/ExprSequenceIter.java
new file mode 100644
index 0000000..c13f2d0
--- /dev/null
+++ b/src/org/apache/xpath/seqctor/ExprSequenceIter.java
@@ -0,0 +1,157 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.seqctor;
+
+import java.util.Vector;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.utils.WrappedRuntimeException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XSequence;
+import org.apache.xpath.objects.XSequenceCachedBase;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 20, 2002
+ * @author sboag
+ */
+public class ExprSequenceIter extends XSequenceCachedBase
+{
+  protected Vector m_exprs;
+  // XSequence[] m_xsequences;
+  int m_exprsIndex = 0;
+  private XSequence m_containedIterator;
+  private XObject m_contextItem;
+  
+  /**
+   * Constructor for ExprSequenceIter.
+   */
+  public ExprSequenceIter(Vector exprs, XPathContext xctxt)
+  {
+    super(xctxt);
+    this.setShouldCache(true); // for now!
+    m_exprs = exprs;
+    m_contextItem = xctxt.getCurrentItem();
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getNext()
+   */
+  public XObject getNext()
+  {
+      XObject xobj;
+      try
+      {
+        m_xctxt.pushCurrentItem(m_contextItem);
+        if (null != m_containedIterator)
+        {
+          xobj = m_containedIterator.next();
+          if (null != xobj)
+          {
+            return xobj;
+          }
+          else
+          {
+            m_containedIterator = null;
+          }
+        }
+
+        if (m_exprsIndex >= m_exprs.size())
+          return null;
+        Expression expr = (Expression) m_exprs.elementAt(m_exprsIndex);
+        m_exprsIndex++;
+        xobj = expr.execute(m_xctxt);
+        if (xobj.isSequenceProper())
+        {
+          m_containedIterator = (XSequence) xobj;
+          return getNext();
+        }
+        else
+          return xobj;
+      }
+      catch (TransformerException e)
+      {
+        throw new WrappedRuntimeException(e);
+      }
+      finally
+      {
+        m_xctxt.popCurrentItem();
+      }
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getPrevious()
+   */
+  public XObject getPrevious()
+  {
+    throw new RuntimeException("ExprSequence can not go backwards without cacheing!");
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#reset()
+   */
+  public void reset()
+  {
+    super.reset();
+    m_exprsIndex = 0;
+  }
+
+}
diff --git a/src/org/apache/xpath/seqctor/FLWRExpr.java b/src/org/apache/xpath/seqctor/FLWRExpr.java
new file mode 100644
index 0000000..faa363e
--- /dev/null
+++ b/src/org/apache/xpath/seqctor/FLWRExpr.java
@@ -0,0 +1,167 @@
+package org.apache.xpath.seqctor;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.utils.QName;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.operations.Variable;
+import org.apache.xpath.parser.Node;
+
+public class FLWRExpr extends Expression implements ExpressionOwner
+{
+  Binding[] m_bindings;
+  Expression m_return;
+
+  /**
+   * Constructor for FLWRExpr
+   */
+  public FLWRExpr()
+  {
+    super();
+  }
+
+  /**
+   * @see SimpleNode#shouldReduceIfOneChild()
+   */
+  public boolean shouldReduceIfOneChild()
+  {
+    return (jjtGetNumChildren() == 1) ? true : false;
+  }
+
+  /**
+   * @see org.apache.xpath.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
+   */
+  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
+  {
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#deepEquals(Expression)
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    return false;
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#execute(XPathContext)
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+    return new FLWRIter(m_bindings, m_return, xctxt);
+  }
+
+  /**
+   * @see org.apache.xpath.Expression#fixupVariables(Vector, int)
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+    vcs.pushStackMark();
+    Binding[] bindings = m_bindings;
+    int globalsSize = vcs.getGlobalsSize();
+    for (int i = 0; i < bindings.length; i++)
+    {
+      Binding binding = bindings[i];
+      binding.getExpr().fixupVariables(vcs);
+      Variable var = binding.getVar();
+      QName varName = var.getQName();
+      int index = vcs.addVariableName(varName) - globalsSize;
+      var.setIndex(index);
+      var.setFixUpWasCalled(true);
+      // var.fixupVariables(vcs);
+    }    
+    m_return.fixupVariables(vcs);
+    vcs.popStackMark();
+  }
+
+  /**
+   * @see org.apache.xpath.ExpressionOwner#getExpression()
+   */
+  public Expression getExpression()
+  {
+    return null;
+  }
+
+  /**
+   * @see org.apache.xpath.ExpressionOwner#setExpression(Expression)
+   */
+  public void setExpression(Expression exp)
+  {
+    m_return = exp;
+  }
+
+  /**
+   * Returns the r.
+   * @return Expression
+   */
+  public Expression getReturn()
+  {
+    return m_return;
+  }
+
+  /**
+   * Sets the inExprs.
+   * @param inExprs The inExprs to set
+   */
+  public void setBindings(Binding[] bindings)
+  {
+    m_bindings = bindings;
+  }
+
+  /**
+   * Sets the r.
+   * @param r The r to set
+   */
+  public void setReturn(Expression r)
+  {
+    m_return = r;
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtAddChild(Node, int)
+   */
+  public void jjtAddChild(Node n, int i)
+  {
+    if(null == m_bindings && 0 == i)
+      m_return = (Expression)fixupPrimarys(n); // Act like a construction node!
+    else if(i == 2)
+      m_return = (Expression)fixupPrimarys(n);
+  }
+  
+  
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtGetChild(int)
+   */
+  public Node jjtGetChild(int i)
+  {
+    if (i == jjtGetNumChildren() - 1)
+      return m_return;
+    else
+      if (null != m_bindings)
+      {
+        if ((i % 2) == 1)
+          return m_bindings[i / 2].getVar();
+        else
+          return m_bindings[i / 2].getExpr();
+      }
+      else
+        return null;
+  }
+
+  /**
+   * @see org.apache.xpath.parser.Node#jjtGetNumChildren()
+   */
+  public int jjtGetNumChildren()
+  {
+    return (((null != m_bindings) ? m_bindings.length : 0)*2)+
+      ((null != m_return) ? 1 : 0);
+  }
+
+}
+
diff --git a/src/org/apache/xpath/seqctor/FLWRIter.java b/src/org/apache/xpath/seqctor/FLWRIter.java
new file mode 100644
index 0000000..5c6257d
--- /dev/null
+++ b/src/org/apache/xpath/seqctor/FLWRIter.java
@@ -0,0 +1,227 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.seqctor;
+
+import java.util.Vector;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.utils.WrappedRuntimeException;
+import org.apache.xpath.Expression;
+import org.apache.xpath.VariableStack;
+import org.apache.xpath.XPath;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XNodeSequenceSingleton;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XSequence;
+import org.apache.xpath.objects.XSequenceCachedBase;
+import org.apache.xpath.objects.XSequenceSingleton;
+
+/**
+ * The FLWRIter must iterate over a set of variable bindings to 
+ * sequences, call an expression for each tuple, and return the 
+ * result.
+ * 
+ * Created Jul 19, 2002
+ * @author sboag
+ */
+public class FLWRIter extends XSequenceCachedBase implements XSequence
+{
+  private Binding[] m_bindings;
+  private XSequence[] m_evaluations;
+  private int m_lastNonNull;
+  private Expression m_returnExpr;
+  private XSequence m_containedIterator;
+  private XObject m_contextItem;
+  int m_evalPos = 0;
+
+  /**
+   * Constructor for FLWRIter.
+   */
+  public FLWRIter(Binding[] bindings, Expression returnExpr, XPathContext xctxt)
+  {
+    super(xctxt);
+    setShouldCache(true);
+    m_xctxt = xctxt;
+    m_returnExpr = returnExpr;
+    m_bindings = bindings;
+    int len = bindings.length;
+    m_evaluations = new XSequence[len];
+    
+    m_lastNonNull = len - 1; // Might not need this
+    
+    m_contextItem = xctxt.getCurrentItem();
+    boolean foundNonEmpty = false;
+        
+  }
+
+  /**
+   * Bind the next tuple of values to the variables.  The tuples are expressed 
+   * as sets within the cartesian product of the 'in' clauses (though note 
+   * that I'm not sure 'cartesian' is strictly good terminology, since it 
+   * applies to only two sets).
+   * @return XObject The last evaluation found, or null if 
+   * there's no more to evaluate.
+   */
+  public XObject evalVariables()
+  {
+    XSequence[] evals = m_evaluations;
+    VariableStack vars = m_xctxt.getVarStack();
+    XObject xobj = null;
+
+    for (int bindex = m_evalPos; bindex < evals.length; bindex++)
+    {
+      XSequence xseq = evals[bindex];
+      if (null == xseq)
+      {
+        try
+        {
+          Binding binding = m_bindings[bindex];
+          XObject result = binding.getExpr().execute(m_xctxt);
+          xseq = result.xseq();
+          m_evaluations[bindex] = xseq;
+        }
+        catch (TransformerException e)
+        {
+          throw new WrappedRuntimeException(e);
+        }
+      }
+      xobj = xseq.next();
+      if (null != xobj)
+      {
+        Binding binding = m_bindings[bindex];
+        int vindex = binding.getVar().getIndex();
+        vars.setLocalVariable(vindex, xobj);
+        m_evalPos = bindex;
+      }
+      else
+        if (bindex != 0)
+        {
+          // m_evalPos = bindex;
+          evals[bindex] = null;
+          bindex-=2;
+          // xseq.reset();
+        }
+        else
+        {
+          m_evalPos = evals.length;
+          break;
+        }
+    }
+    return xobj;
+  }
+    
+  /**
+   * @see org.apache.xpath.objects.XSequence#getNext()
+   */
+  protected XObject getNext()
+  {
+    XObject xobj;
+    if (null != m_containedIterator)
+    {
+      xobj = m_containedIterator.next();
+      if (null != xobj)
+      {
+        return xobj;
+      }
+      else
+        m_containedIterator = null;
+    }
+
+    m_xctxt.pushCurrentItem(m_contextItem);
+    try
+    {
+      if (null == evalVariables())
+        return null;
+      xobj = m_returnExpr.execute(m_xctxt);
+      if (xobj.isSequenceProper())
+      {
+        m_containedIterator = (XSequence) xobj;
+        return getNext();
+      }
+      else
+        return xobj;
+    }
+    catch (TransformerException e)
+    {
+      throw new WrappedRuntimeException(e);
+    }
+    finally
+    {
+      m_xctxt.popCurrentItem();
+    }
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getNext()
+   */
+  protected XObject getPrevious()
+  {
+    assertion(true, "getPrevious() not supported in the FLWRIter!");
+    return null;
+  }
+  
+  /**
+   * @return XSequence object.
+   * @see java.lang.Object#clone()
+   */
+  public Object clone() throws CloneNotSupportedException
+  {
+    return super.clone();
+  }
+
+}
diff --git a/src/org/apache/xpath/seqctor/RangeExpr.java b/src/org/apache/xpath/seqctor/RangeExpr.java
new file mode 100644
index 0000000..13a1481
--- /dev/null
+++ b/src/org/apache/xpath/seqctor/RangeExpr.java
@@ -0,0 +1,32 @@
+/* Generated By:JJTree: Do not edit this line. RangeExpr.java */
+
+package org.apache.xpath.seqctor;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.operations.OpFuncLookupTable;
+import org.apache.xpath.operations.Operation;
+
+public class RangeExpr extends Operation
+{
+  public RangeExpr() {
+    super();
+  }
+
+  /**
+   * @see Expression#execute(XPathContext)
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+    int from = m_left.execute(xctxt).integer();
+    int to = m_right.execute(xctxt).integer();
+    return new RangeIter(from, to);
+  }
+
+}
diff --git a/src/org/apache/xpath/seqctor/RangeIter.java b/src/org/apache/xpath/seqctor/RangeIter.java
new file mode 100644
index 0000000..1710625
--- /dev/null
+++ b/src/org/apache/xpath/seqctor/RangeIter.java
@@ -0,0 +1,319 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.seqctor;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xpath.objects.XInteger;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XSequence;
+
+/**
+ * The responsibility of enclosing_type is to .
+ * 
+ * Created Jul 23, 2002
+ * @author sboag
+ */
+public class RangeIter extends XObject implements XSequence
+{
+  private int m_from;
+  private int m_to;
+  private int m_pos;
+  private XObject m_current;
+  private Object m_obj;
+
+  /**
+   * Constructor for RangeIter.
+   */
+  public RangeIter(int from, int to)
+  {
+    super();
+    m_to = to;
+    m_from = from;
+    m_pos = from-1;
+  }
+
+  /**
+   * Constructor for RangeIter.
+   * @param obj
+   */
+  public RangeIter(Object obj)
+  {
+    //super(obj);
+    m_obj=obj;
+  }
+  
+  public Object object()
+  {
+  	return m_obj;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getTypes()
+   */
+  public int getTypes()
+  {
+    return 0;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#next()
+   */
+  public XObject next()
+  {
+    if (m_pos <= m_to)
+    {
+      m_pos++;
+      if (m_pos <= m_to)
+        return m_current = new XInteger(m_pos);
+      else
+        return m_current = null;
+    }
+    return m_current = null;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#previous()
+   */
+  public XObject previous()
+  {
+    if (m_pos >= m_from)
+    {
+      m_pos--;
+      if (m_pos >= m_from)
+        return m_current = new XInteger(m_pos);
+      else
+        return m_current = null;
+    }
+    else
+      return m_current = null;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getCurrent()
+   */
+  public XObject getCurrent()
+  {
+    return m_current;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isFresh()
+   */
+  public boolean isFresh()
+  {
+    return m_pos == m_from-1;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getTypeNS()
+   */
+  public String getTypeNS()
+  {
+    return XType.XMLSCHEMA_DATATYPE_NAMESPACE;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getTypeLocalName()
+   */
+  public String getTypeLocalName()
+  {
+    return XType.getLocalNameFromType(XType.INTEGER);
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isSchemaType(String, String)
+   */
+  public boolean isSchemaType(String namespace, String localname)
+  {
+    int type = XType.getTypeID(namespace, localname);
+    return type == XType.INTEGER;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isPureNodeSequence()
+   */
+  public boolean isPureNodeSequence()
+  {
+    return false;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#setShouldCache(boolean)
+   */
+  public void setShouldCache(boolean b)
+  {
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getIsRandomAccess()
+   */
+  public boolean getIsRandomAccess()
+  {
+    return true;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isMutable()
+   */
+  public boolean isMutable()
+  {
+    return false;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getCurrentPos()
+   */
+  public int getCurrentPos()
+  {
+    return m_pos-m_from;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#setCurrentPos(int)
+   */
+  public void setCurrentPos(int i)
+  {
+    m_pos = m_from+i;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#getLength()
+   */
+  public int getLength()
+  {
+    return m_to-m_from;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XSequence#isSingletonOrEmpty()
+   */
+  public boolean isSingletonOrEmpty()
+  {
+    return getLength() <= 1;
+  }
+  
+  /**
+   * @see java.lang.Object#clone()
+   */
+  public Object clone() throws CloneNotSupportedException
+  {
+    return super.clone();
+  }
+
+
+  /**
+   * Returns the from.
+   * @return int
+   */
+  public int getFrom()
+  {
+    return m_from;
+  }
+
+  /**
+   * Returns the to.
+   * @return int
+   */
+  public int getTo()
+  {
+    return m_to;
+  }
+
+  /**
+   * Sets the current.
+   * @param current The current to set
+   */
+  public void setCurrent(XObject current)
+  {
+    m_current = current;
+  }
+
+  /**
+   * Sets the from.
+   * @param from The from to set
+   */
+  public void setFrom(int from)
+  {
+    m_from = from;
+  }
+
+  /**
+   * Sets the to.
+   * @param to The to to set
+   */
+  public void setTo(int to)
+  {
+    m_to = to;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#isSequenceProper()
+   */
+  public boolean isSequenceProper()
+  {
+    return true;
+  }
+
+  /**
+   * @see org.apache.xpath.objects.XObject#xseq()
+   */
+  public XSequence xseq()
+  {
+    return this;
+  }
+
+}
diff --git a/src/org/apache/xpath/types/Atomizer.java b/src/org/apache/xpath/types/Atomizer.java
new file mode 100644
index 0000000..2807077
--- /dev/null
+++ b/src/org/apache/xpath/types/Atomizer.java
@@ -0,0 +1,139 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.types;
+
+import org.apache.xml.dtm.XType;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XSequence;
+
+/**
+ * Singleton class that handles automization.
+ * 
+ * Created Jul 30, 2002
+ * @author sboag
+ */
+public class Atomizer
+{
+  public static XObject makeAtom(XObject xobj)
+  {
+    if(XSequence.EMPTY == xobj)
+      return xobj;
+    else if(xobj.isSingletonOrEmpty())
+    {
+      return xobj;
+    }
+    else
+    {
+      XSequence xseq = xobj.xseq();
+      XObject first = xseq.next();
+      if(null == first)
+        return XSequence.EMPTY;
+      XObject second = xseq.next();
+      if(second != null)
+        return xobj;
+      // For now, could be node or atom.  Don't do any 
+      // type checks here.
+      return first;
+    }
+  }
+
+
+  public static XObject makeFallbackAtom(XObject xobj, int requiredType)
+  {
+    switch (requiredType)
+    {
+      case XType.ANYTYPE :
+      case XType.BOOLEAN :
+      case XType.DOUBLE :
+      case XType.STRING :
+      case XType.NODE :
+      case XType.RTREEFRAG :
+
+        // Callers should expect the actual values of these constants to 
+        // changed... i.e. they should not rely on the value itself.
+      case XType.BASE64BINARY :
+      case XType.HEXBINARY :
+      case XType.FLOAT :
+      case XType.DECIMAL :
+      case XType.INTEGER :
+      case XType.ANYURI :
+      case XType.QNAME :
+      case XType.NOTATION :
+      case XType.DURATION :
+      case XType.DATETIME :
+      case XType.TIME :
+      case XType.DATE :
+      case XType.GYEARMONTH :
+      case XType.GYEAR :
+      case XType.GMONTHDAY :
+      case XType.GDAY :
+      case XType.GMONTH :
+
+      case XType.YEARMONTHDURATION :
+      case XType.DAYTIMEDURATION :
+
+      case XType.ANYSIMPLETYPE :
+      case XType.EMPTYSEQ :
+
+        // Answer for a sequence when it hasn't iterated. -sb
+      case XType.SEQ :
+        break;
+      default :
+        }
+    return null;
+  }
+}
diff --git a/src/org/apache/xpath/types/InstanceofExpr.java b/src/org/apache/xpath/types/InstanceofExpr.java
new file mode 100644
index 0000000..01a7574
--- /dev/null
+++ b/src/org/apache/xpath/types/InstanceofExpr.java
@@ -0,0 +1,462 @@
+/* Generated By:JJTree: Do not edit this line. Instanceof.java */
+
+package org.apache.xpath.types;
+
+import java.io.PrintStream;
+import java.util.Vector;
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMFilter;
+import org.apache.xml.dtm.XType;
+import org.apache.xml.utils.QName;
+import org.apache.xpath.Expression;
+import org.apache.xpath.ExpressionNode;
+import org.apache.xpath.ExpressionOwner;
+import org.apache.xpath.VariableComposeState;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.XPathVisitor;
+import org.apache.xpath.objects.XBoolean;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XSequence;
+import org.apache.xpath.parser.Node;
+import org.apache.xpath.parser.SchemaContext;
+import org.apache.xpath.parser.SequenceType;
+import org.apache.xpath.parser.SimpleNode;
+import org.apache.xpath.parser.XPath;
+
+/**
+ * This class implements the "instance of" production for XPath 2.0.
+ * 
+ * <p>(For easy reference, until the spec is more stable...)</p>
+ * <pre>
+ * [9]    InstanceofExpr    ::=    {Expr} ( <"instance" "of"> SequenceType )? 
+ * [51]    SequenceType    ::=    (ItemType OccurrenceIndicator) |  "empty" 
+ * [52]    ItemType    ::=    (("element" |  "attribute") ElemOrAttrType?)
+ *                          |  "node"
+ *                          |  "processing-instruction"
+ *                          |  "comment"
+ *                          |  "text"
+ *                          |  "document"
+ *                          |  "item"
+ *                          |  AtomicType 
+ *                          |  "untyped"
+ *                          |  <"atomic" "value"> 
+ * [53]    ElemOrAttrType    ::=    (QName (SchemaType |  SchemaContext?)) |  SchemaType 
+ * [54]    SchemaType    ::=    <"of" "type"> QName 
+ * [55]    AtomicType    ::=    QName 
+ * [56]    OccurrenceIndicator    ::=    ("*" |  "+" |  "?")? 
+ * </pre>
+ * 
+ * <p>Notes to Joe: You can call just the parser to give a diagnostic dump 
+ * of the expression by calling org.apache.xpath.parser.XPath.main() with 
+ * an argument of a an expression string (quote it): "foo instance of xsd:integer".
+ * This will dump out thus:</p>
+ * <pre>
+ * Test[0]: foo instance of xsd:integer
+ * |instance of
+ * |   child::foo  org.apache.xpath.axes.ChildTestIterator
+ * |   m_atomicTypeID: 2
+ * |   m_elemOrAttrName: null
+ * |   m_occurrenceIndicator: 2
+ * |   m_schemaContext: null
+ * |   m_schemaTypeName: null
+ * |   m_whatToShow: 0
+ * Success!!!!
+ * I've only tested:
+ * "foo instance of xsd:integer"
+ * "foo instance of element of type baz"
+ * "foo instance of element yada of type baz"
+ * "foo instance of node"
+ * "foo instance of text"
+ * "foo instance of comment"
+ * "foo instance of untyped"
+ * </pre>
+ * 
+ * <p>It's highly likely that there are bugs in the construction with 
+ * other expressions.  Come get me if that happens.</p>
+ * <p>SchemaContext &amp; co is unimplemented right now.  Don't worry about 
+ * it for right now.</p>
+ * 
+ * Created Jul 17, 2002
+ * @author sboag
+ */
+public class InstanceofExpr extends Expression implements ExpressionOwner
+{
+  /** The sequence on which to act. **/
+  private Expression m_targetExpr;
+  
+  /** The node type value, one of DTMFilter.SHOW_ATTRIBUTE, etc. 
+   * %REVIEW% Why isn't this just the node type? **/
+  private int m_whatToShow;
+  
+  /** The atomic type ID, one of XType.BOOLEAN, etc. **/
+  private int m_atomicTypeID;
+  
+  // Occurence indicator ID values.
+  public static final int ZERO_OR_MORE = 1;
+  public static final int ONE_OR_MORE = 2;
+  public static final int ZERO_OR_ONE = 3;
+  public static final int EMPTY_SEQ = 4;
+    
+  /** The occurance indicator ID.  One of ZERO_OR_MORE, etc. or EMPTY_SEQ **/
+  private int m_occurrenceIndicator = ONE_OR_MORE;
+  
+  /** The ElemOrAttrType name, meaning the tag QName, may be null. */
+  private QName m_elemOrAttrName;
+
+  /** The SchemaType name, meaning the tag QName, may be null. */
+  private QName m_schemaTypeName;
+  
+  /** SchemaContext is not executable for the moment, so leave it 
+   * as a NEE until we figure out what we want to do with it. **/
+  private SchemaContext m_schemaContext;
+	
+  public InstanceofExpr() {
+    super();
+    
+  }
+
+  /** Accept the visitor. **/
+  public Object jjtAccept(org.apache.xpath.parser.XPathVisitor visitor, Object data) {
+    return visitor.visit(this, data);
+  }
+  
+  /**
+   * @see Expression#deepEquals(Expression)
+   */
+  public boolean deepEquals(Expression expr)
+  {
+    if(!(expr instanceof InstanceofExpr))
+      return false;
+    return false;
+  }
+
+  /**
+   * @see Expression#fixupVariables(Vector, int)
+   */
+  public void fixupVariables(VariableComposeState vcs)
+  {
+    m_targetExpr.fixupVariables(vcs);
+  }
+
+
+  /**
+   * @see Expression#execute(XPathContext)
+   */
+  public XObject execute(XPathContext xctxt) throws TransformerException
+  {
+ 	// m_atomicTypeID: Integer XType primitive, IFF no m_schemaTypeName
+	// m_schemaContext: SchemaContext, UNSPECIFIED AT THIS TIME
+	//	and hence unsupported.
+ 	boolean isInstance=true;
+ 	
+ 	XObject value=m_targetExpr.execute(xctxt);
+ 	
+ 	
+ 	switch(value.getType())
+ 	{
+ 		case XObject.CLASS_UNKNOWN:
+	 		// If not XSLT type, can't be instance of ...?
+	 		// %REVIEW% what SHOW_ITEM and SHOW_UNTYPED mean
+ 		case XObject.CLASS_NULL:
+	 		isInstance=false; 
+	 		break;
+	 		
+		case XObject.CLASS_NODESET:	
+		case XObject.CLASS_RTREEFRAG:
+			int len=0;
+			XSequence valNodeSet= value.xseq();
+ 			for( XObject next=valNodeSet.next();
+ 				isInstance && next!=null;
+ 				next=valNodeSet.next(),++len)
+ 			{
+        int handle = next.getNodeHandle();
+        if(DTM.NULL == handle)
+          continue;
+ 				if(m_whatToShow!=0)
+ 				{
+ 					int nodetype=xctxt.getDTM(handle).getNodeType(handle);
+ 					if(0==(m_whatToShow & 1<<(nodetype-1)))
+ 						isInstance=false;
+ 					else if(m_elemOrAttrName!=null)
+ 					{
+ 						isInstance&=
+ 							(m_elemOrAttrName.getNamespace/*URI*/()
+ 								==xctxt.getDTM(handle).getNamespaceURI(handle))
+ 							&& 
+ 							(m_elemOrAttrName.getLocalName()
+ 								==xctxt.getDTM(handle).getLocalName(handle));
+ 					} 				
+ 				}
+ 				if(m_schemaTypeName!=null)
+ 				{
+ 					isInstance&=
+ 						xctxt.getDTM(handle).isNodeSchemaType(
+ 							handle, 
+ 							m_schemaTypeName.getNamespaceURI(),
+ 							m_schemaTypeName.getLocalName());
+ 				}
+ 				else if(m_atomicTypeID!=0)
+ 				{
+ 					// Unless DTM implements awareness of these
+ 					// typenumbers, or our sequence/nodeset layers
+ 					// handle this for us, we need to convert back
+ 					// to strings. We also have to convert from the
+ 					// Schema_datatype namespace, used in requesting the
+ 					// primitive, to the Schema namespace used when
+ 					// the node was declared.
+ 					isInstance&=
+ 						xctxt.getDTM(handle).isNodeSchemaType(
+ 							handle, 
+ 							XType.XMLSCHEMA_NAMESPACE,
+ 							XType.getLocalNameFromType(m_atomicTypeID));
+ 				} 				
+			} // End scan contents
+ 			switch(m_occurrenceIndicator)
+ 			{
+ 				case ZERO_OR_MORE:
+ 					break; // Anything is OK
+ 				case ONE_OR_MORE:
+ 					isInstance&=(len>=1);
+ 					break;
+ 				case ZERO_OR_ONE:
+ 					isInstance&=(len<2);
+ 					break;
+ 				case EMPTY_SEQ:
+ 					isInstance&=(len==0);
+ 					break;
+ 			}
+ 			break;
+ 	
+ 		case XObject.CLASS_BOOLEAN:
+			isInstance&=(m_elemOrAttrName==null);
+			isInstance&=(m_schemaTypeName==null);
+			isInstance&=(m_whatToShow==0);
+			isInstance&=(m_atomicTypeID==XType.BOOLEAN);
+			break;
+			
+		case XObject.CLASS_NUMBER:
+			isInstance&=(m_elemOrAttrName==null);
+			isInstance&=(m_schemaTypeName==null);
+			isInstance&=(m_whatToShow==0);
+			// %REVIEW% XNumber is just that, a number.
+			// We want *it* to tell *us* whether it's straight
+			// decimal or double or whatever...?
+			isInstance&=(m_atomicTypeID==XType.DECIMAL
+				|| m_atomicTypeID==XType.DOUBLE);
+			break;
+			
+		case XObject.CLASS_STRING:
+			isInstance&=(m_elemOrAttrName==null);
+			isInstance&=(m_schemaTypeName==null);
+			isInstance&=(m_whatToShow==0);
+			isInstance&=(m_atomicTypeID==XType.STRING);
+			break;
+ 			
+ 		default:
+			// Should never arise
+			isInstance=false;
+ 			break;
+ 	}
+ 	
+ 	return isInstance ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+  }
+
+
+  /**
+   * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
+   */
+  public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
+  {
+    m_targetExpr.callVisitors(this, visitor);
+  }
+
+
+  /**
+   * @see ExpressionOwner#getExpression()
+   */
+  public Expression getExpression()
+  {
+    return m_targetExpr;
+  }
+
+
+  /**
+   * @see ExpressionOwner#setExpression(Expression)
+   */
+  public void setExpression(Expression exp)
+  {
+    m_targetExpr = exp;
+  }
+
+  /**
+   * @see SimpleNode#shouldReduceIfOneChild()
+   */
+  public boolean shouldReduceIfOneChild()
+  {
+    return (m_whatToShow == 0 && m_atomicTypeID == 0) ? true : false;
+  }
+
+
+  /**
+   * Returns the occurrenceIndicator.
+   * @return int
+   */
+  public int getOccurrenceIndicator()
+  {
+    return m_occurrenceIndicator;
+  }
+
+  /**
+   * Returns the schemaContext.
+   * @return SchemaContext
+   */
+  public SchemaContext getSchemaContext()
+  {
+    return m_schemaContext;
+  }
+
+  /**
+   * Returns the schemaTypeName.
+   * @return QName
+   */
+  public QName getSchemaTypeName()
+  {
+    return m_schemaTypeName;
+  }
+
+  /**
+   * Returns the targetExpr.
+   * @return Expression
+   */
+  public Expression getTargetExpr()
+  {
+    return m_targetExpr;
+  }
+
+  /**
+   * Returns the whatToShow.
+   * @return int
+   */
+  public int getWhatToShow()
+  {
+    return m_whatToShow;
+  }
+
+  /**
+   * Sets the occurrenceIndicator.
+   * @param occurrenceIndicator The occurrenceIndicator to set
+   */
+  public void setOccurrenceIndicator(int occurrenceIndicator)
+  {
+    m_occurrenceIndicator = occurrenceIndicator;
+  }
+
+  /**
+   * Sets the schemaContext.
+   * @param schemaContext The schemaContext to set
+   */
+  public void setSchemaContext(SchemaContext schemaContext)
+  {
+    m_schemaContext = schemaContext;
+  }
+
+  /**
+   * Sets the schemaTypeName.
+   * @param schemaTypeName The schemaTypeName to set
+   */
+  public void setSchemaTypeName(QName schemaTypeName)
+  {
+    m_schemaTypeName = schemaTypeName;
+  }
+
+  /**
+   * Sets the targetExpr.
+   * @param targetExpr The targetExpr to set
+   */
+  public void setTargetExpr(Expression targetExpr)
+  {
+    m_targetExpr = targetExpr;
+  }
+
+  /**
+   * Sets the whatToShow.
+   * @param whatToShow The whatToShow to set
+   */
+  public void setWhatToShow(int whatToShow)
+  {
+    m_whatToShow = whatToShow;
+  }
+  
+  /**
+   * @see org.apache.xpath.parser.Node#jjtAddChild(Node, int)
+   */
+  public void jjtAddChild(Node n, int i)
+  {
+    if(0 == i)
+    {
+      n = this.fixupPrimarys(n);
+      m_targetExpr = (Expression)n;
+    }
+    else if(2 == i) // skip the child at index 1, which is the instance of keyword.
+    {
+      SequenceType stype = (SequenceType)n;
+      m_atomicTypeID = stype.getAtomicTypeID();
+      m_elemOrAttrName = stype.getElemOrAttrName();
+      m_occurrenceIndicator = stype.getOccurrenceIndicator();
+      m_schemaContext = stype.getSchemaContext();
+      m_schemaTypeName = stype.getSchemaTypeName();
+      m_whatToShow = stype.getWhatToShow();
+    }
+  }
+
+  /**
+   * @see org.apache.xpath.ExpressionNode#exprGetChild(int)
+   */
+  public ExpressionNode exprGetChild(int i)
+  {
+    // This doesn't work perfectly, but it's good enough.
+    return (0 == i) ? m_targetExpr : (1 == 0) ? m_schemaContext : null;
+  }
+
+  /**
+   * @see org.apache.xpath.ExpressionNode#exprGetNumChildren()
+   */
+  public int exprGetNumChildren()
+  {
+    // This doesn't work perfectly, but it's good enough.
+    return ((null == m_targetExpr) ? 1 : 0)+((null == m_schemaContext) ? 1 : 0);
+  }
+
+  /**
+   * @see org.apache.xpath.parser.SimpleNode#dump(String, PrintStream)
+   */
+  public void dump(String prefix, PrintStream ps)
+  {
+    super.dump(prefix, ps);
+    prefix = prefix+"   ";
+    ps.print(prefix);
+    ps.println("m_atomicTypeID: "+m_atomicTypeID);
+    ps.print(prefix);
+    ps.println("m_elemOrAttrName: "+m_elemOrAttrName);
+    ps.print(prefix);
+    ps.println("m_occurrenceIndicator: "+m_occurrenceIndicator);
+    ps.print(prefix);
+    ps.println("m_schemaContext: "+m_schemaContext);
+    ps.print(prefix);
+    ps.println("m_schemaTypeName: "+m_schemaTypeName);
+    ps.print(prefix);
+    ps.println("m_whatToShow: "+m_whatToShow);
+  }
+
+  /**
+   * @see java.lang.Object#toString()
+   */
+  public String toString()
+  {
+    return "instance of";
+  }
+
+}
diff --git a/src/org/apache/xpath/types/Promoter.java b/src/org/apache/xpath/types/Promoter.java
new file mode 100644
index 0000000..55ac14b
--- /dev/null
+++ b/src/org/apache/xpath/types/Promoter.java
@@ -0,0 +1,69 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights 
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Xalan" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Lotus
+ * Development Corporation., http://www.lotus.com.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package org.apache.xpath.types;
+
+/**
+ * Typed operation function.
+ * 
+ * Created Jul 30, 2002
+ * @author sboag
+ */
+public class Promoter
+{
+
+
+}