New implementation for TemplatesHandlerImpl that does not extend
 xsltc.compiler.Parser. The new implementation has a simpler init()
 method. Also, instances of the new class can be re-used (previously,
 there were problems with the output method when an instance was
 used more than once).

diff --git a/src/org/apache/xalan/xsltc/compiler/Parser.java b/src/org/apache/xalan/xsltc/compiler/Parser.java
index 779225a..214ea05 100644
--- a/src/org/apache/xalan/xsltc/compiler/Parser.java
+++ b/src/org/apache/xalan/xsltc/compiler/Parser.java
@@ -117,16 +117,16 @@
     private Hashtable   _variableScope;
     private Stylesheet  _currentStylesheet;
     private SymbolTable _symbolTable; // Maps QNames to syntax-tree nodes
-    private Output      _output = null;
+    private Output      _output;
     private Template    _template;    // Reference to the template being parsed.
 
-    private boolean     _rootNamespaceDef = false; // Used for validity check
+    private boolean     _rootNamespaceDef; // Used for validity check
 
-    private SyntaxTreeNode _root = null;
+    private SyntaxTreeNode _root;
 
     private String _target;
 
-    private int _currentImportPrecedence = 1;
+    private int _currentImportPrecedence;
 
     public Parser(XSLTC xsltc) {
 	_xsltc = xsltc;
@@ -144,6 +144,9 @@
 	_symbolTable         = new SymbolTable();
 	_xpathParser         = new XPathParser(this);
 	_currentStylesheet   = null;
+        _output              = null;
+        _root                = null;
+        _rootNamespaceDef    = false;
 	_currentImportPrecedence = 1;
 	
 	initStdClasses();
diff --git a/src/org/apache/xalan/xsltc/compiler/XSLTC.java b/src/org/apache/xalan/xsltc/compiler/XSLTC.java
index fe6d00f..f05a048 100644
--- a/src/org/apache/xalan/xsltc/compiler/XSLTC.java
+++ b/src/org/apache/xalan/xsltc/compiler/XSLTC.java
@@ -165,10 +165,10 @@
     /**
      * Only for user by the internal TrAX implementation.
      */
-    public void setParser(Parser parser) {
-	_parser = parser;
+    public Parser getParser() {
+        return _parser;
     }
-
+    
     /**
      * Only for user by the internal TrAX implementation.
      */
diff --git a/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java b/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java
index 44f4a8b..44ed3cc 100644
--- a/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java
+++ b/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java
@@ -76,14 +76,17 @@
 import org.apache.xalan.xsltc.compiler.SyntaxTreeNode;
 import org.apache.xalan.xsltc.compiler.XSLTC;
 
+import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.Attributes;
 
 /**
  * Implementation of a JAXP1.1 TemplatesHandler
  */
-public class TemplatesHandlerImpl extends Parser
-    implements TemplatesHandler, SourceLoader
+public class TemplatesHandlerImpl 
+    implements ContentHandler, TemplatesHandler, SourceLoader
 {
     /**
      * System ID for this stylesheet.
@@ -105,6 +108,11 @@
      * object belongs to.
      */
     private TransformerFactoryImpl _tfactory = null;
+    
+    /**
+     * A reference to XSLTC's parser object.
+     */
+    private Parser _parser = null;
 
     /**
      * Default constructor
@@ -112,22 +120,14 @@
     protected TemplatesHandlerImpl(int indentNumber,
 	TransformerFactoryImpl tfactory)
     {
-	super(null);
 	_indentNumber = indentNumber;
 	_tfactory = tfactory;
-    }
-
-    /**
-     * Internal initialization
-     */
-    public void init() {
-	// Create and initialize a stylesheet compiler
-	final XSLTC xsltc = new XSLTC();
-	super.setXSLTC(xsltc);
-	xsltc.init();
-	super.init();
-	xsltc.setParser(this);
-	xsltc.setOutputType(XSLTC.BYTEARRAY_OUTPUT);
+    
+        // Initialize a parser object
+        XSLTC xsltc = new XSLTC();
+        xsltc.init();
+        xsltc.setOutputType(XSLTC.BYTEARRAY_OUTPUT);
+        _parser = xsltc.getParser();
     }
 
     /**
@@ -168,7 +168,7 @@
      */
     public Templates getTemplates() {
 	try {
-	    final XSLTC xsltc = getXSLTC();
+	    XSLTC xsltc = _parser.getXSLTC();
 
 	    // Set a document loader (for xsl:include/import) if defined
 	    if (_uriResolver != null) {
@@ -189,25 +189,25 @@
 	    transletName = xsltc.getClassName();
 
 	    Stylesheet stylesheet = null;
-	    SyntaxTreeNode root = getDocumentRoot();
+	    SyntaxTreeNode root = _parser.getDocumentRoot();
 
 	    // Compile the translet - this is where the work is done!
-	    if (!errorsFound() && root != null) {
+	    if (!_parser.errorsFound() && root != null) {
 		// Create a Stylesheet element from the root node
-		stylesheet = makeStylesheet(root);
+		stylesheet = _parser.makeStylesheet(root);
 		stylesheet.setSystemId(_systemId);
 		stylesheet.setParentStylesheet(null);
-		setCurrentStylesheet(stylesheet);
+		_parser.setCurrentStylesheet(stylesheet);
 
 		// Set it as top-level in the XSLTC object
 		xsltc.setStylesheet(stylesheet);
 
 		// Create AST under the Stylesheet element
-		createAST(stylesheet);
+		_parser.createAST(stylesheet);
 	    }
 
 	    // Generate the bytecodes and output the translet class(es)
-	    if (!errorsFound() && stylesheet != null) {
+	    if (!_parser.errorsFound() && stylesheet != null) {
 		stylesheet.setMultiDocument(xsltc.isMultiDocument());
 
                 // Class synchronization is needed for BCEL
@@ -216,13 +216,13 @@
                 }
 	    }
 
-	    if (!errorsFound()) {
+	    if (!_parser.errorsFound()) {
 		// Check that the transformation went well before returning
 		final byte[][] bytecodes = xsltc.getBytecodes();
 		if (bytecodes != null) {
 		    final TemplatesImpl templates =
 			new TemplatesImpl(xsltc.getBytecodes(), transletName,
-			    getOutputProperties(), _indentNumber, _tfactory);
+			    _parser.getOutputProperties(), _indentNumber, _tfactory);
 
 		    // Set URIResolver on templates object
 		    if (_uriResolver != null) {
@@ -239,16 +239,6 @@
     }
 
     /**
-     * Recieve an object for locating the origin of SAX document events.
-     * Most SAX parsers will use this method to inform content handler
-     * of the location of the parsed document.
-     */
-    public void setDocumentLocator(Locator locator) {
-	super.setDocumentLocator(locator);
-  	setSystemId(locator.getSystemId());
-    }
-
-    /**
      * This method implements XSLTC's SourceLoader interface. It is used to
      * glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes.
      *
@@ -270,6 +260,89 @@
 	}
 	return null;
     }
+    
+    // -- ContentHandler --------------------------------------------------
+    
+    /**
+     * Re-initialize parser and forward SAX2 event.
+     */
+    public void startDocument() {
+        _parser.init();
+        _parser.startDocument();
+    }
+
+    /**
+     * Just forward SAX2 event to parser object.
+     */
+    public void endDocument() { 
+        _parser.endDocument();
+    }
+
+    /**
+     * Just forward SAX2 event to parser object.
+     */
+    public void startPrefixMapping(String prefix, String uri) {
+        _parser.startPrefixMapping(prefix, uri);
+    }
+
+    /**
+     * Just forward SAX2 event to parser object.
+     */
+    public void endPrefixMapping(String prefix) { 
+        _parser.endPrefixMapping(prefix);
+    }
+
+    /**
+     * Just forward SAX2 event to parser object.
+     */
+    public void startElement(String uri, String localname, String qname, 
+        Attributes attributes) throws SAXException 
+    {
+        _parser.startElement(uri, localname, qname, attributes);
+    }
+    
+    /**
+     * Just forward SAX2 event to parser object.
+     */
+    public void endElement(String uri, String localname, String qname) {
+        _parser.endElement(uri, localname, qname);
+    }
+
+    /**
+     * Just forward SAX2 event to parser object.
+     */
+    public void characters(char[] ch, int start, int length) {
+        _parser.characters(ch, start, length);
+    }
+    
+    /**
+     * Just forward SAX2 event to parser object.
+     */
+    public void processingInstruction(String name, String value) {
+        _parser.processingInstruction(name, value);
+    }
+    
+    /**
+     * Just forward SAX2 event to parser object.
+     */
+    public void ignorableWhitespace(char[] ch, int start, int length) { 
+        _parser.ignorableWhitespace(ch, start, length);
+    }
+
+    /**
+     * Just forward SAX2 event to parser object.
+     */
+    public void skippedEntity(String name) { 
+        _parser.skippedEntity(name);
+    }
+
+    /**
+     * Set internal system Id and forward SAX2 event to parser object.
+     */
+    public void setDocumentLocator(Locator locator) {
+        setSystemId(locator.getSystemId());
+        _parser.setDocumentLocator(locator);
+    }
 }
 
 
diff --git a/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java b/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java
index 54bab46..bbfad2c 100644
--- a/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java
+++ b/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java
@@ -764,7 +764,6 @@
     { 
 	final TemplatesHandlerImpl handler = 
 	    new TemplatesHandlerImpl(_indentNumber, this);
-	handler.init();
 	if (_uriResolver != null) {
 	    handler.setURIResolver(_uriResolver);
 	}