Chapter 7. Multiple Documents

For a good many XSLT applications you will find yourself working with different combinations of source, stylesheet, and result documents.

Because numerous development tasks are performed repeatedly, it makes sense to divide your stylesheets into reusable modules. You will also encounter cases where content can be reused, especially when that content takes the form of structured data, or is related to creating common web-page output like menus or footers.

You will also sometimes want to override rules in an existing stylesheet. By importing code into a new stylesheet, you can selectively customize it.

Finally, sometimes you'll need to produce multiple result documents, perhaps dividing a long document into smaller ones, or archiving content in one format while publishing in another.

In this chapter you'll take a look at ways to deal with all three circumstances. You'll learn how to do the following:

  • Create and include modular stylesheets.

  • Override existing stylesheets by importing them into a new one that provides alternative parameters, variables, and template rules.

  • Load multiple XML sources using a single XSLT and XPath function, which will load one or more additional XML sources.

  • Build temporary trees using <xsl:variable>.

  • Create multiple result documents with <xsl:result-document>.

Modular Stylesheets

Writing stylesheet modules to contain frequently used code is a time-saving practice. It is also the case that stylesheets can become quite long and complex, ...

Get Beginning XSLT and XPath: Transforming XML Documents and Data 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.