XSLT / transformation

XSLT Through Practical HTML Templates

Learn XSLT by treating a stylesheet as a declarative template that matches XML nodes and produces HTML, XML, text or JSON output.

Updated2026-07-21
ScopeTechnical reference

XSLT is a rule system

An XSLT stylesheet contains template rules. Each rule matches nodes in a source tree and constructs part of a result tree. This model is easier to understand when it is compared with familiar server-side HTML templates: both combine fixed output with values selected from input. The important difference is that XSLT rules can be selected by patterns and applied recursively across a document.

A minimal transformation

Start with one template that matches the document root, emit the outer HTML structure, and use xsl:apply-templates to delegate child content. Add focused templates for the elements that need distinct presentation. This keeps selection logic out of deeply nested imperative loops and makes modes available when one source node needs several output treatments.

XPath selects the input

The select and match attributes use XPath. Namespace bindings in the stylesheet must match namespace URIs in the source; an unprefixed XPath name does not normally select elements in a default source namespace. Many transformations that appear to produce an empty result are namespace-selection problems rather than XSLT processor failures.

Use the processor version you declare

XSLT 1.0 remains available in browsers and legacy platforms, while XSLT 2.0 and 3.0 add grouping, regular expressions, functions, packages, streaming options and stronger data types. A stylesheet should declare its intended version and deployment should select a processor that implements the required features.

Test output as a contract

Transformation tests should compare significant result structure rather than incidental indentation. Include empty input, repeated values, namespaces, unexpected extension content and characters that require escaping. For HTML output, check accessibility and URL handling in addition to the transformation result.

Implementation notes

Build a transformation from a representative source document and a written result contract. Bind every source namespace explicitly, select an output method, and make the initial template easy to locate. Add templates one semantic unit at a time. A small stylesheet whose modes and imports are obvious is easier to extend than one template containing a long series of nested conditions.

Separate reusable transformation rules from delivery concerns. A core package can create a result tree while a thin entry stylesheet controls parameters, serialization and deployment-specific resource resolution. Use a catalog or controlled resolver for imported stylesheets and documents. That keeps the same tests reproducible on a workstation, in continuous integration and in a service process.

Failure modes

The most common silent failure is an XPath that selects nothing because the source uses a namespace. Other defects include relying on processor-specific extensions, comparing serialized whitespace instead of result structure and constructing markup with escaped text. Inspect the selected node sequence first, then verify which template matched, rather than changing several expressions at once.

Large inputs also expose design assumptions. Sorting, grouping and backward axes can require substantial memory, while an advertised streaming mode accepts only streamable expressions. Measure with realistic documents and keep a non-streaming reference result. A faster stylesheet is not correct if it changes ordering, namespace nodes or character escaping.

Review checklist

  • Declared XSLT and XPath versions
  • Explicit source namespaces
  • Controlled imports and document access
  • Structural result assertions
  • Empty and repeated input fixtures
  • Measured large-document behavior

Questions for a design review

Use this reference to make a review decision, not merely to recognize terminology. Record the concrete document, schema, processor or consumer being discussed; the language and processor versions; and the behavior that must remain compatible. A useful review produces fixtures and an owner for every unresolved assumption.

  • What executable example or test demonstrates the intended behavior for xslt is a rule system?
  • What executable example or test demonstrates the intended behavior for a minimal transformation?
  • What executable example or test demonstrates the intended behavior for xpath selects the input?
  • What executable example or test demonstrates the intended behavior for use the processor version you declare?
  • What executable example or test demonstrates the intended behavior for test output as a contract?

Include at least one ordinary case, one boundary case and one deliberately invalid or unsupported case. Check the result in the actual production toolchain, because parsers, validators, code generators and reasoners do not all implement the same optional features. Store the selected contract version with the test result, then repeat the review when a dependency, namespace, profile or public declaration changes.

XSLT and XPath reference · XML Schema tutorial

Query set / FAQ

Frequently asked questions

01What does the XSLT Through Practical HTML Templates reference cover?

Learn XSLT by treating a stylesheet as a declarative template that matches XML nodes and produces HTML, XML, text or JSON output.

02When should I use this Technical reference guidance?

Use it when designing, reviewing or updating a system that depends on XSLT Through Practical HTML Templates. Apply the guidance to a concrete example and record any project-specific policy that goes beyond the standard.

03How can I verify a XSLT Through Practical HTML Templates design decision?

Create a minimal positive example, a negative or boundary example, and run both through the same processors and consumer versions used in production. Keep the expected outcome with the fixture so the decision remains reproducible.

04What are the limitations of this Technical reference reference?

The page explains a focused technical decision; it does not replace the complete specification, processor documentation or integration testing. Version-specific behavior and external dependencies must still be verified in the target environment.