xsl:assert
The xsl:assert
instruction is new in XSLT 3.0 (and Saxon 9.5). It can be used to make assertions in the form
of XPath expressions, causing a dynamic error if the assertion turns out to be false. For example:
<xsl:assert test="$x > 0">Argument $x must be greater than zero</xsl:assert>
This tests whether the value of $x
is non-negative, and if not, failes with an error message.
It may be useful to add an attribute such as use-when="$DEBUG"
to xsl:assert
instructions;
the global static variable DEBUG
can then be used to switch assertion processing on and off. The variable might
be declared as <xsl:variable name="DEBUG" as="xs:boolean" select="true()"/>
.