Committing the changes in patch5 in XALANJ-2219 to
not replace prefix mappings if one already exists
at that depth for the same prefix.
diff --git a/src/org/apache/xml/serializer/NamespaceMappings.java b/src/org/apache/xml/serializer/NamespaceMappings.java
index 7d533c0..454e9d3 100644
--- a/src/org/apache/xml/serializer/NamespaceMappings.java
+++ b/src/org/apache/xml/serializer/NamespaceMappings.java
@@ -224,92 +224,34 @@
      */
     public boolean pushNamespace(String prefix, String uri, int elemDepth)
     {
-        boolean pushed;
         // Prefixes "xml" and "xmlns" cannot be redefined
-        if (!prefix.startsWith(XML_PREFIX))
+        if (prefix.startsWith(XML_PREFIX))
         {
-
-            Stack stack;
-            // Get the stack that contains URIs for the specified prefix
-            if ((stack = getPrefixStack(prefix)) == null)
-                stack = createPrefixStack(prefix);
-
-            switch (stack.top)
-            {
-                case -1 :
-                    pushed = true;  // stack is empty, so push the new one on the stack
-                    break;
-                case 0 :
-                    {
-                        // only one thing on the stack, if the new one is the
-                        // same prefix/uri mapping as the old one don't push, 
-                        // but if the uri's differ push it on the stack.
-                        MappingRecord pm = (MappingRecord) stack.peek();
-                        if (uri.equals(pm.m_uri))
-                            pushed = false;
-                        else
-                            pushed = true;
-                    }
-                    break;
-                default : // 2 or more things on the stack
-                    {
-                        MappingRecord pm = (MappingRecord) stack.peek();
-                        if (null == pm.m_uri
-                            && !uri.equals(EMPTYSTRING)
-                            && pm.m_declarationDepth == elemDepth)
-                        {
-                            // The top of the stack masks shallower mappings and
-                            // the new mapping is at the same depth as the masking
-                            // and the masked mapping is the same as the new one
-                            
-                            MappingRecord pm2 =
-                                (MappingRecord) stack.peek(stack.top - 1);
-                            if (uri.equals(pm2.m_uri))
-                            {
-                                // The masked mapping is the same as the new one
-                                // so don't push this mapping, but delete the masking
-                                // one by popping it off the top
-                                // This is an optimization to re-use the ancestors mapping.
-                                pushed = false;
-                                stack.pop();
-                            }
-                            else
-                                pushed = true;
-                            // the ancestors mapping differs, so push it
-                        }
-                        else
-                        {
-                            // The mapping at the top of the stack is not a masking
-                            // or is shallower than the new one or the new mapping is
-                            // itself not a masking
-                            if (uri.equals(pm.m_uri))
-                            {
-                                pushed = false;
-                                // old and new URI's are the same, don't push
-                                // this is an optimization to re-use the ancestors mapping
-                            }
-                            else
-                                pushed = true;
-                                // old and new URI's differ, so push                      
-                        }
-                    }
-                break;
-            }
-            if (pushed)
-            {
-
-                MappingRecord namespaceNode =
-                    new MappingRecord(prefix, uri, elemDepth);
-                stack.push(namespaceNode);
-                //        m_nodeStack.push(new Integer(elemDepth));
-                m_nodeStack.push(namespaceNode);
-            }
-
+            return false;
         }
-        else
-            pushed = false;
 
-        return pushed;
+        Stack stack;
+        // Get the stack that contains URIs for the specified prefix
+        if ((stack = (Stack) m_namespaces.get(prefix)) == null)
+        {
+            m_namespaces.put(prefix, stack = new Stack());
+        }
+
+        if (!stack.empty())
+        {
+            MappingRecord mr = (MappingRecord)stack.peek();
+            if (uri.equals(mr.m_uri) || elemDepth == mr.m_declarationDepth) {
+                // If the same prefix/uri mapping is already on the stack
+                // don't push this one.
+                // Or if we have a mapping at the same depth
+                // don't replace by pushing this one. 
+                return false;
+            }
+        }
+        MappingRecord map = new MappingRecord(prefix,uri,elemDepth);
+        stack.push(map);
+        m_nodeStack.push(map);
+        return true;
     }
 
     /**
diff --git a/src/org/apache/xml/serializer/ToStream.java b/src/org/apache/xml/serializer/ToStream.java
index 8ec8aa4..6b0637d 100644
--- a/src/org/apache/xml/serializer/ToStream.java
+++ b/src/org/apache/xml/serializer/ToStream.java
@@ -2347,7 +2347,6 @@
 
         if (pushed)
         {
-            boolean was_added = false;
             /* Brian M.: don't know if we really needto do this. The
              * callers of this object should have injected both
              * startPrefixMapping and the attributes.  We are 
@@ -2357,7 +2356,7 @@
             if (EMPTYSTRING.equals(prefix))
             {
                 name = "xmlns";
-                was_added = addAttributeAlways(XMLNS_URI, name, name, "CDATA", uri, false);
+                addAttributeAlways(XMLNS_URI, name, name, "CDATA", uri, false);
             }
             else
             {
@@ -2370,24 +2369,9 @@
                      *  the      uri is the value, that is why we pass it in the
                      * value, or 5th slot of addAttributeAlways()
                      */
-                    was_added = addAttributeAlways(XMLNS_URI, prefix, name, "CDATA", uri, false);
+                    addAttributeAlways(XMLNS_URI, prefix, name, "CDATA", uri, false);
                 }
             }
-            
-            if (was_added == false && shouldFlush == false) {
-                // We pushed this namespace onto the stack, and we
-                // tried to update the pseudo-attribute value, but that didn't work
-                // so we now pop the value from the namespace stack.
-                //
-                // We already had a pseudo attribute of the form
-                // xmlns='uri' or xmlsn:pfx='uri' on this element.
-                // We were trying to update the value of pseudo-attribute.
-                // was_added is false, so we didn't update the value, hence
-                // we are not even going to accept the mapping itself,
-                // the caller is in error.
-                m_prefixMap.popNamespace(prefix);
-                pushed = false;                
-            }
         }
         return pushed;
     }
@@ -3037,7 +3021,6 @@
 
         if (index >= 0)
         {
-            // Trying to update the value of an existing attribute
             String old_value = null;
             if (m_tracer != null)
             {
@@ -3050,20 +3033,7 @@
              * We may have a null uri or localName, but all we really
              * want to re-set is the value anyway.
              */
-            if ("xmlns".equals(localName)) {
-                // Don't update pseudo-attributes of the form xmlns='uri'
-                ;
-            }
-            else if (rawName != null && rawName.startsWith("xmlns:")) {
-                // Don't update pseudo-attributes of the form xmlns:prf='uri'
-                ;
-            }
-            else {
-                // Update normal attributes, which is OK because this could
-                // be from an xsl:attribute element in the stylesheet.
-                m_attributes.setValue(index, value);
-            }
-            
+            m_attributes.setValue(index, value);
             was_added = false;
             if (old_value != null)
                 firePseudoAttributes();