dbertoni    00/08/27 18:19:44

  Modified:    c/src/XSLT ElemElement.cpp ElemElement.hpp
                        ElemLiteralResult.cpp ElemLiteralResult.hpp
                        ElemTemplate.cpp ElemTemplateElement.cpp
                        ElemTemplateElement.hpp Stylesheet.cpp
                        Stylesheet.hpp StylesheetExecutionContext.hpp
                        StylesheetExecutionContextDefault.cpp
                        StylesheetExecutionContextDefault.hpp
                        StylesheetHandler.cpp StylesheetHandler.hpp
                        XSLTEngineImpl.cpp XSLTEngineImpl.hpp
  Added:       c/src/XSLT NamespacesHandler.cpp NamespacesHandler.hpp
  Log:
  New result tree namespaces implementation.
  
  Revision  Changes    Path
  1.8       +26 -2     xml-xalan/c/src/XSLT/ElemElement.cpp
  
  Index: ElemElement.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemElement.cpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ElemElement.cpp   2000/08/22 20:21:17     1.7
  +++ ElemElement.cpp   2000/08/28 01:19:40     1.8
  @@ -68,6 +68,7 @@
   
   #include "AVT.hpp"
   #include "Constants.hpp"
  +#include "Stylesheet.hpp"
   #include "StylesheetConstructionContext.hpp"
   #include "StylesheetExecutionContext.hpp"
   
  @@ -87,7 +88,10 @@
                        columnNumber,
                        Constants::ELEMNAME_ELEMENT),
        m_nameAVT(0),
  -     m_namespaceAVT(0)       
  +     m_namespaceAVT(0),
  +     m_namespacesHandler(stylesheetTree.getNamespacesHandler(),
  +                                             stylesheetTree.getNamespaces(),
  +                                             
stylesheetTree.getXSLTNamespaceURI())   
   {
        const unsigned int      nAttrs = atts.getLength();
   
  @@ -137,6 +141,24 @@
   
   
   void
  +ElemElement::postConstruction(const NamespacesHandler&       
theParentHandler)
  +{
  +     m_namespacesHandler.postConstruction(getElementName(), 
&theParentHandler);
  +
  +     ElemUse::postConstruction(m_namespacesHandler);
  +}
  +
  +
  +
  +const NamespacesHandler&
  +ElemElement::getNamespacesHandler() const
  +{
  +     return m_namespacesHandler;
  +}
  +
  +
  +
  +void
   ElemElement::execute(
                        StylesheetExecutionContext&             
executionContext,
                        XalanNode*                                              
sourceTree,
  @@ -198,7 +220,7 @@
   
                        if(!isEmpty(elemNameSpace))
                        {
  -                             XalanDOMString  prefix = 
executionContext.getResultPrefixForNamespace(elemNameSpace);
  +                             XalanDOMString          prefix = 
executionContext.getResultPrefixForNamespace(elemNameSpace);
   
                                if(isEmpty(prefix))
                                {
  @@ -223,6 +245,8 @@
        }
   
        ElemUse::execute(executionContext, sourceTree, sourceNode, mode);
  +
  +     m_namespacesHandler.outputResultNamespaces(executionContext);
   
        executeChildren(executionContext, sourceTree, sourceNode, mode);
   
  
  
  
  1.5       +17 -3     xml-xalan/c/src/XSLT/ElemElement.hpp
  
  Index: ElemElement.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemElement.hpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ElemElement.hpp   2000/04/11 15:09:23     1.4
  +++ ElemElement.hpp   2000/08/28 01:19:40     1.5
  @@ -58,7 +58,7 @@
   #define XALAN_ELEMELEMENT_HEADER_GUARD 
   
   /**
  - * $Id: ElemElement.hpp,v 1.4 2000/04/11 15:09:23 dbertoni Exp $
  + * $Id: ElemElement.hpp,v 1.5 2000/08/28 01:19:40 dbertoni Exp $
    * 
    * 
    * $State: Exp $
  @@ -76,6 +76,10 @@
   
   
   
  +#include <XSLT/NamespacesHandler.hpp>
  +
  +
  +
   class AVT;
   
   
  @@ -107,6 +111,12 @@
   
        // These methods are inherited from ElemUse ...
   
  +     virtual const NamespacesHandler&
  +     getNamespacesHandler() const;
  +
  +     virtual void
  +     postConstruction(const NamespacesHandler&       theParentHandler);
  +
        virtual void 
        execute(
                        StylesheetExecutionContext&             
executionContext,
  @@ -122,8 +132,12 @@
        ElemElement&
        operator=(const ElemElement &);
   
  -     const AVT*      m_nameAVT;
  -     const AVT*      m_namespaceAVT;
  +     const AVT*                              m_nameAVT;
  +     const AVT*                              m_namespaceAVT;
  +     /*
  +      * This object handles all result tree namespace processing.
  +      */
  +     NamespacesHandler               m_namespacesHandler;
   };
   
   
  
  
  
  1.19      +85 -126   xml-xalan/c/src/XSLT/ElemLiteralResult.cpp
  
  Index: ElemLiteralResult.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemLiteralResult.cpp,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ElemLiteralResult.cpp     2000/08/22 20:21:18     1.18
  +++ ElemLiteralResult.cpp     2000/08/28 01:19:40     1.19
  @@ -98,7 +98,11 @@
                        name,
                        lineNumber,
                        columnNumber,
  -                     xslToken)
  +                     xslToken),
  +     m_avts(),
  +     m_namespacesHandler(stylesheetTree.getNamespacesHandler(),
  +                                             stylesheetTree.getNamespaces(),
  +                                             
stylesheetTree.getXSLTNamespaceURI())
   {
        const unsigned int      nAttrs = atts.getLength();
   
  @@ -125,9 +129,7 @@
                                {
                                        const XalanDOMString localName = 
substring(aname,indexOfNSSep + 1);
   
  -                                     processPrefixControl(localName, 
atts.getValue(i));
  -
  -                                     if(0 != m_excludeResultPrefixes.size())
  +                                     
if(processPrefixControl(constructionContext, stylesheetTree, localName, 
atts.getValue(i)) == true)
                                        {
                                                needToProcess = false;
                                        }
  @@ -159,8 +161,6 @@
                                                        *this, 
constructionContext));
                        }
                }
  -
  -             removeExcludedPrefixes(m_excludeResultPrefixes);
        }
   
        // Shrink the vector of AVTS, if necessary...
  @@ -187,15 +187,42 @@
   }
   
   
  +
  +const NamespacesHandler&
  +ElemLiteralResult::getNamespacesHandler() const
  +{
  +     return m_namespacesHandler;
  +}
  +
  +
  +
  +void
  +ElemLiteralResult::postConstruction(const NamespacesHandler& 
theParentHandler)
  +{
  +     const XalanDOMString&   theElementName = getElementName();
  +     assert(length(theElementName) > 0);
   
  -void ElemLiteralResult::execute(
  +     const unsigned int              indexOfNSSep = indexOf(theElementName, 
':');
  +
  +     const XalanDOMString    thePrefix = indexOfNSSep < 
length(theElementName) ?
  +                                     substring(theElementName, 0, 
indexOfNSSep) : XalanDOMString();
  +
  +     m_namespacesHandler.postConstruction(thePrefix, &theParentHandler);
  +
  +     ElemUse::postConstruction(m_namespacesHandler);
  +}
  +
  +
  +
  +void
  +ElemLiteralResult::execute(
                        StylesheetExecutionContext&             
executionContext,
                        XalanNode*                                              
sourceTree,
                        XalanNode*                                              
sourceNode,
                        const QName&                                    mode) 
const
   {
        executionContext.startElement(toCharArray(getElementName()));
  -     
  +
        ElemUse::execute(executionContext, sourceTree, sourceNode, mode);
   
        if(0 != m_avts.size())
  @@ -206,109 +233,36 @@
                {
                        const AVT* const        avt = m_avts[i];
   
  -                     XalanDOMString  stringedValue;
  +                     XalanDOMString  theStringedValue;
   
  -                     avt->evaluate(stringedValue, sourceNode, *this, 
executionContext);
  +                     avt->evaluate(theStringedValue, sourceNode, *this, 
executionContext);
   
  -                     if(!isEmpty(stringedValue))
  +                     if(isEmpty(theStringedValue) == false)
                        {
  -                             executionContext.replacePendingAttribute(
  -                                     c_wstr(avt->getName()), 
  -                                     c_wstr(avt->getType()),
  -                                     c_wstr(stringedValue));
  -                     }
  -             }
  -     }
  -
  -     // @@@ JMD:
  -     // This logic has been eliminated in the java version and replaced by a
  -     // method 'processResultNS' in the base class ElemTemplateElement
  -     // This also requires implementation of namespace alias logic
  -     const ElemTemplateElement*      elem = this;
  -
  -     const NamespaceVectorType*      nsVector = &elem->getNameSpace();
  +                             XalanDOMString          thePrefix;
   
  -     bool more = true;
  -
  -     while(more == true)
  -     {
  -             for (NamespaceVectorType::size_type i = 0; i < 
nsVector->size(); i++)
  -             {
  -                     const NameSpace&        ns = (*nsVector)[i];
  -
  -                     if(ns.getResultCandidate() == true)
  -                     {
  -                             const XalanDOMString&   srcURI = ns.getURI();
  +                             const XalanDOMString&   theName = 
avt->getName();
   
  -                             if (!isEmpty(srcURI))
  +                             if (startsWith(theName, 
DOMServices::s_XMLNamespaceWithSeparator) == true)
                                {
  -                                     const bool              hasPrefix = 
!isEmpty(ns.getPrefix());
  -
  -                                     const XalanDOMString    prefix = 
hasPrefix ? ns.getPrefix() : XalanDOMString();
  -
  -                                     XalanDOMString  attrName;
  -
  -                                     if (hasPrefix == true)
  -                                     {
  -                                             reserve(attrName, 
DOMServices::s_XMLNamespaceWithSeparatorLength + length(prefix) + 1);
  -
  -                                             attrName += 
DOMServices::s_XMLNamespaceWithSeparator;
  -                                             attrName += prefix;
  -                                     }
  -                                     else
  -                                     {
  -                                             attrName = 
DOMServices::s_XMLNamespace;
  -                                     }
  -
  -                                     const XalanDOMString    alias = 
getStylesheet().getAliasNamespaceURI(srcURI);
  -
  -                                     const XalanDOMString&   resultURI = 
length(alias) != 0 ? alias : srcURI;
  -
  -                                     const bool      isXSLNS =
  -                                             equals(resultURI, 
executionContext.getXSLNameSpaceURL()) ||
  -                                                        0 != 
getStylesheet().lookupExtensionNSHandler(srcURI) ||
  -                                                        equals(resultURI, 
executionContext.getXalanXSLNameSpaceURL());
  -
  -                                     const XalanDOMString    desturi = 
executionContext.getResultNamespaceForPrefix(prefix);
  -
  -                                     if(!isXSLNS && !equals(resultURI, 
desturi)) // TODO: Check for extension namespaces
  -                                     {
  -                                             
executionContext.addResultAttribute(attrName, resultURI);
  -                                     }
  +                                     thePrefix = substring(theName, 
DOMServices::s_XMLNamespaceWithSeparatorLength);
                                }
  -                     }
  -             }
  -
  -             // We didn't find a namespace, start looking at the parents
  -             if (0 != elem)
  -             {
  -                     elem = elem->getParentNodeElem();
   
  -                     while(0 != elem)
  -                     {
  -                             nsVector = &elem->getNameSpace();
  -
  -                             if(0 == nsVector->size())
  -                                     elem = elem->getParentNodeElem();
  -                             else
  -                                     break;
  +                             if (isEmpty(thePrefix) == true ||
  +                                 shouldExcludeResultNamespaceNode(
  +                                             thePrefix,
  +                                             theStringedValue) == false)
  +                             {
  +                                     
executionContext.replacePendingAttribute(
  +                                             c_wstr(avt->getName()), 
  +                                             c_wstr(avt->getType()),
  +                                             c_wstr(theStringedValue));
  +                             }
                        }
  -
  -                     // Last chance, try the stylesheet namespace
  -                     if (0 == nsVector || 0 == nsVector->size())
  -                             nsVector = &getStylesheet().getNamespaceDecls();
  -                     if (0 == nsVector || 0 == nsVector->size())
  -                             more = false;
                }
  -             else
  -                     more = false;
        }
  -/*
  -     java:
  -    // Handle namespaces(including those on the ancestor chain 
  -    // and stylesheet root declarations).
  -    processResultNS(processor);           
  -*/
  +
  +     m_namespacesHandler.outputResultNamespaces(executionContext);
   
        executeChildren(executionContext, sourceTree, sourceNode, mode);
   
  @@ -349,9 +303,9 @@
   
                        const XalanDOMString    ns = 
getStylesheet().getNamespaceForPrefixFromStack(prefix);
   
  -                     if (equals(ns, 
constructionContext.getXSLTNamespaceURI()) == true)
  +                     if (equals(ns, 
constructionContext.getXSLTNamespaceURI()) == false)
                        {
  -                             isAttrOK = false;
  +                             isAttrOK = true;
                        }
                }
                else
  @@ -367,35 +321,40 @@
   
   
   
  -void
  +bool
   ElemLiteralResult::processPrefixControl(
  -                     const XalanDOMString& localName, 
  -                     const XalanDOMString& attrValue) 
  -{                                                                            
                                       
  -     if(equals(localName, Constants::ATTRNAME_EXTENSIONELEMENTPREFIXES) ||
  -                     equals(localName, 
Constants::ATTRNAME_EXCLUDE_RESULT_PREFIXES))
  +                     StylesheetConstructionContext&  constructionContext,
  +                     const Stylesheet&                               
stylesheetTree,
  +                     const XalanDOMString&                   localName,
  +                     const XalanDOMString&                   attrValue)
  +{
  +     if(equals(localName, Constants::ATTRNAME_EXTENSIONELEMENTPREFIXES))
        {
  -             const XalanDOMString qnames = attrValue;
  -
  -             StringTokenizer tokenizer(qnames, " \t\n\r", false);
  +             
m_namespacesHandler.processExtensionElementPrefixes(c_wstr(attrValue), 
stylesheetTree.getNamespaces(), constructionContext);
   
  -             while(tokenizer.hasMoreTokens() == true)
  -             {
  -                     XalanDOMString  prefix = tokenizer.nextToken();
  +             return true;
  +     }
  +     else if (equals(localName, Constants::ATTRNAME_EXCLUDE_RESULT_PREFIXES))
  +     {
  +             
m_namespacesHandler.processExcludeResultPrefixes(c_wstr(attrValue), 
stylesheetTree.getNamespaces(), constructionContext);
   
  -                     if(equalsIgnoreCase(prefix, 
XALAN_STATIC_UCODE_STRING("#default")) == true)
  -                     {
  -                             clear(prefix);
  -                     }
  +             return true;
  +     }
  +     else
  +     {
  +             return false;
  +     }
  +}
   
  -                     const XalanDOMString    ns = 
getStylesheet().getNamespaceForPrefixFromStack(prefix);
   
  -                     if(isEmpty(ns) == true)
  -                     {
  -                             throw SAXException("Invalid prefix in 
exclude-result-prefixes");
  -                     }
   
  -                     
m_excludeResultPrefixes.insert(String2StringMapType::value_type(prefix, ns));
  -             }
  -     }
  +bool
  +ElemLiteralResult::shouldExcludeResultNamespaceNode(
  +                     const XalanDOMString&   thePrefix,
  +                     const XalanDOMString&   theURI) const
  +{
  +     return m_namespacesHandler.shouldExcludeResultNamespaceNode(
  +                             getStylesheet().getXSLTNamespaceURI(),
  +                             thePrefix,
  +                             theURI);
   }
  
  
  
  1.11      +44 -22    xml-xalan/c/src/XSLT/ElemLiteralResult.hpp
  
  Index: ElemLiteralResult.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemLiteralResult.hpp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ElemLiteralResult.hpp     2000/08/22 20:21:18     1.10
  +++ ElemLiteralResult.hpp     2000/08/28 01:19:40     1.11
  @@ -65,10 +65,14 @@
   
   
   // Base class header file.
  -#include "ElemUse.hpp"
  +#include <XSLT/ElemUse.hpp>
   
   
   
  +#include <XSLT/NamespacesHandler.hpp>
  +
  +
  +
   class AVT;
   
   
  @@ -101,6 +105,12 @@
   
        // These methods are inherited from ElemUse ...
        
  +     virtual const NamespacesHandler&
  +     getNamespacesHandler() const;
  +
  +     virtual void
  +     postConstruction(const NamespacesHandler&       theParentHandler);
  +
        virtual bool
        isAttrOK(
                        int                                             tok,
  @@ -130,37 +140,49 @@
        ElemLiteralResult&
        operator=(const ElemLiteralResult&);
   
  +     /**
  +      * Process the exclude-result-prefixes or the extension-element-prefixes
  +      * attributes, for the purpose of prefix exclusion.
  +      *
  +      * @param constructionContext  context when object consructed
  +      * @param stylesheetTree The current Stylesheet object.
  +      * @param localName The local name of the attribute.
  +      * @param attrValue The value of the attribute.
  +      */
  +     bool
  +     processPrefixControl(
  +                     StylesheetConstructionContext&  constructionContext,
  +                     const Stylesheet&                               
stylesheetTree,
  +                     const XalanDOMString&                   localName, 
  +                     const XalanDOMString&                   attrValue);
  +
  +     /**
  +      * Determine if the namespace node should be excluded.
  +      *
  +      * @param executionContext The current execution context
  +      * @param thePrefix The namespace prefix.
  +      * @param theURI The namespace URI.
  +      */
  +     bool
  +     shouldExcludeResultNamespaceNode(
  +                     const XalanDOMString&   thePrefix,
  +                     const XalanDOMString&   theURI) const;
  +
   #if defined(XALAN_NO_NAMESPACES)
        typedef vector<const AVT*>                              AVTVectorType;
  -     typedef vector<XalanDOMString>                  
ExtensionElementPrefixesVectorType;
   #else
        typedef std::vector<const AVT*>                 AVTVectorType;
  -     typedef std::vector<XalanDOMString>             
ExtensionElementPrefixesVectorType;
   #endif
   
        /**
  -      * A stack to keep track of the attribute elements.
  +      * A vector to keep track of the attribute elements.
         */
  -     AVTVectorType                                                   m_avts;
  +     AVTVectorType           m_avts;
   
  -
  -     ExtensionElementPrefixesVectorType              
m_extensionElementPrefixes;
  -     
  -     /**
  -      * This is in support of the exclude-result-prefixes attribute.  It is
  -      * really needed only at construction time, and so should probably go
  -      * somewhere else.
  -      */
  -     String2StringMapType                                    
m_excludeResultPrefixes;
  -
  -     /**
  -      * Process the exclude-result-prefixes or the extension-element-prefixes
  -      * attributes, for the purpose of prefix exclusion.
  +     /*
  +      * This object handles all result tree namespace processing.
         */
  -     void
  -     ElemLiteralResult::processPrefixControl(
  -                     const XalanDOMString&   localName, 
  -                     const XalanDOMString&   attrValue);
  +     NamespacesHandler               m_namespacesHandler;
   };
   
   
  
  
  
  1.7       +1 -1      xml-xalan/c/src/XSLT/ElemTemplate.cpp
  
  Index: ElemTemplate.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemTemplate.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ElemTemplate.cpp  2000/07/13 22:22:41     1.6
  +++ ElemTemplate.cpp  2000/08/28 01:19:40     1.7
  @@ -157,7 +157,7 @@
                        XalanNode*                                              
