SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Conditions of Use
Using XSLT 2.0
Using XQuery
Handling Source Documents
XML Schema Processing
The XPath API
Standards Conformance
Extensibility
Saxon Extensions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
XPath 2.0 Expression Syntax
| Introduction
| Constants
| Variable References
| Function Calls
| Axis steps
| Parentheses and operator precedence
| Filter expressions
| Path expressions
| Cast as, Treat as
| Set difference and intersection
| Union
| Arithmetic expressions
| Range expressions
| Comparisons
» | Instance of and Castable as
| Conditional Expressions
| Quantified Expressions
| For Expressions
| Boolean expressions: AND and OR
| Sequence expressions
Function Library
XSLT Patterns

# Instance of and Castable as

The expression `E instance of T` tests whether the value of expression `E` is an instance of type T, or of a subtype of T. For example, `$p instance of attribute+` is true if the value of `$p` is a sequence of one or more attribute nodes. It returns false if the sequence is empty or if it contains an item that is not an attribute node. The detailed rules for defining types, and for matching values against a type, are given in the XPath 2.0 specification.

Saxon also allows testing of the type annotation of an element or attribute node using tests of the form `element(*, T)`, `attribute(*, T)`. This is primarily useful with Saxon-SA, since the only way a node can acquire a type annotation is by validating a document against a schema.

The expression `E castable as T` tests whether the expression `E cast as T` would succeed. It is useful, for example, for testing whether a string contains a valid date before attempting to cast it to a date. This is because XPath and XSLT currently provide no way of trapping the error if the cast is attempted and fails.

Next