How to link XSL in XML?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 functionalties enabled. Similarly, there is a way to include or link a xslt stylesheet to display the xml with styles making it more readable.
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>This is my title</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.
The Output
This is my title
This demonstrates the way to include the xslt so it renders
in the browser with a readable format.