Package net.sf.saxon.expr
Class PathExpression
java.lang.Object
net.sf.saxon.expr.Expression
net.sf.saxon.expr.SlashExpression
net.sf.saxon.expr.PathExpression
- All Implemented Interfaces:
Serializable
,SourceLocator
,LocationProvider
,SaxonLocator
,ContextMappingFunction
,EvaluableItem
,SequenceIterable
,InstructionInfo
,Locator
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.
- See Also:
-
Field Summary
Fields inherited from class net.sf.saxon.expr.Expression
EVALUATE_METHOD, ITERATE_METHOD, locationId, PROCESS_METHOD, staticProperties
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddToPathMap
(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet) Add a representation of this expression to a PathMap.int
Get the static properties of this expression (other than its type).copy()
Copy an expression.void
explain
(ExpressionPresenter destination) Diagnostic print of expression structure.Get the first step in this expression.Get the last step of the path expressionGet a path expression consisting of all steps except the lastGet all steps after the first.boolean
Test whether a path expression is an absolute path - that is, a path whose first step selects a document nodeboolean
isHybrid()
Determine whether this expression is capable (as far as static analysis is concerned) of returning a mixture of nodes and atomic values.iterate
(XPathContext context) Iterate the path-expression in a given contextoptimize
(ExpressionVisitor visitor, ItemType contextItemType) Optimize the expression and perform type analysispromote
(PromotionOffer offer) Promote this expression if possiblesimplify
(ExpressionVisitor visitor) Simplify an expressiontoString()
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.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.typeCheck
(ExpressionVisitor visitor, ItemType contextItemType) Perform type analysisMethods inherited from class net.sf.saxon.expr.SlashExpression
computeCardinality, computeDependencies, equals, getItemType, getStartExpression, getStepExpression, hashCode, hasLoopingSubexpression, iterateSubExpressions, makeSlashExpression, map, promoteFocusIndependentSubexpressions, replaceSubExpression, setStartExpression, setStepExpression
Methods inherited from class net.sf.saxon.expr.Expression
adoptChildExpression, checkForUpdatingSubexpressions, checkPermittedContents, computeStaticProperties, display, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, evaluatePendingUpdates, explain, findParentOf, getCardinality, getColumnNumber, getColumnNumber, getConstructType, getContainer, getDependencies, getExecutable, getHostLanguage, getImplementationMethod, getIntrinsicDependencies, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getObjectName, getProperties, getProperty, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, getSystemId, implementsStaticTypeCheck, isUpdatingExpression, iterateEvents, markTailFunctionCalls, process, resetLocalStaticProperties, setContainer, setFiltered, setFlattened, setLocationId, staticTypeCheck, suppressValidation, typeError
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.sf.saxon.expr.ContextMappingFunction
map
-
Constructor Details
-
PathExpression
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 Details
-
isHybrid
public boolean isHybrid()Description copied from class:SlashExpression
Determine whether this expression is capable (as far as static analysis is concerned) of returning a mixture of nodes and atomic values. If so, this needs to be prevented at run time- Overrides:
isHybrid
in classSlashExpression
- Returns:
- true if the static type allows both nodes and atomic values
-
simplify
Simplify an expression- Overrides:
simplify
in classSlashExpression
- Parameters:
visitor
- the expression visitor- Returns:
- the simplified expression
- Throws:
XPathException
- if an error is discovered during expression rewriting
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException Perform type analysis- Overrides:
typeCheck
in classSlashExpression
- Parameters:
visitor
- an expression visitorcontextItemType
- the static type of "." at the point where this expression is invoked. The parameter is set to null if it is known statically that the context item will be undefined. If the type of the context item is not known statically, the argument is set toType.ITEM_TYPE
- Returns:
- the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
optimize
public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException Optimize the expression and perform type analysis- Overrides:
optimize
in classSlashExpression
- Parameters:
visitor
- an expression visitorcontextItemType
- the static type of "." at the point where this expression is invoked. The parameter is set to null if it is known statically that the context item will be undefined. If the type of the context item is not known statically, the argument is set toType.ITEM_TYPE
- Returns:
- the original expression, rewritten if appropriate to optimize execution
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
promote
Promote this expression if possible- Overrides:
promote
in classSlashExpression
- Parameters:
offer
- details of the offer, for example the offer to move expressions that don't depend on the context to an outer level in the containing expression- Returns:
- if the offer is not accepted, return this expression unchanged. Otherwise return the result of rewriting the expression to promote this subexpression
- Throws:
XPathException
- if any error is detected
-
copy
Copy an expression. This makes a deep copy.- Overrides:
copy
in classSlashExpression
- Returns:
- the copy of the original 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.- Overrides:
computeSpecialProperties
in classSlashExpression
- Returns:
- the special properties, as a bit-significant integer
-
getFirstStep
Get the first step in this expression. A path expression A/B/C is represented as (A/B)/C, but the first step is A- Returns:
- the first step in the expression, after expanding any nested path expressions
-
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
-
getLastStep
Get the last step of the path expression- Returns:
- the last step in the expression, after expanding any nested path expressions
-
getLeadingSteps
Get a path expression consisting of all steps except the last- Returns:
- a path expression containing all steps in this path expression other than the last, after expanding any nested path expressions
-
isAbsolute
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
-
tryToMakeAbsolute
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.
-
addToPathMap
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.- Overrides:
addToPathMap
in classExpression
- Parameters:
pathMap
- the PathMap to which the expression should be addedpathMapNodeSet
-- 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
-
iterate
Iterate the path-expression in a given context- Specified by:
iterate
in interfaceSequenceIterable
- Overrides:
iterate
in classSlashExpression
- Parameters:
context
- the evaluation context- Returns:
- a SequenceIterator that can be used to iterate over the result of the expression
- Throws:
XPathException
- if any dynamic error occurs evaluating the expression
-
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- Overrides:
toString
in classExpression
-
explain
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Overrides:
explain
in classSlashExpression
- Parameters:
destination
- the expression presenter used to display the structure
-