net.sf.saxon.tree.AttributeEnumeration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of saxon9 Show documentation
Show all versions of saxon9 Show documentation
Provides a basic XSLT 2.0 and XQuery 1.0 processor (W3C Recommendations,
January 2007). Command line interfaces and implementations of several
Java APIs (DOM, XPath, s9api) are also included.
The newest version!
package net.sf.saxon.tree;
import net.sf.saxon.om.*;
import net.sf.saxon.pattern.NameTest;
import net.sf.saxon.pattern.NodeTest;
import net.sf.saxon.type.Type;
/**
* AttributeEnumeration is an enumeration of all the attribute nodes of an Element.
*/
final class AttributeEnumeration extends AxisIteratorImpl implements LookaheadIterator {
private ElementImpl element;
private NodeTest nodeTest;
private NodeInfo next;
private int index;
private int length;
/**
* Constructor
* @param node: the element whose attributes are required. This may be any type of node,
* but if it is not an element the enumeration will be empty
* @param nodeTest: condition to be applied to the names of the attributes selected
*/
public AttributeEnumeration(NodeImpl node, NodeTest nodeTest) {
this.nodeTest = nodeTest;
if (node.getNodeKind()==Type.ELEMENT) {
element = (ElementImpl)node;
AttributeCollection attlist = element.getAttributeList();
index = 0;
if (nodeTest instanceof NameTest) {
NameTest test = (NameTest)nodeTest;
index = attlist.getIndexByFingerprint(test.getFingerprint());
if (index<0) {
next = null;
} else {
next = new AttributeImpl(element, index);
index = 0;
length = 0; // force iteration to select one node only
}
} else {
index = 0;
length = attlist.getLength();
advance();
}
}
else { // if it's not an element, or if we're not looking for attributes,
// then there's nothing to find
next = null;
index = 0;
length = 0;
}
}
/**
* Test if there are mode nodes still to come.
* ("elements" is used here in the sense of the Java enumeration class, not in the XML sense)
*/
public boolean hasNext() {
return next != null;
}
/**
* Get the next node in the iteration, or null if there are no more.
*/
public Item next() {
if (next == null) {
current = null;
position = -1;
return null;
} else {
current = next;
position++;
advance();
return current;
}
}
/**
* Move to the next node in the enumeration.
*/
private void advance() {
do {
if (index
© 2015 - 2025 Weber Informatics LLC | Privacy Policy