PureXML/Sources/Validation/SchematronModel.swift
Mihaela Mihaljevic a76e9b3da3 feat(schematron): diagnostics
An assert/report may reference <diagnostic> messages by id through its
diagnostics= attribute; each referenced diagnostic is rendered (with the
same value-of/name/let substitution) and appended to the finding for
extra per-failure detail. <diagnostics> is collected schema-wide.

Schema/pattern-level let, abstract patterns, and key()/document() remain.

Part of #80
2026-06-08 16:30:13 +02:00

57 lines
2.2 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]
/// The ids of `<diagnostic>`s referenced by the `diagnostics=` attribute,
/// appended to a failure's message for extra detail.
let diagnostics: [String]
}
/// 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?
/// `<diagnostic id=>` message templates, keyed by id, referenced from an
/// assertion's `diagnostics=` attribute.
let diagnostics: [String: [SchematronMessagePart]]
}
}