Return-Path: Mailing-List: contact xalan-cvs-help@xml.apache.org; run by ezmlm Delivered-To: mailing list xalan-cvs@xml.apache.org Received: (qmail 88326 invoked by uid 1034); 1 Feb 2001 18:32:59 -0000 Date: 1 Feb 2001 18:32:59 -0000 Message-ID: <20010201183259.88325.qmail@apache.org> From: dbertoni@apache.org To: xml-xalan-cvs@apache.org Subject: cvs commit: xml-xalan/c/src/XSLT StylesheetHandler.cpp StylesheetHandler.hpp dbertoni 01/02/01 10:32:59 Modified: c/src/XSLT StylesheetHandler.cpp StylesheetHandler.hpp Log: Support xml:space appropriately. Revision Changes Path 1.55 +89 -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.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- StylesheetHandler.cpp 2001/01/31 01:41:41 1.54 +++ StylesheetHandler.cpp 2001/02/01 18:32:57 1.55 @@ -244,21 +244,26 @@ StylesheetHandler::processSpaceAttr( const XalanDOMChar* aname, const AttributeList& atts, - int which) + int which, + bool& fPreserve) { const bool isSpaceAttr = equals(aname, Constants::ATTRNAME_XMLSPACE); - if(isSpaceAttr) + if(isSpaceAttr == false) { + fPreserve = false; + } + else + { const XalanDOMChar* const spaceVal = atts.getValue(which); if(equals(spaceVal, Constants::ATTRVAL_DEFAULT)) { - m_stylesheet.setDefaultSpaceProcessing(true); + fPreserve = false; } else if(equals(spaceVal, Constants::ATTRVAL_PRESERVE)) { - m_stylesheet.setDefaultSpaceProcessing(false); + fPreserve = true; } else { @@ -271,6 +276,26 @@ +bool +StylesheetHandler::processSpaceAttr( + const AttributeList& atts, + bool& fPreserve) +{ + const unsigned int len = atts.getLength(); + + for (unsigned int i = 0; i < len; ++i) + { + if (processSpaceAttr(atts.getName(i), atts, i, fPreserve) == true) + { + return true; + } + } + + return false; +} + + + void StylesheetHandler::startElement( const XMLCh* const name, @@ -282,11 +307,25 @@ m_inExtensionElementStack.push_back(false); + if (m_preserveSpaceStack.empty() == true) + { + m_preserveSpaceStack.push_back(false); + } + else + { + m_preserveSpaceStack.push_back(m_preserveSpaceStack.back()); + } + try { #if !defined(XALAN_NO_NAMESPACES) using std::for_each; #endif + + // By default, space is not preserved... + bool fPreserveSpace = false; + bool fSpaceAttrProcessed = false; + processAccumulatedText(); // Clean up the whitespace elements. @@ -549,8 +588,6 @@ bool fVersionFound = false; - // bool didSpecifiyIndent = false; //doesn't seem to be used - for(unsigned int i = 0; i < nAttrs; i++) { const XalanDOMChar* const aname = atts.getName(i); @@ -599,8 +636,12 @@ m_stylesheet.setXSLTVerDeclared(DoubleSupport::toDouble(versionStr)); fVersionFound = true; + } + else if(processSpaceAttr(aname, atts, i, fPreserveSpace) == true) + { + fSpaceAttrProcessed = true; } - else if(!(isAttrOK(aname, atts, i) || processSpaceAttr(aname, atts, i))) + else if(isAttrOK(aname, atts, i) == false) { if(false == m_stylesheet.isWrapperless()) { @@ -621,6 +662,18 @@ { throw SAXException(c_wstr(TranscodeFromLocalCodePage("The stylesheet element did not specify a version attribute!"))); } + else + { + if (fPreserveSpace == false) + { + m_stylesheet.setDefaultSpaceProcessing(true); + } + else + { + m_stylesheet.setDefaultSpaceProcessing(false); + } + } + } break; @@ -1050,6 +1103,19 @@ m_elemStack.push_back(elem); } + // If we haven't processed an xml:space attribute already, look for one... + if (fSpaceAttrProcessed == false) + { + fSpaceAttrProcessed = processSpaceAttr(atts, fPreserveSpace); + } + + // Only update the stack if we actually processed an xml:space attribute... + if (fSpaceAttrProcessed == true) + { + // Set the preserve value... + m_preserveSpaceStack.back() = fPreserveSpace; + } + // If for some reason something didn't get pushed, push an empty // object. if(origStackSize == m_elemStack.size()) @@ -1402,6 +1468,10 @@ assert(m_inExtensionElementStack.empty() == false); m_inExtensionElementStack.pop_back(); + + assert(m_preserveSpaceStack.empty() == false); + + m_preserveSpaceStack.pop_back(); } @@ -1525,27 +1595,30 @@ if(m_inTemplate) { ElemTemplateElement* parent = m_elemStack.back(); + assert(parent != 0); + + assert(m_preserveSpaceStack.empty() == false); - bool preserveSpace = false; - bool disableOutputEscaping = false; + bool preserveSpace = m_preserveSpaceStack.back(); + bool disableOutputEscaping = false; - if(Constants::ELEMNAME_TEXT == parent->getXSLToken()) + if (preserveSpace == false && parent->getXSLToken() == Constants::ELEMNAME_TEXT) { #if defined(XALAN_OLD_STYLE_CASTS) disableOutputEscaping = ((ElemText*)parent)->getDisableOutputEscaping(); #else disableOutputEscaping = static_cast(parent)->getDisableOutputEscaping(); #endif - parent = m_elemStack[m_elemStack.size()-2]; preserveSpace = true; + parent = m_elemStack[m_elemStack.size()-2]; } const Locator* const locator = m_constructionContext.getLocatorFromStack(); - const int lineNumber = (0 != locator) ? locator->getLineNumber() : 0; - const int columnNumber = (0 != locator) ? locator->getColumnNumber() : 0; + const int lineNumber = (0 != locator) ? locator->getLineNumber() : 0; + const int columnNumber = (0 != locator) ? locator->getColumnNumber() : 0; - ElemTextLiteral* elem = new ElemTextLiteral(m_constructionContext, + ElemTextLiteral* const elem = new ElemTextLiteral(m_constructionContext, m_stylesheet, lineNumber, columnNumber, chars, 0, length, @@ -1688,6 +1761,7 @@ m_namespaces.swap(theHandler.m_stylesheet.getNamespaces()); m_namespacesHandler.swap(theHandler.m_stylesheet.getNamespacesHandler()); m_inExtensionElementStack.swap(theHandler.m_inExtensionElementStack); + m_preserveSpaceStack.swap(theHandler.m_preserveSpaceStack); } @@ -1720,4 +1794,5 @@ m_handler.m_stylesheet.getNamespaces().swap(m_namespaces); m_handler.m_stylesheet.getNamespacesHandler().swap(m_namespacesHandler); m_handler.m_inExtensionElementStack.swap(m_inExtensionElementStack); + m_handler.m_preserveSpaceStack.swap(m_preserveSpaceStack); } 1.23 +19 -1 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.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- StylesheetHandler.hpp 2001/01/29 01:11:49 1.22 +++ StylesheetHandler.hpp 2001/02/01 18:32:58 1.23 @@ -378,14 +378,28 @@ * @param aname The name of the attribute in question. * @param atts The attribute list that owns the attribute. * @param which The index of the attribute into the attribute list. + * @param fPreserve set to true if the attribute value is "preserve" * @return True if this is a xml:space attribute. */ bool processSpaceAttr( const XalanDOMChar* aname, const AttributeList& atts, - int which); + int which, + bool& fPreserve); + /** + * Tell whether or not this is a xml:space attribute and, if so, process it. + * + * @param atts The attribute list that owns the attribute. + * @param fPreserve set to true if an xml:space attribute value is "preserve" + * @return True if this is a xml:space attribute. + */ + bool + processSpaceAttr( + const AttributeList& atts, + bool& fPreserve); + /** * Process xsl:import. */ @@ -502,6 +516,8 @@ BoolStackType m_inExtensionElementStack; + BoolStackType m_preserveSpaceStack; + // BEGIN SANJIVA CODE bool m_inLXSLTScript; XalanDOMString m_LXSLTScriptBody; @@ -556,6 +572,8 @@ NamespacesHandler m_namespacesHandler; BoolStackType m_inExtensionElementStack; + + BoolStackType m_preserveSpaceStack; }; friend class PushPopIncludeState;