code: private int findPrecedingOrAncestorOrSelf(
            XPathContext xctxt, XPath fromMatchPattern, XPath countMatchPattern, 
            int context, ElemNumber namespaceContext)
              throws javax.xml.transform.TransformerException
    {
      DTM dtm = xctxt.getDTM(context);
      while (DTM.NULL != context)
      {
        if (null != fromMatchPattern)
        {
          if (fromMatchPattern.getMatchScore(xctxt, context)
                  != XPath.MATCH_SCORE_NONE)
          {
            context = DTM.NULL;
  
            break;
          }
        }
  
        if (null != countMatchPattern)
        {
          if (countMatchPattern.getMatchScore(xctxt, context)
                  != XPath.MATCH_SCORE_NONE)
          {
            break;
          }
        }
  
        int prevSibling = dtm.getPreviousSibling(context);
  
        if (DTM.NULL == prevSibling)
        {
          context = dtm.getParent(context);
        }
        else
        {
  
          // Now go down the chain of children of this sibling 
          context = dtm.getLastChild(prevSibling);
  
          if (context == DTM.NULL)
            context = prevSibling;
        }
      }
  
      return context;
    }
docs: Given a 'from' pattern (ala xsl:number), a match pattern
  and a context, find the first ancestor that matches the
  pattern (including the context handed in).
  @param xctxt The XPath runtime state for this.
  @param fromMatchPattern The ancestor must match this pattern.
  @param countMatchPattern The ancestor must also match this pattern.
  @param context The node that "." expresses.
  @param namespaceContext The context in which namespaces in the
  queries are supposed to be expanded.
  
  @return the first preceding, ancestor or self node that
  matches the given pattern
  
  @throws javax.xml.transform.TransformerException