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.
| Track | XML & Web Services |
| Lessons | 14 |
| Level | Beginner to intermediate |
| Reading time | about 3 hours |
| Prerequisites | Helpful, but not required: XPath |
Lessons
- 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.
- Advanced matching and sortingMatch pattern priorities, multi-key sorting with data types, key-based lookup, and grouping without a group-by instruction.
- Output methods and real use casesChoosing between xml, html and text output, controlling encoding and whitespace, and the jobs XSLT still does well.
- 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.
- 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.
- Conditionals, loops and variablesXSLT has no assignment. Every value is bound once, and that single constraint explains most of how stylesheets are structured.
- 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.
- 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.
- Numbering and formatting outputAuto-numbering headings, formatting money and percentages, and the date formatting that only exists from XSLT 2.0 onwards.
- 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.
- 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.
- 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.
- Calling XSLT from Java, .NET and PythonCompile the stylesheet once, pass parameters in, and treat any stylesheet that came from outside as executable code.
- 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.