xsl:comment
xsl:text
xsl:value-of
ELEMENT: xsl:message
<xsl:message
terminates="yes" | "no"
>
</xsl:message>
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.
terminates="yes" | "no"
The optional
terminates
attribute provides the choice of quitting the process or continuing the process if an error is encountered. If set to no, the error in the stylesheet is reported and the process continues. This is the default. If set to yes, the error in the stylesheet is reported and the process terminates.
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"?>
and we name it: xslt_example_message.xml
In this example, we test to see if a phone number is the empty string. If yes, we exit and display a message.
Code for xslt_example_message.xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="devguru_staff/programmer">
NAME: <xsl:value-of select="name" />
<br />
PHONE:
<xsl:if test="phone=''">
<
xsl:message terminate="yes"
>
No phone number is provided
<
/xsl:message
>
</xsl:if>
<xsl:value-of select="phone" />
<br />
<hr />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
Click to view output in separate window
- requires Internet Explorer
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information