XML to HTML TRANFORMATION through XSLT
In this article, I will explain XML to HTML transformation through XSLT. Stylsheet helps to convert xml to html view in the browser. The XML document can be serialized (output) by the processor in standard HTML view using XSLT.
XML to HTML TRANFORMATION through XSLT
XSLT (Extensible Stylesheet Language Transformations) Stylesheet transforms XML to HTML.
To attach external style sheets to XML by means of adding the xml-stylesheet processing instruction like this:
<?xml-stylesheet type="text/xsl" href="sample.xsl"?>
sample.xml
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="sample.xsl"?>
<booK>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<publisher></publisher>
<price>44.95</price>
<publish_date>2012-06-23</publish_date>
<description>An in-depth look at creating applications with XML.</description>
</booK>
Sample.xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>Sample</title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="title">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="publisher">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="price">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="publish_date">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="author">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="description">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
</xsl:stylesheet>
Please find attachment of the sample.xml and sample.xslt files.