XSLT

Transform XML documents with XSLT β€” the declarative transformation language

#XSLT

XSLT (Extensible Stylesheet Language Transformations) is a declarative language for transforming XML documents. It matches patterns on the XML tree to produce any output format.

XSLT transforms XML data into HTML pages, other XML formats, JSON, CSV, or plain text. It is the transformation layer that makes XML practical.

#Getting Started

  • Your First Transform β€” A hands-on introduction. Transform XML to HTML, step by step.

  • Template Matching β€” The core paradigm shift: declarative rules instead of imperative code.

  • Output Methods β€” Producing HTML, XML, JSON, CSV, and text from the same source data.

  • Extensibility β€” Custom functions, packages, extension instructions, and .NET integration.

#Instructions Reference

The complete set of XSLT 3.0/4.0 instructions, organized by purpose:

#Streaming

PhoenixmlDb supports XSLT 3.0 streaming for processing documents that are too large to fit in memory. Streaming processes the input as a forward-only event stream, never building the full tree.

  • Streaming and Accumulators β€” xsl:mode streamable="yes", xsl:source-document, accumulators, xsl:fork, and streamability rules.

Key capabilities:

  • Primary source streaming β€” Declare xsl:mode streamable="yes" to stream the principal input document via XmlReader.

  • External document streaming β€” Use xsl:source-document streamable="yes" to stream documents loaded during transformation.

  • Accumulators β€” Maintain running state (counts, totals, max values) as nodes flow past.

  • Static streamability checking β€” The compiler analyzes your stylesheet and reports streamability violations at compile time.

  • system-property('xsl:supports-streaming') returns "yes".

  • Limitations: last() is not available in streaming mode. xsl:fork branches execute sequentially, not in parallel.

#The Mental Model

XSLT uses declarative rules instead of imperative code. A rule states what output to produce for a given pattern. The engine handles the traversal.

C# Concept

XSLT Equivalent

A method that takes input and returns output

A template rule that matches a node and produces output

switch on type

Template matching with match patterns

foreach over a collection

xsl:for-each or xsl:apply-templates

String interpolation

Attribute value templates: href="{@url}"

Method overloading

Template priority and import precedence

For C# developers: several XSLT constructs mirror familiar C# patterns. Pattern matching on XML trees resembles pattern matching in a Razor view or a CSS selector. The engine runs the traversal automatically. A template rule resembles a method that takes input and returns output. Template matching resembles a switch on type. xsl:for-each and xsl:apply-templates resemble foreach. Attribute value templates resemble string interpolation. Template priority and import precedence resemble method overloading.