XSLT » Elements » xsl:message

  terminates="yes" | "no"

The xsl:message element is primarily used to report errors by displaying a text message and related information of interest in the output.

This element can contain almost any other XSL element. For example, you can use the xsl:text element to add literal text to the xsl:message element and you can use the xsl:value-of element to display values.
Exactly how the text contained in the xsl:message element (and any associated stylesheet error messages) will be displayed in the output will be determined by the XSL processor.
This element also provides a mechanism that gives you the choice to quit the XSL processor (terminate the process) when an error is encountered or to allow the process to continue (the default).
Alternatively, the xsl:comment element can be used to debug errors.
This is not a self-closing element. The separate closing element is mandatory.


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:for-each select="devguru_staff/programmer">
NAME: <xsl:value-of select="name" />
<br />
<xsl:if test="phone=''">
<xsl:message terminate="yes">
No phone number is provided
<xsl:value-of select="phone" />
<br />
<hr />
NAME: Bugs Bunny
PHONE: 865-111-1111

NAME: Daisy Duck
PHONE: 865-222-2222

NAME: Minnie Mouse
PHONE: 865-333-3333

NAME: Pluto

The XML page cannot be displayed

Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

No phone number is provided


In this example, we test to see if a phone number is the empty string. If yes, we exit and display a message. This is the code for xslt_example_message.xsl.
We use the DevGuru Staff List XML file for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_message.xsl"?>

Language(s): XSLT

See Also: