示例#1
0
  @Test
  public void selectParentChild_2() throws XPathException, SAXException, PermissionDeniedException {
    NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", ""));
    NodeSet speakers =
        broker
            .getStructuralIndex()
            .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
    Sequence largeSet =
        executeQuery(broker, "//SPEECH/LINE[fn:contains(., 'love')]/ancestor::SPEECH", 187, null);

    NodeSet result =
        NodeSetHelper.selectParentChild(speakers, largeSet.toNodeSet(), NodeSet.DESCENDANT, -1);
    assertEquals(187, result.getLength());
  }
示例#2
0
  @Test
  public void selectParentChild() throws XPathException, SAXException, PermissionDeniedException {

    NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", ""));
    NodeSet speakers =
        broker
            .getStructuralIndex()
            .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
    Sequence smallSet =
        executeQuery(
            broker, "//SPEECH/LINE[fn:contains(., 'perturbed spirit')]/ancestor::SPEECH", 1, null);

    NodeSet result =
        NodeSetHelper.selectParentChild(speakers, smallSet.toNodeSet(), NodeSet.DESCENDANT, -1);
    assertEquals(1, result.getLength());
    String value = serialize(broker, result.itemAt(0));
    assertEquals(value, "<SPEAKER>HAMLET</SPEAKER>");
  }
 /**
  * Check if any child nodes are found within this node set for a given set of potential ancestor
  * nodes.
  *
  * <p>If mode is {@link #DESCENDANT}, the returned node set will contain all child nodes found in
  * this node set for each parent node. If mode is {@link #ANCESTOR}, the returned set will contain
  * those parent nodes, for which children have been found.
  *
  * @param al a node set containing potential parent nodes
  * @param mode selection mode
  * @param contextId used to track context nodes when evaluating predicate expressions. If
  *     contextId != {@link Expression#NO_CONTEXT_ID}, the current context will be added to each
  *     result of the of the selection.
  */
 public NodeSet selectParentChild(NodeSet al, int mode, int contextId) {
   return NodeSetHelper.selectParentChild(this, al, mode, contextId);
 }