code: NodeVector getMatchingAncestors(
            XPathContext xctxt, int node, boolean stopAtFirstFound)
              throws javax.xml.transform.TransformerException
    {
  
      NodeSetDTM ancestors = new NodeSetDTM(xctxt.getDTMManager());
      XPath countMatchPattern = getCountMatchPattern(xctxt, node);
      DTM dtm = xctxt.getDTM(node);
  
      while (DTM.NULL != node)
      {
        if ((null != m_fromMatchPattern)
                && (m_fromMatchPattern.getMatchScore(xctxt, node)
                    != XPath.MATCH_SCORE_NONE))
        {
  
          // The following if statement gives level="single" different 
          // behavior from level="multiple", which seems incorrect according 
          // to the XSLT spec.  For now we are leaving this in to replicate 
          // the same behavior in XT, but, for all intents and purposes we 
          // think this is a bug, or there is something about level="single" 
          // that we still don't understand.
          if (!stopAtFirstFound)
            break;
        }
  
        if (null == countMatchPattern)
          System.out.println(
            "Programmers error! countMatchPattern should never be null!");
  
        if (countMatchPattern.getMatchScore(xctxt, node)
                != XPath.MATCH_SCORE_NONE)
        {
          ancestors.addElement(node);
  
          if (stopAtFirstFound)
            break;
        }
  
        node = dtm.getParent(node);
      }
  
      return ancestors;
    }
docs: Get the ancestors, up to the root, that match the
  pattern.
  
  @param xctxt The XPath runtime state for this.
  @param node Count this node and it's ancestors.
  @param stopAtFirstFound Flag indicating to stop after the
  first node is found (difference between level = single
  or multiple)
  @return The number of ancestors that match the pattern.
  
  @throws javax.xml.transform.TransformerException