Skip Navigation

Center for Digital Research in the Humanities

Presentation of XML documents

The visual presentation of a TEI encoded document requires the use of a style sheet or other conversion program.

The extensible Stylesheet Language for Transformations (XSLT) was developed to transform XML (Extensible Markup Language) encoded documents into new forms.

It is through the transformative capabilities of an XSLT stylesheet that XML documents can achieve their greatest potential.

Presenting XML with XSLT

An XML encoded document by itself is merely a data storage medium that is not intended for direct use.

XML describes the document in just as little or much detail as needed, and a document in XML should only need to be encoded one time. Subsequent changes to the document should be accomplished with stylesheets.

Simply put, XML tells the document what it is, but not what to do, while stylesheets contain instructions about how the XML document should be organized for display.

Example of the presentation process

XSLT and XML

XSLT stylesheets tells the XML document how to function

XSLT permits one to change the structure and appearance of XML data without the need for changing the XML encoding itself

XML documents can be radically altered for different purposes by changing the XSLT stylesheet alone

Also, there may be many XSLT stylesheets for one XML document

XSLT stylesheets can, in addition to reorganizing content, actually add new content to the original XML source document

XSLT stylesheets can complement CSS (Cascading Style Sheets)

Stylesheets permit the markup language to be suppressed from public view

With a stylesheet it is possible to view formatted text without viewing the XML encoding tags

XSLT Stylesheets

XSLT rules are similar to XML rules: XSLT stylesheets must themselves be well-formed XML documents, meaning that tags must be closed, case matters, etc.

The Structure of XSLT

The creation of XSLT stylsheets operates on the principle of "templates". Using a template the designer describes by example, or "matches", the sections of the XML document that are to be displayed and transformed.

XSLT basic steps:

Identify root element
Enter the XSLT version number:
<?xml version="1.0"?>
Enter the latest XSLT namespace:
<xmlns:xsl="http://www.w3.org/1999/XSLT/Transform">

XSLT Template Example:

This is a simplified example of an XSLT template that is used to convert an XML file into an HTML file.

Namespace

XSLT documents refer to a "namespace" which specifies the version of the XSLT rules to which the stylesheet conforms. The latest version of the XSLT namespace is:
<http://www.w3.org/1999/XSL/Transform>. An older version of the rules, now outdated, is:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

XPath

XSLT stylesheets use another XML standard, Xpath, to describe the exact location of the source document that is to be displayed.

Xpath is based on the idea that XML content is arranged like a "document tree" where there is a single root element off of which exist a few, or many, other "nodes".