xsl:try

In conjunction with xsl:catch, the xsl:try instruction allows recovery from dynamic errors.

Category: instruction
Content: ( sequence-constructor , xsl:catch , ( xsl:catch | xsl:fallback )* )
Permitted parent elements: any XSLT element whose content model is sequence constructor; any literal result element

Attributes

select?

expression

Details

It is possible to have more than one xsl:catch within an xsl:try; the first one that matches the error is used.

Within the xsl:catch, a number of variables are available in the namespace http://www.w3.org/2005/xqt-errors:

The error can be re-thrown by using the error() function.

Examples

Example 1

The following example shows how to recover from an error in evaluating an XPath expression (in this case, divide-by-zero):

<xsl:try select="salary div length-of-service"> <xsl:catch errors="err:FAOR0001" select="()"/> </xsl:try>

Example 2

The following example shows how to recover from an error in evaluating a sequence of XSLT instructions (in this case, a validation error):

<xsl:try> <xsl:copy-of select="$result" validation="strict"/> <xsl:catch> <xsl:message>Warning: validation of result document failed: Error code: <xsl:value-of select="$err:code"/> Reason: <xsl:value-of select="$err:description"/> </xsl:message> <xsl:sequence select="$result"/> </xsl:catch> </xsl:try>

Links to W3C specifications

XSLT 3.0 Specification

See also

xsl:catch

xsl:fallback

error()