Skip to main content

XSLT <xsl:message> Element

The <xsl:message> element is used to display error messages to help debug XSLT processing.

It is similar to JavaScript alerts.

This element buffers a message to the XSLT processor that finishes processing and sends a message to the calling application to display an error message.

<xsl:message> Element


The syntax of <xsl:message> is as follows:

terminate="yes|no" >


The table describes the meaning of the attributes of <xsl:message>:

terminateIt specifies whether the transformation should terminate upon executing this instruction or not. Default value is "yes".


Let's see an example:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="books.xsl"?>

<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<book category="web">
<title lang="en">XQuery Tips</title>
<author>Tom Nolan</author>
<book category="web">
<title lang="en">Learn XML</title>
<author>Tutorial Reference</author>
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="">

<xsl:template match="/">
<h2>The Bookstore</h2>
<table border="1">
<tr bgcolor="#6565d5">
<xsl:for-each select="bookstore/book">

<xsl:if test="author = ''">
<xsl:message terminate="yes">An author field is empty.

<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="year"/></td>
<td><xsl:value-of select="price"/></td>