Skip to content

feat: support top-level xsl:variable#160

Closed
gronke wants to merge 1 commit into
Paligo:mainfrom
no-pictures:global-variables
Closed

feat: support top-level xsl:variable#160
gronke wants to merge 1 commit into
Paligo:mainfrom
no-pictures:global-variables

Conversation

@gronke

@gronke gronke commented Jul 19, 2026

Copy link
Copy Markdown

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

  • 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.
@gronke

gronke commented Jul 19, 2026

Copy link
Copy Markdown
Author

Upon review I've noticed #145 already implements this. Therefore closing.

@gronke gronke 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