The Navigator class provides helper classes for navigating a tree, irrespective
of its implementation
alphaKey
public static String alphaKey(int value)
Construct an alphabetic key from an positive integer; the key collates in the same sequence
as the integer
value
- The positive integer key value (negative values are treated as zero).
appendSequentialKey
public static void appendSequentialKey(SiblingCountingNode node,
FastStringBuffer sb,
boolean addDocNr)
Get a character string that uniquely identifies this node and that collates nodes
into document order
node
- the node whose unique identifier is reuqiredsb
- a buffer to which the unique identifier will be appendedaddDocNr
- true if a unique document number is to be included in the information
compareOrder
public static int compareOrder(SiblingCountingNode first,
SiblingCountingNode second)
Generic (model-independent) method to determine the relative position of two
node in document order. The nodes must be in the same tree.
first
- The first nodesecond
- The second node, whose position is to be compared with the first node
- -1 if this node precedes the other node, +1 if it follows the other
node, or 0 if they are the same node. (In this case, isSameNode() will always
return true, and the two nodes will produce the same result for generateId())
copy
public static void copy(NodeInfo node,
Receiver out,
NamePool namePool,
int whichNamespaces,
boolean copyAnnotations,
int locationId)
throws XPathException
Generic (model-independent) implementation of deep copy algorithm for nodes.
This is available for use by any node implementations that choose to use it.
node
- The node to be copiedout
- The receiver to which events will be sentnamePool
- Namepool holding the name codes (used only to resolve namespace
codes)whichNamespaces
- Indicates which namespace nodes for an element should
be copied. Values are NodeInfo.NO_NAMESPACES
,
NodeInfo.LOCAL_NAMESPACES
, NodeInfo.ALL_NAMESPACES
copyAnnotations
- Indicates whether type annotations should be copiedlocationId
- The location of the instruction invoking the copy
filteredSingleton
public static AxisIterator filteredSingleton(NodeInfo node,
NodeTest nodeTest)
Create an iterator over a singleton node, if it exists and matches a nodetest;
otherwise return an empty iterator
node
- the singleton node, or null if the node does not existnodeTest
- the test to be applied
- an iterator over the node if it exists and matches the test.
getAttributeValue
public static String getAttributeValue(NodeInfo element,
String uri,
String localName)
Get the string value of an attribute of a given element, given the URI and
local part of the attribute name.
element
- the element on which the required attribute appearsuri
- The namespace URI of the attribute name. The null URI is represented as an empty string.localName
- The local part of the attribute name.
- the attribute value, or null if the attribute is not present
getBaseURI
public static String getBaseURI(NodeInfo node)
Helper method to get the base URI of an element or processing instruction node
node
- the node whose base URI is required
getNumberAny
public static int getNumberAny(Expression inst,
NodeInfo node,
Pattern count,
Pattern from,
XPathContext context,
boolean hasVariablesInPatterns)
throws XPathException
Get node number (level="any").
Return one plus the number of previous nodes in the
document that match the supplied pattern
inst
- Identifies the xsl:number expression; this is relevant
when the function is memoised to support repeated use of the same
instruction to number multiple nodesnode
- The node being numberedcount
- Pattern that identifies which nodes should be
counted. Default (null) is the element name if the current node is
an element, or "node()" otherwise.from
- Pattern that specifies where counting starts from.
Default (null) is the root node. Only nodes after the first (most
recent) node that matches the 'from' pattern are counted.context
- The dynamic context for the transformationhasVariablesInPatterns
- if the count or from patterns
contain variables, then it's not safe to get the answer by adding
one to the number of the most recent node that matches
- one plus the number of nodes that precede the current node,
that match the count pattern, and that follow the first node that
matches the from pattern if specified.
getNumberMulti
public static List getNumberMulti(NodeInfo node,
Pattern count,
Pattern from,
XPathContext context)
throws XPathException
Get node number (level="multiple").
Return a vector giving the hierarchic position of this node. See the XSLT spec for details.
node
- The node to be numberedcount
- Pattern that identifies which nodes (ancestors and
their previous siblings) should be counted. Default (null) is the
element name if the current node is an element, or "node()"
otherwise.from
- Pattern that specifies where counting starts from.
Default (null) is the root node. Only nodes below the first (most
recent) node that matches the 'from' pattern are counted.context
- The dynamic context for the transformation
- a vector containing for each ancestor-or-self that matches the
count pattern and that is below the nearest node that matches the
from pattern, an Integer which is one greater than the number of
previous siblings that match the count pattern.
getNumberSimple
public static int getNumberSimple(NodeInfo node,
XPathContext context)
throws XPathException
Get simple node number. This is defined as one plus the number of previous siblings of the
same node type and name. It is not accessible directly in XSL.
node
- The node whose number is requiredcontext
- Used for remembering previous result, for
performance
- the node number, as defined above
getNumberSingle
public static int getNumberSingle(NodeInfo node,
Pattern count,
Pattern from,
XPathContext context)
throws XPathException
Get node number (level="single"). If the current node matches the supplied pattern, the returned
number is one plus the number of previous siblings that match the pattern. Otherwise,
return the element number of the nearest ancestor that matches the supplied pattern.
node
- the current node, the one whose node number is requiredcount
- Pattern that identifies which nodes should be
counted. Default (null) is the element name if the current node is
an element, or "node()" otherwise.from
- Pattern that specifies where counting starts from.
Default (null) is the root node. (This parameter does not seem
useful but is included for the sake of XSLT conformance.)context
- the dynamic context of the transformation, used if
the patterns reference context values (e.g. variables)
- the node number established as follows: go to the nearest
ancestor-or-self that matches the 'count' pattern and that is a
descendant of the nearest ancestor that matches the 'from' pattern.
Return one plus the nunber of preceding siblings of that ancestor
that match the 'count' pattern. If there is no such ancestor,
return 0.
getPath
public static String getPath(NodeInfo node)
Get an absolute XPath expression that identifies a given node within its document
node
- the node whose path is required. If null is supplied,
an empty string is returned - this fact is used in making a recursive call
for a parentless node.
- a path expression that can be used to retrieve the node
isAncestorOrSelf
public static boolean isAncestorOrSelf(NodeInfo a,
NodeInfo d)
Test if one node is an ancestor-or-self of another
a
- the putative ancestor-or-self noded
- the putative descendant node
- true if a is an ancestor-or-self of d
isWhite
public static boolean isWhite(CharSequence content)
since Saxon 8.5: use Whitespace.isWhite(CharSequence)
Determine if a string is all-whitespace
content
- the string to be tested
- true if the supplied string contains no non-whitespace
characters
makeNodeTest
public static NodeTest makeNodeTest(NamePool pool,
int nodeKind,
String uri,
String localName)
Helper method to construct a NodeTest for use with the NodeInfo.iterateAxis
method
pool
- the NamePool. The relevant NamePool can be obtained by calling the method
NodeInfo.getNamePool()
.nodeKind
- The kind of node required, for example Type.ELEMENT
or Type.ATTRIBUTE
.
To select nodes of any kind, use Type.NODE
.uri
- The namespace URI of the nodes to be selected. Supply null to selects nodes from any
namespace or none. Supply "" to select nodes that are not in a namespace.localName
- The local name of the nodes to be selected. Supply null to select nodes irrespective
of their local name.
- a NodeTest that matches the requested nodes