Last updated: July 8, 2019
XSL: Learn the Technologies for Changing and Rendering XML
XSL ( Extensible Stylesheet Language ) is a styling language for XML documents.
Most often when someone is referring to XSL, they are referring to XSLT or XSL-FO. But it also includes XPath and XQuery.
In this guide, we will discuss all of these tools, because without them, XML is really just a simple database.
HTML was designed primarily to present human-readable content on a screen, in a web browser. XML was designed to store and transfer arbitrarily structured content, primarily for consumption by an application, and frequently for presentation on a screen.
But what are you supposed to do if you want to present your XML not on a screen but on printed paper, in a book, catalog, or brochure? Or as a PDF approximation of those formats?
XSLT stands for Extensible Stylesheet Language Transformations, and is a part of XSL — along with XSL-FO, XPath, and XQuery.
The purpose of XSLT is to provide a language that can specify how to transform an XML document into another document. XSLT can be used to transform XML into another XML with a different document type definition or schema.
It can also be used to transform XML into HTML or into an XML Formatting Objects document.
General XSL and XML Guides and Tutorials
- XSL Video Tutorial – XSL Basics covers XSL, XSLT, and XSL-FO in detail, with examples.
- The Skew.org XML & XSLT Resources has a list of links to example XSL documents, along with some helpful resources and tools.
- XML Resources and Validators: learn all about XML itself.
- XSLT Tutorial is one of the most popular ways to learn the basics of XSLT on the web.
- Introduction to XSLT is a detailed technical tutorial from IBM DeveloperWorks.
- How to Transform XML is the beginning of a multi-part tutorial on XSLT, explaining how to use the language in detail.
- XSLT Tutorial – Basics is an introductory, but fairly lengthy and detailed, tutorial explaining the purpose of XSLT and showing how to do relatively simple transformations from XML to HTML.
- Essential XSLT is an excerpt from Steven Holzner’s out of print 2001 book, Inside XSLT.
- XML and XSLT is a short introduction to XSLT, showing a simple (but interactive) XSLT transformation.
- How XSLT Works is an excerpt from XSLT 1.0 Pocket Reference (2005), by Evan Lenz. This is more technical tutorial than many of the other introductory pages, with lots of detailed programming information.
- XSLT Tutorial: Advanced Features covers variables, keys, conditionals, and the difference between push and pull processing. This tutorial is from the David Birnbaum’s Digital Humanties site, so the examples are drawn from XML documents relevant to humanities research.
- What is XSLT? is a fairly extensive tutorial from O’Reilly that covers the XML background, related specifications, and has in-depth information on XSLT.
- XSLT Introduction walks you through each aspect of the XSLT language, with a focus on programming capabilities.
- XSLT Overview from Tutorials Point gives a high-level look at how XSLT is used.
- Transforming XML Data with XSLT is a Java-focused tutorial on the language.
- XSLT 1.0 and XPath 1.0 is a free 8-part tutorial on using XSLT. This is based on a more in-depth premium course with video content, which you can access from the same page.
- Scott Penrose’s XSLT Tutorial is a very practical introduction to XSLT that quickly deals with common misconceptions and questions, and provides great examples along with instructions about how to use the most popular XSLT tools.
- XSLT Tutorial is a beginner’s guide to XSLT and XML.
- How to Create Static HTML Website With Navigation Using XSLT is a practical tutorial on transforming XML to HTML.
- Libxslt Tutorial explains how to use the libxslt C library to transform an XML document into HTML.
- XSLT Tutorial from ActiveState explains how to work with XSLT in the Komodo IDE.
- XSL Languages provides an overview of how XSLT works together with XSL-FO, XPath, XQuery, XML, and other markup languages.
- XML and XSLT Tutorial for Dreamweaver explains how to import an XML document into Dreamweaver, transform it with XSLT, and prepare it for web publishing.
- Transforming XML with XSL describes how to use XSLT to import XML documents into InDesign.
Additional XSLT Learning Materials
- Mozilla Developer Network’s XSLT reference is extensive. It includes a detailed reference on XSLT, tutorials on basic transformations, tips on browser tooling, helpful links, and more.
- XSLT Questions and Answers is a really helpful selection of XSLT-related FAQ.
- XSLT Transformations in Oracle Service Bus explains how XSLT works in OSB. Even if you don’t use OSB, this tutorial gives a good insight into how XSLT is used programmatically within a system to serve enterprise document formatting needs.
- Tools for XSL is an opinionated list of XSL authoring, editing, parsing, and transformation tools, with commentary.
- XMLUrlResolver: Using Embedded XSLT Resources in C# explains an advanced technique for including XML documents into other documents.
- XSL Transformations (XSLT) is the original 1.0 W3C Recommendation on the language.
- XSL Transformations (XSLT) Version 2.0 is the current W3C specification.
- XSL Transformations (XSLT) Version 3.0 is the official W3C recommendation on the latest version of XSLT. As if this writing, XSLT 3.0 is still a Candidate Recommendation, which means it hasn’t been formally adopted yet.
- XSLT 1.0 & XPath 1.0 Quick Reference is a print-ready PDF of a pocket reference you can fold-up and take with you anywhere.
- The Extensible Stylesheet Language Family (XSL) is an index of XSL-related resources from the W3C.
Tools for Working With XSLT
- Transform XML with XSLT is an online XML transformer.
- Online XSLT Test Tool runs XSLT Transformations on XML online. Also includes examples documents for seeing how transformations work.
- Altova MapForce is a desktop UI application that lets you place to XML Schema or DTD models side-by-side and map content from one to the other, automatically generating your XSLT for transforming from one to the other.
- XSLT Standard Library is a set of XSLT tools and templates, written in XSLT itself.
- The oXygen XML Editor provides excellent support for XSLT authoring, editing, and debugging.
- Xalan-C++ is an Open Source XSLT processor from Apache Software Foundation.
- EditiX is a cross-platform XSLT editor and debugger.
- Gulp-Xslt is an XSLT transformation plugin for Gulp.
- Altova’s XMLSpy supports XSLT 1.0 and 2.0.
- SAXON is an XSLT and XQuery processor.
- Xmplify XML Editor for Mac OS X has good support for XSLT.
- Learning XSLT (2003), by Michael James Fitzgerald, is a practical guide to XSLT intended for experienced developers who haven’t worked with XSLT or XPath previously.
- XSLT 1.0 Pocket Reference (2005), by Evan Lenz, is a handy book to have on your desk (or in your pocket) if you use XSLT regularly.
- XSLT and XPath On The Edge (2001), by Jeni Tennison, is not an introductory text on XSLT. Rather, it is a practical guide to implementing XSLT in the real world, with lots of practical solutions to common (and not so common) problems.
- XSL: The Personal Trainer for XSLT, XPath and XSL-FO (2015), by William Stanek, is really a “trainer,” offering a series of practical examples to work through for improving your XSL skills.
- Beginning XSLT 2.0: From Novice to Professional (2005), by Jeni Tennison, is an introductory book that starts with HTML and walks the reader through an understanding of XML and then focuses on how XSLT works.
- XSLT For Dummies (2002), by Richard Wagner, is a great book on the subject and, like most of the “for Dummies” books, covers the material in an engaging, straightforward manner.
- XSLT Programmer’s Reference 2nd Edition (2001), by Michael Kay, is a very popular desk reference, considered essential by many XSLT programmers.
- Special Edition Using XSLT (2002), by Michael Floyd, covers XSLT basics, the relationship of XSLT to XSL-FO, and shows how XSLT can be used to generate a wide range of formats including SVG and PDF.
- Beginning XSLT and XPath: Transforming XML Documents and Data (2009), by Ian Williams, covers the basics but also has a focus on data-driven XML work for programmatic use.
- Sams Teach Yourself XSLT in 21 Days (2002), by Michiel Van Otegem, is one of the most popular tutorial books for learning XSLT.
- XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application (2001), by Westy Rockwell, is a highly practical book for people who work with XML and XSLT in Java.
- XSLT Cookbook: Solutions and Examples for XML and XSLT Developers (2005), by Sal Mangano, provides a number of ready-made examples and documents covering many common XSLT use cases.
- Mastering XSLT (2002), by Chuck White, is an advanced book for developers who already understand XSLT and want to dive into the deep end.
- XSLT, 2nd Edition (2008), by Doug Tidwell, is a detailed reference and tutorial on XSLT 2.0.
- XSLT Jumpstarter: Level the Learning Curve and Put Your XML to Work (2015), by David James Kelly, is an example-driven book designed to get developers up to speed on XML and XSLT quickly.
Why You Need XSLT
If you work with XML documents, and need a way to translate in and out of multiple formats, you should spend some time learning the ins and outs of XSL & XSLT.
HTML has virtually no support for paginated content, and non-HTML versions of XML provide no styling information at all. You can use a print-only CSS stylesheet, but that gives only rudimentary control over the print layout.
The solution starts with the relatively underused standard with huge potential, XSL-FO.
How Does XSL-FO Work?
If you are used to HTML and CSS, XSL-FO might seem a little weird. One of the most important ideas with HTML+CSS is separation of content from styling. The HTML document contains all the content, ideally without any styling or presentational information; the CSS sheet provides styling and presentation.
XSL-FO is more like a TeX/LaTeX, PostScript or Microsoft Word format — it is a page-layout format that contains both the content and the styling. An XSL-FO (or
.fo ) file can be printed directly with a FO Processor.
This doesn’t break the separation of concerns, though. Typically, one does not author
.fo files directly. The standard method is to produce XML or (X)HTML first, either by hand or programmatically (for example, out of a database), and the use XSLT to transform the XML into XSL-FO. XSL-FO can then be consumed by an FO Processor, and turned into printed material for distribution.
XSL-FO, along with the entire XML production chain, is a highly useful tool when you have content that has to be repurposed for different media. The most common use-case is inventory information that has to be displayed in catalogs, brochures, online stores, signage, labels, packaging, and several other formats, all from a single source.
- XSL-FO Tutorial is an in-depth tutorial that covers XSL, XSLT, and XSL-FO in detail, with examples.
- XSL Formatting Objects is a highly-technical tutorial that explains how XSL-FO works and how to use it, with lots of code samples and diagrams to aide understanding.
- What is XSL-FO? is the online version of the first few chapters of Practical Formatting Using XSL-FO by G Ken Holman, an excellent book which is unfortunately no longer in print. (The follow-up, Definitive XSL-FO is still available.)
- Introduction to XSL-FO is a good entry-level explanation of XSL-FO and XML printing.
- A Gentle Introduction to XSL-FO bills itself as “a place to start,” and it is. This is a good introduction if you aren’t highly technical, don’t know a lot about XML, but still need to get a handle on XSL-FO.
- Using XSL-FO, from Sams Teach Yourself XML in 21 Days provides a practical explanation of how XSL-FO is typically used in real life.
- How to Develop Stylesheets Transformations for XML to XSL-FO Transformation (PDF) is an advanced tutorial explaining how to create XSLT stylesheets for converting and printing complex XML documents.
- XSL-FO Tutorial is a 16-part tutorial on XSL-FO, with additional information about Altsoft’s proprietary XSL-FO extensions that help print XML directly to PDF.
- XSL-FO Tutorial explains XSL-FO in the context of XML, XSLT, and XPath. This tutorial also includes quizzes, so you can test your knowledge.
- Using XSL-FO to Create Printable Documents explains how to use XSL-FO as a bridge between information stored in a database or reporting system and printable documents.
- XQuery/Generating PDF From XSL-FO Files gives step-by-step practical instructions and code samples for generating PDFs from XML documents using XSL-FO.
- XPubs: XSL-FO for Documentation Formatting is less a tutorial and more a long-form blog post. The more personal approach provides a helpful perspective on the practical advantages and disadvantages of using XSL-FO for print publishing.
Additional XFL-FO Learning Materials
- XML for Creative Content and Page Layout Applications is a white paper advocating the use of XML as a single-source for content that has to be printed and displayed in a number of different contexts, such as a website, a brochure, a store catalog.
- Transforming Word Documents into the XSL-FO Format is an outdated, but still interesting, guide to generating XSL-FO and PDF documents from
- HTML to Formatting Objects (FO) Conversion Guide provides information and templates for converting HTML documents to PDF, using XSL-FO.
- Fosox: Generating XSL Formatting Objects in Python explains how to use Python to generate PDFs from XML documents in Python, using the fosox module.
- Apache FOP is the industry standard print formatter for XSL-FO. It is open source, written in Java, and can produce PDF, PostScript, PCL, AFP, XML, AWT, PNG, and RTF output.
- J4L FO Designer is a WYSIWYG editor for creating and editing XSL-FO files for consumption by Apache FOP or similar print formatters.
- The Oxygen XML Editor has explicit support for XSL-FO editing.
- XMLmind XSL-FO Converter lets you convert from XML or XSL-FO to Microsoft Word, LibreOffice, or OpenOffice formats.
- XML-FO Online Transformations is an online tool that converts XML documents to PDF, using XSL-FO.
- XSL-FO (2002), by Dave Pawson, is the standard text on the subject from O’Reilly. It’s highly technical, with an emphasis on generating XSL-FO by using XSLT to transform XML documents.
- XSL Formatting Objects Developer’s Handbook (2002), by Doug Lovell, is one of the first, and still one of the best, books to delve specifically into the XSL-FO markup format, instead of simply assuming all XSL-FO would be generated by XSLT transformations.
- Definitive XSL-FO (2003), by G Ken Holman, is more of a reference book than a tutorial. It explains the W3C specification in detail, covering topics that other XSL-FO guides leave out.
XSL-FO Is No Legacy Tool
XSL-FO is one of several XML-related standards that haven’t gotten as much attention since HTML and XML diverged. However, it is an extremely useful technology, and there’s nothing “legacy” about it. It continues to be in heavy use in enterprise and industrial settings that need to manage content and data across multiple media and publications.
XPath is a little different and more general than XSLT and XSL-FO. It is a query language used to locate and select content in an XML or HTML document.
XPath is a more powerful alternative to CSS Selectors. While CSS Selectors are easier to use, but are not always feasible if the document author has omitted common attributes such as
class. XPath provides a way to specify any node in a DOM tree, even without these attributes. This makes it well-suited for web scraping and document analysis.
The language got a lot of attention when it was introduced in 1999. It is still useful and thriving today, but there aren’t as many contemporary tutorials as there might be. So we’ve collected the best available resources for learning and using XPath.
- XPath Tutorial from W3Schools is multi-part, in-depth explanation of XPath, with lots of practical examples and a good explanation of how XPath is related to other XML standards.
- XPath Overview from Tutorials Point provides a easy to follow introduction to the language.
- XPath Tutorial is a community-written tutorial on XPath basics from the Edutech Wiki.
- The 10-Minute XPath Tutorial is a Perl-focused introduction to XPath, primarily geared toward system administrators.
- XML XPath Tutorial is a Java-based introduction to XPath.
- XPath Syntax is a highly technical tutorial on XPath, with a focus on .NET implementation, from Microsoft Developer Network.
- How XPath Works is a Java-focused introduction to XPath, from Oracle.
- What Can XPath Do for Me? is an introduction to XPath, for the benefit of mostly non-tech-savvy academics working in the humanities. This is a very good place to start if you are using XPath to query documents for scholarly research.
- XPath Tutorial is a gentle introduction to using XPath, with a focus on searching ebook content.
- XPath Tutorial Application is an interesting meta-tutorial from Microsoft Developer Network. It helps you learn XPath by showing how to build an application which uses XPath to teach XPath.
- Learning XPath by Example is a visual tutorial on the language.
- XPath for Web Scraping explains how to use XPath to programmatically extract content from web pages with Python.
- PHP Scraping Using DOM and XPath Tutorial explains how to use XPath and PHP to programmatically extract content from web pages.
- Mozilla Developer Network has a wide array of XPath-related documentation, tutorials, reference materials, and tools.
- XSLT and XPath Quick Reference (PDF) is a pocket reference, designed to be printed, folded, and carried with you.
- XPath Examples is an index of example XPath expressions, with explanations.
- XPath Locator Examples is a cookbook-style collection of XPath examples that can help you build complex and powerful XPath queries.
- Free Online XPath Tester is an online XPath tester that lets you test expressions against online document via URL.
- XPath-Tools is a set of command-line utilities for extracting data from HTML and XML documents.
- XPath Visualizer is a Windows desktop tool that provides a visual representation of an XML or HTML tree, and the results of XPath queries performed against it.
- XMLSpy, an XML editor, has a built-in Xpath Editor and Debugger that provides an number of tools for working with XPath, including auto-completion, deep path suggestions, and multi-file evaluations.
- Stylus Studio has several useful XPath tools, including a visual expression generator that will help you build an XPath query by selecting content within a document. Their XPath tutorials are also worth checking out.
XPath Libraries and Implementations
- XPath module for the Gnome XML C Parser provides XPath support in C, and also has bindings to Python, Perl, C++, PHP, Pascal, Ruby, and Tcl.
- XPath Library for the OCaml programming language.
- XPath gem provides XPath support in Ruby.
- Xpath npm package provides Xpath implementation and helpers for Node.js.
- XPath 2.0 Programmer’s Reference (2004), by Michael Kay, is the definitive classic reference work on XPath.
- Definitive XSLT and XPath (2001), by G Ken Holman, is the authoritative guide to XPath and XSLT. It is highly technical and also provides much of the philosophical and theoretical background to how XML is designed and what is actually contained in the specifications. There are easier books for learning how to use XPath, but few that will help you really understand it in this much depth.
- Python and XML (2001), by Jones and Drake, includes sections on using Python to query and manipulate XML documents via XPath.
- XPath Kick Start: Navigating XML with XPath 1.0 and 2.0 (2003), by Steven Holzner, is a concise book designed for beginners.
- XPath and XPointer: Locating Content in XML Documents (2002), by John Simpson, is a relatively short book covering XPath basics. It’s speculation on the future of the standard, from its 2002 vantage point, is a little dated now, but the primary content is still highly relevant.
- XSLT and XPath On The Edge (2001), by Jeni Tennison, is a cookbook style reference manual with tons of highly useful example queries.
- Beginning XSLT and XPath: Transforming XML Documents and Data (2009), by Ian Williams, is a very good introduction to using XSLT and XPath. Written a few years later than most other popular books on the topic, this book has the benefit of several years of experience with the standard.
XPath may not seem trendy right now. When it was first released, most people thought XML was going to become the standard language for web markup. But HTML 5 broke away from strict XML, and JSON has displaced XML as the dominant data serialization format.
However, XPath is as relevant as ever. It is still the most reliable way to query information in an XML (or HTML) document, and is the basis for XSLT. If you’re interested in web scraping, web search and indexing, or document analysis, XPath continues to be an important skill.
If you work with XML documents, you will undoubtedly run into situations where you need a way to translate them into another form. Thus, it is critical to know the tools we’ve discussed here.
Other Interesting Stuff
We have more guides, tutorials, and infographics related to coding and development:
- XML Resources and Validators: learn all about XML itself.
- HTML for Beginners: this article will take you from the very star. But given it is book-length, there’s lots that experienced coders can learn.
- The History of Search Engines: the whole story of slow development from library databases to the modern engine.
What Code Should You Learn?
Confused about what programming language you should learn to code in? Check out our infographic, What Code Should You Learn? It not only discusses different aspects of the languages, it answers important questions such as, “How much money will I make programming Java for a living?”