com.icl.saxon.om
Class Navigator

java.lang.Object
  |
  +--com.icl.saxon.om.Navigator

public class Navigator
extends java.lang.Object

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


Constructor Summary
Navigator()
           
 
Method Summary
static java.lang.String alphaKey(int value)
          Construct an alphabetic key from an positive integer; the key collates in the same sequence as the integer
static ElementInfo getAncestor(NodeInfo node, NodeTest test)
          Get the nearest ancestor element with a given name
static NodeInfo getAncestor(NodeInfo node, Pattern pat, Context c)
          Get the nearest ancestor node that matches the given pattern
static java.lang.String[] getAssociatedStylesheets(DocumentInfo doc, java.lang.String media, java.lang.String title)
          Get the URIs of the stylesheet associated with this document by means of an xml-stylesheet processing instruction.
static NodeInfo getFirstChild(NodeInfo node, Pattern pattern, Context c)
          Get the first child node matching a given pattern
static NodeInfo getLastChild(NodeInfo node, Pattern pattern, Context c)
          Get the last child node matching a given pattern
static NodeInfo getNextSibling(NodeInfo node, Pattern pattern, Context c)
          Get the next sibling node that matches a given pattern.
static java.lang.String getNodeTypeName(int type)
          Translate numeric node type to a string representation
static int getNumberAny(NodeInfo node, Pattern count, Pattern from, Context context)
          Get node number (level="any").
static java.util.Vector getNumberMulti(NodeInfo node, Pattern count, Pattern from, Context context)
          Get node number (level="multiple").
static int getNumberSimple(NodeInfo node)
          Get simple node number.
static int getNumberSimple(NodeInfo node, Context context)
          Get simple node number.
static int getNumberSingle(NodeInfo node, Pattern count, Pattern from, Context context)
          Get node number (level="single").
static NodeInfo getPreviousInDocument(NodeInfo node, Pattern pattern, Context c)
          Get the previous node in document order
static NodeInfo getPreviousSibling(NodeInfo node, Pattern pattern, Context c)
          Get the previous sibling of the node that matches a given pattern.
static boolean isAncestor(NodeInfo node, NodeInfo other)
          Determine whether this node is an ancestor of another node
static boolean isFirstChild(ElementInfo element)
          Determine whether this element is the first element child of its parent.
static boolean isFirstInGroup(ElementInfo element)
          Determine whether this element is the first in a consecutive group.
static boolean isLastChild(ElementInfo element)
          Determine whether this element is the last child element of its parent.
static boolean isLastInGroup(ElementInfo element)
          Determine whether this element is the last in a consecutive group.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Navigator

public Navigator()
Method Detail

getAssociatedStylesheets

public static java.lang.String[] getAssociatedStylesheets(DocumentInfo doc,
                                                          java.lang.String media,
                                                          java.lang.String title)
                                                   throws org.xml.sax.SAXException
Get the URIs of the stylesheet associated with this document by means of an xml-stylesheet processing instruction.
Parameters:
media - The required medium, or null to match any medium
title - The required title, or null to match the preferred stylesheet
Returns:
null if there is no such processing instruction
Throws:
org.xml.sax.SAXException - if there is such a processing instruction and it is invalid

isFirstInGroup

public static boolean isFirstInGroup(ElementInfo element)
Determine whether this element is the first in a consecutive group. A consecutive group is a group of elements of the same type subordinate to the same parent element; there can be intervening character data, white space, or processing instructions, but no elements of a different type.
Parameters:
element - The element being tested
Returns:
True if this is the first child of its parent, or if the previous child was a different element type, or if this element is the root.

isLastInGroup

public static boolean isLastInGroup(ElementInfo element)
Determine whether this element is the last in a consecutive group. A consecutive group is a group of elements of the same type subordinate to the same parent element; there can be intervening character data, white space, or processing instructions, but no elements of a different type.
Parameters:
element - The element being tested
Returns:
True if this is the last child of its parent, or if the next child is a different element type, or if this element is the root.

isFirstChild

public static boolean isFirstChild(ElementInfo element)
Determine whether this element is the first element child of its parent.
Parameters:
element - The element being tested
Returns:
True if this element is the first element child of its parent, or if it is the document element.

isLastChild

