You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@apache.org on 2001/05/15 00:21:21 UTC

cvs commit: xml-xalan/c/src/XSLT ElemElement.cpp ElemElement.hpp NamespacesHandler.cpp NamespacesHandler.hpp

dbertoni    01/05/14 15:21:20

  Modified:    c/src/XSLT ElemElement.cpp ElemElement.hpp
                        NamespacesHandler.cpp NamespacesHandler.hpp
  Log:
  Fixed more namespace bugs (76 and 80).
  
  Revision  Changes    Path
  1.26      +114 -31   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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ElemElement.cpp	2001/05/14 01:03:07	1.25
  +++ ElemElement.cpp	2001/05/14 22:21:05	1.26
  @@ -154,7 +154,7 @@
   
   	XalanDOMString&		elemName = elemNameGuard.get();
   
  -	XalanNode* sourceNode = executionContext.getCurrentNode();
  +	XalanNode* const	sourceNode = executionContext.getCurrentNode();
   
   	m_nameAVT->evaluate(elemName, sourceNode, *this, executionContext);
   
  @@ -167,6 +167,8 @@
   		m_namespaceAVT->evaluate(elemNameSpace, sourceNode, *this, executionContext);
   	}
   
  +	unsigned int		namespaceLen = length(elemNameSpace);
  +
   	bool				isIllegalElement = false;
   
   	bool				hasUnresolvedPrefix = false;
  @@ -175,12 +177,12 @@
   
   	const unsigned int	indexOfNSSep = indexOf(elemName, XalanUnicode::charColon);
   
  +	const bool			haveNamespace = indexOfNSSep == len ? false : true;
  +
   	StylesheetExecutionContext::GetAndReleaseCachedString	prefixGuard(executionContext);
   
   	XalanDOMString&		prefix = prefixGuard.get();
   
  -	const bool			haveNamespace = indexOfNSSep == len ? false : true;
  -
   	if(haveNamespace == true)
   	{
   		if (indexOfNSSep + 1 == len ||
  @@ -212,7 +214,7 @@
   			const XalanDOMString* const		theNamespace =
   				m_namespacesHandler.getNamespace(prefix);
   
  -			if(theNamespace == 0 && isEmpty(elemNameSpace))
  +			if(theNamespace == 0 && namespaceLen == 0)
   			{
   				executionContext.warn("Could not resolve prefix: " + prefix, this, sourceNode);
   
  @@ -234,39 +236,58 @@
   	{
   		executionContext.startElement(c_wstr(elemName));   
   
  -		m_namespacesHandler.outputResultNamespaces(executionContext);
  -
  -		// OK, now let's check to make sure we don't have to change the default namespace...
  -		const XalanDOMString* const		theCurrentDefaultNamespace =
  -				executionContext.getResultNamespaceForPrefix(s_emptyString);
  -
  -		if (theCurrentDefaultNamespace != 0)
  +		if(0 == m_namespaceAVT)
   		{
  -			const XalanDOMString* const		theElementDefaultNamespace =
  -					m_namespacesHandler.getNamespace(s_emptyString);
  -
  -			if (hasUnresolvedPrefix == true || theElementDefaultNamespace == 0)
  -			{
  -				// There was no default namespace, so we have to turn the
  -				// current one off.
  -				executionContext.addResultAttribute(DOMServices::s_XMLNamespace, s_emptyString);
  -			}
  -			else if (equals(*theCurrentDefaultNamespace, *theElementDefaultNamespace) == false)
  -			{
  -				executionContext.addResultAttribute(DOMServices::s_XMLNamespace, *theElementDefaultNamespace);
  -			}
  +			outputResultNamespaces(executionContext, hasUnresolvedPrefix);
   		}
  -
  -		if(0 != m_namespaceAVT)
  +		else
   		{
  -			if(isEmpty(elemNameSpace) == false || hasUnresolvedPrefix == false)
  +			if(namespaceLen == 0 && hasUnresolvedPrefix == true)
  +			{
  +				outputResultNamespaces(
  +					executionContext,
  +					hasUnresolvedPrefix,
  +					length(getParentDefaultNamespace()) == 0 ? true : false);
  +			}
  +			else
   			{
  -				if(indexOfNSSep == len)
  +				if(haveNamespace == false)
   				{
  -					executionContext.addResultAttribute(DOMServices::s_XMLNamespace, elemNameSpace);
  +					if (namespaceLen == 0)
  +					{
  +						// OK, the namespace we're generating is the default namespace,
  +						// so let's make sure that we really need it.  If we don't,
  +						// we end up with another xmlns="" on the element we're
  +						// generating.  Although this isn't really an error, it's
  +						// a bit unsightly, so let's suppress it...
  +						const XalanDOMString& const	theParentDefaultNamespace =
  +							getParentDefaultNamespace();
  +
  +						if (length(theParentDefaultNamespace) == 0)
  +						{
  +							// There's not default namespace in effect, so suppress any
  +							// default namespace in the statically-generated namespaces,
  +							// and don't put out the one we've dynamically generated...
  +							outputResultNamespaces(executionContext, hasUnresolvedPrefix, true);
  +						}
  +						else
  +						{
  +							outputResultNamespaces(executionContext, hasUnresolvedPrefix, false);
  +
  +							executionContext.addResultAttribute(DOMServices::s_XMLNamespace, elemNameSpace);
  +						}
  +					}
  +					else
  +					{
  +						outputResultNamespaces(executionContext, hasUnresolvedPrefix);
  +
  +						executionContext.addResultAttribute(DOMServices::s_XMLNamespace, elemNameSpace);
  +					}
   				}
   				else
   				{
  +					outputResultNamespaces(executionContext, hasUnresolvedPrefix);
  +
   					const XalanDOMString* const		theNamespace =
   						executionContext.getResultNamespaceForPrefix(prefix);
   
  @@ -284,7 +305,7 @@
   
   	ElemUse::execute(executionContext);
   
  -	doExecuteChildren(executionContext, sourceNode, isIllegalElement);
  +	doExecuteChildren(executionContext, isIllegalElement);
   
   	if (isIllegalElement == false)
   	{
  @@ -297,7 +318,6 @@
   void
   ElemElement::doExecuteChildren(
   			StylesheetExecutionContext&		executionContext,			
  -			XalanNode*						sourceNode,
   			bool							skipAttributeChildren) const
   {
   	if (skipAttributeChildren == false)
  @@ -316,6 +336,69 @@
   			{
   				node->execute(executionContext);
   			}
  +		}
  +	}
  +}
  +
  +
  +
  +void
  +ElemElement::outputResultNamespaces(
  +			StylesheetExecutionContext&		executionContext,			
  +			bool							hasUnresolvedPrefix,
  +			bool							supressDefault) const
  +{
  +	m_namespacesHandler.outputResultNamespaces(executionContext, supressDefault);
  +
  +	if (supressDefault == false)
  +	{
  +		// OK, now let's check to make sure we don't have to change the default namespace...
  +		const XalanDOMString* const		theCurrentDefaultNamespace =
  +					executionContext.getResultNamespaceForPrefix(s_emptyString);
  +
  +		if (theCurrentDefaultNamespace != 0)
  +		{
  +			const XalanDOMString* const		theElementDefaultNamespace =
  +						m_namespacesHandler.getNamespace(s_emptyString);
  +
  +			if (hasUnresolvedPrefix == true || theElementDefaultNamespace == 0)
  +			{
  +				// There was no default namespace, so we have to turn the
  +				// current one off.
  +				executionContext.addResultAttribute(DOMServices::s_XMLNamespace, s_emptyString);
  +			}
  +			else if (equals(*theCurrentDefaultNamespace, *theElementDefaultNamespace) == false)
  +			{
  +				executionContext.addResultAttribute(DOMServices::s_XMLNamespace, *theElementDefaultNamespace);
  +			}
  +		}
  +	}
  +}
  +
  +
  +
  +const XalanDOMString&
  +ElemElement::getParentDefaultNamespace() const
  +{
  +	const ElemTemplateElement* const	theParent =
  +		getParentNodeElem();
  +
  +	if (theParent == 0)
  +	{
  +		return s_emptyString;
  +	}
  +	else
  +	{
  +		const XalanDOMString* const		theParentDefaultNamespace =
  +						theParent->getNamespacesHandler().getNamespace(s_emptyString);
  +
  +		if (theParentDefaultNamespace == 0)
  +		{
  +			return s_emptyString;
  +		}
  +		else
  +		{
  +			return *theParentDefaultNamespace;
   		}
   	}
   }
  
  
  
  1.13      +26 -5     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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ElemElement.hpp	2001/03/09 16:20:03	1.12
  +++ ElemElement.hpp	2001/05/14 22:21:08	1.13
  @@ -58,7 +58,7 @@
   #define XALAN_ELEMELEMENT_HEADER_GUARD 
   
   /**
  - * $Id: ElemElement.hpp,v 1.12 2001/03/09 16:20:03 auriemma Exp $
  + * $Id: ElemElement.hpp,v 1.13 2001/05/14 22:21:08 dbertoni Exp $
    * 
    * 
    * $State: Exp $
  @@ -116,17 +116,38 @@
   	/** 
   	 * Process the children of a template.
   	 * 
  -	 * @param executionContext The current execution context	 
  -	 * @param sourceNode current context node
  +	 * @param executionContext The current execution context
   	 * @param skipAttributeChildren If true, attribute children will not be executed.
   	 */
   	virtual void
   	doExecuteChildren(
  -			StylesheetExecutionContext&		executionContext,			
  -			XalanNode*						sourceNode,
  +			StylesheetExecutionContext&		executionContext,
   			bool							skipAttributeChildren) const;
   
   private:
  +
  +	/** 
  +	 * Output the static namespace definitions.
  +	 * 
  +	 * @param executionContext The current execution context
  +	 * @param true if the element being generated has an unresolved prefix.
  +	 * @param supressDefault If true, any default namespace declaration will not be output.
  +	 */
  +	void
  +	outputResultNamespaces(
  +			StylesheetExecutionContext&		executionContext,
  +			bool							hasUnresolvedPrefix,
  +			bool							supressDefault = false) const;
  +
  +	/** 
  +	 * Get the default namespace from the parent of this element.  Returns
  +	 * an empty string if there's no default namespace.
  +	 *
  +	 * @return The default namespace of the parent, if any.
  +	 */
  +	const XalanDOMString&
  +	getParentDefaultNamespace() const;
  +
   
   	// not implemented
   	ElemElement(const ElemElement &);
  
  
  
  1.10      +9 -6      xml-xalan/c/src/XSLT/NamespacesHandler.cpp
  
  Index: NamespacesHandler.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/NamespacesHandler.cpp,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- NamespacesHandler.cpp	2001/05/14 01:03:10	1.9
  +++ NamespacesHandler.cpp	2001/05/14 22:21:10	1.10
  @@ -386,7 +386,7 @@
   void
   NamespacesHandler::outputResultNamespaces(
   			StylesheetExecutionContext&		theExecutionContext,
  -			const XalanDOMString*			theNamespaceToExclude) const
  +			bool							supressDefault) const
   {
   	// Write out the namespace declarations...
   	if (m_namespaceDeclarations.size() > 0)
  @@ -401,13 +401,16 @@
   		{
   			const NameSpaceExtended&	theNamespace = (*i).second;
   
  -			const XalanDOMString&		theResultURI = theNamespace.getURI();
  -			assert(length(theNamespace.getResultAttributeName()) > 0);
  +			const XalanDOMString&		thePrefix = theNamespace.getPrefix();
   
  -//			if (theNamespaceToExclude == 0 ||
  -//				equals(*theNamespaceToExclude, theResultURI) == false)
  +			// If we're not supposed to suppress the default namespace, or
  +			// there's a prefix (so it's not the default), we can continue
  +			// to see if we need to add the result namespace.
  +			if (supressDefault == false ||
  +				length(thePrefix) != 0)
   			{
  -				const XalanDOMString&		thePrefix = theNamespace.getPrefix();
  +				const XalanDOMString&		theResultURI = theNamespace.getURI();
  +				assert(length(theNamespace.getResultAttributeName()) > 0);
   
   				// Get the any namespace declaration currently active for the
   				// prefix.
  
  
  
  1.8       +2 -1      xml-xalan/c/src/XSLT/NamespacesHandler.hpp
  
  Index: NamespacesHandler.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/NamespacesHandler.hpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- NamespacesHandler.hpp	2001/05/14 01:03:10	1.7
  +++ NamespacesHandler.hpp	2001/05/14 22:21:12	1.8
  @@ -350,11 +350,12 @@
   	 * Output the result tree namespace declarations.
   	 *
   	 * @param theExecutionContext The current execution context.
  +	 * @param supressDefault If true, any default namespace declaration will not be output.
   	 */
   	void
   	outputResultNamespaces(
   			StylesheetExecutionContext&		theExecutionContext,
  -			const XalanDOMString*			theNamespaceToExclude = 0) const;
  +			bool							supressDefault = false) const;
   
   	/**
   	 * Clear out the handler.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org