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 2004/04/02 04:45:35 UTC
cvs commit: xml-xalan/c/src/xalanc/XSLT XalanSpaceNodeTester.cpp XalanSpaceNodeTester.hpp ElemCopy.cpp ElemTemplateElement.cpp StylesheetExecutionContext.hpp StylesheetExecutionContextDefault.cpp StylesheetExecutionContextDefault.hpp StylesheetHandler.cpp XSLTEngineImpl.cpp XSLTEngineImpl.hpp XSLTProcessor.hpp
dbertoni 2004/04/01 18:45:35
Modified: c/src/xalanc/XSLT ElemCopy.cpp ElemTemplateElement.cpp
StylesheetExecutionContext.hpp
StylesheetExecutionContextDefault.cpp
StylesheetExecutionContextDefault.hpp
StylesheetHandler.cpp XSLTEngineImpl.cpp
XSLTEngineImpl.hpp XSLTProcessor.hpp
Added: c/src/xalanc/XSLT XalanSpaceNodeTester.cpp
XalanSpaceNodeTester.hpp
Log:
Initial clean up of whitespace stripping. Fixed bug with whitespace stripping and xsl:copy-of.
Revision Changes Path
1.7 +0 -1 xml-xalan/c/src/xalanc/XSLT/ElemCopy.cpp
Index: ElemCopy.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/ElemCopy.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ElemCopy.cpp 26 Feb 2004 22:58:57 -0000 1.6
+++ ElemCopy.cpp 2 Apr 2004 02:45:34 -0000 1.7
@@ -101,7 +101,6 @@
nodeType,
false,
false,
- false,
getLocator());
if(XalanNode::ELEMENT_NODE == nodeType)
1.12 +9 -4 xml-xalan/c/src/xalanc/XSLT/ElemTemplateElement.cpp
Index: ElemTemplateElement.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/ElemTemplateElement.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ElemTemplateElement.cpp 27 Mar 2004 02:11:03 -0000 1.11
+++ ElemTemplateElement.cpp 2 Apr 2004 02:45:34 -0000 1.12
@@ -658,9 +658,14 @@
{
switch(nodeType)
{
- case XalanNode::CDATA_SECTION_NODE:
+ case XalanNode::CDATA_SECTION_NODE:
case XalanNode::TEXT_NODE:
- executionContext.cloneToResultTree(*child, nodeType, false, false, false, getLocator());
+ executionContext.cloneToResultTree(
+ *child,
+ XalanNode::TEXT_NODE,
+ false,
+ false,
+ getLocator());
break;
case XalanNode::ATTRIBUTE_NODE:
@@ -688,8 +693,8 @@
{
if(0 != executionContext.getTraceListeners())
{
- TracerEvent te(executionContext,
- *theTemplate);
+ const TracerEvent te(executionContext,
+ *theTemplate);
executionContext.fireTraceEvent(te);
}
1.17 +1 -3 xml-xalan/c/src/xalanc/XSLT/StylesheetExecutionContext.hpp
Index: StylesheetExecutionContext.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/StylesheetExecutionContext.hpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- StylesheetExecutionContext.hpp 13 Mar 2004 00:44:55 -0000 1.16
+++ StylesheetExecutionContext.hpp 2 Apr 2004 02:45:34 -0000 1.17
@@ -1108,7 +1108,6 @@
*
* @param node node to clone
* @param nodeType the type of the node
- * @param isLiteral true if a literal element
* @param overrideStrip false if white space stripping should be done
* @param shouldCloneAttributes true if attributes should be cloned
* @param locator The Locator, if any
@@ -1117,7 +1116,6 @@
cloneToResultTree(
const XalanNode& node,
XalanNode::NodeType nodeType,
- bool isLiteral,
bool overrideStrip,
bool shouldCloneAttributes,
const LocatorType* locator) = 0;
@@ -1883,7 +1881,7 @@
const XalanDocument& theDocument) const = 0;
virtual bool
- shouldStripSourceNode(const XalanNode& node) = 0;
+ shouldStripSourceNode(const XalanText& node) = 0;
virtual XalanDocument*
getSourceDocument(const XalanDOMString& theURI) const = 0;
1.24 +1 -3 xml-xalan/c/src/xalanc/XSLT/StylesheetExecutionContextDefault.cpp
Index: StylesheetExecutionContextDefault.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/StylesheetExecutionContextDefault.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- StylesheetExecutionContextDefault.cpp 27 Mar 2004 02:11:03 -0000 1.23
+++ StylesheetExecutionContextDefault.cpp 2 Apr 2004 02:45:34 -0000 1.24
@@ -932,7 +932,6 @@
StylesheetExecutionContextDefault::cloneToResultTree(
const XalanNode& node,
XalanNode::NodeType nodeType,
- bool isLiteral,
bool overrideStrip,
bool shouldCloneAttributes,
const LocatorType* locator)
@@ -942,7 +941,6 @@
m_xsltProcessor->cloneToResultTree(
node,
nodeType,
- isLiteral,
overrideStrip,
shouldCloneAttributes,
m_cloneTextNodesOnly,
@@ -2069,7 +2067,7 @@
bool
-StylesheetExecutionContextDefault::shouldStripSourceNode(const XalanNode& node)
+StylesheetExecutionContextDefault::shouldStripSourceNode(const XalanText& node)
{
if (m_xsltProcessor == 0)
{
1.18 +1 -2 xml-xalan/c/src/xalanc/XSLT/StylesheetExecutionContextDefault.hpp
Index: StylesheetExecutionContextDefault.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/StylesheetExecutionContextDefault.hpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- StylesheetExecutionContextDefault.hpp 13 Mar 2004 00:44:55 -0000 1.17
+++ StylesheetExecutionContextDefault.hpp 2 Apr 2004 02:45:34 -0000 1.18
@@ -484,7 +484,6 @@
cloneToResultTree(
const XalanNode& node,
XalanNode::NodeType nodeType,
- bool isLiteral,
bool overrideStrip,
bool shouldCloneAttributes,
const LocatorType* locator);
@@ -893,7 +892,7 @@
const XalanDocument& theDocument) const;
virtual bool
- shouldStripSourceNode(const XalanNode& node);
+ shouldStripSourceNode(const XalanText& node);
virtual XalanDocument*
getSourceDocument(const XalanDOMString& theURI) const;
1.13 +9 -4 xml-xalan/c/src/xalanc/XSLT/StylesheetHandler.cpp
Index: StylesheetHandler.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/StylesheetHandler.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- StylesheetHandler.cpp 26 Feb 2004 22:58:58 -0000 1.12
+++ StylesheetHandler.cpp 2 Apr 2004 02:45:34 -0000 1.13
@@ -53,6 +53,7 @@
#include "Stylesheet.hpp"
#include "StylesheetConstructionContext.hpp"
#include "StylesheetRoot.hpp"
+#include "XalanSpaceNodeTester.hpp"
@@ -993,12 +994,14 @@
const GetAndReleaseCachedString theGuard(m_constructionContext);
- XalanDOMString& wildcardName = theGuard.get();
+ XalanDOMString& theNameTest = theGuard.get();
+
+ const XalanQName::PrefixResolverProxy theProxy(m_stylesheet.getNamespaces(), m_stylesheet.getURI());
while(tokenizer.hasMoreTokens())
{
// Use only the root, at least for right now.
- tokenizer.nextToken(wildcardName);
+ tokenizer.nextToken(theNameTest);
/**
* Creating a match pattern is too much overhead, but it's a reasonably
@@ -1007,8 +1010,10 @@
const XPath* const matchPat =
m_constructionContext.createMatchPattern(
0,
- wildcardName,
- XalanQName::PrefixResolverProxy(m_stylesheet.getNamespaces(), m_stylesheet.getURI()));
+ theNameTest,
+ theProxy);
+
+ const XalanSpaceNodeTester theNodeTest(m_constructionContext, theNameTest, theProxy, locator);
if(isPreserveSpace == true)
{
1.14 +29 -45 xml-xalan/c/src/xalanc/XSLT/XSLTEngineImpl.cpp
Index: XSLTEngineImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/XSLTEngineImpl.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- XSLTEngineImpl.cpp 26 Feb 2004 22:58:58 -0000 1.13
+++ XSLTEngineImpl.cpp 2 Apr 2004 02:45:34 -0000 1.14
@@ -2033,17 +2033,23 @@
void
XSLTEngineImpl::cloneToResultTree(
const XalanText& node,
- bool isLiteral,
bool overrideStrip)
{
- bool stripWhiteSpace = false;
+#if 1
+ assert(m_executionContext != 0 && m_stylesheetRoot != 0);
+ assert(node.getParentNode() == 0 ||
+ node.getParentNode()->getNodeType() != XalanNode::DOCUMENT_NODE);
+
+ if (overrideStrip == true ||
+ shouldStripSourceNode(*m_executionContext, node) == false)
+ {
+ const XalanDOMString& data = node.getData();
+ assert(0 != length(data));
- // If stripWhiteSpace is false, then take this as an override and
- // just preserve the space, otherwise use the XSL whitespace rules.
- if(!overrideStrip)
- {
- stripWhiteSpace = isLiteral ? true : false;
- }
+ characters(toCharArray(data), 0, length(data));
+ }
+#else
+ bool stripWhiteSpace = false;
const bool isIgnorableWhitespace = node.isIgnorableWhitespace();
@@ -2065,7 +2071,8 @@
characters(toCharArray(data), 0, length(data));
}
}
- }
+ }
+#endif
}
@@ -2111,7 +2118,6 @@
*pos,
posNodeType,
false,
- false,
true,
false,
locator);
@@ -2166,7 +2172,6 @@
XSLTEngineImpl::cloneToResultTree(
const XalanNode& node,
XalanNode::NodeType nodeType,
- bool isLiteral,
bool overrideStrip,
bool shouldCloneAttributes,
bool cloneTextNodesOnly,
@@ -2192,7 +2197,7 @@
static_cast<const XalanText&>(node);
#endif
- cloneToResultTree(tx, isLiteral, overrideStrip);
+ cloneToResultTree(tx, overrideStrip);
}
}
else
@@ -2208,7 +2213,7 @@
static_cast<const XalanText&>(node);
#endif
- cloneToResultTree(tx, isLiteral, overrideStrip);
+ cloneToResultTree(tx, overrideStrip);
}
break;
@@ -2340,7 +2345,7 @@
XalanNode::NodeType posNodeType = pos->getNodeType();
- cloneToResultTree(*pos, posNodeType, false, false, false, false, locator);
+ cloneToResultTree(*pos, posNodeType, false, false, false, locator);
XalanNode* nextNode = pos->getFirstChild();
@@ -2430,7 +2435,7 @@
{
flushPending();
- cloneToResultTree(*pos, posNodeType, false, false, true, false, locator);
+ cloneToResultTree(*pos, posNodeType, true, true, false, locator);
XalanNode* nextNode = pos->getFirstChild();
@@ -2968,7 +2973,7 @@
bool
XSLTEngineImpl::shouldStripSourceNode(
StylesheetExecutionContext& executionContext,
- const XalanNode& textNode) const
+ const XalanText& textNode) const
{
if (m_hasStripOrPreserveSpace == false || m_stylesheetRoot == 0)
{
@@ -2976,40 +2981,19 @@
}
else
{
- bool strip = false;
-
assert(m_stylesheetRoot->hasPreserveOrStripSpaceElements() == true);
+ assert(length(textNode.getData()) != 0);
- const XalanNode::NodeType type = textNode.getNodeType();
-
- if(XalanNode::TEXT_NODE == type || XalanNode::CDATA_SECTION_NODE == type)
+ if(textNode.isIgnorableWhitespace() == false)
+ {
+ return false;
+ }
+ else
{
- const XalanText& theTextNode =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (const XalanText&)textNode;
-#else
- static_cast<const XalanText&>(textNode);
-#endif
-
- if(!theTextNode.isIgnorableWhitespace())
- {
- const XalanDOMString& data = theTextNode.getData();
-
- if(0 == length(data))
- {
- strip = true;
- }
- }
- else
- {
- strip =
- m_stylesheetRoot->shouldStripSourceNode(
+ return m_stylesheetRoot->shouldStripSourceNode(
executionContext,
- theTextNode);
- }
+ textNode);
}
-
- return strip;
}
}
1.9 +19 -10 xml-xalan/c/src/xalanc/XSLT/XSLTEngineImpl.hpp
Index: XSLTEngineImpl.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/XSLTEngineImpl.hpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- XSLTEngineImpl.hpp 26 Feb 2004 22:58:58 -0000 1.8
+++ XSLTEngineImpl.hpp 2 Apr 2004 02:45:34 -0000 1.9
@@ -291,11 +291,6 @@
const XalanDOMString& key,
XObjectPtr value);
- virtual bool
- shouldStripSourceNode(
- StylesheetExecutionContext& executionContext,
- const XalanNode& node) const;
-
virtual FormatterListener*
getFormatterListener() const;
@@ -668,6 +663,24 @@
XalanDOMString::size_type length);
/**
+ * Tells, through the combination of the default-space attribute on
+ * xsl:stylesheet, xsl:strip-space, xsl:preserve-space, and the xml:space
+ * attribute, whether or not extra whitespace should be stripped from the
+ * node. Literal elements from template elements should <em>not</em> be
+ * tested with this function.
+ *
+ * @param executionContext current execution context
+ * @param node text node from the source tree
+ * @return true if the text node should be stripped of extra whitespace
+ *
+ * $$$ ToDo: This has no business being here in the engine...
+ */
+ bool
+ shouldStripSourceNode(
+ StylesheetExecutionContext& executionContext,
+ const XalanText& node) const;
+
+ /**
* Clone a node to the result tree
*
* @param node node to clone
@@ -685,7 +698,6 @@
*
* @param node node to clone
* @param nodeType the type of the node
- * @param isLiteral true if a literal element
* @param overrideStrip false if white space stripping should be done
* @param shouldCloneAttributes true if attributes should be cloned
* @param cloneTextNodesOnly if true, only text nodes will be cloned
@@ -695,7 +707,6 @@
cloneToResultTree(
const XalanNode& node,
XalanNode::NodeType nodeType,
- bool isLiteral,
bool overrideStrip,
bool shouldCloneAttributes,
bool cloneTextNodesOnly,
@@ -706,7 +717,7 @@
*
* @param value the XObject to output
* @param outputTextNodesOnly if true, only text nodes will be copied
- * @param locator the Locator for the event, if any.
+ * @param locator the Locator for the event, if any.
*/
void
outputToResultTree(
@@ -1464,13 +1475,11 @@
* Clone a text node to the result tree
*
* @param node node to clone
- * @param isLiteral true if a literal element
* @param overrideStrip false if white space stripping should be done
*/
void
cloneToResultTree(
const XalanText& node,
- bool isLiteral,
bool overrideStrip);
/**
1.7 +0 -18 xml-xalan/c/src/xalanc/XSLT/XSLTProcessor.hpp
Index: XSLTProcessor.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/XSLTProcessor.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XSLTProcessor.hpp 26 Feb 2004 22:58:58 -0000 1.6
+++ XSLTProcessor.hpp 2 Apr 2004 02:45:34 -0000 1.7
@@ -248,24 +248,6 @@
const XalanDOMString& expression) = 0;
/**
- * Tells, through the combination of the default-space attribute on
- * xsl:stylesheet, xsl:strip-space, xsl:preserve-space, and the xml:space
- * attribute, whether or not extra whitespace should be stripped from the
- * node. Literal elements from template elements should <em>not</em> be
- * tested with this function.
- *
- * @param executionContext current execution context
- * @param node text node from the source tree
- * @return true if the text node should be stripped of extra whitespace
- *
- * $$$ ToDo: This has no business being here in the engine...
- */
- virtual bool
- shouldStripSourceNode(
- StylesheetExecutionContext& executionContext,
- const XalanNode& node) const = 0;
-
- /**
* Get the current formatter listener.
*
* @return pointer to formatter listener
1.1 xml-xalan/c/src/xalanc/XSLT/XalanSpaceNodeTester.cpp
Index: XalanSpaceNodeTester.cpp
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "XalanSpaceNodeTester.hpp"
#include "xalanc/PlatformSupport/DOMStringHelper.hpp"
#include "xalanc/PlatformSupport/XalanMessageLoader.hpp"
#include "Constants.hpp"
#include "StylesheetConstructionContext.hpp"
XALAN_CPP_NAMESPACE_BEGIN
XalanSpaceNodeTester::XalanSpaceNodeTester() :
m_nodeTester(),
m_matchScore(XPath::eMatchScoreNone)
{
}
static const XalanDOMString s_emptyString;
XalanSpaceNodeTester::XalanSpaceNodeTester(
StylesheetConstructionContext& theConstructionContext,
const XalanDOMString& theNameTest,
const PrefixResolver& thePrefixResolver,
const LocatorType* theLocator) :
m_nodeTester(),
m_matchScore(XPath::eMatchScoreNone)
{
const XalanDOMString::size_type theLength =
length(theNameTest);
if (theLength == 1 && theNameTest[0] == XPath::PSEUDONAME_ANY[0])
{
m_nodeTester = XPath::NodeTester(s_emptyString, s_emptyString, m_matchScore);
}
else
{
const XalanDOMString::size_type theIndex =
indexOf(theNameTest, XalanUnicode::charColon);
// If there's no ':', it's an NCName...
if (theIndex == theLength)
{
if (XalanQName::isValidNCName(theNameTest) == false)
{
theConstructionContext.error(
XalanMessageLoader::getMessage(
XalanMessages::IsNotValidQName_1Param,
theNameTest),
0,
theLocator);
}
else
{
m_nodeTester =
XPath::NodeTester(
s_emptyString,
theConstructionContext.getPooledString(theNameTest),
m_matchScore);
}
}
else
{
StylesheetConstructionContext::GetAndReleaseCachedString scratchGuard(theConstructionContext);
XalanDOMString& theScratchString = scratchGuard.get();
theScratchString.assign(theNameTest, 0, theIndex);
// Get the namespace URI for the prefix...
const XalanDOMString* const theNamespaceURI =
thePrefixResolver.getNamespaceForPrefix(theScratchString);
if (theNamespaceURI == 0)
{
theConstructionContext.error(
XalanMessageLoader::getMessage(
XalanMessages::UndeclaredNamespacePrefix_1Param,
theScratchString),
0,
theLocator);
}
else
{
// OK, now we have a namespace URI...
if (XalanQName::isValidNCName(theScratchString) == false)
{
theConstructionContext.error(
XalanMessageLoader::getMessage(
XalanMessages::IsNotValidQName_1Param,
theNameTest),
0,
theLocator);
}
else if (theIndex == theLength - 2 &&
theNameTest[theIndex + 1] == XPath::PSEUDONAME_ANY[0])
{
// It's of the form "NCName:*"
m_nodeTester =
XPath::NodeTester(
theConstructionContext.getPooledString(*theNamespaceURI),
s_emptyString,
m_matchScore);
}
else
{
theScratchString.assign(theNameTest, theIndex + 1, theLength - theIndex - 1);
if (XalanQName::isValidNCName(theScratchString) == false)
{
theConstructionContext.error(
XalanMessageLoader::getMessage(
XalanMessages::IsNotValidQName_1Param,
theNameTest),
0,
theLocator);
}
else
{
// It's of the form "NCName:NCName"
m_nodeTester =
XPath::NodeTester(
theConstructionContext.getPooledString(*theNamespaceURI),
theConstructionContext.getPooledString(theScratchString),
m_matchScore);
}
}
}
}
}
assert(m_matchScore != XPath::eMatchScoreNone);
}
XalanSpaceNodeTester::~XalanSpaceNodeTester()
{
}
XALAN_CPP_NAMESPACE_END
1.1 xml-xalan/c/src/xalanc/XSLT/XalanSpaceNodeTester.hpp
Index: XalanSpaceNodeTester.hpp
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(XALAN_SPACENODETESTER_HEADER_GUARD_1357924680)
#define XALAN_SPACENODETESTER_HEADER_GUARD_1357924680
/**
* $Id: XalanSpaceNodeTester.hpp,v 1.1 2004/04/02 02:45:34 dbertoni Exp $
*
* $State: Exp $
*
*/
// Base include file. Must be first.
#include "XSLTDefinitions.hpp"
#include "xalanc/XPath/XPath.hpp"
XALAN_CPP_NAMESPACE_BEGIN
class PrefixResolver;
class StylesheetConstructionContext;
class XalanSpaceNodeTester
{
public:
XalanSpaceNodeTester();
XalanSpaceNodeTester(
StylesheetConstructionContext& theContext,
const XalanDOMString& theNameTest,
const PrefixResolver& thePrefixResolver,
const LocatorType* theLocator);
~XalanSpaceNodeTester();
XPath::eMatchScore
getMatchScore() const
{
return m_matchScore;
}
XPath::eMatchScore
operator()(const XalanNode& context) const
{
return m_nodeTester(context);
}
private:
XPath::NodeTester m_nodeTester;
XPath::eMatchScore m_matchScore;
};
XALAN_CPP_NAMESPACE_END
#endif // !defined(XALAN_SPACENODETESTER_HEADER_GUARD_1357924680)
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org