XSLT

From DARC (Digital Archive Research Collective)
Jump to navigation Jump to search

What is XSLT?

XSLT stands for Extensible Stylesheet Language for Transformations. It is a method (or a series of rules) for converting data from one XML language to another. With an XSLT stylesheet, you can “transform” a TEI document into HTML, which is then visible on a web browser.

In most basic terms, XSLT works by mapping one set of standards into another. In this case, we map TEI into HTML by turning each TEI element into its equivalent in HTML. For example, we might take a <head> element in TEI (which encodes headings) and turn it into a <h1> element in HTML (which indicates a first-level heading). Or, we might take <line> (for a line of text) in TEI, and turn it into <p> (for paragraph) in HTML. The code for these instructions in the XSLT file would appear like so:

<xsl:template match=”head”> <h1><xsl:apply-templates/></h1> </xsl:template> <xsl:template match=”line”> <p><xsl:apply-templates/></p> </xsl:template> Don’t worry if this code looks unfamiliar. All it does is take everything within the <head> and <line> tags in TEI and places it inside <h1> and <p> tags, respectively. All XSLT files contains a list of such instructions, which transfer information from a TEI format into an HTML format.

Who would want to use it?

XSLT will allow you to transform XML/TEI into other formats, such as for web publishing. It is often used in conjunction with projects based on Text Encoding Initiative (TEI). For more information, check out our TEI Wiki page).

How do I get access to it?

You can write stylesheets in any text editor. However, since the language is challenging, most people just use existing stylesheets on their own project. Two popular programs that contain pre-existing stylesheets are oXygen and TEI Boilerplate.

[1], an XML editor, is not free, but it’s by far the best XML editor out there. Running a transformation with oXygen is super easy because the application allows you to run the “Transformation Scenario” right then and there. To get oXygen, you have to download the program (you can get a free trial version for 30 days, and/or obtain a yearly academic license for about $100). To run the transformation, first open your TEI files in oXygen. Then, on the right side of the application window, you’ll see a panel that reads “Transformation Scenario.” You’ll want to check off the appropriate scenario, which is “TEI P5 XHTML.” This option indicates that you want to process your TEI for an HTML output. Then, you’ll press the red play button at the top of the window. A few seconds later, your browser will open the transformed TEI file. It should look something like the image of the diplomatic transcription above.

TEI Boilerplate. This is by far the easiest, free way to transform your TEI for the web. Developed by a team at Indiana University, TEI Boilerplate is meant to be lightweight and relatively quick to implement. To use the editor, first download the TEI Boilerplate files to your computer. Then, add your TEI files to the teibp/content directory of TEI Boilerplate. Then, open your TEI files in a text editor and add a piece of processing instructions to the top of each TEI file. It should go after the XML declaration and before the first <TEI> element: <?xml-stylesheet type=”text/xsl” href=”teibp.xsl”?> This piece of code indicates that the XML should be processed by the TEI Boilerplate XSLT stylesheet. After adding it to your TEI file, you can open that file in the browser to see the transformation. With my Dorian Gray passage, the transformation looks like this:

Where can I get more help with it?

From Filipa Calado’s blog post on Tagging the Tower, TEI for the Web,” provides a good general overview of what XSLT can do.

To learn more about XSLT in general, refer to the following resources. These excellent tutorials, articles, and slideshows are only a starting point, but they should get you well on your way to running (and customizing!) your own TEI transformations.

What are some projects built with it?

The Shelley-Godwin Archive, containing the manuscripts of Percy Shelley, Mary Shelley, William Godwin, and Mary Wollstonecraft, publishes their project files (including XSLT) on github.

When you feel ready to implement XSLT in your project, check out the TEI Consortium XSLT stylesheets on github.