PureXML/Sources/XSLT/XSLTRuntime.swift
Mihaela Mihaljevic 4f11bafa28 feat(xslt): implement xsl:apply-imports
Re-applies templates to the current node in the current mode, considering
only templates of lower import precedence than the one being instantiated,
falling back to the built-in rule when none match. Threads the current
mode and import precedence through the evaluation context, and moves the
transformer runtime types into XSLTRuntime.swift (namespaced, via private
aliases) to stay within the file-length and namespacing gates.
2026-06-09 01:49:33 +02:00

45 lines
1.5 KiB
Swift

extension PureXML.XSLT {
/// One produced item: a node for the result tree, or an attribute to attach to
/// the enclosing element.
enum ResultItem {
case node(PureXML.Model.Node)
case attribute(PureXML.Model.Attribute)
}
/// The evaluation context during instantiation.
struct XSLTContext {
var node: PureXML.Model.TreeNode
var position: Int
var size: Int
var variables: [String: PureXML.XPath.Value]
/// The mode of the template currently being instantiated, so `apply-imports`
/// re-applies in the same mode.
var mode: String?
/// The import precedence of the template currently being instantiated, so
/// `apply-imports` considers only templates below it. `.max` outside a template.
var importPrecedence: Int
init(
node: PureXML.Model.TreeNode,
position: Int,
size: Int,
variables: [String: PureXML.XPath.Value],
mode: String? = nil,
importPrecedence: Int = .max,
) {
self.node = node
self.position = position
self.size = size
self.variables = variables
self.mode = mode
self.importPrecedence = importPrecedence
}
}
/// Shared, mutable signal that an `xsl:message terminate="yes"` fired, carrying
/// its text. A reference type so the value-semantics transformer can set it.
final class Termination {
var message: String?
}
}