Display XML with XSLT

You can use an XSL file to indicate how I view the XML data elements.

Syntax to incorporate a XSLT to an XML file

<?xml-stylesheet type="text/xml" href="message.xsl"?>

Example XML with XSL

<?xml version="1.0" encoding="UTF-8" ?> <?xml-stylesheet type="text/xml" href="message.xsl"?> <messages>     <message>         <from>James</from>         <to>Peter</to>         <title>Meeting</title>         <text>Remember our meeting</text>     </message>     <message>         <from>John</from>         <to>Smith</to>         <title>Report</title>         <text>Create sales report</text>     </message> </messages>

This is the file "message.xsl"

<?xml version="1.0" encoding="UTF-8"?> <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"> <body style="font-family:Arial;font-size:12pt;background-color:white"> <xsl:for-each select="messages/message">     <div style="background-color:blue;color:white;padding:4px">         <span style="font-weight:bold">             <xsl:value-of select="from"/>         </span>          - <xsl:value-of select="to"/>     </div>     <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">         <xsl:value-of select="title"/> :         <span style="font-style:italic">              <xsl:value-of select="text"/>         </span>     </div> </xsl:for-each> </body> </html>

This is the result in the browser

XML XSLT browser