mmidy 00/04/07 12:37:25
Modified: src/org/apache/xalan/xpath Tag: Bxalan_1_0_0
SimpleNodeLocator.java XPathSupport.java
XPathSupportDefault.java
Log:
Make sure the context nodes are counted correctly. Fixed problem with
Position() and predicates.
Revision Changes Path
No revision
No revision
1.18.2.2 +71 -7
xml-xalan/src/org/apache/xalan/xpath/SimpleNodeLocator.java
Index: SimpleNodeLocator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/SimpleNodeLocator.java,v
retrieving revision 1.18.2.1
retrieving revision 1.18.2.2
diff -u -r1.18.2.1 -r1.18.2.2
--- SimpleNodeLocator.java 2000/03/15 15:22:50 1.18.2.1
+++ SimpleNodeLocator.java 2000/04/07 19:37:24 1.18.2.2
@@ -60,6 +60,7 @@
import java.io.*;
import org.w3c.dom.*;
import org.apache.xalan.xpath.res.XPATHErrorResources;
+import org.apache.xalan.xpath.xml.ProblemListenerDefault;
/**
* <meta name="usage" content="advanced"/>
@@ -715,6 +716,7 @@
if(Node.DOCUMENT_FRAGMENT_NODE != context.getNodeType())
{
Node c = context.getFirstChild();
+ int realPos = 0;
while( null != c )
{
if(XPath.MATCH_SCORE_NONE != nodeTest(xpath, execContext, c, opPos,
argLen, stepType))
@@ -724,10 +726,31 @@
// subQueryResults.addNode(c);
if(isSimpleFollowing && (null != callback))
{
+ // We need to increment the current node position
+ // before we do the predicate, so that the predicate
+ // can test the current position. i.e. if I am testing
+ // if this is the second node, then the current node position
+ // needs to be set to 2 inside the predicate test.
+ // In the meantime, when we execute, we need to set
+ // the context node position to the found count.
+ // What is really going on, is the "contextNodePosition" is
+ // overloaded to do two things: 1) the current node count, and
+ // 2) the context node position. This needs to be fixed at
+ // some point, I think, as this is pretty hacky.
execContext.incrementContextNodePosition(c);
if(predicate(xpath, execContext, c, opPos+argLen))
{
- callback.processLocatedNode(execContext, c, callbackInfo);
+ realPos++;
+ int savedPos = execContext.getContextNodePosition();
+ execContext.setContextNodePosition(realPos);
+ try
+ {
+ callback.processLocatedNode(execContext, c, callbackInfo);
+ }
+ finally
+ {
+ execContext.setContextNodePosition(savedPos);
+ }
if(stopAtFirst)
break;
}
@@ -744,6 +767,7 @@
{
NodeList children = context.getChildNodes();
int n = children.getLength();
+ int realPos = 0;
for(int i = 0; i < n; i++)
{
Node c = children.item(i);
@@ -752,10 +776,22 @@
// subQueryResults.addNode(c);
if(isSimpleFollowing && (null != callback))
{
+ // See note in first part of findChildren for what is going
+ // on with the position stuff.
execContext.incrementContextNodePosition(c);
if(predicate(xpath, execContext, c, opPos+argLen))
{
- callback.processLocatedNode(execContext, c, callbackInfo);
+ realPos++;
+ int savedPos = execContext.getContextNodePosition();
+ execContext.setContextNodePosition(realPos);
+ try
+ {
+ callback.processLocatedNode(execContext, c, callbackInfo);
+ }
+ finally
+ {
+ execContext.setContextNodePosition(savedPos);
+ }
if(stopAtFirst)
break;
}
@@ -812,6 +848,7 @@
// we can not use the next-sibling business at the top level.
if(Node.DOCUMENT_FRAGMENT_NODE != context.getNodeType())
{
+ int realPos = 0;
while(null != pos)
{
if((stepType == XPath.FROM_DESCENDANTS_OR_SELF) || (context != pos))
@@ -821,10 +858,22 @@
// subQueryResults.addNode(pos);
if(isSimpleFollowing && (null != callback))
{
+ // See note in first part of findChildren for what is going
+ // on with the position stuff.
execContext.incrementContextNodePosition(pos);
if(predicate(xpath, execContext, pos, opPos+argLen))
{
- callback.processLocatedNode(execContext, pos, callbackInfo);
+ realPos++;
+ int savedPos = execContext.getContextNodePosition();
+ execContext.setContextNodePosition(realPos);
+ try
+ {
+ callback.processLocatedNode(execContext, pos,
callbackInfo);
+ }
+ finally
+ {
+ execContext.setContextNodePosition(savedPos);
+ }
if(stopAtFirst)
break;
}
@@ -858,6 +907,7 @@
{
NodeList children = context.getChildNodes();
int n = children.getLength();
+ int realPos = 0;
for(int i = 0; i < n; i++)
{
pos = children.item(i);
@@ -870,10 +920,22 @@
{
if(isSimpleFollowing && (null != callback))
{
+ // See note in first part of findChildren for what is going
+ // on with the position stuff.
execContext.incrementContextNodePosition(pos);
if(predicate(xpath, execContext, pos, opPos+argLen))
{
- callback.processLocatedNode(execContext, pos,
callbackInfo);
+ realPos++;
+ int savedPos = execContext.getContextNodePosition();
+ execContext.setContextNodePosition(realPos);
+ try
+ {
+ callback.processLocatedNode(execContext, pos,
callbackInfo);
+ }
+ finally
+ {
+ execContext.setContextNodePosition(savedPos);
+ }
if(stopAtFirst)
break;
}
@@ -1052,7 +1114,7 @@
boolean isSimpleFollowing, boolean
stopAtFirst)
throws org.xml.sax.SAXException
{
- int argLen = xpath.getArgLengthOfStep(opPos);
+ // int argLen = xpath.getArgLengthOfStep(opPos);
opPos = xpath.getFirstChildPosOfStep(opPos);
Document docContext = (Node.DOCUMENT_NODE == context.getNodeType())
@@ -1286,7 +1348,7 @@
boolean
isSimpleFollowing, boolean stopAtFirst)
throws org.xml.sax.SAXException
{
- int argLen = xpath.getArgLengthOfStep(opPos);
+ // int argLen = xpath.getArgLengthOfStep(opPos);
opPos = xpath.getFirstChildPosOfStep(opPos);
xpath.error(context, XPATHErrorResources.ER_UNKNOWN_AXIS, new Object[]
{Integer.toString(stepType)}); //"unknown axis: "+stepType);
return subQueryResults;
@@ -1846,9 +1908,11 @@
*/
class DOMXPath extends XPath
{
+ private static final ProblemListenerDefault m_problemListener = new
ProblemListenerDefault();
+
public DOMXPath()
{
- super(new org.apache.xalan.xpath.xml.ProblemListenerDefault());
+ super(m_problemListener);
}
/**
1.10.2.1 +6 -0 xml-xalan/src/org/apache/xalan/xpath/XPathSupport.java
Index: XPathSupport.java
===================================================================
RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/XPathSupport.java,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -r1.10 -r1.10.2.1
--- XPathSupport.java 2000/03/02 20:37:44 1.10
+++ XPathSupport.java 2000/04/07 19:37:25 1.10.2.1
@@ -104,6 +104,12 @@
* Increment the current context node position.
*/
void incrementContextNodePosition(Node node);
+
+ /**
+ * <meta name="usage" content="experimental"/>
+ * Set the current context node position.
+ */
+ public void setContextNodePosition(int newNodePos);
/**
* <meta name="usage" content="experimental"/>
1.17.2.2 +9 -0
xml-xalan/src/org/apache/xalan/xpath/XPathSupportDefault.java
Index: XPathSupportDefault.java
===================================================================
RCS file:
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/XPathSupportDefault.java,v
retrieving revision 1.17.2.1
retrieving revision 1.17.2.2
diff -u -r1.17.2.1 -r1.17.2.2
--- XPathSupportDefault.java 2000/03/16 18:12:09 1.17.2.1
+++ XPathSupportDefault.java 2000/04/07 19:37:25 1.17.2.2
@@ -229,6 +229,15 @@
/**
* <meta name="usage" content="experimental"/>
+ * Set the current context node position.
+ */
+ public void setContextNodePosition(int newNodePos)
+ {
+ m_contextCounts.setTop(newNodePos);
+ }
+
+ /**
+ * <meta name="usage" content="experimental"/>
* Increment the current context node position.
*/
public void incrementContextNodePosition(Node node)