You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mm...@locus.apache.org on 2000/01/20 15:40:08 UTC

cvs commit: xml-xalan/src/org/apache/xalan/xslt ElemElement.java ElemLiteralResult.java ElemTemplateElement.java

mmidy       00/01/20 06:40:08

  Modified:    src/org/apache/xalan/xpath/xml NameSpace.java
               src/org/apache/xalan/xslt ElemElement.java
                        ElemLiteralResult.java ElemTemplateElement.java
  Log:
  Move Namespace processing so that xsl:element and xsl:literalResultElement can both use it. Delete reference to namespace.m_resultCandidate
  
  Revision  Changes    Path
  1.2       +0 -1      xml-xalan/src/org/apache/xalan/xpath/xml/NameSpace.java
  
  Index: NameSpace.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/NameSpace.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NameSpace.java	1999/11/08 20:55:55	1.1
  +++ NameSpace.java	2000/01/20 14:40:06	1.2
  @@ -68,7 +68,6 @@
     public NameSpace m_next = null;
     public String m_prefix;
     public String m_uri; // if null, then Element namespace is empty.
  -  public boolean m_resultCandidate = true;
     
     /**
      * Construct a namespace for placement on the 
  
  
  
  1.5       +4 -0      xml-xalan/src/org/apache/xalan/xslt/ElemElement.java
  
  Index: ElemElement.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemElement.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ElemElement.java	2000/01/05 23:05:30	1.4
  +++ ElemElement.java	2000/01/20 14:40:07	1.5
  @@ -146,6 +146,10 @@
         
         super.execute(processor, sourceTree, sourceNode, mode);
         
  +      // Handle namespaces(including those on the ancestor chain 
  +      // and stylesheet root declarations).
  +      processResultNS(processor); 
  +      
         executeChildren(processor, sourceTree, 
                         sourceNode, mode);
         
  
  
  
  1.14      +21 -43    xml-xalan/src/org/apache/xalan/xslt/ElemLiteralResult.java
  
  Index: ElemLiteralResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemLiteralResult.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ElemLiteralResult.java	2000/01/14 16:09:54	1.13
  +++ ElemLiteralResult.java	2000/01/20 14:40:07	1.14
  @@ -109,6 +109,7 @@
             if((null != ns) 
                && ns.equals( m_stylesheet.m_XSLNameSpaceURL ))
             {
  +            // process xsl:extension-element-prefixes - Stripped from result tree
               String localName = aname.substring(indexOfNSSep+1);
               if(localName.equals(Constants.ATTRNAME_EXTENSIONELEMENTPREFIXES))
               {
  @@ -122,11 +123,13 @@
                   m_excludeResultPrefixes = m_stylesheet.processExcludeResultPrefixes(m_extensionElementPrefixes[k], null);
                 }
               }
  +            // process xsl:exclude-result-prefixes - Stripped from result tree
               else if(localName.equals(Constants.ATTRNAME_EXCLUDE_RESULT_PREFIXES))
               {
                 needToProcess = false;
                 m_excludeResultPrefixes = m_stylesheet.processExcludeResultPrefixes(atts.getValue(i), null);
               }
  +            // process xsl:version
               else if (localName.equals(Constants.ATTRNAME_VERSION))
               {
                 String versionStr = atts.getValue(i);
  @@ -140,6 +143,8 @@
         {
           boolean _processUseAttributeSets = processUseAttributeSets(aname, atts, i);
           boolean _processSpaceAttr = processSpaceAttr(aname, atts, i);
  +        // Add xmlns attribute(except xmlns:xsl), xml:space, etc... 
  +        // Ignore anything with xsl:xxx 
           if(!_processUseAttributeSets && isAttrOK(aname, atts, i))
           {
             if(null == m_avts)
  @@ -192,8 +197,10 @@
              SAXException
     {
       processor.m_resultTreeHandler.startElement (m_qname);
  +    // Process any possible attributes from xsl:use-attribute-sets first
       super.execute(processor, sourceTree, sourceNode, mode);
  -        
  +    
  +    // Process the list of avts next
       if(null != m_avts)
       {
         int nAttrs = m_avts.size();
  @@ -203,15 +210,18 @@
           XPathSupport execContext = processor.getXMLProcessorLiaison();
           String stringedValue = avt.evaluate(execContext, sourceNode, this,
                                               new StringBuffer());        
  -
  +        
           if(null != stringedValue)
           {
  +          // Handle if the avt was a namespace definition         
             String nsprefix = null;
             if (avt.m_name.startsWith("xmlns:"))
             {
  -            // get the namespace prefix and make sure it is not in the excluded list
  +            // get the namespace prefix 
               nsprefix = avt.m_name.substring(avt.m_name.indexOf(":") + 1);
  -          }  
  +          }
  +          // Make sure namespace is not in the excluded list then
  +          // add to result tree
             if(nsprefix == null ||!(m_stylesheet.shouldExcludeResultNamespaceNode(this, nsprefix, stringedValue)))
             {            
               processor.m_pendingAttributes.removeAttribute(avt.m_name);
  @@ -219,47 +229,15 @@
                                                                 stringedValue);
             }
               
  -        }
  -      }
  -    }
  -
  -    {
  -      ElemTemplateElement[] elem = {this};
  -      org.apache.xalan.xpath.xml.NameSpace ns = (NameSpace)elem[0].m_namespaces;
  -      
  -      if(null == ns)
  -        ns = getNextNamespace(elem, ns);
  -      
  -      while(null != ns)
  -      {
  -        if((null != ns.m_uri) && ns.m_resultCandidate)
  -        {
  -          boolean hasPrefix = (ns.m_prefix != null) && (ns.m_prefix.length() > 0);
  -          String prefix = hasPrefix ? ns.m_prefix : "";
  -          String desturi = processor.getResultNamespaceForPrefix(prefix);
  -          String attrName = hasPrefix ? ("xmlns:"+prefix) : "xmlns";
  -          String srcURI = ns.m_uri;
  -          // Look for an alias for this URI. If one is found, use it as the result URI   
  -          String aliasURI = m_stylesheet.lookForAlias(srcURI);
  -          if(!aliasURI.equals(desturi)) // TODO: Check for extension namespaces
  -          {
  -            if(m_stylesheet.shouldExcludeResultNamespaceNode(this, prefix, srcURI))
  -            {
  -              ns.m_resultCandidate = false;
  -            }
  -            else
  -            {
  -              addResultAttribute(processor.m_resultNameSpaces, 
  -                                 processor.m_pendingAttributes, 
  -                                 attrName, srcURI);
  -            }
  -          }
           }
  -        
  -        ns = getNextNamespace(elem, ns);
  -      }
  -    }
  +      } // end for
  +    }        
  +    
  +    // Handle namespaces(including those on the ancestor chain 
  +    // and stylesheet root declarations).
  +    processResultNS(processor);           
   
  +    // Now process all the elements in this subtree
       // TODO: Process m_extensionElementPrefixes && m_attributeSetsNames
       executeChildren(processor, sourceTree, sourceNode, mode);
       processor.m_resultTreeHandler.endElement (m_qname);
  
  
  
  1.12      +70 -0     xml-xalan/src/org/apache/xalan/xslt/ElemTemplateElement.java
  
  Index: ElemTemplateElement.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemTemplateElement.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ElemTemplateElement.java	2000/01/05 23:05:32	1.11
  +++ ElemTemplateElement.java	2000/01/20 14:40:07	1.12
  @@ -441,6 +441,76 @@
       return true;
     }
     
  +  // Get the next namespace in the ancestor chain.
  +  private NameSpace getNextNamespace(ElemTemplateElement[] elem, NameSpace ns)
  +  {
  +    if(null != ns)
  +      ns = ns.m_next;
  +    
  +    if(null == ns)
  +    {
  +      if(null != elem[0])
  +      {
  +        elem[0] = elem[0].m_parentNode;
  +        while(null != elem[0])
  +        {
  +          ns = elem[0].m_namespaces;
  +          if(null == ns)
  +            elem[0] = elem[0].m_parentNode;
  +          else
  +            break;
  +        }
  +        if(null == ns)
  +          ns = m_stylesheet.m_namespaceDecls;
  +      }
  +    }
  +    return ns;
  +  }
  +  
  +  /*
  +   * Decide which namespace declarations to output
  +   */
  +  void processResultNS( XSLTEngineImpl processor) throws SAXException
  +  {  
  +    ElemTemplateElement[] elem = {this};
  +    org.apache.xalan.xpath.xml.NameSpace ns = (NameSpace)elem[0].m_namespaces;
  +      
  +    // Handle namespaces(including those on the ancestor chain 
  +    // and stylesheet root declarations).       
  +    if(null == ns)
  +      ns = getNextNamespace(elem, ns);
  +    
  +    while(null != ns)
  +    {
  +      if(null != ns.m_uri)
  +      {
  +        boolean hasPrefix = (ns.m_prefix != null) && (ns.m_prefix.length() > 0);
  +        String prefix = hasPrefix ? ns.m_prefix : "";
  +        String desturi = processor.getResultNamespaceForPrefix(prefix);
  +        String attrName = hasPrefix ? ("xmlns:"+prefix) : "xmlns";
  +        String srcURI = ns.m_uri;
  +        // Look for an alias for this URI. If one is found, use it as the result URI   
  +        String aliasURI = m_stylesheet.lookForAlias(srcURI);
  +        if(!aliasURI.equals(desturi)) // TODO: Check for extension namespaces
  +        {
  +          // NOTE: shouldExcludeResultNamespaceNode climbs up the ancestor 
  +          // chain every time.  Clearly, this is a performance bottleneck.
  +          // In general, I think this whole section for handling result namespaces
  +          // should have most of this logic figured out at the stylesheet 
  +          // build time (i.e. in the constructor)... how feasible is this?
  +          if(!m_stylesheet.shouldExcludeResultNamespaceNode(this, prefix, srcURI))
  +          {
  +            addResultAttribute(processor.m_resultNameSpaces, 
  +                                 processor.m_pendingAttributes, 
  +                                 attrName, srcURI);
  +          }
  +        }
  +      }
  +        
  +      ns = getNextNamespace(elem, ns);
  +    } // end while
  +  }   
  +  
     /** Execute the element's primary function.  Subclasses of this
      * function may recursivly execute down the element tree.
      *