dbertoni    01/06/25 13:17:33

  Modified:    c/src/XSLT ElemAttribute.cpp StylesheetExecutionContext.hpp
                        StylesheetExecutionContextDefault.cpp
                        StylesheetExecutionContextDefault.hpp
                        XSLTEngineImpl.cpp XSLTEngineImpl.hpp
  Log:
  Don't manufacture a result prefix unless necessary.
  
  Revision  Changes    Path
  1.26      +4 -2      xml-xalan/c/src/XSLT/ElemAttribute.cpp
  
  Index: ElemAttribute.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemAttribute.cpp,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ElemAttribute.cpp 2001/06/06 21:55:17     1.25
  +++ ElemAttribute.cpp 2001/06/25 20:17:17     1.26
  @@ -242,12 +242,14 @@
                                                newPrefix = 
substring(origAttrName, 0, indexOfNSSep);
   
                                                // OK, make sure that the 
prefix provided maps to
  -                                             // the same namespace as the 
one the user requested...
  +                                             // the same namespace as the 
one the user requested,
  +                                             // and see if it's in use...
                                                const XalanDOMString* const     
theNamespace =
                                                        
executionContext.getResultNamespaceForPrefix(newPrefix);
   
                                                if (theNamespace != 0 &&
  -                                                     equals(*theNamespace, 
attrNameSpace) == false)
  +                                                     equals(*theNamespace, 
attrNameSpace) == false &&
  +                                                     
