SDK - Your first WCM XSLT stylesheet

  • KM507251
  • 20-Sep-2008
  • 20-Sep-2008

Archived Content: This information is no longer maintained and is provided "as is" for your convenience.

Reference

Your first WCM XSLT stylesheet

Overview

At the very core of deploying a WCM site is the development of HTML templates coded using XSLT. XSLT is a language for transforming one type XML document to another type of XML document. In WCM it is usually used to transform a WCM XML document into an XHTML document. This article describes the creation of the simplest WCM XSLT style sheet.

Prerequisites

The requirements to test the XSLT style sheet are:

  • a page template (with at least one field, field type not important for this sample),
  • a section,
  • a page.


The best order to create them in is:

  1. XSLT style sheet,
  2. page template,
  3. Section (ensure the correct XSLT style sheet(transformation) is selected in the section publishing),
  4. a default page will be created with section.

Sample XSLT

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:wcm="http://www.towersoft.com/ns/wcm/1.0"
exclude-result-prefixes="wcm">

<xsl:output 
	method="html" 
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" 
	doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />

<xsl:template match="/wcm:wcm">
	<html>
		<head></head>
		<body>
			<h1>Hello world!</h1>
		</body>
	</html>
</xsl:template>
</xsl:stylesheet>

Examination of Sample XSLT

The sample XSLT creates an XHTML page containing the text “Hello world!” allowing us to examine some core XSLT required in any WCM XSL transformation. Things to notice include:

  • The first element must always be the xml declaration.
  • The root element is always the xsl:stylesheet element.
  • the XSLT namespace attribute is required for all XSL transormations.
  • The wcm namespace attribute tells the XSLT to link the prefix wcm with the WCM XML namesspace (http://www.towersoft.com/ns/wcm/1.0)).
  • The xsl:output element sets the outpout method to html (it could potentially be text or xml).
  • The two doctype attributes allow us to choose what sort of HTML to output.
  • The xsl:template element matches the root element in the WCM XML document, this moot in this transformation as it does not go on to refer to any further elements from the WCM XML, however if it did matching the top level means that all future references to the XML only need to be relative (parentElement/childElement not /wcm:wcm/parentElement/childElement).
  • The elements within the xsl:template element are all standard XHTML.