#XSLT
XSLT (Extensible Stylesheet Language Transformations) is a declarative language for transforming XML documents. If you've written Razor views, Handlebars templates, or even CSS selectors, XSLT takes that idea further — pattern matching on XML trees to produce any output format.
XSLT is how you turn XML data into HTML pages, other XML formats, JSON, CSV, or plain text. It's 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:
-
Instructions Overview — Index of all instruction categories
-
Output — value-of, text, sequence, message
-
Control Flow — if, choose, switch (4.0), where-populated
-
Variables and Parameters — variable, param, static params, tunnel params
-
Iteration and Sorting — for-each, sort, iterate/break/next-iteration
-
Grouping — for-each-group with all four modes
-
Copying and Identity — copy, copy-of, identity transform pattern
-
Node Construction — element, attribute, namespace, AVTs
-
Multiple Outputs — result-document, named output formats
-
Functions — Defining reusable XPath functions
-
Keys — Indexing for fast lookup
-
String Analysis — Regex-based processing
-
Error Handling — try/catch, assert, fallback
-
Merging — Combining sorted inputs
-
Maps, Arrays, Records — Structured data (3.0/4.0)
-
Streaming — Large document processing with accumulators
-
Packages — Reusable stylesheet libraries
-
Dynamic Evaluation — Runtime XPath evaluation
-
Number Formatting — Numbering, decimal formats, character maps
#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:forkbranches execute sequentially (not in parallel)
#The Mental Model
If you're a C# developer, think of XSLT like this:
|
C# Concept |
XSLT Equivalent |
|---|---|
|
A method that takes input and returns output |
A template rule that matches a node and produces output |
|
|
Template matching with |
|
|
|
|
String interpolation |
Attribute value templates: |
|
Method overloading |
Template priority and import precedence |
The key difference: in C# you write imperative code that says how to process data. In XSLT you write declarative rules that say what to produce for each pattern. The XSLT engine handles the traversal.