You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mm...@locus.apache.org on 2000/04/07 21:13:21 UTC

cvs commit: xml-xalan/src/org/apache/xalan/xpath SimpleNodeLocator.java XPathSupport.java XPathSupportDefault.java

mmidy       00/04/07 12:13:21

  Modified:    src/org/apache/xalan/xpath SimpleNodeLocator.java
                        XPathSupport.java XPathSupportDefault.java
  Log:
  Make sure context nodes and current nodes are counted correctly. This fixes a problem with the Position function and predicates.
  
  Revision  Changes    Path
  1.22      +65 -4     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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- SimpleNodeLocator.java	2000/03/29 03:51:54	1.21
  +++ SimpleNodeLocator.java	2000/04/07 19:13:20	1.22
  @@ -716,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))
  @@ -725,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;
               }
  @@ -745,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);
  @@ -753,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;
               }
  @@ -813,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))
  @@ -822,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;
                 }
  @@ -859,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);
  @@ -871,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;
                   }
  
  
  
  1.11      +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.11
  diff -u -r1.10 -r1.11
  --- XPathSupport.java	2000/03/02 20:37:44	1.10
  +++ XPathSupport.java	2000/04/07 19:13:20	1.11
  @@ -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.19      +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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- XPathSupportDefault.java	2000/03/16 17:33:33	1.18
  +++ XPathSupportDefault.java	2000/04/07 19:13:20	1.19
  @@ -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)