A more detailed example

Let’s take a closer look at an example with more elements to transform. This slide will be useful to come back to as we continue on throughout this tutorial, but let’s have an introductory look now. We’ll add more details later.

Looking at the templates themselves: You will notice that each template in the stylesheet is represented by an <xsl:template> element. The @match attribute tells us what element on the input tree we are dealing with. This attribute essentially specifies a condition that has to be met: "if we find the "x" element, perform this transformation." It is important to note that the value of @match specifies a location on the tree. This means that we can provide different rules for elements when they occur in different contexts. We can treat a <persName> that occurs in <body> differently than we treat a <persName> that occurs in the <teiHeader>. We will learn how to specify the context of the element later in this primer.

Now that we know how the <xsl:template> interacts with the input tree, we should ask: what does the template do? Inside these templates, there is a snippet of the output tree (in this case, html). There is also the <xsl:apply-templates> element, which essentially indicates to the stylesheet: don’t stop here! go back and process the children or spit out text! Another, more precise way of interpreting this element is to say "go ahead and process any children of the matched element." Without this instruction, the stylesheet logic reaches a dead end.

A Gentle Introduction to XSLT slide 05 of 8
© 2012 Syd Bauman, Julia Flanders, and the Women Writers Project This TEI-encoded XML file is available under the terms of the Creative Commons Attribution-ShareAlike 3.0 (Unported) license.