public static boolean isLastChild(ElementInfo element)
Determine whether this element is the last child element of its parent.
Parameters:
element - The element being tested
Returns:
True if this element is the last child element of its parent, or if it is the root element.

getAncestor

public static ElementInfo getAncestor(NodeInfo node,
                                      NodeTest test)
Get the nearest ancestor element with a given name
Parameters:
node - The starting node
test - NodeTest that the required ancestor must satisfy.
Returns:
The NodeInfo for the nearest ancestor with the given tag; null if there is no such ancestor

getAncestor

public static NodeInfo getAncestor(NodeInfo node,
                                   Pattern pat,
                                   Context c)
                            throws org.xml.sax.SAXException
Get the nearest ancestor node that matches the given pattern
Parameters:
node - The starting node
pattern - A pattern that the ancestor node must satisfy.
Returns:
The NodeInfo for the nearest ancestor node that matches the given pattern; null if there is no such ancestor

isAncestor

public static boolean isAncestor(NodeInfo node,
                                 NodeInfo other)
Determine whether this node is an ancestor of another node
Parameters:
node - the putative ancestor node
other - the other node (the putative descendant of this node)
Returns:
true of this node is an ancestor of the other node

getNextSibling

public static NodeInfo getNextSibling(NodeInfo node,
                                      Pattern pattern,
                                      Context c)
                               throws org.xml.sax.SAXException
Get the next sibling node that matches a given pattern.
Parameters:
node - The starting node
pattern - The match-pattern that the required sibling must match
Returns:
The NodeInfo object describing the next node at the same level. Returns null if there is no subsequent child of the same parent that matches the supplied pattern.

getFirstChild

public static NodeInfo getFirstChild(NodeInfo node,
                                     Pattern pattern,
                                     Context c)
                              throws org.xml.sax.SAXException
Get the first child node matching a given pattern
Parameters:
node - The starting node
pattern - the pattern to be matched
Returns:
the the first child node of the required type, or null if there is no such child

getPreviousSibling

public static NodeInfo getPreviousSibling(NodeInfo node,
                                          Pattern pattern,
                                          Context c)
                                   throws org.xml.sax.SAXException
Get the previous sibling of the node that matches a given pattern.
Parameters:
node - The starting node
pattern - The match-pattern that the required sibling must match
Returns:
The NodeInfo object describing the previous node at the same level that matches the pattern. Returns null if there is no previous child of the same parent that matches the supplied pattern.

getPreviousInDocument

public static NodeInfo getPreviousInDocument(NodeInfo node,
                                             Pattern pattern,
                                             Context c)
                                      throws org.xml.sax.SAXException
Get the previous node in document order
Parameters:
node - the starting node
pattern: - identifies a pattern the required node
Returns:
the previous node in the document of the required type, or null if there is no such node

getLastChild

public static NodeInfo getLastChild(NodeInfo node,
                                    Pattern pattern,
                                    Context c)
                             throws org.xml.sax.SAXException
Get the last child node matching a given pattern
Parameters:
node - the starting node
pattern - the pattern to be matched
Returns:
the the last child node of the required type, or null if there is no such child

getNumberSimple

public static int getNumberSimple(NodeInfo node,
                                  Context context)
                           throws org.xml.sax.SAXException
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:
context - Used for remembering previous result, for performance

getNumberSimple

public static int getNumberSimple(NodeInfo node)
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. This version doesn't require the context, and therefore doesn't remember previous results

getNumberSingle

public static int getNumberSingle(NodeInfo node,
                                  Pattern count,
                                  Pattern from,
                                  Context context)
                           throws org.xml.sax.SAXException
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:
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.)
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.

getNumberAny

public static int getNumberAny(NodeInfo node,
                               Pattern count,
                               Pattern from,
                               Context context)
                        throws org.xml.sax.SAXException
Get node number (level="any"). Return one plus the number of previous nodes in the document that match the supplied pattern
Parameters:
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.
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.

getNumberMulti

public static java.util.Vector getNumberMulti(NodeInfo node,
                                              Pattern count,
                                              Pattern from,
                                              Context context)
                                       throws org.xml.sax.SAXException
Get node number (level="multiple"). Return a vector giving the hierarchic position of this node. See the XSLT spec for details.
Parameters:
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.
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.

getNodeTypeName

public static java.lang.String getNodeTypeName(int type)
Translate numeric node type to a string representation

alphaKey

public static java.lang.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).