## 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:
  java.io.Serializable, javax.xml.transform.SourceLocator, LocationProvider, SaxonLocator, ContextMappingFunction, EvaluableItem, SequenceIterable, InstructionInfo, org.xml.sax.Locator

    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.

See Also:
  Serialized Form

Field Summary

Fields inherited from class net.sf.saxon.expr.Expression
`EVALUATE_METHOD, ITERATE_METHOD, locationId, PROCESS_METHOD, staticProperties`

Constructor Summary
`PathExpression(Expression start, Expression step)` Constructor

Method Summary
`PathMap.PathMapNodeSet` `addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)` Add a representation of this expression to a PathMap.
`int` `computeSpecialProperties()` Get the static properties of this expression (other than its type).
`Expression` `copy()` Copy an expression.
`void` `explain(ExpressionPresenter destination)` Diagnostic print of expression structure.
`Expression` `getFirstStep()` Get the first step in this expression.
`Expression` `getLastStep()` Get the last step of the path expression
`Expression` `getLeadingSteps()` Get a path expression consisting of all steps except the last
`Expression` `getRemainingSteps()` Get all steps after the first.
`boolean` `isAbsolute(TypeHierarchy th)` Test whether a path expression is an absolute path - that is, a path whose first step selects a document node
`boolean` `isHybrid()` Determine whether this expression is capable (as far as static analysis is concerned) of returning a mixture of nodes and atomic values.
`SequenceIterator` `iterate(XPathContext context)` Iterate the path-expression in a given context
`Expression` `optimize(ExpressionVisitor visitor, ItemType contextItemType)` Optimize the expression and perform type analysis
`Expression` `promote(PromotionOffer offer)` Promote this expression if possible
`Expression` `simplify(ExpressionVisitor visitor)` Simplify an expression
`java.lang.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.
`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.
`Expression` `typeCheck(ExpressionVisitor visitor, ItemType contextItemType)` Perform type analysis

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

### 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 class `SlashExpression`
  Returns:
    true if the static type allows both nodes and atomic values

### simplify

    public Expression simplify(ExpressionVisitor visitor)
                        throws XPathException

  Simplify an expression

  Overrides:
    `simplify` in class `SlashExpression`
  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 class `SlashExpression`
  Parameters:
    `visitor` - an expression visitor
    `contextItemType` - 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 to `Type.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 class `SlashExpression`
  Parameters:
    `visitor` - an expression visitor
    `contextItemType` - 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 to `Type.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

    public Expression promote(PromotionOffer offer)
                       throws XPathException

  Promote this expression if possible

  Overrides:
    `promote` in class `SlashExpression`
  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

    public Expression copy()

  Copy an expression. This makes a deep copy.

  Overrides:
    `copy` in class `SlashExpression`
  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 class `SlashExpression`
  Returns:
    the special properties, as a bit-significant integer

### getFirstStep

    public Expression 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

    public 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

### getLastStep

    public Expression getLastStep()

  Get the last step of the path expression

  Returns:
    the last step in the expression, after expanding any nested path expressions

### getLeadingSteps

    public Expression 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

    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

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

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

  Overrides:
    `addToPathMap` in class `Expression`
  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

### iterate

    public SequenceIterator iterate(XPathContext context)
                             throws XPathException

  Iterate the path-expression in a given context

  Specified by:
    `iterate` in interface `SequenceIterable`
  Overrides:
    `iterate` in class `SlashExpression`
  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

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

  Overrides:
    `toString` in class `Expression`

### explain

    public void explain(ExpressionPresenter destination)

  Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.

  Overrides:
    `explain` in class `SlashExpression`
  Parameters:
    `destination` - the expression presenter used to display the structure

Copyright (c) Saxonica Limited. All rights reserved.