Error Handling in XSLT
Use
In substantial XSLT programs it makes sense for the system to display an explanatory message when an error occurs. For this purpose there is the XSLT command <xsl:message> . For example, the source document might contain a value that is not expected by the mapping program. In this case the system can display a message, and, if necessary, terminate processing of the mapping.
Integration
Messages that are produced using the XSLT command <xsl:message> or the AbstractTrace object are visible in the trace function of the technical monitor.
Features
The XLST command <xsl:message> has the following syntax:
<xsl:message terminate=" [yes|no] ">
<!- Output Message -->
</xsl:message>
The attribute Terminate determines whether processing of the XSLT program should be terminated (terminate= “yes” ) or not (terminate= “no” ). In both instances you can view the error message text by using the trace function for a message in monitoring. (provided that you activated the trace function for the Integration Engine).
Example
The following example of a section of an XSLT program is taken from a mapping program with the name Person2Passenger.xsl. The XSLT commands in this section evaluate the current value of a tag from the source document and map the values as follows:
|
Source Document |
Target Document |
|
0 |
Mr. |
|
1 |
Mrs. |
|
(Other) |
Mr. or Mrs. |
The last instance is an exception for non-interpretable values. To retain this exception in the trace, a message is produced using <xsl:message> :
<xsl:choose>
<xsl:when test="test()=0">Mr.</xsl:when> <xsl:when test="test()=1">Mrs.</xsl:when>
<xsl:otherwise> Mr. or Mrs.
<xsl:message terminate="no">
Gender has neither value 0 nor 1! "Mr. or Mrs." was chosen for title.
</xsl:message>
</xsl:otherwise>
</xsl:choose>
Since the target field can still be completed appropriately, processing is not terminated ( terminate="no" ).
Trace Output
In the technical monitor, the section in the trace for the third instance looks as follows:
<CALL kind=" ENTER " func=" CL_XMS_PLSRV_MAPPING~ENTER_PLSRV " />
<trc1>XSLT transformation: xslt/wsxx/Person2Passenger completed. Gender has neither value 0 nor 1! "Mr. or Mrs." was chosen for title. </trc1>
<CALL kind=" EXIT " func=" CL_XMS_PLSRV_MAPPING~ENTER_PLSRV " />