Open In App

XSLT <message> Element

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:

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"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                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:




Article Tags :