xsl:try
Catches dynamic errors raised while evaluating its body.
<xsl:try>
<xsl:value-of select="xs:integer($input)"/>
<xsl:catch>
<xsl:text>not a number</xsl:text>
</xsl:catch>
</xsl:try>If an XPath or XSLT dynamic error is raised while running the try body, the matching xsl:catch clause runs instead. Multiple xsl:catch clauses can filter on specific error codes via the errors attribute. Inside xsl:catch, the variable $err:code holds the QName of the caught error.
Attributes
| Attribute | Description |
|---|---|
select |
Optional XPath expression as an alternative to a sequence constructor body. |
rollback-output |
yes (default) or no. With yes, partial output produced before the error is discarded. |
xsl:catch attributes
| Attribute | Description |
|---|---|
errors |
Space-separated list of error QNames or * (default) to catch any error. |
select |
Optional XPath expression as an alternative to a sequence constructor body. |
Example
Filtering on a specific error code:
<xsl:try>
<xsl:sequence select="$x div $y"/>
<xsl:catch errors="err:FOAR0001">
<xsl:sequence select="0"/>
</xsl:catch>
<xsl:catch>
<xsl:message>unexpected error: <xsl:value-of select="$err:code"/></xsl:message>
</xsl:catch>
</xsl:try>