sboag       00/12/15 01:12:23

  Modified:    java/src/org/apache/xpath/axes FollowingWalker.java
                        PrecedingSiblingWalker.java
  Log:
  Fixed support for following sibling from an attribute, and adapted
  XalanC method for following axes after an attribute, though both
  XT and SAXON give different results.  Xalan treats the children of the
  owning element as if they were siblings following the attribute, which
  the are in a sense.  XT and SAXON process everything following the
  owning element.  Since self, following, descendants, preceding, and
  ancestors are supposed to encompass the entire document, and attributes
  obviously can't have descendants, and the children of the owning
  element clearly don't occur before the attributes, I think Xalan
  is right.
  
  Revision  Changes    Path
  1.3       +45 -6     
xml-xalan/java/src/org/apache/xpath/axes/FollowingWalker.java
  
  Index: FollowingWalker.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/FollowingWalker.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FollowingWalker.java      2000/10/30 18:58:49     1.2
  +++ FollowingWalker.java      2000/12/15 09:12:22     1.3
  @@ -88,11 +88,31 @@
      * NEEDSDOC @param root
      */
     public void setRoot(Node root)
  -  {
  +  {      
   
       super.setRoot(root);
  -
  -    m_currentAncestor = root;
  +    
  +    if(root.getNodeType() == Node.ATTRIBUTE_NODE)
  +    {
  +      // The current node could be an attribute node, so getNextSibling() 
will 
  +      // always return null.  In that case, we want to continue the search 
  +      // with the first child of the owner element, as if the attribute 
nodes 
  +      // are children which are always _before_ the first child element.  We 
  +      // don't have to consider following attributes, since they never match 
  +      // the following axes.
  +      /*
  +      Node e = m_lpi.getDOMHelper().getParentOfNode(root);
  +      root = e.getLastChild();
  +      if(null == root)
  +        root = e;
  +      m_currentAncestor = e.getParentNode();
  +      */
  +      Node e = m_lpi.getDOMHelper().getParentOfNode(root);
  +      m_currentNode = e;
  +      m_currentAncestor = e.getOwnerDocument(); // Not totally sure why
  +    } 
  +    else
  +      m_currentAncestor = root;
   
       // Following is always moving up the tree, 
       // so I think this should be OK.
  @@ -154,8 +174,26 @@
     public Node firstChild()
     {
   
  -    Node n = (m_currentAncestor == m_currentNode)
  -             ? m_currentNode.getNextSibling() : 
m_currentNode.getFirstChild();
  +    Node n;
  +    if(m_currentAncestor == m_currentNode)
  +    {
  +//      if(m_currentNode.getNodeType() == Node.ATTRIBUTE_NODE)
  +//      {
  +//        // The current node could be an attribute node, so 
getNextSibling() will 
  +//        // always return null.  In that case, we want to continue the 
search 
  +//        // with the first child of the owner element, as if the attribute 
nodes 
  +//        // are children which are always _before_ the first child element. 
 We 
  +//        // don't have to consider following attributes, since they never 
match 
  +//        // the following axes.
  +//        n = 
m_lpi.getDOMHelper().getParentOfNode(m_currentNode).getFirstChild();
  +//      } 
  +//      else
  +        n = m_currentNode.getNextSibling();
  +    }
  +    else
  +    {
  +      n = m_currentNode.getFirstChild();
  +    }
   
       m_nextLevelAmount = (null == n) ? 0 : (n.hasChildNodes() ? 1 : 0);
   
  @@ -172,7 +210,8 @@
     public Node nextSibling()
     {
   
  -    Node n = m_currentNode.getNextSibling();
  +    Node n;    
  +    n = m_currentNode.getNextSibling();
   
       m_nextLevelAmount = (null == n) ? 0 : (n.hasChildNodes() ? 1 : 0);
   
  
  
  
  1.3       +17 -7     
xml-xalan/java/src/org/apache/xpath/axes/PrecedingSiblingWalker.java
  
  Index: PrecedingSiblingWalker.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/PrecedingSiblingWalker.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PrecedingSiblingWalker.java       2000/10/30 18:58:52     1.2
  +++ PrecedingSiblingWalker.java       2000/12/15 09:12:22     1.3
  @@ -96,19 +96,29 @@
   
       if (m_currentNode == m_root)
       {
  -      Node parent = m_lpi.getDOMHelper().getParentOfNode(m_currentNode);
  -
  -      if (null == parent)
  -        return null;
  -
  -      next = parent.getFirstChild();
  +      if(m_currentNode.getNodeType() == Node.ATTRIBUTE_NODE)
  +      {
  +        // then don't bother, since attributes don't have siblings.
  +        // Otherwise, we would go up to the parent, and get the so-called 
  +        // first attribute.
  +        next = null;
  +      }
  +      else
  +      {
  +        Node parent = m_lpi.getDOMHelper().getParentOfNode(m_currentNode);
  +  
  +        if (null == parent)
  +          return null;
  +  
  +        next = parent.getFirstChild();
  +      }
       }
       else
       {
         next = m_currentNode.getNextSibling();
       }
   
  -    if (next.equals(m_root))
  +    if (null != next && next.equals(m_root))
         next = null;
   
       return setCurrentIfNotNull(next);
  
  
  

Reply via email to