code: public static boolean isNodeAfter(Node node1, Node node2)
    {
  
      // Assume first that the nodes are DTM nodes, since discovering node 
      // order is massivly faster for the DTM.
      if(node1 instanceof DOMOrder && node2 instanceof DOMOrder)
      {
        int index1 = ((DOMOrder) node1).getUid();
        int index2 = ((DOMOrder) node2).getUid();
  
        return index1 <= index2;
      }
      else
      {
  
        // isNodeAfter will return true if node is after countedNode 
        // in document order. The base isNodeAfter is sloooow (relatively).
        return DOMHelper.isNodeAfter(node1, node2);
      }
    }
docs: Figure out whether node2 should be considered as being later
  in the document than node1, in Document Order as defined
  by the XPath model. This may not agree with the ordering defined
  by other XML applications.
  <p>
  There are some cases where ordering isn't defined, and neither are
  the results of this function -- though we'll generally return true.
  <p>
  TODO: Make sure this does the right thing with attribute nodes!!!
  
  @param node1 DOM Node to perform position comparison on.
  @param node2 DOM Node to perform position comparison on .
  
  @return false if node2 comes before node1, otherwise return true.
  You can think of this as
  <code>(node1.documentOrderPosition &lt;= node2.documentOrderPosition)</code>.