--- xalan-j_2_7_1/src/org/apache/xml/utils/DOMBuilder.java	2007-11-22 15:43:54.000000000 -0600
+++ xalan-j/src/org/apache/xml/utils/DOMBuilder.java	2014-02-13 11:50:06.611549099 -0600
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 /*
- * $Id: DOMBuilder.java 472634 2006-11-08 20:43:55Z jycli $
+ * $Id$
  */
 package org.apache.xml.utils;
 
@@ -68,6 +68,9 @@ public class DOMBuilder
   /** Namespace support */
   protected Vector m_prefixMappings = new Vector();
   
+  /** Used to build text nodes efficiently */
+  private StringBuffer m_textBuffer = new StringBuffer();
+  
   /**
    * DOMBuilder instance constructor... it will add the DOM nodes
    * to the document fragment.
@@ -319,7 +322,7 @@ public class DOMBuilder
           String ns, String localName, String name, Attributes atts)
             throws org.xml.sax.SAXException
   {
-
+    appendTextNode();
     Element elem;
 
 	// Note that the namespace-aware call must be used to correctly
@@ -425,6 +428,7 @@ public class DOMBuilder
   public void endElement(String ns, String localName, String name)
           throws org.xml.sax.SAXException
   {
+    appendTextNode();
     m_elemStack.pop();
     m_currentNode = m_elemStack.isEmpty() ? null : (Node)m_elemStack.peek();
   }
@@ -477,15 +481,15 @@ public class DOMBuilder
       return;
     }
 
-    String s = new String(ch, start, length);
-    Node childNode;
-    childNode =  m_currentNode != null ? m_currentNode.getLastChild(): null;
-    if( childNode != null && childNode.getNodeType() == Node.TEXT_NODE ){
-       ((Text)childNode).appendData(s);
+    m_textBuffer.append(ch, start, length);
     }
-    else{
-       Text text = m_doc.createTextNode(s);
+
+  private void appendTextNode() throws org.xml.sax.SAXException
+  {
+     if(m_textBuffer.length() > 0){
+       Text text = m_doc.createTextNode(m_textBuffer.toString());
        append(text);
+       m_textBuffer.setLength(0);
     }
   }
 
@@ -614,6 +618,7 @@ public class DOMBuilder
   public void processingInstruction(String target, String data)
           throws org.xml.sax.SAXException
   {
+    appendTextNode();
     append(m_doc.createProcessingInstruction(target, data));
   }
 
@@ -630,6 +635,7 @@ public class DOMBuilder
    */
   public void comment(char ch[], int start, int length) throws org.xml.sax.SAXException
   {
+    appendTextNode();
     append(m_doc.createComment(new String(ch, start, length)));
   }
 
--- xalan-j_2_7_1/src/org/apache/xalan/xsltc/trax/SAX2DOM.java	2007-11-22 15:43:55.000000000 -0600
+++ xalan-j/src/org/apache/xalan/xsltc/trax/SAX2DOM.java	2014-02-13 11:50:06.610549090 -0600
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 /*
- * $Id: SAX2DOM.java 468653 2006-10-28 07:07:05Z minchau $
+ * $Id$
  */
 
 
@@ -54,6 +54,8 @@ public class SAX2DOM implements ContentH
     private Stack _nodeStk = new Stack();
     private Vector _namespaceDecls = null;
     private Node _lastSibling = null;
+    private StringBuffer _textBuffer = new StringBuffer();
+    private Node _nextSiblingCache = null;
 
     public SAX2DOM() throws ParserConfigurationException {
 	final DocumentBuilderFactory factory = 
@@ -93,17 +95,21 @@ public class SAX2DOM implements ContentH
 
 	// No text nodes can be children of root (DOM006 exception)
         if (last != _document) {
-            final String text = new String(ch, start, length);
-            if( _lastSibling != null && _lastSibling.getNodeType() == Node.TEXT_NODE ){
-                  ((Text)_lastSibling).appendData(text);
+            _nextSiblingCache = _nextSibling;
+            _textBuffer.append(ch, start, length);
             }
-            else if (last == _root && _nextSibling != null) {
-                _lastSibling = last.insertBefore(_document.createTextNode(text), _nextSibling);
+    }
+
+    private void appendTextNode() {
+        if (_textBuffer.length() > 0) {
+            final Node last = (Node)_nodeStk.peek();
+            if (last == _root && _nextSiblingCache != null) {
+                _lastSibling = last.insertBefore(_document.createTextNode(_textBuffer.toString()), _nextSiblingCache);
             }
             else {
-                _lastSibling = last.appendChild(_document.createTextNode(text));
+                _lastSibling = last.appendChild(_document.createTextNode(_textBuffer.toString()));
             }
-            
+            _textBuffer.setLength(0);
         }
     }
 
@@ -118,6 +124,7 @@ public class SAX2DOM implements ContentH
     public void startElement(String namespace, String localName, String qName,
 	Attributes attrs) 
     {
+        appendTextNode();
 	final Element tmp = (Element)_document.createElementNS(namespace, qName);
 
 	// Add namespace declarations first
@@ -166,6 +173,7 @@ public class SAX2DOM implements ContentH
     }
 
     public void endElement(String namespace, String localName, String qName) {
+        appendTextNode();
 	_nodeStk.pop();  
 	_lastSibling = null;
     }
@@ -193,6 +201,7 @@ public class SAX2DOM implements ContentH
      * adds processing instruction node to DOM.
      */
     public void processingInstruction(String target, String data) {
+        appendTextNode();
 	final Node last = (Node)_nodeStk.peek();
 	ProcessingInstruction pi = _document.createProcessingInstruction(
 		target, data);
@@ -225,6 +234,7 @@ public class SAX2DOM implements ContentH
      * Lexical Handler method to create comment node in DOM tree.
      */
     public void comment(char[] ch, int start, int length) {
+        appendTextNode();
 	final Node last = (Node)_nodeStk.peek();
 	Comment comment = _document.createComment(new String(ch,start,length));
 	if (comment != null){
