XSL (eXtensible stylesheets language) contain XSLT commands used to transform the contents of XML documents into a desired output; for example, HTML, XHTML, and PDF. Within OU Campus, an implementation will have several individual XSL files that are used for various purposes. For XML/XSL implementations, the PCF will have at least one pcf-stylesheet declaration that determines the XSL that will be used to initialize the transformation of the content. One XSL might also import one or more XSLs. The XSLs are used to transform the content contained in the pcf file, which is an XML file, into the style, structure, and data that will be used in the final output. This most frequently includes HTML structure as pages are frequently output to HTML, as well as including links to the CSS, JavaScript, include, and any other supporting files that are used. 

XSL tranformations uses declarations and XPath to locate specific structures and do something with the content or the with the content and structure. 

From an editing standpoint, XSLs are edited on the staging server and do not need to be published. Changes are immediate and the change in the transformation of the content can be seen by re-previewing a page or otherwise refreshing the mode that is being used. 

The Process

The process of creating XSL stylesheets and XML content can seem daunting at first, but done properly the results can be quite powerful and rewarding. To begin the process, start with a simple XML document that requires styling. This XML file should contain all of the content that the final page will display and have a file extension of PCF (which will classify it as a Publish Control File). If working within a currently live implmentation or workshop, an entire directory can be copied or a single page file can be copied and used to test with so that erronous changes will not effect a live page. Also, commit a version of the XSL, before performing extensive editing, as it may be necessary to revert to a previous version. Once such a document is in place, the content portion of the XML/XSLT combination is complete. The look and feel of the content will be supplied by an XSL stylesheet. Much like an HTML document references a CSS file to provide formatting, an XML document references an XSL stylesheet to provide the structure for the content and the processing of the formatting that visitors will see.

PCF Example - faculty-directory.pcf

Download Source (Zip file)

XSL Stylesheet Example - faculty-directory.xsl

Download Source (Zip file)

PCF Stylesheet Declarations

The pcf-stylesheet is used to call an XSL stylesheet from the PCF:

<?pcf-stylesheet path="/faculty-stylesheet.xsl" extension="html"?>

Download the PCF example, open it in a text editor, and notice the prologue at the top of the file.

For more information about the attributes and usage of this processing instruction, please visit the PCF (Publish Control File) Overview page.

Styling XML Content with XSLT

Once the PCF file references an XSL, the next step is to start structuring how the XML content should be displayed and formatted. This is accomplished that through the use of the XSL statements and some XPath values similar to the following:

<xsl:value-of select="document/title" />
<xsl:copy-of select="document/content/node()" />

For a complete reference of the available XSL elements, visit the XSL Reference page.

Combining XML/XSLT to create HTML

The next step is to publish the page. Unless specifically coded otherwise, the preview of a page will also render a transformation. 

The Advanced XSL section includes a topic with more advanced information about XSL.