I need XSLT to stop processing with an error, when an external document is not available. From what I've found out the <xsl:message> tag seems to be the right way to do it, but so far it doesn't work. Here's what I tried:
<xsl:if test="not(document('some_external_doc.xml')//myxpath)">
<xsl:message terminate="yes">ERROR: Missing element!</xsl:message>
<h1>Error detected!</h1>
</xsl:if>
The missing document/xpath is detected by the <xsl:if> and the <h1> will be displayed, but for some reason the terminate attribute of the <xsl:message> is ignored. The transformation is done in Railo, so the XSLT processor use should be the Java default, but I wasn't able to find something definitive about the processor Railo is using.
You have the right idea, however...
If your XSLT processor implements XSLT 1.0, it technically does not have to terminate. Note the use of the word should rather than must in the spec for
xsl:message
:Interestingly, XSLT 2.0 changes the should to a must:
Note also that order of execution of
xsl:message
statements is processor-dependent; keep this in mind when looking forxsl:message
output in the logs.Finally, you have some additional exception processing options under XSLT 2.0 (error() function) and XSLT 3.0 (xsl:try and xsl:catch).