What is XML style sheet?

XSL is a language for expressing style sheets. An XSL style sheet is, like with CSS, a file that describes how to display an XML document of a given type. XSL shares the functionality and is compatible with CSS2 (although it uses a different syntax). It also adds:

Styling requires a source XML documents, containing the information that the style sheet will display and the style sheet itself, which describes how to display a document of a given type.


XSL Hello World Example

XML document containing 'Hello World' data.

	<?xml version="1.0"?>
	<?xml-stylesheet type="text/xsl" href="helloworldXSL.xsl"?>
	<prompt>
		<greeting>Hello World</greeting>
	</prompt>

XSL style sheet with instruction to transform, and format, to HTML.


	<?xml version="1.0"?>
	<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:template match= "/">
		<html>
		 <body>
		    <xsl:for-each select="prompt">
			<div align="center">
			  <h1>
			    <xsl:value-of select="greeting" />
			  </h1>
			</div>
		    </xsl:for-each>
		 </body>
		</html>
	</xsl:template>
	</xsl:stylesheet>

HTML output produced by Parser.


	<html>
	  <body>
		<div align="center">
			<h1>Hello World</h1>
		</div>
	  </body>
	</html>