Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-1053

The result of ancestor-or-self()::node() contains duplicated Document nodes.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Resolution: Duplicate
    • 2.3
    • None
    • XPath
    • None
    • Operating System: Other
      Platform: All
    • 9801

    Description

      The following code simply sets the root element to the context node and
      selects "ancestor-or-self()::node()". Expected result is a node-set
      consisted of two nodes, Document and `root' Element, and actual result is
      a node-set that has three nodes, Document, Document and `root' Element.

      // ----------------------------------------------------------------
      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;
      import org.apache.xpath.XPathAPI;
      import org.apache.xpath.objects.XObject;
      import org.w3c.dom.Document;
      import org.w3c.dom.Element;
      import org.w3c.dom.Node;
      import org.w3c.dom.traversal.NodeIterator;

      public class XPathBug0612 {
      public static void main(String[] argv) throws Exception {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.newDocument();
      Element root = doc.createElement("root");
      doc.appendChild(root);

      NodeIterator nl = XPathAPI.selectNodeIterator(root, "ancestor-or-
      self::node()");
      Node n;
      int i = 0;
      while ((n = nl.nextNode()) != null)

      { System.out.println(n.getNodeName()); i++; }

      // assertEquals(2, i);
      }
      }
      // ----------------------------------------------------------------

      Attachments

        Activity

          People

            Unassigned Unassigned
            kent@haun.org kent
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: