XSL Stylesheet

The XSL stylesheet is where the actual page that will be displayed is constructed.  The XML document provides the "raw material" or data out of which the page will be built, but the order in which components are included, their format and spacing, and other similar matters are defined by the stylesheet.

Constructing a page using an XSL stylesheet and an XML document requires a parsing and transformation program.  Understanding the several steps and the order in which each operation is carried out is essential.  For a discussion, with useful graphical illustrations, see Day's "Hands-on XSL" tutorial, referred to above.  Discussions of several such program appear in subsequent sections.  here, the focus is on the XSL stylesheet, itself.

Several notable features are shown in bold in the example XSL stylesheet, below.

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>addresss entry xsl stylesheet</TITLE>
</HEAD>
<BODY>
<xsl:apply-templates/>
</BODY>
</HTML> 
</xsl:template>

<xsl:template match="entry">
<HR/>
<xsl:apply-templates select="name_"/>
<xsl:apply-templates select="address_"/>
</xsl:template>

<xsl:template match="name_"> 
<p>
<xsl:value-of select="name_first"/>
<xsl:value-of select="name_middle"/>
<xsl:value-of select="name_last"/>
</p>
</xsl:template>

<xsl:template match="address_"> 
<p>
<xsl:value-of select="address_1"/><br/>
<xsl:value-of select="city"/>,
<xsl:value-of select="state"/>,
<xsl:value-of select="zip"/>
</p>
</xsl:template>

</xsl:stylesheet>

When the XSL stylesheet, above, is combined with the XML document, discussed in another section, the following HTML is generated.

<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>addresss entry xsl stylesheet</TITLE>
</HEAD>
<BODY>
		
<HR>
<p>John B. Smith </p>
		
<p>100 Evans Ct.<br>Carrboro, 
NC,
27510</p>
	
</BODY>
</HTML>

You can also see these amazing results rendered.