Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

The <xsl:message>element sends a text message to either the message buffer or a message dialog box, depending on the environment in which the element call is made. It also raises a system-level error message that can be trapped through typical error-handling mechanisms.

Syntax

<xsl:message
  terminate = "yes|no" >
</xsl:message>

Attributes

terminate

The terminateattribute indicates that the XSLT document should stop processing.

Element Information

Number of occurrences

Unlimited

Parent elements

Any element where the content is a template.

Child elements

Any element that can occur in a template.

Remarks

The <xsl:message>element provides a mechanism to debug XSL Transformations (XSLT) style sheets in progress. Whenever an <xsl:message>element is encountered, if the terminateflag is set to "yes" (the default), then the XSLT processor quits, and sends a system-level error message. Expressions contained within the <xsl:message>element evaluate relative to the current context, making messagea good way to watch individual elements.

If terminateis set to "no", then the Microsoft XML Parser (MSXML) 3.0 ignores the command. This is a good way to disable error handling without removing it entirely from your Extensible Stylesheet Language (XSL) style sheet, although upcoming implementations can send such messages out to a log file. (This is not currently supported.)

Example

The following sample demonstrates use of the <xsl:message> element.

In the following file, a name is not supplied for the name element in the second record element.

Copy Code
<?xml version="1.0"?>
<?xml-stylesheet href="message.xsl" type="text/xsl"?>
<records>
   <record>
	<name>Hansen Claus</name>
	<address>222 Cherry</address>
	<phone>425-555-0102</phone>
   </record>
   <record>
	<name></name>
	<address>312 Elm</address>
	<phone>425-555-0103</phone>
   </record>
</records>

message.xsl

The following style sheet verifies that the name element within a record element has been filled in. If a name field is empty, then a message indicating that the XML is invalid is output.

Copy Code
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
  <xsl:template match="/">
	 <xsl:apply-templates select="*"/>
	 <xsl:copy-of select="."/>
  </xsl:template>

  <xsl:template match="*">
	 <xsl:apply-templates select="//record"/>
  </xsl:template>

  <xsl:template match="record">
	 <xsl:if test="name=''">
		 <xsl:message terminate="yes">A name field is empty.
		 </xsl:message>
	 </xsl:if>
  </xsl:template>
</xsl:stylesheet>

Output

Copy Code
A name field is empty.

See Also