Share via


xsl:message Element

A version of this page is also available for

Windows Embedded CE 6.0 R3

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 terminate attribute 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 terminate flag 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 message a good way to watch individual elements.

If terminate is 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.

<?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.

<xsl:stylesheet xmlns:xsl="https://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

A name field is empty.

See Also

Reference

XSLT Elements
xsl:comment Element