- A Little Background
- XSLT - XSL Transformations
- XSL-FO: XSL Formatting Objects
- The W3C Specifications
- XSLT Versions
- About This Article
XSLT - XSL Transformations
XSLT lets you work with the contents of XML documents directly. For example, you might have a huge XML document that holds all baseball statistics for the most recent baseball season, but you might be interested only in the statistics for pitchers. To extract the data on pitchers, you can write your own program in Java, Visual Basic, or C++ that works with XML parsers, which are special software packages that read XML documents and pass all the data in the document, piece by piece, to your own code. You can then write a new XML document, pitchers.xml, that contains only data about pitchers.
That way of doing things works, but it involves quite a bit of programming, as well as the investment of a lot of time and testing. XSLT was invented to solve problems such as this. XSLT can be read by XSLT processors, which work on XML documents for you; all you have to do is create an XSLT stylesheet that specifies the rules you want to apply to transform one document into another. No programming needed - and that's what makes it attractive to many people, even experienced programmers. For the baseball example, all you'd have to do is write an XSLT stylesheet that specifies what you want to do, and let the XSLT processor do the rest.
Besides transforming one XML document into another XML document, you can also transform XML documents into other types of documents, such as HTML documents, rich text (RTF) documents, XSL-FO documents, and others. You can also transform XML documents into other XML-based languages, such as MathML, MusicML, VML, XHTML, and more, all without programming.
In many ways, XSLT can function like a database language such as SQL (Structured Query Language, the famous database-access language), because it enables you to extract the data you want from XML documents, much like applying an SQL statement to a database. Some people even think of XSLT as the SQL of the Web, and if you're familiar with SQL, that gives you some idea of the boundless horizons available to XSLT. For example, using an XSLT stylesheet, you can extract a subset of data from an XML document, create an entire table of contents for a long document, find all elements that match a specific test - such as customers in a particular ZIP code - and so on. And you can do it all in one stylesheet!