Namespaces and languages

As you’ve probably noticed, we are dealing with three different languages during this process: the input language (in this case, TEI), the language of the output document (in this case HTML), and the language of the XSLT stylesheet itself (which contains elements like template and apply-templates

Within the stylesheet itself, it is important that we keep these languages distinct from each other, so that the processor knows what piece of the tree it is dealing with. We differentiate between the languages using namespaces.

If you do not know about namespaces (or if you feel you could use a refresher), take this time to continue to the next slide for an overview. You can come back to this slide for any additional information that you need.

Each of the languages used (input, output, and XSL) plays a specific role in the stylesheet ecology and gets referenced in a distinctive way.

The output tree, as you can see, doesn’t use a namespace prefix on each element. This is because we have already specified the namespace using the xmlns attribute on xsl:stylesheet (See the blue section on the stylesheet).

The next fairly simple case is the input tree, which also looks as if it’s not getting a namespace in the stylesheet. How are we keeping this separate from the output tree? The trick here is that the input tree is always accessed via the match and select (and similar) attributes. These attributes all access the input tree via XPath, and up at the top, we provided a default namespace for all XPaths (via xpath-default-namespace)

And finally, the stylesheet document has its namespace specified as the XSL namespace (see the bit that says xmlns:xsl=). Since the default namespace of the document is HTML, we must use the the XSL prefix for all the elements we want to use that are in the XSL namespace.

The XSLT Processing Model, slide 9 of 10