Skip to main content
XMLDir

Search 309 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

Parsing and processing

XSLT

A language for transforming XML into other XML, HTML or text, written as templates that match patterns in the source tree.

An XSLT stylesheet is itself an XML document, and it is declarative: you write templates that say what to output for a matching node, and the processor decides the order by walking the source. That inversion is what makes it strange at first and concise once it clicks.

It is still the standard way to render a feed in a browser, to reshape one vocabulary into another, and to produce HTML from documentation source. Version 1.0 is the one browsers implement; 2.0 and 3.0 need a dedicated processor.

Defined in
XSLT 1.0 / 2.0 / 3.0
Category
Parsing and processing
Also written
XSL Transformations, stylesheet

Shown, not asserted

All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.

  • A stylesheet is an XML document, so it must be well-formed before it can transform anything.

    document.xml
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><out/></xsl:template></xsl:stylesheet>

    What the engine returns

    Well-formed.
  • Its match patterns are XPath, and the same namespace rules apply to them.

    document.xml
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><out/></xsl:template></xsl:stylesheet>
    expression
    string(//*[local-name()='template']/@match)

    What the engine returns

    /

What catches people out

  • Browsers implement XSLT 1.0 only. A stylesheet using 2.0 features will fail silently in one and work in your build.
  • Template match patterns are XPath, so the namespace trap applies: match a namespaced element without a prefix and the template never fires.
  • The built-in templates apply when nothing else matches, which is why an unexpected transform often emits stray text rather than nothing.

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.