The saxon:type-alias element declares a simple name that can be used to represent an item type.

Category: declaration
Content: none
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 array(array(xs:integer)), while a move or possible move might be represented as map(xs:string, xs:integer). 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 ~board and ~move. So a function that takes a board and a move as input, and produces a new board as its result, would have the signature function ($board as ~board, $move as ~move) as ~board.

The element 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 ~typename syntax anywhere within the stylesheet, including in another saxon:type-alias 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 in XSLT as and type attributes, and in XPath instance of and 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 xsl:include.

Type aliases are not recognized in static expressions (for example, in use-when).

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.


<saxon:type-alias name="square" type="xs:integer"/> <saxon:type-alias name="piece" type="xs:string"/> <saxon:type-alias name="board" type="array(array(~square))"/> <saxon:type-alias name="move" type="map(~piece, ~square)"/>