Chapter 14. Alternative Stylesheets

Up to this point, the XSLT stylesheets you’ve seen have had the stylesheet element as their document element and have been separate documents from the source documents. This chapter will show you several alternatives to this model.

The first alternative is called a literal result element stylesheet. (I’ll sometimes call it a literal stylesheet in this book, just to be brief.) This simplified stylesheet (as XSLT 2.0 calls it), in essence, has a literal result element as its document element rather than stylesheet. You can read more about this kind of stylesheet in Section 2.3 of the XSLT specification.

The second alternative is called an embedded stylesheet, which embeds an XSLT stylesheet in the same document that it transforms. It’s a sort of self-contained source and stylesheet combined. This requires the use of the id attribute on the stylesheet element. See Section 2.7 of the XSLT specification for more information on embedded stylesheets.

In addition, this chapter will discuss the namespace-alias element. This element allows you to swap a namespace aliased in a stylesheet with a different one in the result. You’ll also see how to exclude unneeded namespaces with the exclude-result-prefixes attribute.

The opening example shows you how to use a literal stylesheet.

A Literal Result Element Stylesheet

Tired of the same old stylesheet? You can try a literal result element stylesheet. The original design idea behind a literal stylesheet was to provide ...

Get Learning XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.