diff --git a/extensions/transformiix/source/xpath/BasicNodeExpr.cpp b/extensions/transformiix/source/xpath/BasicNodeExpr.cpp
index 163587875cd..38c7905cfe0 100644
--- a/extensions/transformiix/source/xpath/BasicNodeExpr.cpp
+++ b/extensions/transformiix/source/xpath/BasicNodeExpr.cpp
@@ -21,14 +21,14 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
- * $Id: BasicNodeExpr.cpp,v 1.2 2001-01-12 20:06:31 axel%pike.org Exp $
+ * $Id: BasicNodeExpr.cpp,v 1.3 2001-04-11 15:00:57 axel%pike.org Exp $
*/
#include "Expr.h"
/**
* @author Keith Visco
- * @version $Revision: 1.2 $ $Date: 2001-01-12 20:06:31 $
+ * @version $Revision: 1.3 $ $Date: 2001-04-11 15:00:57 $
**/
//- Constructors -/
@@ -108,6 +108,9 @@ MBool BasicNodeExpr::matches(Node* node, Node* context, ContextState* cs) {
case NodeExpr::PI_EXPR :
return (MBool) (node->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE);
default: //-- node()
+ if(node->getNodeType() == Node::TEXT_NODE)
+ return !cs->isStripSpaceAllowed(node);
+ return MB_TRUE;
break;
}
return MB_TRUE;
diff --git a/extensions/transformiix/source/xpath/Expr.h b/extensions/transformiix/source/xpath/Expr.h
index 206d93abf1c..66c4e23babb 100644
--- a/extensions/transformiix/source/xpath/Expr.h
+++ b/extensions/transformiix/source/xpath/Expr.h
@@ -25,7 +25,7 @@
* - changed constant short declarations in many of the classes
* with enumerations, commented with //--LF
*
- * $Id: Expr.h,v 1.10 2001-04-08 14:33:45 peterv%netscape.com Exp $
+ * $Id: Expr.h,v 1.11 2001-04-11 15:00:57 axel%pike.org Exp $
*/
@@ -46,7 +46,7 @@
/*
XPath class definitions.
Much of this code was ported from XSL:P.
- @version $Revision: 1.10 $ $Date: 2001-04-08 14:33:45 $
+ @version $Revision: 1.11 $ $Date: 2001-04-11 15:00:57 $
*/
//necessary prototypes
@@ -930,6 +930,7 @@ private:
short axisIdentifier;
void fromDescendants(Node* context, ContextState* cs, NodeSet* nodes);
+ void fromDescendantsRev(Node* context, ContextState* cs, NodeSet* nodes);
}; //-- LocationStep
diff --git a/extensions/transformiix/source/xpath/LocationStep.cpp b/extensions/transformiix/source/xpath/LocationStep.cpp
index 5ae6034a9e2..5914e97255f 100644
--- a/extensions/transformiix/source/xpath/LocationStep.cpp
+++ b/extensions/transformiix/source/xpath/LocationStep.cpp
@@ -21,12 +21,12 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
- * $Id: LocationStep.cpp,v 1.4 2001-01-22 09:36:17 kvisco%ziplink.net Exp $
+ * $Id: LocationStep.cpp,v 1.5 2001-04-11 15:00:58 axel%pike.org Exp $
*/
/*
Implementation of an XPath LocationStep
- @version $Revision: 1.4 $ $Date: 2001-01-22 09:36:17 $
+ @version $Revision: 1.5 $ $Date: 2001-04-11 15:00:58 $
*/
#include "Expr.h"
@@ -109,14 +109,14 @@ ExprResult* LocationStep::evaluate(Node* context, ContextState* cs) {
Node* node = context;
switch (axisIdentifier) {
case ANCESTOR_AXIS :
- if (node) node = context->getParentNode();
+ node = cs->getParentNode(context);
//-- do not break here
case ANCESTOR_OR_SELF_AXIS :
while (node) {
if (nodeExpr->matches(node, context, cs)) {
nodes->add(node);
}
- node = node->getParentNode();
+ node = cs->getParentNode(node);
}
break;
case ATTRIBUTE_AXIS :
@@ -124,7 +124,7 @@ ExprResult* LocationStep::evaluate(Node* context, ContextState* cs) {
NamedNodeMap* atts = context->getAttributes();
if ( atts ) {
for ( UInt32 i = 0; i < atts->getLength(); i++ ) {
- Attr* attr = (Attr*)atts->item(i);
+ Node* attr = atts->item(i);
if ( nodeExpr->matches(attr, context, cs) ) nodes->add(attr);
}
}
@@ -139,21 +139,25 @@ ExprResult* LocationStep::evaluate(Node* context, ContextState* cs) {
break;
case FOLLOWING_AXIS :
{
- node = context->getNextSibling();
+ if ( node->getNodeType() == Node::ATTRIBUTE_NODE) {
+ node = cs->getParentNode(node);
+ fromDescendants(node, cs, nodes);
+ }
+ while (node && !node->getNextSibling()) {
+ node = cs->getParentNode(node);
+ }
while (node) {
+ node = node->getNextSibling();
+
if (nodeExpr->matches(node, context, cs))
nodes->add(node);
if (node->hasChildNodes())
fromDescendants(node, cs, nodes);
- Node* tmpNode = node->getNextSibling();
- if (!tmpNode) {
+ while (node && !node->getNextSibling()) {
node = node->getParentNode();
- if ((node) && (node->getNodeType() != Node::DOCUMENT_NODE))
- node = node->getNextSibling();
}
- else node = tmpNode;
}
break;
}
@@ -170,21 +174,27 @@ ExprResult* LocationStep::evaluate(Node* context, ContextState* cs) {
break;
case PARENT_AXIS :
{
- Node* parent = context->getParentNode();
+ Node* parent = cs->getParentNode(context);
if ( nodeExpr->matches(parent, context, cs) )
nodes->add(parent);
break;
}
case PRECEDING_AXIS :
- node = context->getPreviousSibling();
- if ( !node ) node = context->getParentNode();
+ while (node && !node->getPreviousSibling()) {
+ node = cs->getParentNode(node);
+ }
while (node) {
+ node = node->getPreviousSibling();
+
+ if (node->hasChildNodes())
+ fromDescendantsRev(node, cs, nodes);
+
if (nodeExpr->matches(node, context, cs))
nodes->add(node);
- Node* temp = node->getPreviousSibling();
- if (!temp) node = node->getParentNode();
- else node = temp;
+ while (node && !node->getPreviousSibling()) {
+ node = node->getParentNode();
+ }
}
break;
case PRECEDING_SIBLING_AXIS:
@@ -237,19 +247,39 @@ double LocationStep::getDefaultPriority(Node* node, Node* context, ContextState*
void LocationStep::fromDescendants(Node* context, ContextState* cs, NodeSet* nodes) {
- if (( !context ) || (! nodeExpr )) return;
+ if ( !context || !nodeExpr ) return;
- NodeList* nl = context->getChildNodes();
- for (UInt32 i = 0; i < nl->getLength(); i++) {
- Node* child = nl->item(i);
+ Node* child = context->getFirstChild();
+ while (child) {
if (nodeExpr->matches(child, context, cs))
nodes->add(child);
//-- check childs descendants
- if (child->hasChildNodes()) fromDescendants(child, cs, nodes);
+ if (child->hasChildNodes())
+ fromDescendants(child, cs, nodes);
+
+ child = child->getNextSibling();
}
} //-- fromDescendants
+void LocationStep::fromDescendantsRev(Node* context, ContextState* cs, NodeSet* nodes) {
+
+ if ( !context || !nodeExpr ) return;
+
+ Node* child = context->getLastChild();
+ while (child) {
+ //-- check childs descendants
+ if (child->hasChildNodes())
+ fromDescendantsRev(child, cs, nodes);
+
+ if (nodeExpr->matches(child, context, cs))
+ nodes->add(child);
+
+ child = child->getPreviousSibling();
+ }
+
+} //-- fromDescendantsRev
+
/**
* Determines whether this PatternExpr matches the given node within
* the given context
@@ -260,11 +290,18 @@ MBool LocationStep::matches(Node* node, Node* context, ContextState* cs) {
if ( !nodeExpr->matches(node, context, cs) ) return MB_FALSE;
- NodeSet nodes;
- nodes.add(node);
- evaluatePredicates(&nodes, cs);
+ MBool result = MB_TRUE;
+ if ( !isEmpty() ) {
+ NodeSet* nodes = (NodeSet*)evaluate(cs->getParentNode(node),cs);
+ result = nodes->contains(node);
+ delete nodes;
+ }
+ else if (axisIdentifier == CHILD_AXIS ) {
+ if (!node->getParentNode())
+ result = MB_FALSE;
+ }
- return (MBool)(nodes.size() > 0);
+ return result;
} //-- matches
diff --git a/extensions/transformiix/source/xpath/TextExpr.cpp b/extensions/transformiix/source/xpath/TextExpr.cpp
index 08c9eab6c9a..23e07c1e4b4 100644
--- a/extensions/transformiix/source/xpath/TextExpr.cpp
+++ b/extensions/transformiix/source/xpath/TextExpr.cpp
@@ -21,7 +21,7 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
- * $Id: TextExpr.cpp,v 1.2 2001-01-12 20:06:37 axel%pike.org Exp $
+ * $Id: TextExpr.cpp,v 1.3 2001-04-11 15:01:03 axel%pike.org Exp $
*/
#include "Expr.h"
@@ -74,7 +74,8 @@ short TextExpr::getType() {
**/
MBool TextExpr::matches(Node* node, Node* context, ContextState* cs) {
if ( node ) {
- return (MBool) (node->getNodeType() == Node::TEXT_NODE);
+ if(node->getNodeType() == Node::TEXT_NODE)
+ return !cs->isStripSpaceAllowed(node);
}
return MB_FALSE;
} //-- matches
diff --git a/extensions/transformiix/source/xslt/ProcessorState.cpp b/extensions/transformiix/source/xslt/ProcessorState.cpp
index e31582478a4..705001f150d 100644
--- a/extensions/transformiix/source/xslt/ProcessorState.cpp
+++ b/extensions/transformiix/source/xslt/ProcessorState.cpp
@@ -25,13 +25,13 @@
* -- added code in ::resolveFunctionCall to support the
* document() function.
*
- * $Id: ProcessorState.cpp,v 1.23 2001-04-08 14:32:37 peterv%netscape.com Exp $
+ * $Id: ProcessorState.cpp,v 1.24 2001-04-11 15:01:05 axel%pike.org Exp $
*/
/**
* Implementation of ProcessorState
* Much of this code was ported from XSL:P
- * @version $Revision: 1.23 $ $Date: 2001-04-08 14:32:37 $
+ * @version $Revision: 1.24 $ $Date: 2001-04-11 15:01:05 $
**/
#include "ProcessorState.h"
@@ -792,7 +792,11 @@ MBool ProcessorState::isStripSpaceAllowed(Node* node) {
break;
}
case Node::TEXT_NODE:
+ if (!XMLUtils::shouldStripTextnode(node->getNodeValue()))
+ return MB_FALSE;
return isStripSpaceAllowed(node->getParentNode());
+ case Node::DOCUMENT_NODE:
+ return MB_TRUE;
default:
break;
}
diff --git a/extensions/transformiix/source/xslt/XSLTProcessor.cpp b/extensions/transformiix/source/xslt/XSLTProcessor.cpp
index 92fc9aa7d2e..c2cb74aae08 100644
--- a/extensions/transformiix/source/xslt/XSLTProcessor.cpp
+++ b/extensions/transformiix/source/xslt/XSLTProcessor.cpp
@@ -38,7 +38,7 @@
* Olivier Gerardin
* -- Changed behavior of passing parameters to templates
*
- * $Id: XSLTProcessor.cpp,v 1.39 2001-04-08 14:32:16 peterv%netscape.com Exp $
+ * $Id: XSLTProcessor.cpp,v 1.40 2001-04-11 15:01:05 axel%pike.org Exp $
*/
#include "XSLTProcessor.h"
@@ -66,7 +66,7 @@
/**
* XSLTProcessor is a class for Processing XSL stylesheets
* @author Keith Visco
- * @version $Revision: 1.39 $ $Date: 2001-04-08 14:32:16 $
+ * @version $Revision: 1.40 $ $Date: 2001-04-11 15:01:05 $
**/
/**
@@ -1295,16 +1295,6 @@ void XSLTProcessor::processAction
break;
}
exprResult->stringValue(value);
- //-- handle whitespace stripping
- if ( exprResult->getResultType() == ExprResult::NODESET) {
- NodeSet* nodes = (NodeSet*)exprResult;
- if ( nodes->size() > 0) {
- Node* node = nodes->get(0);
- if ( ps->isStripSpaceAllowed(node) &&
- XMLUtils::shouldStripTextnode(value))
- value.clear();
- }
- }
if (value.length()>0)
ps->addToResultTree(resultDoc->createTextNode(value));
delete exprResult;