feat: support top-level xsl:variable#160
Closed
gronke wants to merge 1 commit into
Closed
Conversation
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.
Author
|
Upon review I've noticed #145 already implements this. Therefore closing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A stylesheet's global variables are the backbone of a real transform, holding document lookups and localisation that every template reads.
xsl:variablegets a slot, indexed by declaration order.SetGlobalstores a computed value, andLoadGlobalreads 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.xsl:variabledeclaration, which it rejected before.Tests
test_global_variablereads a global inside a template,test_global_variable_from_sourcereads the source document,test_global_variable_references_earlier_globalcovers declaration order, andtest_local_variable_shadows_globalcovers 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.