net.sf.saxon.expr

Class PathExpression

public final class PathExpression extends SlashExpression implements ContextMappingFunction

An expression that establishes a set of nodes by following relationships between nodes in the document. Specifically, it consists of a start expression which defines a set of nodes, and a step which defines a relationship to be followed from those nodes to create a new set of nodes.

This class inherits from SlashExpression; it is used in the common case where the SlashExpression is known to return nodes rather than atomic values.

This class is not responsible for sorting the results into document order or removing duplicates. That is done by a DocumentSorter expression which is wrapped around the path expression. However, this class does contain the logic for deciding statically whether the DocumentSorter is needed or not.

Constructor Summary
PathExpression(Expression start, Expression step)
Constructor
Method Summary
ExpressionaddDocumentSorter()
Add a document sorting node to the expression tree, if needed
PathMap.PathMapNodeSetaddToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap.
intcomputeSpecialProperties()
Get the static properties of this expression (other than its type).
Expressioncopy()
Copy an expression.
voidexplain(ExpressionPresenter destination)
Diagnostic print of expression structure.
ExpressiongetRemainingSteps()
Get all steps after the first.
booleanisAbsolute(TypeHierarchy th)
Test whether a path expression is an absolute path - that is, a path whose first step selects a document node
booleanisHybrid()
SequenceIteratoriterate(XPathContext context)
Iterate the path-expression in a given context
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
Optimize the expression and perform type analysis
Expressionpromote(PromotionOffer offer, Expression parent)
Promote this expression if possible
Expressionsimplify(ExpressionVisitor visitor)
Simplify an expression
StringtoString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath.
PathExpressiontryToMakeAbsolute(TypeHierarchy th)
Test whether a path expression is an absolute path - that is, a path whose first step selects a document node; if not, see if it can be converted to an absolute path.
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Perform type analysis

Constructor Detail

PathExpression

public PathExpression(Expression start, Expression step)
Constructor

Parameters: start A node-set expression denoting the absolute or relative set of nodes from which the navigation path should start. step The step to be followed from each node in the start expression to yield a new node-set

Method Detail

addDocumentSorter

Expression addDocumentSorter()
Add a document sorting node to the expression tree, if needed

addToPathMap

public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap. The PathMap captures a map of the nodes visited by an expression in a source tree.

Parameters: pathMap the PathMap to which the expression should be added pathMapNodeSet

Returns: the pathMapNode representing the focus established by this expression, in the case where this expression is the first operand of a path expression or filter expression

computeSpecialProperties

public int computeSpecialProperties()
Get the static properties of this expression (other than its type). The result is bit-signficant. These properties are used for optimizations. In general, if property bit is set, it is true, but if it is unset, the value is unknown.

copy

public Expression copy()
Copy an expression. This makes a deep copy.

Returns: the copy of the original expression

explain

public void explain(ExpressionPresenter destination)
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.

getRemainingSteps

Expression getRemainingSteps()
Get all steps after the first. This is complicated by the fact that A/B/C is represented as ((A/B)/C; we are required to return B/C

Returns: a path expression containing all steps in this path expression other than the first, after expanding any nested path expressions

isAbsolute

public boolean isAbsolute(TypeHierarchy th)
Test whether a path expression is an absolute path - that is, a path whose first step selects a document node

Parameters: th the type hierarchy cache

Returns: true if the first step in this path expression selects a document node

isHybrid

public boolean isHybrid()

iterate

public SequenceIterator iterate(XPathContext context)
Iterate the path-expression in a given context

Parameters: context the evaluation context

optimize

public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)
Optimize the expression and perform type analysis

promote

public Expression promote(PromotionOffer offer, Expression parent)
Promote this expression if possible

simplify

public Expression simplify(ExpressionVisitor visitor)
Simplify an expression

Parameters: visitor the expression visitor

Returns: the simplified expression

toString

public String toString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath. In the case of XSLT instructions, the toString() method gives an abstracted view of the syntax

tryToMakeAbsolute

public PathExpression tryToMakeAbsolute(TypeHierarchy th)
Test whether a path expression is an absolute path - that is, a path whose first step selects a document node; if not, see if it can be converted to an absolute path. This is possible in cases where the path expression has the form a/b/c and it is known that the context item is a document node; in this case it is safe to change the path expression to /a/b/c

Parameters: th the type hierarchy cache

Returns: the path expression if it is absolute; the converted path expression if it can be made absolute; or null if neither condition applies.

typeCheck

public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Perform type analysis