XSLT Stylesheet

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

XSLT - Stylesheet Reference

This lesson will teach you how to link your XML document to your XSLT stylesheet. This is the magic step that connects your XML to a XSLT file! If you do not follow the steps in this lesson to link your files, XSLT will not work properly.

XSLT - xml-stylesheet

xml-stylesheet is a special declaration in XML for linking XML with stylesheets. Place this after your XML declaration to link your XML file to your XSLT code.

xml-stylesheet has two attributes:

  1. type: the type of file being linked to. We will be using the value text/xsl to specify XSLT.

  2. href: the location of the file. If you saved your XSLT and XML file in the same directory, you can simply use the XSLT filename.

If you have been following along with this tutorial, your XSLT file should be named class.xsl. Make sure that both your XSLT and XML file are in the same directory.

XML Code:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="class.xsl"?>
<class>
	<student>Jack</student>
	<student>Harry</student>
	<student>Rebecca</student>
	<teacher>Mr. Bean</teacher>
</class>

Save this XML file as class.xml, and your XML file will be linked to your XSLT file. After you have finished this step, you can continue learning XSLT!