sourceTree,
                        XalanNode*                                              
sourceNode,
                        const QName&                                    mode) 
const
  -{    
  +{
        ElemTemplateElement::execute(executionContext, sourceTree, sourceNode, 
mode);
   
        executeChildren(executionContext, sourceTree, sourceNode, mode);
  
  
  
  1.31      +112 -206  xml-xalan/c/src/XSLT/ElemTemplateElement.cpp
  
  Index: ElemTemplateElement.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemTemplateElement.cpp,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- ElemTemplateElement.cpp   2000/08/22 20:21:20     1.30
  +++ ElemTemplateElement.cpp   2000/08/28 01:19:40     1.31
  @@ -96,6 +96,7 @@
   #include "ElemForEach.hpp"
   #include "ElemSort.hpp"
   #include "ElemTemplate.hpp"
  +#include "NamespacesHandler.hpp"
   #include "Stylesheet.hpp"
   #include "StylesheetExecutionContext.hpp"
   #include "StylesheetRoot.hpp"
  @@ -127,7 +128,6 @@
        m_columnNumber(columnNumber),
        m_defaultSpace(true),
        m_finishedConstruction(false),
  -     m_namespaces(),
        m_elemName(name),
        m_xslToken(xslToken),
        m_parentNode(0),
  @@ -139,36 +139,6 @@
        m_baseIndentifier(stylesheetTree.getCurrentIncludeBaseIdentifier())
   {
        assert(length(m_baseIndentifier) > 0);
  -
  -     /*
  -      * Copy the stylesheet namespaces to the element namespace vector
  -      */
  -     const Stylesheet::NamespacesStackType& stylesheetNamespaces =
  -             m_stylesheet.getNamespaces();
  -
  -     const int       n = stylesheetNamespaces.size();
  -
  -     for(int i = (n-1); i >= 0; i--)
  -     {
  -             const Stylesheet::NamespaceVectorType& nsVector = 
stylesheetNamespaces[i];
  -
  -             for(unsigned int j = 0; j < nsVector.size(); j++)
  -             {
  -                     const NameSpace&        ns = nsVector[j];
  -
  -                     if(isEmpty(ns.getURI()) == false)
  -                     {
  -                             
if(!shouldExcludeResultNamespaceNode(ns.getPrefix(), ns.getURI()))
  -                             {
  -                                     m_namespaces.push_back(ns);
  -                             }
  -                             else
  -                             {
  -                                     
m_excludedNamespaces.insert(String2StringMapType::value_type(ns.getPrefix(), 
ns.getURI()));
  -                             }
  -                     }
  -             }
  -     }
   }
   
   
  @@ -182,6 +152,21 @@
   
   
   
  +const NamespacesHandler&
  +ElemTemplateElement::getNamespacesHandler() const
  +{
  +     if (m_parentNode != 0)
  +     {
  +             return m_parentNode->getNamespacesHandler();
  +     }
  +     else
  +     {
  +             return m_stylesheet.getNamespacesHandler();
  +     }
  +}
  +
  +
  +
   bool
   ElemTemplateElement::isAttrOK(
                        int                                             tok,
  @@ -332,6 +317,7 @@
        // a string.
        DOMStringPrintWriter            thePrintWriter;
   
  +     // Create a FormatterToText.
        FormatterToText                         theFormatter(thePrintWriter);
   
        // Create an object to set and restore the execution state.
  @@ -913,133 +899,112 @@
                        const QName&                            mode,
                        int                                                     
xslToken) const
   {
  -     bool                            doApplyTemplate = true;
  -     bool                            shouldStrip = false;
  -
        const XalanNode::NodeType       nodeType = child->getNodeType();
   
  -     const Stylesheet*       stylesheetTree = &stylesheet_tree;
  +     if(0 == theTemplate)
  +     {
  +             // Find the XSL template that is the best match for the 
  +             // element, and call buildResultFromTemplate.
  +             const Stylesheet*       foundStylesheet = 0;
   
  -     const bool                      isApplyImports = xslToken == 
Constants::ELEMNAME_APPLY_IMPORTS;
  +             const bool                      isApplyImports = xslToken == 
Constants::ELEMNAME_APPLY_IMPORTS;
   
  -     if(!shouldStrip) // rcw: odd, seems that shouldStripis always false
  -     {
  -             if(0 == theTemplate)
  -             {
  -                     // Find the XSL template that is the best match for the 
  -                     // element, and call buildResultFromTemplate.
  -                     const Stylesheet*       foundStylesheet = 0;
  +             const Stylesheet*       stylesheetTree = isApplyImports ?
  +                                                             
&stylesheet_tree :
  +                                                             
&getStylesheet().getStylesheetRoot();
   
  -                     if(!isApplyImports)
  -                     {
  -                             
  -                             stylesheetTree = 
&getStylesheet().getStylesheetRoot();
  -                     }
  -                     
  -                     theTemplate = 
stylesheetTree->findTemplate(executionContext, sourceTree, child, mode,
  -                             isApplyImports, foundStylesheet);
  -                     
  -                     if(isApplyImports && (0 != theTemplate))
  -                     {
  -                             stylesheetTree = foundStylesheet;
  -                     }
  -                     // mode = null; // non-sticky modes
  -             }
  +             theTemplate = stylesheetTree->findTemplate(
  +                                             executionContext,
  +                                             sourceTree,
  +                                             child,
  +                                             mode,
  +                                             isApplyImports,
  +                                             foundStylesheet);
  +     }
   
  -             if(doApplyTemplate)  //rcw: seems to always be true
  +     if(0 == theTemplate)
  +     {
  +             switch(nodeType)
                {
  -                     if(0 == theTemplate)
  -                     {
  -                             switch(nodeType)
  -                             {
  -                             case XalanNode::DOCUMENT_FRAGMENT_NODE:
  -                             case XalanNode::ELEMENT_NODE:
  -                                     theTemplate = 
getStylesheet().getStylesheetRoot().getDefaultRule();
  -                                     break;
  -
  -                             case XalanNode::CDATA_SECTION_NODE:
  -                             case XalanNode::TEXT_NODE:
  -                             case XalanNode::ATTRIBUTE_NODE:
  -                                     theTemplate = 
getStylesheet().getStylesheetRoot().getDefaultTextRule();
  -                                     break;
  -
  -                             case XalanNode::DOCUMENT_NODE:
  -                                     theTemplate = 
getStylesheet().getStylesheetRoot().getDefaultRootRule();
  -                                     break;
  +             case XalanNode::DOCUMENT_FRAGMENT_NODE:
  +             case XalanNode::ELEMENT_NODE:
  +                     theTemplate = 
getStylesheet().getStylesheetRoot().getDefaultRule();
  +                     break;
   
  -                             default:
  -                                     break;
  +             case XalanNode::CDATA_SECTION_NODE:
  +             case XalanNode::TEXT_NODE:
  +             case XalanNode::ATTRIBUTE_NODE:
  +                     theTemplate = 
getStylesheet().getStylesheetRoot().getDefaultTextRule();
  +                     break;
   
  -                             }     
  +             case XalanNode::DOCUMENT_NODE:
  +                     theTemplate = 
getStylesheet().getStylesheetRoot().getDefaultRootRule();
  +                     break;
   
  -                             if(0 != theTemplate)
  -                             {
  -                               // Not sure if this is needed. -sb
  -                                     stylesheetTree = 
&getStylesheet().getStylesheetRoot();
  -                             }
  -                     }
  +             default:
  +                     break;
  +             }     
  +     }
                        
  -                     if(0 != theTemplate)
  -                     {
  -                             executionContext.resetCurrentState(sourceTree, 
child);
  +     if(0 != theTemplate)
  +     {
  +             executionContext.resetCurrentState(sourceTree, child);
                                
  -                             if(theTemplate == 
getStylesheet().getStylesheetRoot().getDefaultTextRule())
  -                             {
  -                                     switch(nodeType)
  -                                     {
  -                                     case XalanNode::CDATA_SECTION_NODE:
  -                                     case XalanNode::TEXT_NODE:
  -                                             
executionContext.cloneToResultTree(
  +             if(theTemplate == 
getStylesheet().getStylesheetRoot().getDefaultTextRule())
  +             {
  +                     switch(nodeType)
  +                     {
  +                     case XalanNode::CDATA_SECTION_NODE:
  +                     case XalanNode::TEXT_NODE:
  +                             executionContext.cloneToResultTree(
                                                        *child, false, false, 
false);
  -                                             break;
  +                             break;
   
  -                                     case XalanNode::ATTRIBUTE_NODE:
  -                                             {
  -                                                     const XalanAttr* const  
attr =
  +                     case XalanNode::ATTRIBUTE_NODE:
  +                             {
  +                                     const XalanAttr* const  attr =
   #if defined(XALAN_OLD_STYLE_CASTS)
  -                                                             (const 
XalanAttr*)child;
  +                                             (const XalanAttr*)child;
   #else
  -                                                             
static_cast<const XalanAttr*>(child);
  +                                             static_cast<const 
XalanAttr*>(child);
   #endif
   
  -                                                     const XalanDOMString    
val = attr->getValue();
  +                                     const XalanDOMString    val = 
attr->getValue();
   
  -                                                     
executionContext.characters(toCharArray(val), 
  -                                                                             
                                0,
  -                                                                             
                                length(val));
  -                                             }
  -                                             break;
  -
  -                                     default:
  -                                             assert(false);
  -                                             break;
  -                                     }
  +                                     
executionContext.characters(toCharArray(val), 
  +                                                                             
                0,
  +                                                                             
                length(val));
                                }
  -                             else
  -                             {
  -                                     if(0 != 
executionContext.getTraceListeners())
  -                                     {
  -                                             TracerEvent te(executionContext,
  -                                                                        
sourceTree,
  -                                                                        
child, 
  -                                                                             
mode,
  -                                                                             
*theTemplate);
  -
  -                                             
executionContext.fireTraceEvent(te);
  -                                     }
  -
  -                                     
theTemplate->executeChildren(executionContext, 
  -                                                                             
                 sourceTree,
  -                                                                             
                 child,
  -                                                                             
                 mode);
  -                             }
  +                             break;
  +
  +                     default:
  +                             assert(false);
  +                             break;
  +                     }
  +             }
  +             else
  +             {
  +                     if(0 != executionContext.getTraceListeners())
  +                     {
  +                             TracerEvent te(executionContext,
  +                                                        sourceTree,
  +                                                        child, 
  +                                                             mode,
  +                                                             *theTemplate);
   
  -                             executionContext.resetCurrentState(sourceTree, 
selectContext);
  +                             executionContext.fireTraceEvent(te);
                        }
  +
  +                     theTemplate->executeChildren(executionContext, 
  +                                                                             
 sourceTree,
  +                                                                             
 child,
  +                                                                             
 mode);
                }
  +
  +             executionContext.resetCurrentState(sourceTree, selectContext);
        }
   
  -     return doApplyTemplate;
  +     return true;
   }
   
   
  @@ -1370,69 +1335,14 @@
   }
   
   
  -void
  -ElemTemplateElement::removeExcludedPrefixes(const String2StringMapType&      
        excludeResultPrefixes)
  -{
  -     if(0 !=excludeResultPrefixes.size() && 0 != m_namespaces.size())
  -     {
  -             const NamespaceVectorType::iterator             theEnd =
  -                     m_namespaces.end();
  -
  -             for(NamespaceVectorType::iterator it = m_namespaces.begin();
  -                             it != theEnd; )
  -             {
  -                     const NameSpace&        ns = *it;
   
  -                     const XalanDOMString&   prefix = ns.getPrefix();
  -
  -                     const String2StringMapType::const_iterator      it2 =
  -                             excludeResultPrefixes.find(prefix);
  -
  -                     if(it2 != excludeResultPrefixes.end())
  -                     {
  -                             
m_excludedNamespaces.insert(String2StringMapType::value_type(prefix, 
ns.getURI()));
  -
  -                             it = m_namespaces.erase(it);
  -                     }
  -                     else
  -                     {
  -                             ++it;
  -                     }
  -             }
  -     }
  -}
  - 
  -
  - 
  -bool
  -ElemTemplateElement::shouldExcludeResultNamespaceNode(
  -             const XalanDOMString&   prefix,
  -             const XalanDOMString&   uri)
  +void
  +ElemTemplateElement::postConstruction(const NamespacesHandler&       
theParentHandler)
   {
  -/*
  -     @@ JMD: Need to implement this ---
  -
  -     if(uri.equals(m_stylesheet.m_XSLNameSpaceURL)
  -                     || (null != m_stylesheet.lookupExtensionNSHandler(uri))
  -                     || uri.equals("http://xml.apache.org/xslt";)
  -                     || uri.equals("http://xsl.lotus.com/";)
  -                     || uri.equals("http://xsl.lotus.com";))
  -             return true; 
  -     ElemTemplateElement elem = this;
  -     while(0 != elem)
  -     {
  -             elem = elem.m_parentNode;
  -             if(0 == elem)
  -             {
  -                     if(0 != m_stylesheet.m_excludeResultPrefixes)
  -                     {
  -                             
if(m_stylesheet.m_excludeResultPrefixes.contains(prefix))
  -                                     return true;
  -                     }
  -             }
  +    for (ElemTemplateElement* node = m_firstChild; node != 0; node = 
node->m_nextSibling) 
  +    {
  +             node->postConstruction(theParentHandler);
        }
  -*/
  -     return false;
   }
   
   
  @@ -1575,20 +1485,16 @@
                         }
                         else
                         {
  -                              const ElemTemplateElement*  elem = this;
  -
  -                              while(isEmpty(nameSpace) && elem != 0)
  -                              {
  -                                      const NamespaceVectorType&             
nsVector = elem->getNameSpace();
  +                              nameSpace = 
getNamespacesHandler().getNamespace(prefix);
   
  -                                      nameSpace = 
QName::getNamespaceForPrefix(nsVector, prefix);
  -
  -                                      if (!isEmpty(nameSpace))
  -                                              break;
  -
  -                                      elem = elem->getParentNodeElem();
  -                              }
  -                      }
  +                             if(isEmpty(nameSpace) == true)
  +                             {
  +                                      if (m_parentNode != 0)
  +                                      {
  +                                             nameSpace = 
m_parentNode->getNamespaceForPrefixInternal(prefix, false);
  +                                      }
  +                             }
  +                     }
                }
                else
                {
  
  
  
  1.17      +27 -66    xml-xalan/c/src/XSLT/ElemTemplateElement.hpp
  
  Index: ElemTemplateElement.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemTemplateElement.hpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ElemTemplateElement.hpp   2000/08/22 20:21:20     1.16
  +++ ElemTemplateElement.hpp   2000/08/28 01:19:40     1.17
  @@ -81,7 +81,6 @@
   
   
   #include <XPath/PrefixResolver.hpp>
  -#include <XPath/NameSpace.hpp>
   
   
   
  @@ -90,6 +89,7 @@
   
   
   class AttributeList;
  +class NamespacesHandler;
   class NodeRefListBase;
   class QName;
   class Stylesheet;
  @@ -205,7 +205,7 @@
         * Execute the element's primary function.  Subclasses of this function 
may
         * recursively execute down the element tree.
         * 
  -      * @param processor  XSLT Processor
  +      * @param executionContext  The current execution context
         * @param sourceTree input source tree
         * @param sourceNode current context node
         * @param mode       current mode
  @@ -236,19 +236,7 @@
         * Take the contents of a template element, process it, and
         * convert it to a string.
         * 
  -      * @exception XSLProcessorException thrown from one of the child 
execute  
  -      *                                  methods
  -      * @exception java.net.MalformedURLException might be thrown from the   
    
  -      *                                  document() function, or from 
xsl:include or xsl:import
  -      * @exception java.io.FileNotFoundException might be thrown from the    
    
  -      *                                  document() function, or from
  -      *                                  xsl:include or xsl:import
  -      * @exception java.io.IOException might be thrown from the  document()  
    
  -      *                                function, or from xsl:include or
  -      *                                xsl:import
  -      * @exception SAXException might be thrown from the  document() 
function, or
  -      *                         from xsl:include or xsl:import
  -      * @param processor  XSLT processor instance
  +      * @param executionContext  The current execution context
         * @param sourceTree primary source tree
         * @param sourceNode current source node context
         * @param mode       current mode
  @@ -322,24 +310,21 @@
        }
   
   #if defined(XALAN_NO_NAMESPACES)
  -     typedef vector<NameSpace>               NamespaceVectorType;
  -     typedef map<XalanDOMString, XalanDOMString, less<XalanDOMString> >      
String2StringMapType;
  +     typedef map<XalanDOMString,
  +                             XalanDOMString,
  +                             less<XalanDOMString> >  StringToStringMapType;
   #else
  -     typedef std::vector<NameSpace>          NamespaceVectorType;
  -     typedef std::map<XalanDOMString, XalanDOMString>        
String2StringMapType;
  -
  +     typedef std::map<XalanDOMString,
  +                                      XalanDOMString>        
StringToStringMapType;
   #endif
   
        /** 
  -      * Get the list of namespaces for this element.
  +      * Get the namespaces handler for this element.
         * 
  -      * @return vector of namespaces
  +      * @return The element's NamespacesHandler instance.
         */
  -     const NamespaceVectorType&
  -     getNameSpace() const
  -     {
  -             return m_namespaces;
  -     }
  +     virtual const NamespacesHandler&
  +     getNamespacesHandler() const;
   
        /**
         * Retrieve the stylesheet from which this element comes
  @@ -354,22 +339,18 @@
   
        /** 
         * Set a flag indicating construction of the element is completed.
  -      * 
  -      * @param bFinished true if construction completed
         */
        void
  -     setFinishedConstruction(bool bFinished)
  +     finishedConstruction()
        {
  -             m_finishedConstruction = bFinished;
  +             m_finishedConstruction = true;
        }
   
  -  /**
  -   * Remove any excluded prefixes from the current namespaces.
  -     * 
  -     * @param map of prefixes and associated namespaces to be excluded
  -   */
  -  void removeExcludedPrefixes(const String2StringMapType& 
excludeResultPrefixes);
  -
  +     /**
  +      * Called after construction is completed.
  +      */
  +     virtual void
  +     postConstruction(const NamespacesHandler&       theParentHandler);
   
        // Type-safe getters/setters...
   
  @@ -671,6 +652,7 @@
        /**
         * Perform a query if needed, and call transformChild for each child.
         * 
  +      * @param executionContext  The current execution context
         * @param stylesheetTree The owning stylesheet tree.
         * @param xslInstruction The stylesheet element context (deprecated -- 
I do 
         *      not think we need this).
  @@ -700,6 +682,7 @@
        /**
         * Perform a query if needed, and call transformChild for each child.
         * 
  +      * @param executionContext The current execution context
         * @param stylesheetTree The owning stylesheet tree.
         * @param xslInstruction The stylesheet element context (deprecated -- 
I do 
         *      not think we need this).
  @@ -731,6 +714,7 @@
        /**
         * Perform a query if needed, and call transformChild for each child.
         * 
  +      * @param executionContext The current execution context
         * @param stylesheetTree The owning stylesheet tree.
         * @param xslInstruction The stylesheet element context (deprecated -- 
I do 
         *      not think we need this).
  @@ -772,26 +756,11 @@
                        const NodeRefListBase&                          
sourceNodes,
                        unsigned int                                            
sourceNodesCount) const;
   
  -  /**
  -   * Tell if the result namespace decl should be excluded.  Should be called 
before 
  -   * namespace aliasing (I think).
  -   * TODO: I believe this contains a bug, in that included elements will 
check with with 
  -   * their including stylesheet, since in this implementation right now the 
included 
  -   * templates are merged with the including stylesheet.  The XSLT 
Recommendation says: "The 
  -   * designation of a namespace as an excluded namespace is effective within 
  -   * the subtree of the stylesheet rooted at the element bearing the 
  -   * <code>exclude-result-prefixes</code> or 
<code>xsl:exclude-result-prefixes</code> 
  -   * attribute; a subtree rooted at an <code>xsl:stylesheet</code> element
  -   * does not include any stylesheets imported or included by children
  -   * of that <code>xsl:stylesheet</code> element."
  -   */
  -  bool shouldExcludeResultNamespaceNode(
  -               const XalanDOMString& prefix, const XalanDOMString& uri);
  -
        /**
         * Given an element and mode, find the corresponding
         * template and process the contents.
         * 
  +      * @param executionContext The current execution context
         * @param stylesheetTree The current Stylesheet object.
         * @param xslInstruction The calling element (deprecated -- I dont 
think we 
         *      need this).
  @@ -831,6 +800,10 @@
        virtual bool
        childTypeAllowed(int    xslToken) const;
   
  +protected:
  +
  +     bool                                    m_finishedConstruction;
  +
   private:
   
        Stylesheet&                             m_stylesheet;
  @@ -838,19 +811,7 @@
        const int                               m_lineNumber;
        const int                               m_columnNumber;
   
  -     NamespaceVectorType     m_namespaces;
  -
  -     /** 
  -      * The table of namespaces that are excluded from being 
  -      * used in the result tree but which need to be used 
  -      * in to resolve prefixes.
  -      * @serial
  -      */
  -     String2StringMapType    m_excludedNamespaces;
  -
        bool                                    m_defaultSpace;
  -     bool                                    m_finishedConstruction;
  -
        const XalanDOMString    m_elemName;
   
        const int                               m_xslToken;
  
  
  
  1.34      +57 -4     xml-xalan/c/src/XSLT/Stylesheet.cpp
  
  Index: Stylesheet.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/Stylesheet.cpp,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- Stylesheet.cpp    2000/08/22 20:21:26     1.33
  +++ Stylesheet.cpp    2000/08/28 01:19:41     1.34
  @@ -144,11 +144,13 @@
        m_surrogateChildren(*this),
        m_fakeAttributes(),
        m_elemDecimalFormats(),
  -     m_prefixAliases()
  +     m_prefixAliases(),
  +     m_namespacesHandler()
   {
        if (length(m_baseIdent) != 0)
        {
                const XalanDOMString urlString = 
constructionContext.getURLStringFromString(m_baseIdent);
  +
                if (length(urlString) != 0)
                {
                        m_includeStack.push_back(urlString);
  @@ -321,6 +323,41 @@
   
   
   
  +void
  +Stylesheet::postConstruction()
  +{
  +     // Get any aliases from the imported stylesheets, in reverse order, to
  +     // preserve import precedence.
  +     const StylesheetVectorType::reverse_iterator    theEnd = 
m_imports.rend();
  +     StylesheetVectorType::reverse_iterator  i = m_imports.rbegin();
  +
  +     while(i != theEnd)
  +     {
  +             
m_namespacesHandler.copyNamespaceAliases((*i)->getNamespacesHandler());
  +
  +             ++i;
  +     }
  +
  +     // Call postConstruction() on our own handler...
  +     m_namespacesHandler.postConstruction();
  +
  +     ElemTemplateElement* node = m_firstTemplate;
  +
  +    for (; node != 0; node = node->getNextSiblingElem()) 
  +    {
  +             node->postConstruction(m_namespacesHandler);
  +     }
  +
  +     node = m_wrapperlessTemplate;
  +
  +    for (; node != 0; node = node->getNextSiblingElem())
  +    {
  +             node->postConstruction(m_namespacesHandler);
  +     }
  +}
  +
  +
  +
   bool
   Stylesheet::isAttrOK(
                        const XalanDOMChar*                     attrName,
  @@ -1068,11 +1105,14 @@
                        ExtensionNSHandler*             nsh)
   {
        
m_extensionNamespaces.insert(ExtensionNamespacesMapType::value_type(uri, nsh));
  +
  +     m_namespacesHandler.addExtensionNamespaceURI(uri);
   }
   
   
   
  -void Stylesheet::pushTopLevelVariables(
  +void
  +Stylesheet::pushTopLevelVariables(
                        StylesheetExecutionContext&     executionContext,
                        const ParamVectorType&                  topLevelParams) 
const
   {
  @@ -1228,6 +1268,8 @@
   #if 1
                // $$$ ToDo: Enable other code.  Perhaps an error?
                m_prefixAliases[stylesheetNamespace] = resultNamespace;
  +
  +             m_namespacesHandler.setNamespaceAlias(stylesheetNamespace, 
resultNamespace);
   #else
                const PrefixAliasesMapType::iterator    i =
                        m_prefixAliases.find(stylesheetNamespace);
  @@ -1256,7 +1298,7 @@
   {
        XalanDOMString  result;
   
  -     const PrefixAliasesMapType::const_iterator      i =
  +     const StringToStringMapType::const_iterator     i =
                m_prefixAliases.find(uri);
   
        if (i != m_prefixAliases.end())
  @@ -1286,6 +1328,16 @@
   
   
   
  +void
  +Stylesheet::processExcludeResultPrefixes(
  +             const XalanDOMChar*                             theValue,
  +             StylesheetConstructionContext&  theConstructionContext)
  +{
  +     m_namespacesHandler.processExcludeResultPrefixes(theValue, 
m_namespaces, theConstructionContext);
  +}
  +
  +
  +
   const Stylesheet*
   Stylesheet::getPreviousImport(const Stylesheet*              stylesheet) 
const
   {
  @@ -1395,7 +1447,8 @@
    * contain the same attribute unless there is a definition of the attribute 
    * set with higher import precedence that also contains the attribute."
    */
  -void Stylesheet::applyAttrSets(
  +void
  +Stylesheet::applyAttrSets(
                        const QNameVectorType&                  
attributeSetsNames, 
                        StylesheetExecutionContext&     executionContext, 
                        XalanNode*                                              
sourceTree, 
  
  
  
  1.25      +49 -10    xml-xalan/c/src/XSLT/Stylesheet.hpp
  
  Index: Stylesheet.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/Stylesheet.hpp,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Stylesheet.hpp    2000/08/22 20:21:26     1.24
  +++ Stylesheet.hpp    2000/08/28 01:19:41     1.25
  @@ -85,6 +85,7 @@
   
   
   
  +#include "NamespacesHandler.hpp"
   #include "KeyDeclaration.hpp"
   #include "StylesheetExecutionContext.hpp"
   
  @@ -120,10 +121,14 @@
   
   public:
   
  +     typedef StylesheetExecutionContext::ParamVectorType             
ParamVectorType;
  +     typedef NamespacesHandler::NamespaceVectorType                  
NamespaceVectorType;
  +     typedef NamespacesHandler::NamespacesStackType                  
NamespacesStackType;
  +
   #if defined(XALAN_NO_NAMESPACES)
        typedef map<XalanDOMString,
                                XalanDOMString,
  -                             less<XalanDOMString> >                          
PrefixAliasesMapType;
  +                             less<XalanDOMString> >                          
StringToStringMapType;
        typedef map<XalanDOMString,
                                ExtensionNSHandler*,
                                less<XalanDOMString> >                          
ExtensionNamespacesMapType;
  @@ -137,15 +142,13 @@
        typedef map<const XalanNode*,
                                KeyTable*,
                                less<const XalanNode*> >                        
KeyTablesTableType;
  -     typedef vector<NameSpace>                                               
NamespaceVectorType;
  -     typedef vector<NamespaceVectorType>                             
NamespacesStackType;
        typedef vector<QName>                                                   
QNameVectorType;
        typedef vector<const Stylesheet*>                               
StylesheetVectorType;
        typedef vector<XalanDOMString>                                  
URLStackType;
        typedef vector<const XPath*>                                    
XPathVectorType;
        typedef vector<ElemDecimalFormat*>                              
ElemDecimalFormatVectorType;
   #else
  -     typedef std::map<XalanDOMString, XalanDOMString>                
PrefixAliasesMapType;
  +     typedef std::map<XalanDOMString, XalanDOMString>                
StringToStringMapType;
        typedef std::map<XalanDOMString, ExtensionNSHandler*>   
ExtensionNamespacesMapType;
        typedef std::map<QName, ElemTemplate*>                                  
ElemTemplateMapType;
        typedef std::vector<ElemAttributeSet*>                                  
AttributeSetMapType;
  @@ -153,8 +156,6 @@
        typedef std::vector<KeyDeclaration>                                     
        KeyDeclarationVectorType;
        typedef std::vector<KeyTable*>                                          
        KeyTableVectorType;
        typedef std::map<const XalanNode*, KeyTable*>                   
KeyTablesTableType;
  -     typedef std::vector<NameSpace>                                          
        NamespaceVectorType;
  -     typedef std::vector<NamespaceVectorType>                                
NamespacesStackType;
        typedef std::vector<QName>                                              
                QNameVectorType;
        typedef std::vector<const Stylesheet*>                                  
StylesheetVectorType;
        typedef std::vector<XalanDOMString>                                     
        URLStackType;
  @@ -162,9 +163,6 @@
        typedef std::vector<ElemDecimalFormat*>                                 
ElemDecimalFormatVectorType;
   #endif
   
  -
  -     typedef StylesheetExecutionContext::ParamVectorType     ParamVectorType;
  -
        /**
         * Constructor for a Stylesheet needs a Document.
         * @exception XSLProcessorException thrown if the active 
ProblemListener and XMLParserLiaison decide 
  @@ -267,6 +265,18 @@
                return m_namespaces;
        }
   
  +     const NamespacesHandler&
  +     getNamespacesHandler() const
  +     {
  +             return m_namespacesHandler;
  +     }
  +
  +     NamespacesHandler&
  +     getNamespacesHandler()
  +     {
  +             return m_namespacesHandler;
  +     }
  +
        /**
         * Retrieve the list of namespace declarations currently in effect
         * 
  @@ -322,6 +332,12 @@
        void
        popNamespaces();
   
  +     /**
  +      * Called after construction is completed.
  +      */
  +     virtual void
  +     postConstruction();
  +
        /** 
         * See if this is a xmlns attribute, and, if so, process it.
         * 
  @@ -367,6 +383,18 @@
        getAliasNamespaceURI(const XalanDOMString&      uri) const;
   
        /**
  +      * See if a namespace should be excluded.
  +      * 
  +      * @param theValue the prefix of the namespace.
  +      * @param theConstructionContext the current construction context.
  +      * @return
  +      */
  +     void
  +     processExcludeResultPrefixes(
  +             const XalanDOMChar*                             theValue,
  +             StylesheetConstructionContext&  theConstructionContext);
  +
  +     /**
         * This recursive function is called starting from the
         * stylesheet root, and tries to find a match for the
         * passed stylesheet, and then will return the previous
  @@ -1139,6 +1167,15 @@
   
   private:     
   
  +     // Not defined...
  +     Stylesheet(const Stylesheet&);
  +
  +     Stylesheet&
  +     operator=(const Stylesheet&);
  +
  +     bool
  +     operator==(const Stylesheet&) const;
  +
        /**
         * The full XSLT Namespace URI.  To be replaced by the one actually
         * found.
  @@ -1281,8 +1318,10 @@
        XalanEmptyNamedNodeMap  m_fakeAttributes;
   
        ElemDecimalFormatVectorType             m_elemDecimalFormats;
  +
  +     StringToStringMapType                   m_prefixAliases;
   
  -     PrefixAliasesMapType    m_prefixAliases;
  +     NamespacesHandler               m_namespacesHandler;
   };
   
   
  
  
  
  1.30      +2 -2      xml-xalan/c/src/XSLT/StylesheetExecutionContext.hpp
  
  Index: StylesheetExecutionContext.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetExecutionContext.hpp,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- StylesheetExecutionContext.hpp    2000/08/22 20:21:27     1.29
  +++ StylesheetExecutionContext.hpp    2000/08/28 01:19:41     1.30
  @@ -569,7 +569,7 @@
         * 
         * @param theNamespace namespace for prefix
         */
  -     virtual XalanDOMString
  +     virtual const XalanDOMString&
        getResultPrefixForNamespace(const XalanDOMString&       theNamespace) 
const = 0;
   
        /**
  @@ -577,7 +577,7 @@
         * 
         * @param thePrefix prefix for namespace
         */
  -     virtual XalanDOMString
  +     virtual const XalanDOMString&
        getResultNamespaceForPrefix(const XalanDOMString&       thePrefix) 
const = 0;
   
        /**
  
  
  
  1.32      +2 -2      
xml-xalan/c/src/XSLT/StylesheetExecutionContextDefault.cpp
  
  Index: StylesheetExecutionContextDefault.cpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/c/src/XSLT/StylesheetExecutionContextDefault.cpp,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- StylesheetExecutionContextDefault.cpp     2000/08/22 20:21:27     1.31
  +++ StylesheetExecutionContextDefault.cpp     2000/08/28 01:19:41     1.32
  @@ -324,7 +324,7 @@
   
   
   
  -XalanDOMString
  +const XalanDOMString&
   StylesheetExecutionContextDefault::getResultPrefixForNamespace(
                        const XalanDOMString&   theNamespace) const
   {
  @@ -333,7 +333,7 @@
   
   
   
  -XalanDOMString
  +const XalanDOMString&
   StylesheetExecutionContextDefault::getResultNamespaceForPrefix(const 
XalanDOMString& thePrefix) const
   {
        return m_xsltProcessor.getResultNamespaceForPrefix(thePrefix);
  
  
  
  1.31      +2 -2      
xml-xalan/c/src/XSLT/StylesheetExecutionContextDefault.hpp
  
  Index: StylesheetExecutionContextDefault.hpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/c/src/XSLT/StylesheetExecutionContextDefault.hpp,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- StylesheetExecutionContextDefault.hpp     2000/08/22 20:21:28     1.30
  +++ StylesheetExecutionContextDefault.hpp     2000/08/28 01:19:41     1.31
  @@ -174,10 +174,10 @@
                        const XalanNode&        src,
                        bool                            srcIsStylesheetTree);
   
  -     virtual XalanDOMString
  +     virtual const XalanDOMString&
        getResultPrefixForNamespace(const XalanDOMString&       theNamespace) 
const;
   
  -     virtual XalanDOMString
  +     virtual const XalanDOMString&
        getResultNamespaceForPrefix(const XalanDOMString&       thePrefix) 
const;
   
        virtual XalanDOMString
  
  
  
  1.40      +8 -14     xml-xalan/c/src/XSLT/StylesheetHandler.cpp
  
  Index: StylesheetHandler.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetHandler.cpp,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- StylesheetHandler.cpp     2000/08/22 23:27:58     1.39
  +++ StylesheetHandler.cpp     2000/08/28 01:19:41     1.40
  @@ -548,18 +548,7 @@
                                                }
                                                else if(equals(aname, 
Constants::ATTRNAME_EXCLUDE_RESULT_PREFIXES))
                                                {
  -                                                     
m_constructionContext.warn(Constants::ATTRNAME_EXCLUDE_RESULT_PREFIXES
  -                                                                     + " not 
supported yet!");
  -
  -                                             /*
  -                                                     @@ TODO: implement this 
---
  -                                                     StringToStringTable 
excluded =
  -                                                             
m_stylesheet.getExcludeResultPrefixes();
  -                                                     excluded =
  -                                                             
m_stylesheet.processExcludeResultPrefixes(atts.getValue(i),
  -                                                                             
excluded);
  -                                                     
m_stylesheet.setExcludeResultPrefixes(excluded);
  -                                             */
  +                                                     
m_stylesheet.processExcludeResultPrefixes(atts.getValue(i), 
m_constructionContext);
                                                }
                                                else if(equals(aname, 
Constants::ATTRNAME_EXTENSIONELEMENTPREFIXES))
                                                {
  @@ -1202,6 +1191,8 @@
   
                        m_constructionContext.parseXML(hrefUrl, &tp, 
importedStylesheet.get());
   
  +                     importedStylesheet->postConstruction();
  +
                        // Add it to the front of the imports, releasing the 
XalanAutoPtr...
                        m_stylesheet.addImport(importedStylesheet.release(), 
true);
   
  @@ -1290,7 +1281,7 @@
        m_lastPopped = m_elemStack.back();
        m_elemStack.pop_back();
        m_elemStackParentedElements.erase(m_lastPopped);
  -     m_lastPopped->setFinishedConstruction(true);
  +     m_lastPopped->finishedConstruction();
   
        const int tok = m_lastPopped->getXSLToken();
   
  @@ -1628,7 +1619,8 @@
        m_XSLNameSpaceURL(theHandler.m_stylesheet.getXSLTNamespaceURI()),
        m_foundNotImport(theHandler.m_foundNotImport),
        m_namespaceDecls(),
  -     m_namespaces()
  +     m_namespaces(),
  +     m_namespacesHandler()
   {
        m_handler.m_elemStack.clear();
        m_handler.m_pTemplate = 0;
  @@ -1641,6 +1633,7 @@
        // underlying data.  This clears out the stack as well...
        m_namespaceDecls.swap(theHandler.m_stylesheet.getNamespaceDecls());
        m_namespaces.swap(theHandler.m_stylesheet.getNamespaces());
  +     
m_namespacesHandler.swap(theHandler.m_stylesheet.getNamespacesHandler());
   }
   
   
  @@ -1670,4 +1663,5 @@
        // underlying data.
        m_handler.m_stylesheet.getNamespaceDecls().swap(m_namespaceDecls);
        m_handler.m_stylesheet.getNamespaces().swap(m_namespaces);
  +     m_handler.m_stylesheet.getNamespacesHandler().swap(m_namespacesHandler);
   }
  
  
  
  1.18      +3 -0      xml-xalan/c/src/XSLT/StylesheetHandler.hpp
  
  Index: StylesheetHandler.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetHandler.hpp,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- StylesheetHandler.hpp     2000/08/23 20:16:45     1.17
  +++ StylesheetHandler.hpp     2000/08/28 01:19:41     1.18
  @@ -79,6 +79,7 @@
   
   
   
  +#include <XSLT/NamespacesHandler.hpp>
   #include <XSLT/Stylesheet.hpp>
   
   
  @@ -520,6 +521,8 @@
                Stylesheet::NamespaceVectorType         m_namespaceDecls;
   
                Stylesheet::NamespacesStackType         m_namespaces;
  +
  +             NamespacesHandler                                       
m_namespacesHandler;
        };
   
        friend class PushPopIncludeState;
  
  
  
  1.59      +8 -2      xml-xalan/c/src/XSLT/XSLTEngineImpl.cpp
  
  Index: XSLTEngineImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/XSLTEngineImpl.cpp,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- XSLTEngineImpl.cpp        2000/08/22 20:21:31     1.58
  +++ XSLTEngineImpl.cpp        2000/08/28 01:19:41     1.59
  @@ -582,6 +582,8 @@
                                if(0 != m_diagnosticsPrintWriter)
                                        
displayDuration(XALAN_STATIC_UCODE_STRING("Parse of ") + xslIdentifier, 
&xslIdentifier);
                        }
  +
  +                     theStylesheet->postConstruction();
                }
                catch(const XSLException&)
                {
  @@ -881,6 +883,8 @@
                        
displayDuration(XalanDOMString(XALAN_STATIC_UCODE_STRING("Setup of ")) +
                                                                
localXSLURLString,
                                                                &frag);
  +
  +                     stylesheet->postConstruction();
                }
                else
                {
  @@ -925,6 +929,8 @@
   
                m_parserLiaison.parseXMLStream(inputSource, 
stylesheetProcessor);
   
  +             stylesheet->postConstruction();
  +
                displayDuration("Parsing and init of " + localXSLURLString, 
&localXSLURLString);
        }
   
  @@ -2330,7 +2336,7 @@
   
   
   
  -XalanDOMString
  +const XalanDOMString&
   XSLTEngineImpl::getResultNamespaceForPrefix(const XalanDOMString&    prefix) 
const
   {
        // Search vector from first element back
  @@ -2339,7 +2345,7 @@
     
   
   
  -XalanDOMString
  +const XalanDOMString&
   XSLTEngineImpl::getResultPrefixForNamespace(const XalanDOMString&    
theNamespace) const
   {
        // Search vector from first element back
  
  
  
  1.45      +2 -2      xml-xalan/c/src/XSLT/XSLTEngineImpl.hpp
  
  Index: XSLTEngineImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/XSLTEngineImpl.hpp,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- XSLTEngineImpl.hpp        2000/08/22 20:21:31     1.44
  +++ XSLTEngineImpl.hpp        2000/08/28 01:19:41     1.45
  @@ -812,7 +812,7 @@
         * @param prefix prefix for namespace
         * @return string for namespace URI
         */
  -     XalanDOMString
  +     const XalanDOMString&
        getResultNamespaceForPrefix(const XalanDOMString&       prefix) const;
     
        /**
  @@ -821,7 +821,7 @@
         * @param theNamespace namespace for prefix
         * @return string for namespace prefix
         */
  -     XalanDOMString
  +     const XalanDOMString&
        getResultPrefixForNamespace(const XalanDOMString&       theNamespace) 
const;
   
        /**
  
  
  
  1.1                  xml-xalan/c/src/XSLT/NamespacesHandler.cpp
  
  Index: NamespacesHandler.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *      notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *      notice, this list of conditions and the following disclaimer in
   *      the documentation and/or other materials provided with the
   *      distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *      if any, must include the following acknowledgment:  
   *             "This product includes software developed by the
   *              Apache Software Foundation (http://www.apache.org/)."
   *      Alternately, this acknowledgment may appear in the software itself,
   *      if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *      not be used to endorse or promote products derived from this
   *      software without prior written permission. For written 
   *      permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *      nor may "Apache" appear in their name, without prior written
   *      permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.        IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $ Id: $
   *
   */
  
  
  // Class header file...
  #include "NamespacesHandler.hpp"
  
  
  
  #include <PlatformSupport/StringTokenizer.hpp>
  
  
  
  #include <DOMSupport/DOMServices.hpp>
  
  
  
  #include <XPath/QName.hpp>
  
  
  
  #include "Constants.hpp"
  #include "StylesheetConstructionContext.hpp"
  #include "StylesheetExecutionContext.hpp"
  
  
  
  const XalanDOMString  NamespacesHandler::s_dummyEmptyString;
  
  
  
  NamespacesHandler::NamespacesHandler() :
        m_excludedResultPrefixes(),
        m_namespaceDeclarations(),
        m_extensionNamespaceURIs(),
        m_namespaceAliases()
  {
  }
  
  
  
  NamespacesHandler::NamespacesHandler(
                        const NamespacesHandler&        
stylesheetNamespacesHandler,
                        const NamespacesStackType&      theCurrentNamespaces,
                        const XalanDOMString&           theXSLTNamespaceURI) :
        m_excludedResultPrefixes(),
        m_namespaceDeclarations(),
        m_extensionNamespaceURIs(),
        m_namespaceAliases()
  {
        // Go through the namespaces stack in reverse order...
        const NamespacesStackType::const_reverse_iterator       theEnd =
                theCurrentNamespaces.rend();
  
        NamespacesStackType::const_reverse_iterator             i =
                theCurrentNamespaces.rbegin();
  
        for(; i != theEnd; ++i)
        {
                // Process each namespace in the current vector...
                const NamespaceVectorType::const_iterator       theVectorEnd =
                        (*i).end();
  
                NamespaceVectorType::const_iterator                     j =
                        (*i).begin();
  
                for(; j != theVectorEnd; ++j)
                {
                        const NameSpace&                theNamespace = *j;
  
                        const XalanDOMString&   theURI = theNamespace.getURI();
                        assert(length(theURI) > 0);
  
                        const XalanDOMString&   thePrefix = 
theNamespace.getPrefix();
  
                        if(shouldExcludeResultNamespaceNode(
                                        theXSLTNamespaceURI,
                                        stylesheetNamespacesHandler,
                                        theNamespace) == false)
                        {
                                if (m_namespaceDeclarations.count(thePrefix) == 
0)
                                {
                                        
m_namespaceDeclarations.insert(NamespacesMapType::value_type(thePrefix, 
theNamespace));
                                }
                        }
                        else
                        {
                                m_excludedResultPrefixes.insert(
                                                
ExcludedResultPrefixesMapType::value_type(thePrefix, theURI));
                        }
                }
        }
  }
  
  
  
  NamespacesHandler::NamespacesHandler(const NamespacesHandler& theSource) :
        m_excludedResultPrefixes(theSource.m_excludedResultPrefixes),
        m_namespaceDeclarations(theSource.m_namespaceDeclarations),
        m_extensionNamespaceURIs(theSource.m_extensionNamespaceURIs),
        m_namespaceAliases(theSource.m_namespaceAliases)
  {
  }
  
  
  
  NamespacesHandler::~NamespacesHandler()
  {
  }
  
  
  
  const XalanDOMString&
  NamespacesHandler::getNamespace(const XalanDOMString& thePrefix) const
  {
        // Check the excluded result prefixes first...
        const ExcludedResultPrefixesMapType::const_iterator             i =
                        m_excludedResultPrefixes.find(thePrefix);
  
        if (i != m_excludedResultPrefixes.end())
        {
                return (*i).second;
        }
        else
        {
                // Not found, so check the namespace declarations...
                const NamespacesMapType::const_iterator         i =
                                m_namespaceDeclarations.find(thePrefix);
  
                if (i != m_namespaceDeclarations.end())
                {
                        return (*i).second.getURI();
                }
                else
                {
                        return s_dummyEmptyString;
                }
        }
  }
  
  
  
  void
  NamespacesHandler::copyNamespaceAliases(const NamespacesHandler&      
parentNamespacesHandler)
  {
        copyNamespaceAliases(parentNamespacesHandler.m_namespaceAliases);
  }
  
  
  
  const XalanDOMString&
  NamespacesHandler::getNamespaceAlias(const XalanDOMString&            
theStylesheetNamespace) const
  {
        if (m_namespaceAliases.size() == 0)
        {
                return s_dummyEmptyString;
        }
        else
        {
                const NamespaceAliasesMapType::const_iterator   i =
                                                
m_namespaceAliases.find(theStylesheetNamespace);
  
                if (i != m_namespaceAliases.end())
                {
                        return (*i).second;
                }
                else
                {
                        return s_dummyEmptyString;
                }
        }
  }
  
  
  
  void
  NamespacesHandler::processExcludeResultPrefixes(
                const XalanDOMChar*                             theValue,
                const NamespacesStackType&              theCurrentNamespaces,
                StylesheetConstructionContext&  theConstructionContext)
  {
        StringTokenizer         tokenizer(
                                        theValue,
                                        XALAN_STATIC_UCODE_STRING(" \t\n\r"),
                                        false);
  
      while(tokenizer.hasMoreTokens() == true)
      {
                XalanDOMString  thePrefix = tokenizer.nextToken();
  
                if(equalsIgnoreCase(thePrefix, 
Constants::ATTRVAL_DEFAULT_PREFIX) == true)
                {
                        ::clear(thePrefix);
                }
  
                const XalanDOMString&   theNamespace =
                        QName::getNamespaceForPrefix(theCurrentNamespaces, 
thePrefix);
  
                if(length(theNamespace) == 0)
                {
                        XalanDOMString  theMessage("Invalid prefix in 
exclude-result-prefixes: ");
  
                        theMessage += thePrefix;
  
                        theConstructionContext.error(theMessage);
                }
  
                m_excludedResultPrefixes[thePrefix] = theNamespace;
      }
  }
  
  
  
  void
  NamespacesHandler::processExtensionElementPrefixes(
                        const XalanDOMChar*                             
theValue,
                        const NamespacesStackType&              
theCurrentNamespaces,
                        StylesheetConstructionContext&  theConstructionContext)
  {
        StringTokenizer         tokenizer(
                                        theValue,
                                        XALAN_STATIC_UCODE_STRING(" \t\n\r"),
                                        false);
  
      while(tokenizer.hasMoreTokens() == true)
      {
                XalanDOMString  thePrefix = tokenizer.nextToken();
  
                if(equalsIgnoreCase(thePrefix, 
Constants::ATTRVAL_DEFAULT_PREFIX) == true)
                {
                        ::clear(thePrefix);
                }
  
                const XalanDOMString&   theNamespace =
                        QName::getNamespaceForPrefix(theCurrentNamespaces, 
thePrefix);
  
                if(length(theNamespace) == 0)
                {
                        XalanDOMString  theMessage("Invalid prefix in 
extension-element-prefixes: ");
  
                        theMessage += thePrefix;
  
                        theConstructionContext.error(theMessage);
                }
  
                m_extensionNamespaceURIs.insert(theNamespace);
      }
  }
  
  
  
  void
  NamespacesHandler::postConstruction(
                        const XalanDOMString&           theElementName,
                        const NamespacesHandler*        parentNamespacesHandler)
  {
        // Copy everything from the parent handler, if there is one...
        if (parentNamespacesHandler != 0)
        {
                
copyNamespaceAliases(parentNamespacesHandler->m_namespaceAliases);
  
                
copyExtensionNamespaceURIs(parentNamespacesHandler->m_extensionNamespaceURIs);
  
                
copyExcludeResultPrefixes(parentNamespacesHandler->m_excludedResultPrefixes);
        }
  
        // Figure out the prefix of the owning element, to make sure we
        // don't exclude it's prefix.
        const unsigned int              indexOfNSSep = indexOf(theElementName, 
':');
  
        const XalanDOMString    thePrefix = indexOfNSSep < 
length(theElementName) ?
                                        substring(theElementName, 0, 
indexOfNSSep) : XalanDOMString();
  
        processExcludeResultPrefixes(thePrefix);
  
        // $$ ToDo: Does this happen before or after exclude-result-prefixes?
        processNamespaceAliases();
  
        createResultAttributeNames();
  }
  
  
  
  NamespacesHandler&
  NamespacesHandler::operator=(const NamespacesHandler& theRHS)
  {
        if (&theRHS != this)
        {
                m_excludedResultPrefixes = theRHS.m_excludedResultPrefixes;
  
                m_namespaceDeclarations = theRHS.m_namespaceDeclarations;
  
                m_extensionNamespaceURIs = theRHS.m_extensionNamespaceURIs;
  
                m_namespaceAliases = theRHS.m_namespaceAliases;
        }
  
        return *this;
  }
  
  
  
  bool
  NamespacesHandler::shouldExcludeResultNamespaceNode(
                        const XalanDOMString&   theXSLTNamespaceURI,
                        const XalanDOMString&   thePrefix,
                        const XalanDOMString&   theURI) const
  {
        // These are commone namespaces that are always excluded...
        if(equals(theURI, theXSLTNamespaceURI)
                        || m_extensionNamespaceURIs.find(theURI) != 
m_extensionNamespaceURIs.end()
                        || equals(theURI, 
XALAN_STATIC_UCODE_STRING("http://xml.apache.org/xslt";))
                        || equals(theURI, 
XALAN_STATIC_UCODE_STRING("http://xsl.lotus.com/";))
                        || equals(theURI, 
XALAN_STATIC_UCODE_STRING("http://xsl.lotus.com";)))
        {
                return true;
        }
        else if (m_excludedResultPrefixes.count(thePrefix) != 0)
        {
                // It was found in the excluded result prefixes...
                return true;
        }
        else
        {
                return false;
        }
  }
  
  
  
  void
  NamespacesHandler::outputResultNamespaces(StylesheetExecutionContext& 
theExecutionContext) const
  {
        // Write out the namespace declarations...
        if (m_namespaceDeclarations.size() > 0)
        {
                const NamespacesMapType::const_iterator theEnd =
                                m_namespaceDeclarations.end();
  
                NamespacesMapType::const_iterator       i =
                                m_namespaceDeclarations.begin();
  
                for(; i != theEnd; ++i)
                {
                        const NameSpaceExtended&        theNamespace = 
(*i).second;
  
                        const XalanDOMString&           theResultURI = 
theNamespace.getURI();
                        assert(length(theResultURI) > 0);
                        assert(length(theNamespace.getResultAttributeName()) > 
0);
  
                        const XalanDOMString&           thePrefix = 
theNamespace.getPrefix();
  
                        // Get the any namespace declaration currently active 
for the
                        // prefix.
                        const XalanDOMString&           desturi =
                                
theExecutionContext.getResultNamespaceForPrefix(thePrefix);
  
                        // Is there already an active namespace declaration?
                        if(!equals(theResultURI, desturi))
                        {
                                // No, so add one...
                                
theExecutionContext.addResultAttribute(theNamespace.getResultAttributeName(), 
theResultURI);
                        }
                }
        }
  }
  
  
  
  bool
  NamespacesHandler::shouldExcludeResultNamespaceNode(
                        const XalanDOMString&           theXSLTNamespaceURI,
                        const NamespacesHandler&        
stylesheetNamespacesHandler,
                        const NameSpace&                        theNamespace) 
const
  {
        const XalanDOMString&   thePrefix = theNamespace.getPrefix();
        const XalanDOMString&   theURI = theNamespace.getURI();
  
        
        if(shouldExcludeResultNamespaceNode(theXSLTNamespaceURI, thePrefix, 
theURI) == true)
        {
                return true;
        }
        else
        {
                // $$$ ToDo: Ask Scott what this code does...
  #if 0
                const ElemTemplateElement*      elem = this;
  
                while(0 != elem)
                {
                        elem = elem->getParentNodeElem();
  
                        if(0 == elem)
                        {
                                return 
getStylesheet().shouldExcludeResultNamespace(prefix);
                        }
                }
        }
  
        return false;
  #else
  
                return 
stylesheetNamespacesHandler.hasExcludedPrefix(theNamespace.getPrefix());
        }
  #endif
  }
  
  
  
  void
  NamespacesHandler::clear()
  {
        m_excludedResultPrefixes.clear();
  
        m_namespaceDeclarations.clear();
  
        m_extensionNamespaceURIs.clear();
  
        m_namespaceAliases.clear();
  }
  
  
  
  void
  NamespacesHandler::swap(NamespacesHandler&    theOther)
  {
        m_excludedResultPrefixes.swap(theOther.m_excludedResultPrefixes);
  
        m_namespaceDeclarations.swap(theOther.m_namespaceDeclarations);
  
        m_extensionNamespaceURIs.swap(theOther.m_extensionNamespaceURIs);
  
        m_namespaceAliases.swap(theOther.m_namespaceAliases);
  }
  
  
  
  void
  NamespacesHandler::createResultAttributeNames()
  {
        // Go through all of the result namespaces and create the attribute
        // name that will be used when they're written to the result tree.
        // This is more efficient if the stylesheet is used multiple times.
        if (m_namespaceDeclarations.size() > 0)
        {
                const NamespacesMapType::iterator       theEnd =
                                m_namespaceDeclarations.end();
  
                NamespacesMapType::iterator             i =
                                m_namespaceDeclarations.begin();
  
                for(; i != theEnd; ++i)
                {
                        NameSpaceExtended&              theNamespace = 
(*i).second;
  
                        const XalanDOMString&   thePrefix = 
theNamespace.getPrefix();
  
                        if (isEmpty(thePrefix) == false)
                        {
                                // Create a name of the form xmlns:prefix, 
where "prefix" is the
                                // text of the prefix.
                                XalanDOMString  theName;
  
                                // Reserve the appropriate amount of space in 
the string.
                                reserve(theName, 
DOMServices::s_XMLNamespaceWithSeparatorLength + length(thePrefix) + 1);
  
                                theName += 
DOMServices::s_XMLNamespaceWithSeparator;
                                theName += thePrefix;
  
                                theNamespace.setResultAttributeName(theName);
                        }
                        else
                        {
                                // It's the default namespace...
                                
theNamespace.setResultAttributeName(DOMServices::s_XMLNamespace);
                        }
                }
        }
  }
  
  
  
  void
  NamespacesHandler::processExcludeResultPrefixes(const XalanDOMString& 
theElementPrefix)
  {
        if (m_excludedResultPrefixes.size() > 0)
        {
                const NamespacesMapType::iterator       theEnd =
                                m_namespaceDeclarations.end();
  
                NamespacesMapType::iterator             i =
                                m_namespaceDeclarations.begin();
  
                // Check for any result prefixes we should exclude...
                while(i != theEnd)
                {
                        const NameSpace&                theNamespace = 
(*i).second;
  
                        const XalanDOMString&   thePrefix = 
theNamespace.getPrefix();
                        const XalanDOMString&   theURI = theNamespace.getURI();
  
                        // We can never exclude the prefix of our owner 
element, so
                        // check that first...
                        if ((isEmpty(thePrefix) ||
                                 equals(thePrefix, theElementPrefix) == false) 
&&
                                (m_excludedResultPrefixes.find(thePrefix) != 
m_excludedResultPrefixes.end() ||
                                 m_extensionNamespaceURIs.find(theURI) != 
m_extensionNamespaceURIs.end()))
                        {
                                // It's excluded, so remove it...
                                i = m_namespaceDeclarations.erase(i);
                        }
                        else
                        {
                                ++i;
                        }
                }
        }
  }
  
  
  
  void
  NamespacesHandler::processNamespaceAliases()
  {
        if (m_namespaceDeclarations.size() > 0)
        {
                const NamespacesMapType::iterator       theEnd =
                                m_namespaceDeclarations.end();
  
                NamespacesMapType::iterator             i =
                                m_namespaceDeclarations.begin();
  
                // Look at everyone of my namespaces for an alias, and 
substitute the
                // alias as appropriate...
                for(; i != theEnd; ++i)
                {
                        NameSpace&      theNamespace = (*i).second;
  
                        const XalanDOMString&   theURI = theNamespace.getURI();
  
                        const XalanDOMString&   theAlias = 
getNamespaceAlias(theURI);
  
                        // Is there a local alias?
                        if (length(theAlias) != 0)
                        {
                                // Yup, so use it...
                                theNamespace.setURI(theAlias);
                        }
                }
        }
  }
  
  
  
  void
  NamespacesHandler::copyNamespaceAliases(const NamespaceAliasesMapType&        
theNamespaceAliases)
  {
        if (theNamespaceAliases.size() > 0)
        {
                if (m_namespaceAliases.size() == 0)
                {
                        m_namespaceAliases = theNamespaceAliases;
                }
                else
                {
                        const NamespaceAliasesMapType::const_iterator   theEnd =
                                        theNamespaceAliases.end();
  
                        NamespaceAliasesMapType::const_iterator         i =
                                        theNamespaceAliases.begin();
  
                        // Add them in...
                        while(i != theEnd)
                        {
                                m_namespaceAliases.insert(*i);
  
                                ++i;
                        }
                }
        }
  }
  
  
  
  void
  NamespacesHandler::copyExtensionNamespaceURIs(const 
ExtensionNamespaceURISetType&     theExtensionNamespaceURIs)
  {
        if (theExtensionNamespaceURIs.size() > 0)
        {
                if (m_extensionNamespaceURIs.size() == 0)
                {
                        m_extensionNamespaceURIs = theExtensionNamespaceURIs;
                }
                else
                {
                        const ExtensionNamespaceURISetType::const_iterator      
theEnd =
                                        theExtensionNamespaceURIs.end();
  
                        ExtensionNamespaceURISetType::const_iterator    i =
                                        theExtensionNamespaceURIs.begin();
  
                        // Add them in...
                        while(i != theEnd)
                        {
                                m_extensionNamespaceURIs.insert(*i);
  
                                ++i;
                        }
                }
        }
  }
  
  
  
  void
  NamespacesHandler::copyExcludeResultPrefixes(const 
ExcludedResultPrefixesMapType&     theExcludeResultPrefixes)
  {
        if (theExcludeResultPrefixes.size() > 0)
        {
                if (m_excludedResultPrefixes.size() == 0)
                {
                        m_excludedResultPrefixes = theExcludeResultPrefixes;
                }
                else
                {
                        const ExcludedResultPrefixesMapType::const_iterator     
theEnd =
                                        theExcludeResultPrefixes.end();
  
                        ExcludedResultPrefixesMapType::const_iterator   i =
                                        theExcludeResultPrefixes.begin();
  
                        // Add them in...
                        while(i != theEnd)
                        {
                                m_excludedResultPrefixes.insert(*i);
  
                                ++i;
                        }
                }
        }
  }
  
  
  
  1.1                  xml-xalan/c/src/XSLT/NamespacesHandler.hpp
  
  Index: NamespacesHandler.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *      notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *      notice, this list of conditions and the following disclaimer in
   *      the documentation and/or other materials provided with the
   *      distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *      if any, must include the following acknowledgment:  
   *             "This product includes software developed by the
   *              Apache Software Foundation (http://www.apache.org/)."
   *      Alternately, this acknowledgment may appear in the software itself,
   *      if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *      not be used to endorse or promote products derived from this
   *      software without prior written permission. For written 
   *      permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *      nor may "Apache" appear in their name, without prior written
   *      permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.        IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $ Id: $
   *
   */
  
  #if !defined(XALAN_NAMESPACESHANDLER_HEADER_GUARD)
  #define XALAN_NAMESPACESHANDLER_HEADER_GUARD
  
  
  
  // Base include file.  Must be first.
  #include <XSLT/XSLTDefinitions.hpp>
  
  
  
  #include <map>
  #include <set>
  #include <vector>
  
  
  
  #include <XalanDOM/XalanDOMString.hpp>
  
  
  
  #include <XPath/NameSpace.hpp>
  
  
  
  class StylesheetConstructionContext;
  class StylesheetExecutionContext;
  
  
  
  class XALAN_XSLT_EXPORT NamespacesHandler
  {
  public:
  
        class NameSpaceExtended : public NameSpace
        {
        public:
  
                NameSpaceExtended(
                                        const XalanDOMString&   prefix = 
XalanDOMString(),
                                        const XalanDOMString&   uri = 
XalanDOMString()) :
                        NameSpace(prefix, uri),
                        m_resultAttributeName()
                {
                }
  
                NameSpaceExtended(const NameSpace&      theNamespace) :
                        NameSpace(theNamespace),
                        m_resultAttributeName()
                {
                }
  
                /**
                 * Retrieve the name of the result attribute.
                 * 
                 * @return name string
                 */
                const XalanDOMString&
                getResultAttributeName() const
                {
                        return m_resultAttributeName;
                }
  
                /**
                 * Set the name of the result attribute.
                 * 
                 * @param name The new name value
                 */
                void
                setResultAttributeName(const XalanDOMString&    name)
                {
                        m_resultAttributeName = name;
                }
  
        private:
  
                XalanDOMString  m_resultAttributeName;
        };
  
  #if defined(XALAN_NO_NAMESPACES)
        typedef map<XalanDOMString,
                                XalanDOMString,
                                less<XalanDOMString> >                          
        ExcludedResultPrefixesMapType;
  
        typedef map<XalanDOMString,
                                NameSpaceExtended,
                                less<XalanDOMString> >                          
        NamespacesMapType;
  
        typedef map<XalanDOMString,
                                XalanDOMString,
                                less<XalanDOMString> >                          
        NamespaceAliasesMapType;
  
        typedef vector<NameSpace>                                               
        NamespaceVectorType;
        typedef vector<NamespaceVectorType>                                     
NamespacesStackType;
  
        typedef set<XalanDOMString
                                less<XalanDOMString> >                          
        ExtensionNamespaceURISetType;
  #else
        typedef std::map<XalanDOMString, XalanDOMString>        
ExcludedResultPrefixesMapType;
  
        typedef std::map<XalanDOMString,
                                         NameSpaceExtended>                     
                NamespacesMapType;
  
        typedef std::map<XalanDOMString, XalanDOMString>        
NamespaceAliasesMapType;
  
        typedef std::vector<NameSpace>                                          
NamespaceVectorType;
        typedef std::vector<NamespaceVectorType>                        
NamespacesStackType;
  
        typedef std::set<XalanDOMString>                                        
ExtensionNamespaceURISetType;
  #endif
  
        /**
         * Create a default, empty instance.
         */
        explicit
        NamespacesHandler();
  
        /**
         * Create an instance namespace handler using the
         * current namespaces in effect.
         *
         * @param stylesheetNamespacesHandler The stylesheet's handler.
         * @param theCurrentNamespaces The stack of active namespace 
declarations.
         * @param theXSLTNamespaceURI The namespace URI for XSLT.
         */
        NamespacesHandler(
                        const NamespacesHandler&        
stylesheetNamespacesHandler,
                        const NamespacesStackType&      theCurrentNamespaces,
                        const XalanDOMString&           theXSLTNamespaceURI);
  
        NamespacesHandler(const NamespacesHandler&      theSource);
  
        ~NamespacesHandler();
  
        /**
         * Process an exclude-result-prefixes attribute.
         *
         * @param theValue The attribute's value.
         * @param theCurrentNamespaces The stack of active namespace 
declarations.
         * @param theConstructionContext The current construction context.
         */
        void
        processExcludeResultPrefixes(
                        const XalanDOMChar*                             
theValue,
                        const NamespacesStackType&              
theCurrentNamespaces,
                        StylesheetConstructionContext&  theConstructionContext);
  
        /**
         * Process an extension-element-prefixes attribute.
         *
         * @param theValue The attribute's value.
         * @param theCurrentNamespaces The stack of active namespace 
declarations.
         * @param theConstructionContext The current construction context.
         */
        void
        processExtensionElementPrefixes(
                        const XalanDOMChar*                             
theValue,
                        const NamespacesStackType&              
theCurrentNamespaces,
                        StylesheetConstructionContext&  theConstructionContext);
  
        /**
         * Notify the instance that the stylesheet is fully constructed.
         *
         * @param theElementName The name of the owning element.
         * @param parentNamespacesHandler The parent handler, if any.
         */
        void
        postConstruction(
                        const XalanDOMString&           theElementName = 
XalanDOMString(),
                        const NamespacesHandler*        parentNamespacesHandler 
= 0);
  
        NamespacesHandler&
        operator=(const NamespacesHandler&      theRHS);
  
        /**
         * Determine of a given namespace should be excluded.
         *
         * @param theXSLTNamespaceURI The namespace URI for XSLT.
         * @param thePrefix The namespace prefix.
         * @param theURI The namespace URI.
         * @return true of the namespace should be excluded, false if not.
         */
        bool
        shouldExcludeResultNamespaceNode(
                        const XalanDOMString&   theXSLTNamespaceURI,
                        const XalanDOMString&   thePrefix,
                        const XalanDOMString&   theURI) const;
  
        /**
         * Determine if a given prefix is in the list of excluded
         * prefixes.
         *
         * @param thePrefix The namespace prefix.
         * @return true of the prefix should be excluded, false if not.
         */
        bool
        hasExcludedPrefix(const XalanDOMString&         thePrefix) const
        {
                return m_excludedResultPrefixes.count(thePrefix) != 0 ? true : 
false;
        }
  
        /**
         * Add a URI as an extension namespace prefixes.
         *
         * @param theURI The namespace URI.
         */
        void
        addExtensionNamespaceURI(const XalanDOMString&  theURI)
        {
                m_extensionNamespaceURIs.insert(theURI);
        }
  
        /**
         * Get the namespace URI for the given prefix.
         *
         * @param thePrefix The namespace prefix.
         * @return The namespace URI
         */
        const XalanDOMString&
        getNamespace(const XalanDOMString&      thePrefix) const;
  
        /**
         * Get the namespace alias URI for the given namespace.
         *
         * @param theStylesheetNamespace The namespace as declared in the 
stylesheet.
         * @return The namespace alias URI
         */
        const XalanDOMString&
        getNamespaceAlias(const XalanDOMString&         theStylesheetNamespace) 
const;
  
        /**
         * Set the namespace alias URI for the given namespace.
         *
         * @param theStylesheetNamespace The namespace as declared in the 
stylesheet.
         * @param theResultNamespace The namespace as it should appear in the 
result tree.
         */
        void
        setNamespaceAlias(
                        const XalanDOMString&   theStylesheetNamespace,
                        const XalanDOMString&   theResultNamespace)
        {
                m_namespaceAliases[theStylesheetNamespace] = theResultNamespace;
        }
  
        /**
         * Copy the aliases from the given NamespacesHandler.
         *
         * @param parentNamespacesHandler The parent handler.
         */
        void
        copyNamespaceAliases(const NamespacesHandler&   
parentNamespacesHandler);
  
        /**
         * Output the result tree namespace declarations.
         *
         * @param theExecutionContext The current execution context.
         */
        void
        outputResultNamespaces(StylesheetExecutionContext&      
theExecutionContext) const;
  
        /**
         * Clear out the handler.
         */
        void
        clear();
  
        /**
         * Swap the contents of this instance with another.
         *
         * @param theOther The other instance.
         */
        void
        swap(NamespacesHandler&         theOther);
  
  private:
  
        /**
         * Create all of the result attribute names.
         */
        void
        createResultAttributeNames();
  
        /**
         * Process the exclude result prefix data.
         *
         * @param theElementPrefix The prefix of the owning element.
         */
        void
        processExcludeResultPrefixes(const XalanDOMString&      
theElementPrefix);
  
        /**
         * Process the namespace aliases data.
         */
        void
        processNamespaceAliases();
  
        /**
         * Copy the contents of the supplied map
         *
         * @param theNamespaceAliases The map to copy.
         */
        void
        copyNamespaceAliases(const NamespaceAliasesMapType&             
theNamespaceAliases);
  
        /**
         * Copy the contents of the supplied set
         *
         * @param theExtensionNamespaceURIs The set to copy.
         */
        void
        copyExtensionNamespaceURIs(const ExtensionNamespaceURISetType&  
theExtensionNamespaceURIs);
  
        /**
         * Copy the contents of the supplied map
         *
         * @param theExcludeResultPrefixes The map to copy.
         */
        void
        copyExcludeResultPrefixes(const ExcludedResultPrefixesMapType&  
theExcludeResultPrefixes);
  
        /**
         * Determine of a given namespace should be excluded.  For use during
         * stylesheet construction only.
         *
         * @param theXSLTNamespaceURI The namespace URI for XSLT.
         * @param parentNamespacesHandler The parent handler instance.
         * @param theNamespace The namespace.
         * @return true of the namespace should be excluded, false if not.
         */
        bool
        shouldExcludeResultNamespaceNode(
                        const XalanDOMString&           theXSLTNamespaceURI,
                        const NamespacesHandler&        parentNamespacesHandler,
                        const NameSpace&                        theNamespace) 
const;
  
        // Not implemented...
        bool
        operator==(const NamespacesHandler&) const;
  
        // Data members...
        ExcludedResultPrefixesMapType   m_excludedResultPrefixes;
  
        NamespacesMapType                               m_namespaceDeclarations;
  
        ExtensionNamespaceURISetType    m_extensionNamespaceURIs;
  
        NamespaceAliasesMapType                 m_namespaceAliases;
  
        const static XalanDOMString             s_dummyEmptyString;
  };
  
  
  
  #endif        // XALAN_NAMESPACESHANDLER_HEADER_GUARD
  
  
  

Reply via email to