Converting XML To HTML Using ColdFusion And XSLT

<!--- Define the XSL Transformation (XSLT). --->
<cfsavecontent variable="strXSLT">
 
	<!--- Document type declaration. --->
	<?xml version="1.0" encoding="ISO-8859-1"?>
 
	<xsl:transform
		version="1.0"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
		<!---
			Tell the ColdFusion XSLT engine that we are
			going to be producing an HTML document and that we
			want to use indenting.
		--->
		<xsl:output
			method="html"
			indent="yes"
			/>
 
		<!---
			Bind this template to the root of the XML document
			using the "/" match attribute.
		--->
		<xsl:template match="/">
 
			<html>
			<head>
				<title>
					<!--- Output the page title. --->
					<xsl:value-of select="page/title" />
				</title>
 
				<!--- Output meta data template. --->
				<xsl:apply-templates select="page/meta" />
			</head>
			<body>
 
				<h1>
					<xsl:value-of select="page/title" />
				</h1>
 
				<!--- Output primary navigation. --->
				<xsl:apply-templates select="//primarynav" />
 
				<!--- Output page content. --->
				<xsl:apply-templates
					select="page/primarycontent"
					/>
 
			</body>
			</html>
 
		</xsl:template>
 
 
		<!--- Template for HTLM meta data. --->
		<xsl:template match="meta">
 
			<!--- Output met akeywords element. --->
			<xsl:element name="meta">
				<xsl:attribute name="keywords">
					<xsl:value-of select="keywords" />
				</xsl:attribute>
			</xsl:element>
 
			<!--- Output meta description element. --->
			<xsl:element name="meta">
				<xsl:attribute name="description">
					<xsl:value-of select="description" />
				</xsl:attribute>
			</xsl:element>
 
		</xsl:template>
 
 
		<!--- Template for the primary navigation items. --->
		<xsl:template match="primarynav">
 
			<ul id="primarynav">
				<!--- Loop over nav items. --->
				<xsl:for-each select="navitem">
 
					<li>
						<!--- Define the nav link HTML. --->
						<xsl:element name="a">
							<xsl:attribute name="href">
								<xsl:value-of select="@href" />
							</xsl:attribute>
 
							<!---
								Check to see if this link is on.
								If so, then we have to add the
								appropriate class.
							--->
							<xsl:if test="@ison = 'true'">
								<xsl:attribute name="class">
									on
								</xsl:attribute>
							</xsl:if>
 
							<!--- Text of link. --->
							<xsl:value-of select="@text" />
						</xsl:element>
					</li>
 
				</xsl:for-each>
			</ul>
 
		</xsl:template>
 
 
		<!--- Template for primary page content. --->
		<xsl:template match="primarycontent">
 
			<div id="sitecontent">
 
				<!---
					When outputting the page's primary content,
					make sure to DISABLE escaping so that our
					XHTML will come through properly.
				--->
				<xsl:value-of
					select="."
					disable-output-escaping="yes"
					/>
 
			</div>
 
		</xsl:template>
 
	</xsl:transform>
 
</cfsavecontent>
 
 
<!---
	Output the transformed XML page data into an
	HTML formatted web page using XSLT.
--->
#XmlTransform(
	xmlPage,
	Trim( strXSLT )
	)#

For Cut-and-Paste