diff -rupNw xalan-j_2_7_1.original/src/org/apache/xml/utils/SecuritySupport12.java xalan-j_2_7_1/src/org/apache/xml/utils/SecuritySupport12.java
--- xalan-j_2_7_1.original/src/org/apache/xml/utils/SecuritySupport12.java	2007-11-22 15:43:53.000000000 -0600
+++ xalan-j_2_7_1/src/org/apache/xml/utils/SecuritySupport12.java	2013-04-18 09:21:49.345290835 -0500
@@ -55,6 +55,17 @@ class SecuritySupport12 extends Security
         });
     }
 
+    void setContextClassLoader(final ClassLoader cl) {
+        AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                try {
+                    Thread.currentThread().setContextClassLoader(cl);
+                } catch (SecurityException ex) { }
+                return null;
+            }
+        });
+    }
+    
     ClassLoader getSystemClassLoader() {
         return (ClassLoader)
             AccessController.doPrivileged(new PrivilegedAction() {
diff -rupNw xalan-j_2_7_1.original/src/org/apache/xml/utils/SecuritySupport.java xalan-j_2_7_1/src/org/apache/xml/utils/SecuritySupport.java
--- xalan-j_2_7_1.original/src/org/apache/xml/utils/SecuritySupport.java	2007-11-22 15:43:53.000000000 -0600
+++ xalan-j_2_7_1/src/org/apache/xml/utils/SecuritySupport.java	2013-04-18 09:21:49.345290835 -0500
@@ -87,6 +87,9 @@ class SecuritySupport {
 	return null;
     }
 
+    void setContextClassLoader(ClassLoader cl) {
+    }
+    
     ClassLoader getSystemClassLoader() {
         return null;
     }
diff -rupNw xalan-j_2_7_1.original/src/org/apache/xml/utils/XMLReaderManager.java xalan-j_2_7_1/src/org/apache/xml/utils/XMLReaderManager.java
--- xalan-j_2_7_1.original/src/org/apache/xml/utils/XMLReaderManager.java	2007-11-22 15:43:53.000000000 -0600
+++ xalan-j_2_7_1/src/org/apache/xml/utils/XMLReaderManager.java	2013-04-18 09:21:49.345290835 -0500
@@ -20,15 +20,14 @@
  */
 package org.apache.xml.utils;
 
-import java.util.Hashtable;
-
 import javax.xml.parsers.FactoryConfigurationError;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
 import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
 import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLReaderFactory;
 
 /**
  * Creates XMLReader objects and caches them for re-use.
@@ -36,27 +35,26 @@ import org.xml.sax.SAXException;
  */
 public class XMLReaderManager {
 
-    private static final String NAMESPACES_FEATURE =
-                             "http://xml.org/sax/features/namespaces";
-    private static final String NAMESPACE_PREFIXES_FEATURE =
-                             "http://xml.org/sax/features/namespace-prefixes";
     private static final XMLReaderManager m_singletonManager =
                                                      new XMLReaderManager();
 
     /**
      * Parser factory to be used to construct XMLReader objects
      */
-    private static SAXParserFactory m_parserFactory;
-
+    private static final SAXParserFactory m_parserFactory;
     /**
-     * Cache of XMLReader objects
+     * Do we cache the objects or recreate every time?
      */
-    private ThreadLocal m_readers;
+    private static final boolean m_enableCaching;
 
     /**
-     * Keeps track of whether an XMLReader object is in use.
+     * Cached SAXParser object
      */
-    private Hashtable m_inUse;
+    private ThreadLocal m_parser = new ThreadLocal();
+    /**
+     * Active XMLReader
+     */
+    private ThreadLocal m_activeReader = new ThreadLocal();
 
     /**
      * Hidden constructor
@@ -77,52 +75,31 @@ public class XMLReaderManager {
      * longer needs the reader, it must release it with a call to
      * {@link #releaseXMLReader}.
      */
-    public synchronized XMLReader getXMLReader() throws SAXException {
-        XMLReader reader;
-        boolean readerInUse;
-
-        if (m_readers == null) {
-            // When the m_readers.get() method is called for the first time
-            // on a thread, a new XMLReader will automatically be created.
-            m_readers = new ThreadLocal();
-        }
-
-        if (m_inUse == null) {
-            m_inUse = new Hashtable();
-        }
-
-        // If the cached reader for this thread is in use, construct a new
-        // one; otherwise, return the cached reader.
-        reader = (XMLReader) m_readers.get();
-        boolean threadHasReader = (reader != null);
-        if (!threadHasReader || m_inUse.get(reader) == Boolean.TRUE) {
-            try {
+    public XMLReader getXMLReader() throws SAXException {
+    	final SecuritySupport ss = SecuritySupport.getInstance() ;
+        final ClassLoader context = ss.getContextClassLoader() ;
                 try {
-                    // According to JAXP 1.2 specification, if a SAXSource
-                    // is created using a SAX InputSource the Transformer or
-                    // TransformerFactory creates a reader via the
-                    // XMLReaderFactory if setXMLReader is not used
-                    reader = XMLReaderFactory.createXMLReader();
-                } catch (Exception e) {
-                   try {
-                        // If unable to create an instance, let's try to use
-                        // the XMLReader from JAXP
-                        if (m_parserFactory == null) {
-                            m_parserFactory = SAXParserFactory.newInstance();
-                            m_parserFactory.setNamespaceAware(true);
-                        }
-
-                        reader = m_parserFactory.newSAXParser().getXMLReader();
-                   } catch (ParserConfigurationException pce) {
-                       throw pce;   // pass along pce
-                   }
+            if (m_enableCaching && (m_activeReader.get() == null)) {
+            	ss.setContextClassLoader(getClass().getClassLoader()) ;
+                final SAXParser cached = (SAXParser) m_parser.get() ;
+                final XMLReader reader ;
+                if (cached != null) {
+                    reader = cached.getXMLReader() ;
+                } else {
+                    final SAXParser parser = m_parserFactory.newSAXParser() ;
+                    m_parser.set(parser) ;
+                    reader = parser.getXMLReader() ;
                 }
+                m_activeReader.set(reader) ;
+                return reader ;
+            } else{
                 try {
-                    reader.setFeature(NAMESPACES_FEATURE, true);
-                    reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
-                } catch (SAXException se) {
-                    // Try to carry on if we've got a parser that
-                    // doesn't know about namespace prefixes.
+            		return XMLReaderFactory.createXMLReader(); 
+            	} catch (final Exception ex) {
+            		final SAXParserFactory factory = SAXParserFactory.newInstance();
+                    factory.setNamespaceAware(true);
+            		return factory.newSAXParser().getXMLReader();
+            	}
                 }
             } catch (ParserConfigurationException ex) {
                 throw new SAXException(ex);
@@ -130,19 +107,10 @@ public class XMLReaderManager {
                 throw new SAXException(ex1.toString());
             } catch (NoSuchMethodError ex2) {
             } catch (AbstractMethodError ame) {
+        } finally {
+        	ss.setContextClassLoader(context) ;
             }
-
-            // Cache the XMLReader if this is the first time we've created
-            // a reader for this thread.
-            if (!threadHasReader) {
-                m_readers.set(reader);
-                m_inUse.put(reader, Boolean.TRUE);
-            }
-        } else {
-            m_inUse.put(reader, Boolean.TRUE);
-        }
-
-        return reader;
+        return null ;
     }
 
     /**
@@ -151,11 +119,24 @@ public class XMLReaderManager {
      *
      * @param reader The XMLReader that's being released.
      */
-    public synchronized void releaseXMLReader(XMLReader reader) {
-        // If the reader that's being released is the cached reader
-        // for this thread, remove it from the m_isUse list.
-        if (m_readers.get() == reader && reader != null) {
-            m_inUse.remove(reader);
+    public void releaseXMLReader(XMLReader reader) {
+    	if (m_enableCaching && (reader == m_activeReader.get())) {
+    		m_activeReader.set(null) ;
+    		try {
+        		((SAXParser)m_parser.get()).reset() ;
+    		} catch (final Throwable th) {
+    			m_parser.set(null) ;
+    		}
+    	}
+    }
+
+    static {
+    	m_enableCaching = Boolean.getBoolean("xalan.enableParserCaching");
+    	if (m_enableCaching) {
+    		m_parserFactory = SAXParserFactory.newInstance();
+    		m_parserFactory.setNamespaceAware(true);
+    	} else {
+    		m_parserFactory = null;
         }
     }
 }
