XSLT Documentation Renderer
Overview
This stylesheet turns an XSLT source file into a prose-and-diagram documentation page.
It is the renderer invoked by the stylesheet route template in
src/xsl/index.xsl, which loads an XSL document via
document(@src) and applies templates against it.
The page you are reading is produced by running this stylesheet against itself, which means every rendered element below is both an example of the vocabulary and a live demonstration of the template that consumes it.
The doc: vocabulary
Authors annotate an XSLT module by interleaving elements in the
'https://swa.sh/doc/' namespace between the normal
xsl: declarations. The most common elements are listed below.
doc:module— top-of-file header with title, version, and sections.doc:section/doc:subsection— narrative groupings with headings.doc:para— a paragraph; may contain inlinedoc:ref,doc:code,doc:file,doc:path,doc:attr,doc:em,doc:string.doc:note— boxed aside with adoc:typechooser (architecture, implementation, performance, security, design, convention, UX, pattern, styling).doc:example— dispatches on structure:doc:input/doc:output/doc:process/doc:result, ordoc:code[@language], ordoc:flow/doc:case/doc:parsed.doc:algorithmwithdoc:stepchildren (optionally nesteddoc:substep,doc:code,doc:note).doc:template/doc:param/doc:variable/doc:key— placed as a following sibling of the matchingxsl:declaration; the renderer couples them by name/match/mode.
Rendering pipeline
The main entry point matches the root xsl:stylesheet and walks its
children in document order, dispatching each to a type-specific template.
- Emit the article shell with Tailwind typography.
- Apply templates to the union of doc:* authoring elements and xsl:* declarations.
- Each matched element chooses its own presentation template.
doc:type child picks a color
palette and glyph; unknown or missing types fall back to a neutral gray.
<doc:note> <doc:type>performance</doc:type> <doc:content>XSL keys give O(1) lookup instead of a linear scan.</doc:content> </doc:note>
doc:step children. Each step may embed a
short doc:code snippet, a doc:note, or a list of
doc:substep children for finer detail.
tokenize(), so this named template walks the string,
peeling off one class at a time and calling render-single-class.
classes— The raw space-separated class attribute value.processed(optional)— Accumulator (currently unused; reserved for future deduplication).- Normalize whitespace.
- If the remainder contains a space, split into first/rest, render first, recurse on rest.
- Otherwise render the final token and stop.