saxon:type-alias element declares a simple name that can be used
to represent an item type.
Permitted parent elements: any XSLT element whose content model is sequence-constructor; any literal result element
The name to be used for the type
The item type represented by the name
With maps and arrays, item types can become quite complex, and they are not always
very meaningful. For example, in a Saxon-JS stylesheet implementing an interactive
chess game, the state of the board might be represented by the type
while a move or possible move might be represented as
Such types do little to make the code more readable, and they create a potential problem in exposing
design decisions as to how particular concepts are implemented internally. Type aliases allow
such types to be written as, for example
~move. So a function
that takes a board and a move as input, and produces a new board as its result, would have the
function ($board as ~board, $move as ~move) as ~board.
saxon:type-alias can appear as a top-level declaration in the stylesheet.
A type that is declared anywhere in the stylesheet can be referenced using the
syntax anywhere within the stylesheet, including in another
declaration. Forwards references are allowed, but circular references are not.
Item types such as
~board can be used anywhere an item type is permitted, for example
type attributes, and in XPath
cast as expressions (but not as the name of a constructor function, unless a user-defined
function is explicitly written with the same name). Where a Sequence Type is allowed, the name can be followed
by an occurrence indicator, for example
~move* represents a sequence of moves.
Import precedence works in the usual way. Type aliases are currently local to a stylesheet package;
if you are writing a library package and want client applications to use aliases for the type names used in your API, issue
a stylesheet module containing the aliases, that users can include using
Type aliases are not recognized in static expressions (for example, in
Use of the
saxon:type-alias syntax requires Saxon-PE or higher. Use of the "~" syntax
in XPath expressions requires the configuration option
Feature.ALLOW_SYNTAX_EXTENSIONS to be enabled.
For further information about the syntax extension, see Type aliases.