PureXML/Sources/Validation/SchematronModel.swift
Mihaela Mihaljevic d0671e40ba feat(schematron): rule-level let variable bindings
<rule> may now declare <let name= value=> bindings, evaluated at each
context node in order (so a later binding can reference an earlier one
through $name). The bindings are available to the rule's assert/report
tests and to <value-of select="$name"> in messages, using the XPath
engine's existing variable support.

Schema- and pattern-level let, abstract rules/extends, diagnostics, and
key()/document() remain.

Part of #80
2026-06-08 16:23:26 +02:00

51 lines
1.9 KiB
Swift

extension PureXML.Validation {
/// One piece of an assertion message: literal text, a `<value-of select=>`
/// whose XPath is evaluated against the context node, or a `<name>` rendering
/// the context node's name. Lets a finding report actual values.
enum SchematronMessagePart {
case text(String)
case valueOf(PureXML.XPath.Query)
case name
}
/// One `<assert>` or `<report>`: a compiled XPath test and its message
/// template. An assert flags when its test is false; a report flags when its
/// test is true.
struct SchematronAssertion {
let isReport: Bool
let test: PureXML.XPath.Query
let message: [SchematronMessagePart]
}
/// A `<let name= value=>` variable binding: its name and the compiled XPath
/// whose value is bound to `$name` for the rule's assertions.
struct SchematronLet {
let name: String
let value: PureXML.XPath.Query
}
/// One `<rule>`: a compiled context that selects the nodes the rule fires on,
/// its `<let>` variable bindings, and its assertions.
struct SchematronRule {
let context: PureXML.XPath.Query
let lets: [SchematronLet]
let assertions: [SchematronAssertion]
}
/// One `<pattern>`: an optional id (referenced by `<active>` in a phase) and a
/// list of rules. A node is processed by the first rule in the pattern whose
/// context selects it (the ISO Schematron firing rule).
struct SchematronPattern {
let id: String?
let rules: [SchematronRule]
}
/// A compiled Schematron schema: its patterns and its phases (each phase id
/// mapped to the pattern ids it activates), plus the declared default phase.
struct SchematronSchema {
let patterns: [SchematronPattern]
let phases: [String: [String]]
let defaultPhase: String?
}
}