TipsCow

How To Include Xsl in Xml

by aditya bajaj on October 26, 2012 | Last Updated: August 11th, 2013


You can refer a css or a javascript file in an html page so whenever that html page is opened in a browser, it renders with the styles and the functionalities enabled. Similarly, this article teaches How To Include Xsl in Xml. There is a way to include or link a xslt stylesheet to display the xml with styles making it more readable.

how to Include Xsl in Xml

How To Include Xsl in Xml

The following xsl is a very basic code sample to demonstrate the xslt include in xml:

The XSL

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="mytext">
<h1>
<xsl:value-of select="myhead" />
</h1>
<p>
<xsl:value-of select="mypara" />
</p>
</xsl:template>
</xsl:stylesheet>

The XML

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="style.xslt"?>
<mytext>
<myhead>Demo: How To Include Xsl in Xml</myhead>
<mypara>This demonstrates the way to include the xslt so it
 renders in the browser with a readable format.</mypara>
</mytext>

Save the above XML as data.xml and the xsl code as style.xslt. And then see the following output in the browser.

To view in browser, select the data.xml file and right click then select Open with> Internet Explorer (or your favorite browser)

The Output

Demo: How To Include Xsl in Xml

This demonstrates the way to include the xslt so it renders
in the browser with a readable format.

Leave a Reply

Your email address will not be published. Required fields are marked *