Documentation Center

Example XSLT stylesheet

The following example XSLT stylesheet show how your XSLT might interact with Content Manager.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
	xmlns:script="urn:script">

	<msxsl:script language="JScript" implements-prefix="script">
		function Test()
		{
			return "Hello";
		}
	</msxsl:script>

	<!-- Custom parameter -->
	<xsl:param name="testParam">default value</xsl:param>
	<!-- SDL Tridion defined parameters -->
	<xsl:param name="tcm:Publication" />
	<xsl:param name="tcm:ResolvedItem" />

	<!-- Produce HTML output -->
	<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" />

	<xsl:template match="/">
		<h2>XSLT Component Template output:</h2>
		<h3>Custom Parameters:</h3>
		<table border="1">
			<tr>
				<td>Name</td>
				<td>Value</td>
			</tr>
			<tr>
				<td>testParam</td>
				<td><xsl:value-of select="$testParam"/></td>
			</tr>
		</table>
		<h3>Structure of input document:</h3>
		<!-- Write elements as an ordered list -->
		<ol>
			<xsl:apply-templates />
		</ol>
		<h3>Context Publication:</h3>
		<!-- Write the properties of the Publication as an ordered list -->
		<ol>
			<xsl:apply-templates select="$tcm:Publication/*" />
		</ol>
		<h3>Context Page:</h3>
		<!-- Write the properties of the Content Manager item being transformed as an ordered list -->
		<ol>
			<xsl:apply-templates select="$tcm:ResolvedItem/*" />
		</ol>
		<h3>Result of test script:</h3>
		<xsl:value-of select="script:Test()" />
	</xsl:template>

	<xsl:template match="*">
		<li>
			<xsl:value-of select="name(.)" />
			<!-- Write attributes as a bullet list -->
			<ul>
				<xsl:apply-templates select="@*" />
			</ul>
			<!-- Write subelements as an ordered list -->
			<ol>
				<xsl:apply-templates />
			</ol>
		</li>
	</xsl:template>

	<!-- Write an attribute as its name and its value. -->
	<xsl:template match="@*">
		<li>Attribute: "<xsl:value-of select="name(.)"/>". Value: "<xsl:value-of select="string(.)"/>".</li>
	</xsl:template>

	<!-- Write a text node 'as is'. -->
	<xsl:template match="text()">
		<li>Text node: "<xsl:value-of select="string(.)"/>".</li>
	</xsl:template>

</xsl:stylesheet>