In XSLT (eXtensible Stylesheet Language Transformations), the ‘<xsl: message>’ element outputs messages during the transformation process. It’s a way to communicate information or provide feedback during the transformation. This element contains all the other XSL elements such as <xsl: text>, <xsl:value-of>, etc.
Syntax:
<xsl:message terminate="yes"|"no">
[message-body]
</xsl: message>
Attributes:
- terminate: It is used to complete the transformation after the message is executed on the given instruction. By default, the value of terminate is “yes”.
Example: In this example, we will see the use of the terminate attribute and see how it works. The messages that are displayed during the transformation, provide information about the progress or actions being taken.
<!--'input.xml'--> < xsl:stylesheet version = "1.0"
xmlns:xsl='http://www.w3.org/1999/XSl/Transform">
< class >
< books >
< book >
< title >The Complete Reference</ title >
< author >Herbert Schildt</ author >
</ book >
< book >
< title >Thinking in Java</ title >
< author >Prentice Hall</ author >
</ book >
</ books >
</ class >
|
<!--stylesheet. xsl--> <? xml version = "1.0" encoding = "UTF-8" ?>
version = "1.0" >
< xsl:template match = "/" >
< xsl:message terminate = "no" >
Starting the transformation.
</ xsl:message >
< output >
< xsl:apply-templates select = "books/book" />
</ output >
</ xsl:template >
< xsl:template match = "book" >
< xsl:message terminate = "no" >
Proessing book:
< xsl:value-of select = "title" /></ xsl:message >
< bookInfo >
< title >< xsl:value-of select = "title" /></ title >
< author >< xsl:value-of select = "author" /></ author >
</ bookInfo >
</ xsl:template >
</ xsl:stylesheet >
|
To run this, use the below command:
java -jar saxon9he.jar -s:input.xml -xsl:stylesheet.xsl -o:output.xml
Output: