Methods Summary |
---|
public static org.w3c.dom.NodeList | difference(org.w3c.dom.NodeList nl1, org.w3c.dom.NodeList nl2)The set:difference function returns the difference between two node sets - those nodes that
are in the node set passed as the first argument that are not in the node set passed as the
second argument.
NodeSet ns1 = new NodeSet(nl1);
NodeSet ns2 = new NodeSet(nl2);
NodeSet diff = new NodeSet();
diff.setShouldCacheNodes(true);
for (int i = 0; i < ns1.getLength(); i++)
{
Node n = ns1.elementAt(i);
if (!ns2.contains(n))
diff.addElement(n);
}
return diff;
|
public static org.w3c.dom.NodeList | distinct(org.w3c.dom.NodeList nl)The set:distinct function returns a subset of the nodes contained in the node-set NS passed
as the first argument. Specifically, it selects a node N if there is no node in NS that has
the same string value as N, and that precedes N in document order.
NodeSet dist = new NodeSet();
dist.setShouldCacheNodes(true);
Hashtable stringTable = new Hashtable();
for (int i = 0; i < nl.getLength(); i++)
{
Node currNode = nl.item(i);
String key = toString(currNode);
if (key == null)
dist.addElement(currNode);
else if (!stringTable.containsKey(key))
{
stringTable.put(key, currNode);
dist.addElement(currNode);
}
}
return dist;
|
public static boolean | hasSameNode(org.w3c.dom.NodeList nl1, org.w3c.dom.NodeList nl2)The set:has-same-node function returns true if the node set passed as the first argument shares
any nodes with the node set passed as the second argument. If there are no nodes that are in both
node sets, then it returns false.
The Xalan extensions MethodResolver converts 'has-same-node' to 'hasSameNode'.
Note: Not to be confused with hasSameNodes in the Xalan namespace, which returns true if
the two node sets contain the exactly the same nodes (perhaps in a different order),
otherwise false.
NodeSet ns1 = new NodeSet(nl1);
NodeSet ns2 = new NodeSet(nl2);
for (int i = 0; i < ns1.getLength(); i++)
{
if (ns2.contains(ns1.elementAt(i)))
return true;
}
return false;
|
public static org.w3c.dom.NodeList | intersection(org.w3c.dom.NodeList nl1, org.w3c.dom.NodeList nl2)The set:intersection function returns a node set comprising the nodes that are within
both the node sets passed as arguments to it.
NodeSet ns1 = new NodeSet(nl1);
NodeSet ns2 = new NodeSet(nl2);
NodeSet inter = new NodeSet();
inter.setShouldCacheNodes(true);
for (int i = 0; i < ns1.getLength(); i++)
{
Node n = ns1.elementAt(i);
if (ns2.contains(n))
inter.addElement(n);
}
return inter;
|
public static org.w3c.dom.NodeList | leading(org.w3c.dom.NodeList nl1, org.w3c.dom.NodeList nl2)The set:leading function returns the nodes in the node set passed as the first argument that
precede, in document order, the first node in the node set passed as the second argument. If
the first node in the second node set is not contained in the first node set, then an empty
node set is returned. If the second node set is empty, then the first node set is returned.
if (nl2.getLength() == 0)
return nl1;
NodeSet ns1 = new NodeSet(nl1);
NodeSet leadNodes = new NodeSet();
Node endNode = nl2.item(0);
if (!ns1.contains(endNode))
return leadNodes; // empty NodeSet
for (int i = 0; i < nl1.getLength(); i++)
{
Node testNode = nl1.item(i);
if (DOMHelper.isNodeAfter(testNode, endNode)
&& !DOMHelper.isNodeTheSame(testNode, endNode))
leadNodes.addElement(testNode);
}
return leadNodes;
|
public static org.w3c.dom.NodeList | trailing(org.w3c.dom.NodeList nl1, org.w3c.dom.NodeList nl2)The set:trailing function returns the nodes in the node set passed as the first argument that
follow, in document order, the first node in the node set passed as the second argument. If
the first node in the second node set is not contained in the first node set, then an empty
node set is returned. If the second node set is empty, then the first node set is returned.
if (nl2.getLength() == 0)
return nl1;
NodeSet ns1 = new NodeSet(nl1);
NodeSet trailNodes = new NodeSet();
Node startNode = nl2.item(0);
if (!ns1.contains(startNode))
return trailNodes; // empty NodeSet
for (int i = 0; i < nl1.getLength(); i++)
{
Node testNode = nl1.item(i);
if (DOMHelper.isNodeAfter(startNode, testNode)
&& !DOMHelper.isNodeTheSame(startNode, testNode))
trailNodes.addElement(testNode);
}
return trailNodes;
|