dbertoni    2003/07/07 16:53:43

  Modified:    c/src/xalanc/XSLT ElemElement.cpp ElemElement.hpp
  Log:
  Fixes for bug 21385.
  
  Revision  Changes    Path
  1.3       +65 -78    xml-xalan/c/src/xalanc/XSLT/ElemElement.cpp
  
  Index: ElemElement.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/ElemElement.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ElemElement.cpp   30 Jun 2003 23:38:30 -0000      1.2
  +++ ElemElement.cpp   7 Jul 2003 23:53:43 -0000       1.3
  @@ -183,8 +183,6 @@
   
                XalanDOMString::size_type       namespaceLen = 
length(elemNameSpace);
   
  -             bool    hasUnresolvedPrefix = false;
  -
                bool    foundResultNamespaceForPrefix = false;
   
                XalanDOMString::size_type                       len = 
length(elemName);
  @@ -222,8 +220,6 @@
   
                                        if (m_namespaceAVT != 0)
                                        {
  -                                             hasUnresolvedPrefix = true;
  -
                                                elemName.erase(0, indexOfNSSep 
+ 1);
                                        }
                                        else
  @@ -252,80 +248,62 @@
                        if(0 == m_namespaceAVT &&
                           (havePrefix == false || 
foundResultNamespaceForPrefix == true))
                        {
  -                             outputResultNamespaces(executionContext, 
hasUnresolvedPrefix);
  +                             if (havePrefix == false)
  +                             {
  +                                     fixupDefaultNamespace(executionContext);
  +                             }
                        }
                        else
                        {
  -                             if(namespaceLen == 0 && hasUnresolvedPrefix == 
true)
  -                             {
  -                                     outputResultNamespaces(
  -                                             executionContext,
  -                                             hasUnresolvedPrefix,
  -                                             
length(getParentDefaultNamespace()) == 0 ? true : false);
  -                             }
  -                             else
  +                             if(havePrefix == false)
                                {
  -                                     if(havePrefix == false)
  +                                     if (namespaceLen > 0)
                                        {
  -                                             if (namespaceLen > 0)
  -                                             {
  -                                                     
outputResultNamespaces(executionContext, hasUnresolvedPrefix, true);
  -
  -                                                     const XalanDOMString* 
const             theDefaultNamespace =
  +                                             const XalanDOMString* const     
        theDefaultNamespace =
                                                                
executionContext.getResultNamespaceForPrefix(s_emptyString);
   
  -                                                     if (theDefaultNamespace 
== 0 ||
  -                                                             
equals(*theDefaultNamespace, elemNameSpace) == false)
  -                                                     {
  -                                                             
executionContext.addResultAttribute(
  +                                             if (theDefaultNamespace == 0 ||
  +                                                     
equals(*theDefaultNamespace, elemNameSpace) == false)
  +                                             {
  +                                                     
executionContext.addResultAttribute(
                                                                        
DOMServices::s_XMLNamespace,
                                                                        
elemNameSpace);
  -                                                     }
                                                }
  -                                             else
  -                                             {
  -                                                     // OK, the namespace 
we're generating is the default namespace,
  -                                                     // so let's make sure 
that we really need it.  If we don't,
  -                                                     // we end up with 
another xmlns="" on the element we're
  -                                                     // generating.  
Although this isn't really an error, it's
  -                                                     // a bit unsightly, so 
let's suppress it...
  -                                                     const XalanDOMString&   
theParentDefaultNamespace =
  +                                     }
  +                                     else
  +                                     {
  +                                             // OK, the namespace we're 
generating is the default namespace,
  +                                             // so let's make sure that we 
really need it.  If we don't,
  +                                             // we end up with another 
xmlns="" on the element we're
  +                                             // generating.  Although this 
isn't really an error, it's
  +                                             // a bit unsightly, so let's 
suppress it...
  +                                             const XalanDOMString&   
theParentDefaultNamespace =
                                                                
getParentDefaultNamespace();
   
  -                                                     if 
(length(theParentDefaultNamespace) == 0)
  -                                                     {
  -                                                             // There's not 
default namespace in effect, so suppress any
  -                                                             // default 
namespace in the statically-generated namespaces,
  -                                                             // and don't 
put out the one we've dynamically generated...
  -                                                             
outputResultNamespaces(executionContext, hasUnresolvedPrefix, true);
  -
  -                                                             if 
(executionContext.getResultNamespaceForPrefix(s_emptyString) != 0)
  -                                                             {
  -                                                                     
executionContext.addResultAttribute(DOMServices::s_XMLNamespace, elemNameSpace);
  -                                                             }
  -                                                     }
  -                                                     else
  +                                             if 
(length(theParentDefaultNamespace) == 0)
  +                                             {
  +                                                     if 
(executionContext.getResultNamespaceForPrefix(s_emptyString) != 0)
                                                        {
  -                                                             
outputResultNamespaces(executionContext, hasUnresolvedPrefix, false);
  -
                                                                
executionContext.addResultAttribute(DOMServices::s_XMLNamespace, elemNameSpace);
                                                        }
                                                }
  +                                             else
  +                                             {
  +                                                     
executionContext.addResultAttribute(DOMServices::s_XMLNamespace, elemNameSpace);
  +                                             }
                                        }
  -                                     else
  -                                     {
  -                                             
outputResultNamespaces(executionContext, hasUnresolvedPrefix);
  -
  -                                             const XalanDOMString* const     
        theNamespace =
  +                             }
  +                             else
  +                             {
  +                                     const XalanDOMString* const             
theNamespace =
                                                        
executionContext.getResultNamespaceForPrefix(prefix);
   
  -                                             if (theNamespace == 0 ||
  -                                                     equals(*theNamespace, 
elemNameSpace) == false)
  -                                             {
  -                                                     insert(prefix, 0, 
DOMServices::s_XMLNamespaceWithSeparator);
  +                                     if (theNamespace == 0 ||
  +                                             equals(*theNamespace, 
elemNameSpace) == false)
  +                                     {
  +                                             insert(prefix, 0, 
DOMServices::s_XMLNamespaceWithSeparator);
   
  -                                                     
executionContext.addResultAttribute(prefix, elemNameSpace);
  -                                             }
  +                                             
executionContext.addResultAttribute(prefix, elemNameSpace);
                                        }
                                }
                        }
  @@ -393,31 +371,40 @@
   
   
   void
  -ElemElement::outputResultNamespaces(
  -                     StylesheetExecutionContext&             
executionContext,                       
  -                     bool                                                    
hasUnresolvedPrefix,
  -                     bool                                                    
supressDefault) const
  +ElemElement::fixupDefaultNamespace(StylesheetExecutionContext&       
executionContext) const
   {
  -     getNamespacesHandler().outputResultNamespaces(executionContext, 
supressDefault);
  +     // OK, now let's check to make sure we don't have to change the default 
namespace...
  +     const XalanDOMString* const             theCurrentDefaultNamespace =
  +                             
executionContext.getResultNamespaceForPrefix(s_emptyString);
   
  -     if (supressDefault == false)
  -     {
  -             // OK, now let's check to make sure we don't have to change the 
default namespace...
  -             const XalanDOMString* const             
theCurrentDefaultNamespace =
  -                                     
executionContext.getResultNamespaceForPrefix(s_emptyString);
  +     const XalanDOMString* const             theElementDefaultNamespace =
  +                             
getNamespacesHandler().getNamespace(s_emptyString);
   
  -             if (theCurrentDefaultNamespace != 0)
  +     if (theCurrentDefaultNamespace != 0)
  +     {
  +             if (theElementDefaultNamespace == 0)
  +             {
  +                     // There was no default namespace, so we have to turn 
the
  +                     // current one off.
  +                     
executionContext.addResultAttribute(DOMServices::s_XMLNamespace, s_emptyString);
  +             }
  +             else if (equals(*theCurrentDefaultNamespace, 
*theElementDefaultNamespace) == false)
                {
  -                     const XalanDOMString* const             
theElementDefaultNamespace =
  -                                             
getNamespacesHandler().getNamespace(s_emptyString);
  +                     // There is a default namespace, but it's different 
from the current one,
  +                     // so we have to change it.
  +                     
executionContext.addResultAttribute(DOMServices::s_XMLNamespace, 
*theElementDefaultNamespace);
  +             }
  +     }
  +     else
  +     {
  +             // There's no current default namespace in the result tree, but 
there may be
  +             // on for this xsl:element instance, so we have to add it, if 
so.
  +             const XalanDOMString&   theParentDefaultNamespace =
  +                                     getParentDefaultNamespace();
   
  -                     if (hasUnresolvedPrefix == true || 
theElementDefaultNamespace == 0)
  -                     {
  -                             // There was no default namespace, so we have 
to turn the
  -                             // current one off.
  -                             
executionContext.addResultAttribute(DOMServices::s_XMLNamespace, s_emptyString);
  -                     }
  -                     else if (equals(*theCurrentDefaultNamespace, 
*theElementDefaultNamespace) == false)
  +             if (theElementDefaultNamespace != 0)
  +             {
  +                     if (length(theParentDefaultNamespace) == 0 || 
theParentDefaultNamespace != *theElementDefaultNamespace)
                        {
                                
executionContext.addResultAttribute(DOMServices::s_XMLNamespace, 
*theElementDefaultNamespace);
                        }
  
  
  
  1.2       +3 -8      xml-xalan/c/src/xalanc/XSLT/ElemElement.hpp
  
  Index: ElemElement.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/ElemElement.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ElemElement.hpp   29 Jun 2003 03:58:07 -0000      1.1
  +++ ElemElement.hpp   7 Jul 2003 23:53:43 -0000       1.2
  @@ -137,17 +137,12 @@
   private:
   
        /** 
  -      * Output the static namespace definitions.
  +      * Do any necessary fixup for the default namespace
         * 
         * @param executionContext The current execution context
  -      * @param true if the element being generated has an unresolved prefix.
  -      * @param supressDefault If true, any default namespace declaration 
will not be output.
         */
        void
  -     outputResultNamespaces(
  -                     StylesheetExecutionContext&             
executionContext,
  -                     bool                                                    
hasUnresolvedPrefix,
  -                     bool                                                    
supressDefault = false) const;
  +     fixupDefaultNamespace(StylesheetExecutionContext&       
executionContext) const;
   
        /** 
         * Get the default namespace from the parent of this element.  Returns
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to