Skip to content

feat: support top-level xsl:variable#3

Closed
no-pictures[bot] wants to merge 1 commit into
mainfrom
global-variables
Closed

feat: support top-level xsl:variable#3
no-pictures[bot] wants to merge 1 commit into
mainfrom
global-variables

Conversation

@no-pictures

@no-pictures no-pictures Bot commented Jul 19, 2026

Copy link
Copy Markdown

Top-level xsl:variable declarations, independent of the named-template work.

A stylesheet's global variables are the backbone of a real transform, holding document lookups and localisation that every template reads.

How it works

  • Each top-level xsl:variable gets a slot, indexed by declaration order.
  • The main function evaluates the globals into their slots before it applies templates, with the source document as the context, so a global can read from the input tree.
  • Two instructions carry the values: SetGlobal stores a computed value, and LoadGlobal reads it. They live on the interpreter state for the whole run, so a rule or named template reads the same values even though it is invoked as its own function without a captured scope.
  • A reference resolves to a local, then a closed-over name, then a global, so a local variable of the same name shadows the global.
  • The AST parser gained the xsl:variable declaration, which it rejected before.

Tests

test_global_variable reads a global inside a template, test_global_variable_from_source reads the source document, test_global_variable_references_earlier_global covers declaration order, and test_local_variable_shadows_global covers shadowing.

Not covered

A global whose value references a later global reads an empty sequence, because the values fill in declaration order rather than by dependency.

Global variables compile to slots that the main function fills before it applies templates, so a rule or named template reads them through the new LoadGlobal instruction rather than a captured scope.
They evaluate in declaration order with the source document as the context, and a local variable of the same name shadows the global.
The AST parser gained the xsl:variable declaration it was missing.
@no-pictures

no-pictures Bot commented Jul 19, 2026

Copy link
Copy Markdown
Author

Closing in favor of Paligo#145, which implements top-level xsl:variable. The global-variables branch stays for reference.

@no-pictures no-pictures Bot closed this Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant