XSLT

Transforming XML into other formats.

XSLT is taught here in 14 lessons, running from Templates and apply-templates through to XSL-FO and PDF generation pipelines. Each lesson takes one topic, shows the working code, and links onward to the next, so the course can be read straight through in order.

TrackXML & Web Services
Lessons14
LevelBeginner to intermediate
Reading timeabout 3 hours
PrerequisitesHelpful, but not required: XPath

Lessons

  1. Templates and apply-templatesThe processing model behind XSLT: template rules matched against nodes, apply-templates driving traversal, and the built-in rules that fill the gaps.
  2. Advanced matching and sortingMatch pattern priorities, multi-key sorting with data types, key-based lookup, and grouping without a group-by instruction.
  3. Output methods and real use casesChoosing between xml, html and text output, controlling encoding and whitespace, and the jobs XSLT still does well.
  4. XSLT versions, engines and where transformations runXSLT 1.0 is universal and XSLT 3.0 is far more capable, but the version you can use is decided by the engine you deploy.
  5. Match patterns versus select expressionsA stylesheet contains two different XPath dialects, and confusing them produces templates that never fire or select far more than intended.
  6. Conditionals, loops and variablesXSLT has no assignment. Every value is bound once, and that single constraint explains most of how stylesheets are structured.
  7. Reusing stylesheets: includes, imports and named templatesSharing templates across stylesheets relies on precedence rules that decide which duplicate wins, so know the difference between include and import.
  8. Whitespace, text and special charactersIndentation from the source document leaks into the output, and the standard fix for escaping is also the standard security hole.
  9. Numbering and formatting outputAuto-numbering headings, formatting money and percentages, and the date formatting that only exists from XSLT 2.0 onwards.
  10. Debugging and testing stylesheetsThe two hard parts of XSLT are knowing which template ran and knowing which one should have. Both have cheap, systematic answers.
  11. XSLT 2.0 and 3.0 beyond version 1.0Grouping, regular expressions, functions, maps and error handling are the features that make the upgrade worth the engine change.
  12. Streaming very large XML documentsA normal transform builds the whole tree in memory. Streaming templates process a document in a single forward pass at roughly constant cost.
  13. Calling XSLT from Java, .NET and PythonCompile the stylesheet once, pass parameters in, and treat any stylesheet that came from outside as executable code.
  14. XSL-FO and PDF generation pipelinesXSL-FO is a page description language driven by XSLT. It still produces the best paginated output, at the cost of a second transform and a heavier toolchain.

More in XML & Web Services

XML XPath SOAP RESTful APIs RSS & Atom

FAQ

How long does the XSLT course take?
It has 14 lessons, about 3 hours of reading. Expect roughly twice that if you type out and run every example.
Do I need prior experience for XSLT?
Not strictly. It helps to have read XPath first, because some lessons build on it, but every lesson explains its own assumptions.
What should I read after XSLT?
Continue with SOAP (14 lessons), the next course in XML & Web Services.