- SAX.c entities.c parser.c: changed completely the way entities
  are handled when running the parser in entity substitution mode.
  This fixes a bug reported by Stephan Kulow and nearly divides
  by 3 the amount of memory required by libxslt to load and process
  DocBook TDG.
Daniel
diff --git a/SAX.c b/SAX.c
index 72b82e4..a107928 100644
--- a/SAX.c
+++ b/SAX.c
@@ -885,7 +885,8 @@
 	    ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
 					       ctxt->node, ret, value);
 	}
-    } else if (ctxt->external != 2){
+    } else if (((ctxt->replaceEntities == 0) && (ctxt->external != 2)) ||
+	       ((ctxt->replaceEntities != 0) && (ctxt->inSubset == 0))) {
         /*
 	 * when validating, the ID registration is done at the attribute
 	 * validation level. Otherwise we have to do specific handling here.