saxon:try()

try($arg1 as item()*, $arg2 as item()) ==> item()*

This function is available only in Saxon-SA

This function provides a simple way of recovering from dynamic errors (including type errors). It returns the value of the first argument, unless evaluation of the first argument fails, in which case it returns the value of the second argument.

No information is made available about the cause of the error.

Example: saxon:try(1 div 0, "divide by zero") returns the string "divide by zero".

To recover from failures occurring in XSLT instructions, for example schema validation errors, wrap the instructions in a stylesheet function (xsl:function) and call this function within a call of saxon:try().

Technically this is a pseudo-function, because it does not use the standard function calling rules. The second argument is not evaluated unless evaluation of the first argument fails.

Expand

Up  Next