sboag       01/05/21 05:37:47

  Modified:    java/src/org/apache/xalan/templates ElemCopy.java
                        ElemValueOf.java
               java/src/org/apache/xalan/transformer TreeWalker2Result.java
               java/src/org/apache/xpath/functions FuncLast.java
  Log:
  Fix for bugs reported by the Eclipse folks for TransformState, where
  some operations (xsl:value-of, xsl-copy) were not pushing the
  current node on the current node stack.  Addresses
  http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1524.
  
  Revision  Changes    Path
  1.13      +5 -0      
xml-xalan/java/src/org/apache/xalan/templates/ElemCopy.java
  
  Index: ElemCopy.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemCopy.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ElemCopy.java     2001/02/13 20:28:57     1.12
  +++ ElemCopy.java     2001/05/21 12:37:34     1.13
  @@ -135,6 +135,7 @@
     {
       try
       {
  +      transformer.getXPathContext().pushCurrentNode(sourceNode);
         short nodeType = sourceNode.getNodeType();
   
         if ((Node.DOCUMENT_NODE != nodeType) && (Node.DOCUMENT_FRAGMENT_NODE 
!= nodeType))
  @@ -175,6 +176,10 @@
       catch(org.xml.sax.SAXException se)
       {
         throw new TransformerException(se);
  +    }
  +    finally
  +    {
  +      transformer.getXPathContext().popCurrentNode();
       }
     }
   }
  
  
  
  1.14      +13 -1     
