The XSLT processing model: processing more children

Next we start processing the children of body Note that there are two templates here that look somewhat similar. This example is a little bit more complicated than the ones we’ve dealt with before, but the same principle we’ve been discussing applies here. In both cases, the first part of the value for match (before the slash) indicates a context for the element. In the first case the context is body So the matched element is the head that is the child of body In the second example, the match value indicates the head that is the child of div The syntax here is XPath (a way of navigating the document tree which will be introduced in the next tutorial in this primer).

What if we had wanted to just match any head in the input document? In that case, we would have simply used a template that matched head on its own. Instead of providing context (i.e. the specifications for body and div), we would have simply made the value on match for xsl:template equal to head.

However, it may be useful to think about why we would distinguish between two different locations for head As you can see from the output, the two different TEI head elements were converted into the HTML elements of h1 and h2 If you are familiar with HTML, you probably know that h1 and h2 usually display differently. The numbered h elements in HTML typically indicate a hierarchy of headings, ie. h2 is a sub-heading of h1 In this case, we are allowing our document heading (the TEI head that is the child of body) to be displayed differently than our chapter headings. There are many instances in which we would want elements to function differently depending on their context. For example, we may want the persNames in our structured personography to display differently than the persNames in the body of our text. Providing context allows us to differentiate between elements depending on their context.

Since the xsl:apply-templates element is present in both head templates and neither element has any children, the processor simply spits out the text in those elements in the output document.

The XSLT Processing Model, slide 6 of 10