Chapter 8. XSLT

Every tradesman's tool case has one tool that is a little more worn than the others. It is the favorite tool, the "go to" tool that gets used when all other tools have failed, or maybe even the first tool for all problems. For XML developers, that tool is often XSLT (eXtensible Stylesheet Language Transformations). XSLT is a templating language that can be used to convert XML into something else. The result of the transformation can be XML, HTML, XHTML, or even plain text or binary. XSLT is a powerful tool and, like many powerful tools, it has a few sharp edges you should avoid. As XSLT is a functional language, it can seem a little alien at first for developers used to procedural languages such as C# or Java. In addition, XSLT has limited support for variables and conditional logic than either of those languages. This chapter shows you how you can use XSLT in your applications and avoid its potential problems. Examples will show how you can use XSLT standalone, or combined with other programming languages and tools.

What Is XSLT?

XSLT is a transformation language for XML. Its purpose is to take a source tree of XML nodes and convert them into a result by using a series of templates or rules. XSLT is itself an XML syntax (see Listing 8-1). The result of an XSLT transformation does not have to be XML, however. The XSLT specification allows the output to be XML, HTML, or text. In addition, you can target some other form of output, perhaps even binary content.

Example 8-1. Sample ...

Get Professional XML 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.