## com.saxonica.schema
Class PathSelection

    java.lang.Object
      com.saxonica.schema.PathSelection

All Implemented Interfaces:
  Selection, java.io.Serializable

    public class PathSelection

extends java.lang.Object
implements Selection, java.io.Serializable

A PathSelection is a Selection that applies a NodeTest to each element between the context element and the node being tested, and returns true if they all match. This class is used internally in the validation of instance documents against uniqueness and identity constraints; it is not intended for use by user applications.

See Also:
  Serialized Form

Field Summary

Fields inherited from interface com.saxonica.schema.Selection
`MATCHES_AS_PARENT, MATCHES_AS_SELF`

Constructor Summary
`PathSelection(NodeTest[] tests, boolean anchored, NodeTest attributeTest, Expression xpath)` Create a PathSelection - a limited form of XPath expression that can be evaluated on-the-fly

Method Summary
`boolean` `canMatchAttributes()` Determine whether the selection can match attribute nodes
`boolean` `canMatchElementContent()` Determin whether the selection can match element content
`void` `displayExpression(ExpressionPresenter out)` Diagnostic print of expression structure.
`NodeTest` `getAttributeTest()` Get the attribute test at the end of the path, if there is one
`ItemType` `getItemType()` Determine the item type of the nodes matched by the last NodeTest
`ItemType` `getItemType(TypeHierarchy th)` Return the type of the nodes selected by this selection
`boolean` `matchesAttribute(int fingerprint)` Determine whether a given attribute matches the Selection
`int` `matchesElement(int[] stack, int length, int contextPosition)` Determine whether the selector matches a given element.
`java.lang.String` `typeCheck(ExpressionVisitor visitor, ItemType contextItemType)` Check that the selection makes sense in the context of a given ItemType.

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

Constructor Detail

### PathSelection

    public PathSelection(NodeTest[] tests,
                         boolean anchored,
                         NodeTest attributeTest,
                         Expression xpath)

  Create a PathSelection - a limited form of XPath expression that can be evaluated on-the-fly

  Parameters:
    `tests` - an array of node tests, representing a sequence of axis steps; these are all tests on the child axis, except possibly the last, which is a test on the attribute axis if attributeTest is true
    `anchored` - if true, the first test applies to children of the root node; if false, it applies to descendants of the root node
    `attributeTest` - if true, the last test applies to attributes rather than elements.
    `xpath` - An XPath expression equivalent to the PathSelection. This is never evaluated, but is used for type analysis and diagnostic display.

Method Detail

### matchesElement

    public int matchesElement(int[] stack,
                              int length,
                              int contextPosition)

  Determine whether the selector matches a given element. The element is identified by an array of integers representing the fingerprints of the names of this element and each of its ancestors, in document order (i.e., root element first, matched element last).

  Specified by:
    `matchesElement` in interface `Selection`
  Parameters:
    `stack` - the array of name fingerprints
    `length` - the effective length of the array; any items beyond this position are ignored
    `contextPosition` - the position in this array of the context element for the selection.
  Returns:
    true if the element matches

### getAttributeTest

    public NodeTest getAttributeTest()

  Get the attribute test at the end of the path, if there is one

  Returns:
    the attribute test if there is one, or null otherwise

### matchesAttribute

    public boolean matchesAttribute(int fingerprint)

  Determine whether a given attribute matches the Selection

  Specified by:
    `matchesAttribute` in interface `Selection`
  Parameters:
    `fingerprint` - the integer nameCode of an attribute
  Returns:
    true if it matches, false if it does not match

### canMatchAttributes

    public boolean canMatchAttributes()

  Determine whether the selection can match attribute nodes

  Specified by:
    `canMatchAttributes` in interface `Selection`
  Returns:
    true if the selection can match attributes

### canMatchElementContent

    public boolean canMatchElementContent()

  Determin whether the selection can match element content

  Specified by:
    `canMatchElementContent` in interface `Selection`
  Returns:
    true if the selection can match elements

### getItemType

    public ItemType getItemType()

  Determine the item type of the nodes matched by the last NodeTest

  Returns:
    the item type of the selected nodes

### typeCheck

    public java.lang.String typeCheck(ExpressionVisitor visitor,
                                      ItemType contextItemType)

  Check that the selection makes sense in the context of a given ItemType. Return null if the selection is OK, otherwise an error message

  Specified by:
    `typeCheck` in interface `Selection`
  Parameters:
    `visitor` - the expression visitor
    `contextItemType` - the type of the context item
  Returns:
    an error messge if the expression is invalid

### getItemType

    public ItemType getItemType(TypeHierarchy th)

  Return the type of the nodes selected by this selection

  Specified by:
    `getItemType` in interface `Selection`
  Parameters:
    `th` - the type hierarchy cache
  Returns:
    the item type of the selected nodes

### displayExpression

    public void displayExpression(ExpressionPresenter out)

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

  Specified by:
    `displayExpression` in interface `Selection`
  Parameters:
    `out` - the place where the structure is to be written

Copyright (c) Saxonica Limited. All rights reserved.