xml-xalan/java/src/org/apache/xalan/templates/ElemValueOf.java
  
  Index: ElemValueOf.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemValueOf.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ElemValueOf.java  2001/01/12 07:35:55     1.13
  +++ ElemValueOf.java  2001/05/21 12:37:35     1.14
  @@ -230,14 +230,15 @@
             TransformerImpl transformer, Node sourceNode, QName mode)
               throws TransformerException
     {
  +    boolean didPushCurrent = false;
   
       try
       {
         if (TransformerImpl.S_DEBUG)
           transformer.getTraceManager().fireTraceEvent(sourceNode, mode, this);
   
  -      Node child;
         XObject value;
  +      Node child;
         
         // Optimize for "."
         if(m_isDot && !TransformerImpl.S_DEBUG)
  @@ -266,6 +267,8 @@
         String s;                                                              
                               
         if(null != child)
         {
  +        transformer.getXPathContext().pushCurrentNode(child);
  +        didPushCurrent = true;
           if (child.isSupported(SaxEventDispatch.SUPPORTSINTERFACE, "1.0"))
           {
             if (m_disableOutputEscaping)
  @@ -285,7 +288,9 @@
           }
         }
         else
  +      {
           s = value.str();
  +      }
   
         
         int len = (null != s) ? s.length() : 0;
  @@ -306,6 +311,13 @@
       catch(SAXException se)
       {
         throw new TransformerException(se);
  +    }
  +    finally
  +    {
  +      if(didPushCurrent)
  +      {
  +        transformer.getXPathContext().popCurrentNode();
  +      }
       }
     }
   
  
  
  
  1.10      +112 -80   
xml-xalan/java/src/org/apache/xalan/transformer/TreeWalker2Result.java
  
  Index: TreeWalker2Result.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TreeWalker2Result.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TreeWalker2Result.java    2001/03/12 02:12:53     1.9
  +++ TreeWalker2Result.java    2001/05/21 12:37:39     1.10
  @@ -64,6 +64,7 @@
   import org.apache.xml.utils.MutableAttrListImpl;
   import org.apache.xalan.templates.ElemTemplateElement;
   import org.apache.xpath.DOMHelper;
  +import org.apache.xpath.XPathContext;
   
   /**
    * <meta name="usage" content="internal"/>
  @@ -81,7 +82,7 @@
   
     /** Node where to start the tree walk           */
     Node m_startNode;
  -
  +  
     /**
      * Constructor.
      *
  @@ -112,6 +113,23 @@
   
       super.traverse(pos);
     }
  +  
  +  /**
  +   * End processing of given node 
  +   *
  +   *
  +   * @param node Node we just finished processing
  +   *
  +   * @throws org.xml.sax.SAXException
  +   */
  +  protected void endNode(Node node) throws org.xml.sax.SAXException
  +  {
  +    super.endNode(node);
  +    if(Node.ELEMENT_NODE == node.getNodeType())
  +    {
  +      m_transformer.getXPathContext().popCurrentNode();
  +    }
  +  }
   
     /**
      * Start traversal of the tree at the given node
  @@ -123,97 +141,111 @@
      */
     protected void startNode(Node node) throws org.xml.sax.SAXException
     {
  -
  +    
  +    XPathContext xcntxt = m_transformer.getXPathContext();
  +    
       try
       {
  -      if ((Node.ELEMENT_NODE == node.getNodeType()) && (m_startNode == node))
  +      if (Node.ELEMENT_NODE == node.getNodeType())
         {
  -        DOMHelper dhelper = m_transformer.getXPathContext().getDOMHelper();
  -        String elemName = node.getNodeName();
  -        String localName = dhelper.getLocalNameOfNode(node);
  -        String namespace = dhelper.getNamespaceOfNode(node);
  -
  -        m_handler.startElement(namespace, localName, elemName, null);
  -
  -        for (Node parent = node; parent != null;
  -             parent = parent.getParentNode())
  +        xcntxt.pushCurrentNode(node);
  +        
  +        if(m_startNode != node)
           {
  -          if (Node.ELEMENT_NODE != parent.getNodeType())
  -            continue;
  -
  -          NamedNodeMap atts = ((Element) parent).getAttributes();
  -          int n = atts.getLength();
  -
  -          for (int i = 0; i < n; i++)
  +          super.startNode(node);
  +        }
  +        else
  +        {
  +          DOMHelper dhelper = xcntxt.getDOMHelper();
  +          String elemName = node.getNodeName();
  +          String localName = dhelper.getLocalNameOfNode(node);
  +          String namespace = dhelper.getNamespaceOfNode(node);
  +  
  +          xcntxt.pushCurrentNode(node);
  +          m_handler.startElement(namespace, localName, elemName, null);
  +  
  +          for (Node parent = node; parent != null;
  +               parent = parent.getParentNode())
             {
  -            String nsDeclPrefix = null;
  -            Attr attr = (Attr) atts.item(i);
  -            String name = attr.getName();
  -            String value = attr.getValue();
  -
  -            if (name.startsWith("xmlns:"))
  -            {
  -
  -              // get the namespace prefix 
  -              nsDeclPrefix = name.substring(name.indexOf(":") + 1);
  -            }
  -            else if (name.equals("xmlns"))
  -            {
  -              nsDeclPrefix = "";
  -            }
  -
  -            if ((nsDeclPrefix == null) && (node != parent))
  +            if (Node.ELEMENT_NODE != parent.getNodeType())
                 continue;
  -
  -            /*
  -            else if(nsDeclPrefix != null)
  -            {
  -            String desturi = m_processor.getURI(nsDeclPrefix);
  -            // Look for an alias for this URI. If one is found, use it as 
the result URI
  -            String aliasURI = m_elem.m_stylesheet.lookForAlias(value);
  -            if(aliasURI.equals(desturi)) // TODO: Check for extension 
namespaces
  -            {
  -            continue;
  -            }
  -            }
  -            */
  -            m_handler.addAttribute(dhelper.getNamespaceOfNode(attr),
  -                                   dhelper.getLocalNameOfNode(attr), name,
  -                                   "CDATA", value);
  -
  -            // Make sure namespace is not in the excluded list then
  -            // add to result tree
  -
  -            /*
  -            if(!m_handler.getPendingAttributes().contains(name))
  -            {
  -            if(nsDeclPrefix == null)
  -            {
  -            m_handler.addAttribute(name, "CDATA", value);
  -            }
  -            else
  -            {
  -            String desturi
  -            = m_handler.getURI(nsDeclPrefix);
  -            if(null == desturi)
  -            {
  -            m_handler.addAttribute(name, "CDATA", value);
  -            }
  -            else if(!desturi.equals(value))
  -            {
  -            m_handler.addAttribute(name, "CDATA", value);
  -            }
  -            }
  +  
  +            NamedNodeMap atts = ((Element) parent).getAttributes();
  +            int n = atts.getLength();
  +  
  +            for (int i = 0; i < n; i++)
  +            {
  +              String nsDeclPrefix = null;
  +              Attr attr = (Attr) atts.item(i);
  +              String name = attr.getName();
  +              String value = attr.getValue();
  +  
  +              if (name.startsWith("xmlns:"))
  +              {
  +  
  +                // get the namespace prefix 
  +                nsDeclPrefix = name.substring(name.indexOf(":") + 1);
  +              }
  +              else if (name.equals("xmlns"))
  +              {
  +                nsDeclPrefix = "";
  +              }
  +  
  +              if ((nsDeclPrefix == null) && (node != parent))
  +                continue;
  +  
  +              /*
  +              else if(nsDeclPrefix != null)
  +              {
  +              String desturi = m_processor.getURI(nsDeclPrefix);
  +              // Look for an alias for this URI. If one is found, use it as 
the result URI
  +              String aliasURI = m_elem.m_stylesheet.lookForAlias(value);
  +              if(aliasURI.equals(desturi)) // TODO: Check for extension 
namespaces
  +              {
  +              continue;
  +              }
  +              }
  +              */
  +              m_handler.addAttribute(dhelper.getNamespaceOfNode(attr),
  +                                     dhelper.getLocalNameOfNode(attr), name,
  +                                     "CDATA", value);
  +  
  +              // Make sure namespace is not in the excluded list then
  +              // add to result tree
  +  
  +              /*
  +              if(!m_handler.getPendingAttributes().contains(name))
  +              {
  +              if(nsDeclPrefix == null)
  +              {
  +              m_handler.addAttribute(name, "CDATA", value);
  +              }
  +              else
  +              {
  +              String desturi
  +              = m_handler.getURI(nsDeclPrefix);
  +              if(null == desturi)
  +              {
  +              m_handler.addAttribute(name, "CDATA", value);
  +              }
  +              else if(!desturi.equals(value))
  +              {
  +              m_handler.addAttribute(name, "CDATA", value);
  +              }
  +              }
  +              }
  +              */
               }
  -            */
             }
  -        }
  -
  -        // m_handler.processResultNS(m_elem);           
  +  
  +          // m_handler.processResultNS(m_elem); 
  +        }          
         }
         else
         {
  +        xcntxt.pushCurrentNode(node);
           super.startNode(node);
  +        xcntxt.popCurrentNode();
         }
       }
       catch(javax.xml.transform.TransformerException te)
  
  
  
  1.7       +4 -2      
xml-xalan/java/src/org/apache/xpath/functions/FuncLast.java
  
  Index: FuncLast.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncLast.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FuncLast.java     2000/12/18 08:49:14     1.6
  +++ FuncLast.java     2001/05/21 12:37:43     1.7
  @@ -93,7 +93,7 @@
       // assert(null != m_contextNodeList, "m_contextNodeList must be 
non-null");
       // If we're in a predicate, then this will return non-null.
       SubContextList iter = xctxt.getSubContextList();
  -
  +    // System.out.println("iter: "+iter);
       if (null != iter)
         return iter.getLastPos(xctxt);
   
  @@ -145,6 +145,8 @@
      */
     public XObject execute(XPathContext xctxt) throws 
javax.xml.transform.TransformerException
     {
  -    return new XNumber((double) getCountOfContextNodeList(xctxt));
  +    XNumber xnum = new XNumber((double) getCountOfContextNodeList(xctxt));
  +    // System.out.println("last: "+xnum.num());
  +    return xnum;
     }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to