code: public void startElement(
            StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes)
              throws SAXException
    {
      String msg = "";
  
      super.startElement(handler, uri, localName, rawName, attributes);
      ElemTemplateElement ancestor = handler.getElemTemplateElement().getParentElem();
      while (ancestor != null && !(ancestor instanceof ElemExsltFunction))
      {
        if (ancestor instanceof ElemVariable 
            || ancestor instanceof ElemParam
            || ancestor instanceof ElemExsltFuncResult)
        {
          msg = "func:result cannot appear within a variable, parameter, or another func:result.";
          handler.error(msg, new SAXException(msg));
        }
        ancestor = ancestor.getParentElem();
      }
      if (ancestor == null)
      {
        msg = "func:result must appear in a func:function element";
        handler.error(msg, new SAXException(msg));
      }
    }
docs: Verify that the func:result element does not appear within a variable,
  parameter, or another func:result, and that it belongs to a func:function
  element.