Convert jQuery XML Documentation To HTML / PDF Using ColdFusion And XSLT

<!---
	Read in the jquery XML documentation. Unfortunately, I
	had a real hard time trying to find the most up-to-date
	XML docs, so I had to go with the quite outdated 1.1.
--->
<cffile
	action="read"
	file="#ExpandPath( './jquery-1.1.xml' )#"
	variable="xmlDocumentation"
	/>
 
 
<!---
	Create the XSLT document that will transform out jQuery
	XML into an XHTML web page.
--->
<cfxml variable="xmlTransform">
 
	<!--- 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">
 
		<xsl:output
			omit-xml-declaration="yes"
			method="xml"
			version="1.0"
			encoding="UTF-8"
			doctype-public="-//W3C//DTD XHTML 1.1//EN"
			doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
			indent="yes"
			/>
 
 
		<!--- Match the root-level node. --->
		<xsl:template match="/">
 
			<html>
			<head>
				<title>jQuery Documentation</title>
				<cfinclude template="jquery_stylesheet.txt" />
			</head>
			<body>
 
				<h1>
					jQuery 1.1 Documentation
				</h1>
 
				<!---
					Apply templates to direct descendents of the
					root node (should be the CAT nodes).
				--->
				<xsl:apply-templates />
 
			</body>
			</html>
 
		</xsl:template>
 
 
		<xsl:template match="cat">
 
			<h2>
				<!---
					Check to see if this category is a
					sub-category. If so, we have to add the
					conditional class attribute.
				--->
				<xsl:if test="../../cat">
					<xsl:attribute name="class">
						<xsl:text>sub</xsl:text>
					</xsl:attribute>
				</xsl:if>
 
				<xsl:value-of select="@value" />
			</h2>
 
			<!---
				Apply templates to all direct descendents of the
				current category node.
			--->
			<xsl:apply-templates />
 
		</xsl:template>
 
 
		<xsl:template match="method">
 
			<h3>
				<xsl:value-of select="@name" />
 
				<!--- Output the named params. --->
				<span class="params">
					<xsl:text>( </xsl:text>
					<xsl:for-each select="params">
 
						<xsl:value-of select="@name" />
						<xsl:if test="position() != last()">
							<xsl:text>, </xsl:text>
						</xsl:if>
 
					</xsl:for-each>
					<xsl:text> )</xsl:text>
				</span>
			</h3>
 
			<div class="methodbody">
 
				<xsl:apply-templates select="desc" />
 
				<xsl:if test="params">
 
					<h4>
						<xsl:text>Parameterss</xsl:text>
					</h4>
 
					<xsl:apply-templates select="params" />
 
				</xsl:if>
 
				<xsl:if test="options">
 
					<h4>
						<xsl:text>Hash Options</xsl:text>
					</h4>
 
					<xsl:apply-templates select="options" />
 
				</xsl:if>
 
				<xsl:if test="@type">
 
					<h4>
						<xsl:text>Returns</xsl:text>
					</h4>
 
					<p>
						<xsl:value-of select="@type" />
					</p>
 
				</xsl:if>
 
				<xsl:apply-templates select="examples" />
 
				<xsl:if test="see">
 
					<h4>
						<xsl:text>See Also</xsl:text>
					</h4>
 
					<p>
						<xsl:for-each select="see">
							<xsl:value-of select="." />
							<br />
						</xsl:for-each>
					</p>
 
				</xsl:if>
 
			</div>
 
		</xsl:template>
 
 
		<!---
			This template will match params or options
			which are formatted in the same way.
		--->
		<xsl:template match="params|options">
 
			<p>
				<xsl:if test="@name != ''">
					<strong>
						<xsl:value-of select="@name" />
					</strong>
					<xsl:text>: </xsl:text>
				</xsl:if>
 
				<xsl:if test="@type != ''">
					<em>
						<xsl:value-of select="@type" />
					</em>
					<xsl:text>: </xsl:text>
				</xsl:if>
 
				<xsl:value-of select="." />
			</p>
 
		</xsl:template>
 
 
		<xsl:template match="desc">
 
			<p class="description">
				<xsl:value-of select="." />
			</p>
 
		</xsl:template>
 
 
		<xsl:template match="examples">
 
			<h4>
				<xsl:text>Example</xsl:text>
			</h4>
 
			<xsl:if test="desc">
				<p>
					<xsl:value-of select="desc" />
				</p>
			</xsl:if>
 
			<xsl:if test="code">
				<p>
					<xsl:value-of select="code" />
				</p>
			</xsl:if>
 
			<xsl:if test="before">
				<h5>
					<xsl:text>Before</xsl:text>
				</h5>
 
				<p>
					<xsl:value-of select="before" />
				</p>
			</xsl:if>
 
			<xsl:if test="result">
				<h5>
					<xsl:text>Result</xsl:text>
				</h5>
 
				<p>
					<xsl:value-of select="result" />
				</p>
			</xsl:if>
 
		</xsl:template>
 
	</xsl:transform>
 
</cfxml>
 
 
<!--- Output the jQuery XML documention transformation. --->
<cfset WriteOutput(
	XmlTransform(
		xmlDocumentation,
		xmlTransform
		)
	) />

For Cut-and-Paste