code: protected int countAncestors(ElemTemplateElement elem)
    {
    	int count = 0;
    	while(null != elem)
    	{
    		count++;
    		elem = elem.getParentElem();
    	}
    	return count;
    }
docs: Count the number of ancestors that a ElemTemplateElement has.
  
  @param elem An representation of an element in an XSLT stylesheet.
  @return The number of ancestors of elem (including the element itself).