# Navigator
Keywords: net.sf.saxon.om.Navigator class

## net.sf.saxon.om
Class Navigator

    java.lang.Object
      net.sf.saxon.om.Navigator

    public final class Navigator

extends Object

The Navigator class provides helper classes for navigating a tree, irrespective of its implementation

Author:
  Michael H. Kay

Nested Class Summary
`static class` `Navigator.AncestorEnumeration` General-purpose implementation of the ancestor and ancestor-or-self axes
`static class` `Navigator.AxisFilter` AxisFilter is an iterator that applies a NodeTest filter to the nodes returned by an underlying AxisIterator.
`static class` `Navigator.BaseEnumeration` BaseEnumeration is an abstract implementation of an AxisIterator, it simplifies the implementation of the underlying AxisIterator by requiring it to provide only two methods: advance(), and getAnother().
`static class` `Navigator.DescendantEnumeration` General-purpose implementation of the descendant and descendant-or-self axes, in terms of the child axis.
`static class` `Navigator.FollowingEnumeration` General purpose implementation of the following axis, in terms of the ancestor, child, and following-sibling axes
`static class` `Navigator.PrecedingEnumeration` Helper method to iterate over the preceding axis, or Saxon's internal preceding-or-ancestor axis, by making use of the ancestor, descendant, and preceding-sibling axes.

Method Summary
`static String` `alphaKey(int value)` Construct an alphabetic key from an positive integer; the key collates in the same sequence as the integer
`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
`static int` `compareOrder(SiblingCountingNode first, SiblingCountingNode second)` Generic (model-independent) method to determine the relative position of two node in document order.
`static void` `copy(NodeInfo node, Receiver out, NamePool namePool, int whichNamespaces, boolean copyAnnotations, int locationId)` Generic (model-independent) implementation of deep copy algorithm for nodes.
`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
`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.
`static String` `getBaseURI(NodeInfo node)` Helper method to get the base URI of an element or processing instruction node
`static int` `getNumberAny(Expression inst, NodeInfo node, Pattern count, Pattern from, XPathContext context, boolean hasVariablesInPatterns)` Get node number (level="any").
`static List` `getNumberMulti(NodeInfo node, Pattern count, Pattern from, XPathContext context)` Get node number (level="multiple").
`static int` `getNumberSimple(NodeInfo node, XPathContext context)` Get simple node number.
`static int` `getNumberSingle(NodeInfo node, Pattern count, Pattern from, XPathContext context)` Get node number (level="single").
`static String` `getPath(NodeInfo node)` Get an absolute XPath expression that identifies a given node within its document
`static boolean` `isAncestorOrSelf(NodeInfo a, NodeInfo d)` Test if one node is an ancestor-or-self of another
`static boolean` `isWhite(CharSequence content)` Deprecated. since Saxon 8.5: use `Whitespace.isWhite(java.lang.CharSequence)`
`static void` `sendNamespaceDeclarations(NodeInfo node, Receiver out, boolean includeAncestors)` Output all namespace nodes associated with this element.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### 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.

  Parameters:
    `uri` - The namespace URI. The null URI is represented as an empty string.
    `localName` - The local part of the name.
  Returns:
    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

### sendNamespaceDeclarations

    public static void sendNamespaceDeclarations(NodeInfo node,
                                                 Receiver out,
                                                 boolean includeAncestors)
                                          throws XPathException

  Output all namespace nodes associated with this element. Does nothing if the node is not an element. This is a helper method to allow the method `NodeInfo.sendNamespaceDeclarations(net.sf.saxon.event.Receiver, boolean)` to be implemented if `NodeInfo.getDeclaredNamespaces(int[])` is available.

  Parameters:
    `out` - The relevant outputter
    `includeAncestors` - True if namespaces declared on ancestor elements must be output
  Throws:
    `XPathException`

### getPath

    public static String getPath(NodeInfo node)

  Get an absolute XPath expression that identifies a given node within its document

  Parameters:
    `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.
  Returns:
    a path expression that can be used to retrieve the node

### 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.

  Parameters:
    `node` - The node whose number is required
    `context` - Used for remembering previous result, for performance
  Returns:
    the node number, as defined above
  Throws:
    `XPathException` - if any error occurs

### 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.

  Parameters:
    `node` - the current node, the one whose node number is required
    `count` - 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)
  Returns:
    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.
  Throws:
    `XPathException` - when any error occurs in processing

### 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

  Parameters:
    `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 nodes
    `node` - The node being numbered
    `count` - 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 transformation
    `hasVariablesInPatterns` - 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
  Returns:
    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.
  Throws:
    `XPathException`

### 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.

  Parameters:
    `node` - The node to be numbered
    `count` - 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
  Returns:
    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.
  Throws:
    `XPathException`

### 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.

  Parameters:
    `node` - The node to be copied
    `out` - The receiver to which events will be sent
    `namePool` - 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 copied
  Throws:
    `XPathException` - on any failure reported by the Receiver

### 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.

  Parameters:
    `first` - The first node
    `second` - The second node, whose position is to be compared with the first node
  Returns:
    -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())

### 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

### 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

  Parameters:
    `value` - The positive integer key value (negative values are treated as zero).

### isWhite

    public static final boolean isWhite(CharSequence content)

  Deprecated. since Saxon 8.5: use `Whitespace.isWhite(java.lang.CharSequence)`

  Determine if a string is all-whitespace

  Parameters:
    `content` - the string to be tested
  Returns:
    true if the supplied string contains no non-whitespace characters

### isAncestorOrSelf

    public static boolean isAncestorOrSelf(NodeInfo a,
                                           NodeInfo d)

  Test if one node is an ancestor-or-self of another

  Parameters:
    `a` - the putative ancestor-or-self node
    `d` - the putative descendant node
  Returns:
    true if a is an ancestor-or-self of d

### 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

  Parameters:
    `node` - the singleton node, or null if the node does not exist
    `nodeTest` - the test to be applied
  Returns:
    an iterator over the node if it exists and matches the test.

Copyright (C) Michael H. Kay. All rights reserved.