executionContext.isPendingResultPrefix(newPrefix) == true)
                                                {
                                                        // It doesn't, so we'll 
need to manufacture a
                                                        // prefix.
  
  
  
  1.58      +15 -0     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.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- StylesheetExecutionContext.hpp    2001/06/25 15:20:07     1.57
  +++ StylesheetExecutionContext.hpp    2001/06/25 20:17:18     1.58
  @@ -350,6 +350,8 @@
         * Retrieve the result prefix corresponding to a namespace.
         * 
         * @param theNamespace namespace for prefix
  +      *
  +      * @return A pointer to a string containing the prefix, or 0 if the 
namespace is not mapped.
         */
        virtual const XalanDOMString*
        getResultPrefixForNamespace(const XalanDOMString&       theNamespace) 
const = 0;
  @@ -358,9 +360,22 @@
         * Retrieve the result namespace corresponding to a prefix.
         * 
         * @param thePrefix prefix for namespace
  +      *
  +      * @return A pointer to a string containing the namespace, or 0 if the 
prefix is not mapped.
         */
        virtual const XalanDOMString*
        getResultNamespaceForPrefix(const XalanDOMString&       thePrefix) 
const = 0;
  +
  +     /**
  +      * Determine whether or not a prefix is in use on the pending element or
  +      * the pending attributes.
  +      * 
  +      * @param thePrefix prefix for namespace
  +      *
  +      * @return true if the prefix is in use, false if not.
  +      */
  +     virtual bool
  +     isPendingResultPrefix(const XalanDOMString&     thePrefix) = 0;
   
        /**
         * Generate a random namespace prefix guaranteed to be unique.
  
  
  
  1.68      +10 -0     
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.67
  retrieving revision 1.68
  diff -u -r1.67 -r1.68
  --- StylesheetExecutionContextDefault.cpp     2001/06/25 15:20:07     1.67
  +++ StylesheetExecutionContextDefault.cpp     2001/06/25 20:17:19     1.68
  @@ -401,6 +401,16 @@
   
   
   
  +bool
  +StylesheetExecutionContextDefault::isPendingResultPrefix(const 
XalanDOMString&       thePrefix)
  +{
  +     assert(m_xsltProcessor != 0);
  +
  +     return m_xsltProcessor->isPendingResultPrefix(thePrefix);
  +}
  +
  +
  +
   XalanDOMString
   StylesheetExecutionContextDefault::getUniqueNamespaceValue() const
   {
  
  
  
  1.62      +3 -0      
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.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- StylesheetExecutionContextDefault.hpp     2001/06/25 15:20:08     1.61
  +++ StylesheetExecutionContextDefault.hpp     2001/06/25 20:17:21     1.62
  @@ -319,6 +319,9 @@
        virtual const XalanDOMString*
        getResultNamespaceForPrefix(const XalanDOMString&       thePrefix) 
const;
   
  +     virtual bool
  +     isPendingResultPrefix(const XalanDOMString&     thePrefix);
  +
        virtual XalanDOMString
        getUniqueNamespaceValue() const;
   
  
  
  
  1.102     +151 -0    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.101
  retrieving revision 1.102
  diff -u -r1.101 -r1.102
  --- XSLTEngineImpl.cpp        2001/06/14 19:28:26     1.101
  +++ XSLTEngineImpl.cpp        2001/06/25 20:17:22     1.102
  @@ -2455,6 +2455,157 @@
   
   
   
  +inline bool
  +isPrefixUsed(
  +                     const XalanDOMString&   thePrefix,
  +                     unsigned int                    thePrefixLength,
  +                     const XalanDOMChar*             theName,
  +                     unsigned int                    theNameLength)
  +{
  +     assert(thePrefixLength != 0);
  +
  +     // The name must be greater than the length of the prefix + 1, since
  +     // there must be a ':' to separate the prefix from the local part...
  +     if (theNameLength <= thePrefixLength + 1)
  +     {
  +             return false;
  +     }
  +     else
  +     {
  +             assert(theName != 0);
  +
  +             const unsigned int      theIndex = indexOf(
  +                     theName,
  +                     XalanUnicode::charColon);
  +
  +             // OK, if the index of the ':' is the same as the length of the 
prefix,
  +             // and theElementName starts with thePrefix, then the prefix is 
in use.
  +             if (theIndex == thePrefixLength &&
  +                     startsWith(theName, thePrefix) == true)
  +             {
  +                     return true;
  +             }
  +             else
  +             {
  +                     return false;
  +             }
  +     }
  +}
  +
  +
  +
  +inline bool
  +isPrefixUsed(
  +                     const XalanDOMString&   thePrefix,
  +                     unsigned int                    thePrefixLength,
  +                     const XalanDOMString&   theName)
  +{
  +     return isPrefixUsed(thePrefix, thePrefixLength, c_wstr(theName), 
length(theName));
  +}
  +
  +
  +
  +inline bool
  +isPrefixUsedOrDeclared(
  +                     const XalanDOMString&   thePrefix,
  +                     unsigned int                    thePrefixLength,
  +                     const XalanDOMChar*             theName,
  +                     unsigned int                    theNameLength)
  +{
  +     if (isPrefixUsed(thePrefix, thePrefixLength, theName, theNameLength) == 
true)
  +     {
  +             return true;
  +     }
  +     else
  +     {
  +             const unsigned int      theDeclarationLength =
  +                     thePrefixLength + 
DOMServices::s_XMLNamespaceWithSeparatorLength;
  +
  +             // If this is a namespace declaration for this prefix, then all 
of
  +             // these conditions must be true...
  +             if (theDeclarationLength == theNameLength &&
  +                     startsWith(theName, 
DOMServices::s_XMLNamespaceWithSeparator) == true &&
  +                     endsWith(theName, c_wstr(thePrefix)) == true)
  +             {
  +                     return true;
  +             }
  +             else
  +             {
  +                     return false;
  +             }
  +     }
  +}
  +
  +
  +
  +inline bool
  +isPendingAttributePrefix(
  +                     const AttributeList&            thePendingAttributes,
  +                     const XalanDOMString&           thePrefix,
  +                     unsigned int                            thePrefixLength)
  +{
  +     const unsigned int      thePendingAttributesCount =
  +                             thePendingAttributes.getLength();
  +
  +     if (thePendingAttributesCount == 0)
  +     {
  +             // No attributes, no problem...
  +             return false;
  +     }
  +     else
  +     {
  +             bool    fResult = false;
  +
  +             // Check each attribute...
  +             for (unsigned int i = 0; i < thePendingAttributesCount; ++i)
  +             {
  +                     const XalanDOMChar* const       thePendingAttributeName 
=
  +                                                     
thePendingAttributes.getName(i);
  +                     assert(thePendingAttributeName != 0);
  +
  +                     if (isPrefixUsedOrDeclared(
  +                                     thePrefix,
  +                                     thePrefixLength,
  +                                     thePendingAttributeName,
  +                                     length(thePendingAttributeName)) == 
true)
  +                     {
  +                             fResult = true;
  +
  +                             break;
  +                     }
  +             }
  +
  +             return fResult;
  +     }
  +}
  +
  +
  +
  +bool
  +XSLTEngineImpl::isPendingResultPrefix(const XalanDOMString&          
thePrefix) const
  +{
  +     const unsigned int      thePrefixLength = length(thePrefix);
  +     assert(thePrefixLength > 0);
  +
  +     // The element name must be greater than the length of the prefix + 1, 
since
  +     // there must be a ':' to separate the prefix from the local part...
  +     if (isPrefixUsed(thePrefix, thePrefixLength, getPendingElementName()) 
== true)
  +     {
  +             return true;
  +     }
  +     else
  +     {
  +             // The element is not using the prefix, so check the
  +             // pending attributes...
  +             return isPendingAttributePrefix(
  +                                             getPendingAttributes(),
  +                                             thePrefix,
  +                                             thePrefixLength);
  +     }
  +}
  +
  +
  +
   void
   XSLTEngineImpl::addResultNamespace(
                        const XalanNode&        theNode,
  
  
  
  1.69      +11 -0     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.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- XSLTEngineImpl.hpp        2001/06/14 19:28:27     1.68
  +++ XSLTEngineImpl.hpp        2001/06/25 20:17:24     1.69
  @@ -924,6 +924,17 @@
        getResultPrefixForNamespace(const XalanDOMString&       theNamespace) 
const;
   
        /**
  +      * Determine whether or not a prefix is in use on the pending element or
  +      * the pending attributes.
  +      * 
  +      * @param thePrefix prefix for namespace
  +      *
  +      * @return true if the prefix is in use, false if not.
  +      */
  +     bool
  +     isPendingResultPrefix(const XalanDOMString&             thePrefix) 
const;
  +
  +     /**
         * Evaluate an xpath string and return the result as a numberic score.
         *
         * @param str                      string to evaluate
  
  
  

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

Reply via email to