My First ColdFusion XML / XSLT Example

<!--- Define the ColdFusion XML document object. --->
<cfxml variable="xmlData">
 
	<messages>
		<message id="1">
			<text>Hello World</text>
		</message>
		<message id="2">
			<text>Eating kittens is just plain wrong!</text>
		</message>
		<message id="3">
			<text>Honk if you love justice!</text>
		</message>
	</messages>
 
</cfxml>
 
 
<!--- 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">
 
		<!---
			Bind this template to the root of the XML document
			using the "/" match attribute.
		--->
		<xsl:template match="/">
 
			<html>
			<head>
				<title>My ColdFusion XSLT Hello World</title>
			</head>
			<body>
 
				<h1>
					Messages
				</h1>
 
				<!--- Loop over each message node. --->
				<xsl:for-each select="//message">
 
					<p>
						<!---
							Output the ID of the current
							contextual message node.
						--->
						<xsl:value-of
							select="@id"
							/>:
 
						<!---
							Get the Text value of the descendent
							TEXT node of the current contextual
							message node.
						--->
						<xsl:value-of
							select="text"
							/>
					</p>
 
				</xsl:for-each>
 
			</body>
			</html>
 
		</xsl:template>
 
	</xsl:transform>
 
</cfsavecontent>
 
 
<!--- Output the transformed XML document. --->
#XmlTransform(
	xmlData,
	Trim( strXSLT )
	)#

For Cut-and-Paste