pyxsd.schematron.model

Native Schematron validation report and message value model.

The native model is the stable surface between the rule driver, the message expander, and the serializers. Validation returns one immutable SchematronReport. Original-instance outcomes are produced in candidate-major order: every active pattern or group attempts a candidate before the next candidate, and each fired rule emits its checks in authored order. An ordinary pattern fires its first matching rule at a node; every matching rule of an independent 2025 group fires. Without a phase from, outcomes from a container’s subordinate documents follow that original traversal, grouped by container and then by the documents query’s order; a bounded phase switches to the document-major order described below. Active patterns and groups and fired rules are retained even when they produce no outcome, because a report describes what the schema did, not only what failed.

Every record carries the pattern_ordinal of the container that produced it: the container’s position in the compiled schema’s native order. That ordinal, paired with the document URI, is the native identity that pairs an active container with its own fired rules and outcomes. The authored pattern_id is optional, so it never identifies a record: two identifier-less containers stay distinct through their ordinals.

Every firing also carries a report-unique firing_id, and every outcome carries the identity of the firing that produced it. That is the exact pairing key for identifier-less group rules that fire at one node, where an ordinal plus context cannot tell two firings apart. A report also retains the instance documents it owned, primary first, so a serializer can distinguish a real instance node from a constructed temporary tree without guessing from a path.

The message classes are data containers. The message stage fills them from a check’s compiled message, its diagnostics, and its properties; serializers read the parts and their flattened text without reparsing anything.

A 2025 phase/@from narrows candidate traversal for the original document only; documents admitted through pattern/@documents remain unrestricted. The native active-pattern record for the original document retains the effective roots, in document order and deduplicated by identity, while an empty selection keeps an empty tuple and its document identity. A bounded validation produces outcomes in document-major order: the original document’s selected candidates first, then each distinct subordinate document in first seen order, and for every candidate the applicable patterns in native order. A validation without a phase from keeps the pre-existing candidate-major original traversal followed by subordinate passes grouped by container.

A 2025 visit-each firing keeps two identities. The fired rule’s context and every outcome’s context stay the outer matched rule node, while each outcome carries its own visited item plus zero-based visited_ordinal. The firing itself retains only the item count and a bounded preview, so a huge sequence is never duplicated into the report; serializers emit that count and preview and mark a truncated payload. A visited instance node may act as the default subject; atomic and synthetic items never acquire an invented node path or byte span.

Attributes

Classes

MessagePart

One evaluated component of a native Schematron message.

SchematronMessage

One check, diagnostic, or property message as native structured parts.

DiagnosticMessage

One reusable diagnostic resolved for an outcome.

PropertyMessage

One reusable property resolved for an outcome.

ActivePattern

One pattern or group that was active for one document.

FiredRule

One rule that matched one context node in one pattern.

SchematronOutcome

One failed assertion or successful report.

SchematronReport

The immutable result of one native validation.

Module Contents

pyxsd.schematron.model.OutcomeKind
pyxsd.schematron.model.VISITED_PREVIEW_LIMIT = 10
class pyxsd.schematron.model.MessagePart

One evaluated component of a native Schematron message.

text is the component’s flattened string value. nodes retains the XDM nodes a value-of or name selected, in selection order. name, attributes, and children describe one markup element; literal text has no nodes or markup. The rule driver’s message expansion fills this model by evaluating compiled parts at the rule focus; serializers read the parts and never reparse or invent content. A selected node from a constructed temporary tree is not a validated instance node: JSON reports instance_node: false with a null path, document URI, and span, and no serializer fabricates a location for it. A node from a foreign parsed document keeps that document’s real URI with instance_node: false and a null path and span: it owns the URI but has no validated instance path.

text: str
nodes: tuple[pyxsd.xdm.nodes.XdmNode, ...] = ()
name: str | None = None
attributes: tuple[tuple[str, str], ...] = ()
children: tuple[MessagePart, ...] = ()
class pyxsd.schematron.model.SchematronMessage

One check, diagnostic, or property message as native structured parts.

parts: tuple[MessagePart, ...]
property text: str

The flattened string value of every part, in authored order.

Return type:

str

class pyxsd.schematron.model.DiagnosticMessage

One reusable diagnostic resolved for an outcome.

id is the authored diagnostic identifier and message its evaluated parts. origin is the diagnostic’s schema occurrence; language and role are the diagnostic’s own metadata, never the referencing check’s.

id: str
message: SchematronMessage
origin: pyxsd.locations.IssueLocation | None
language: str | None
role: str | None
class pyxsd.schematron.model.PropertyMessage

One reusable property resolved for an outcome.

A property carries a scheme in addition to the diagnostic metadata, and its message may name the context node.

id: str
message: SchematronMessage
origin: pyxsd.locations.IssueLocation | None
language: str | None
role: str | None
scheme: str | None
class pyxsd.schematron.model.ActivePattern

One pattern or group that was active for one document.

pattern_id is None for an identifier-less container, which can only be active when no phase restricts the active set. origin is the container’s schema occurrence, and document_uri is the URI of the instance document it applied to, when it has one. kind distinguishes an ordinary pattern from a 2025 independent rule group; it defaults to "pattern" for a pre-group constructor call shape. pattern_ordinal is the container’s position in the compiled schema’s native order; one container applied to two documents yields two records that share the ordinal and differ in document_uri.

roots records an effective 2025 phase/@from root set for the original document: None when no phase from applied or when this is an admitted subordinate document, an empty tuple when the original document’s selection was empty (the record stays because the pattern was still active), and otherwise the effective nodes in document order, deduplicated by identity. from never restricts a subordinate document, so a subordinate record always carries None. Every selected root belongs to the original document and lies within any supplied validation subtree.

title, role, and documents_source are the compiled container metadata the 2025 SVRL active-set attributes report: the authored title (including an empty one), the authored role, and the lexical @documents query source. documents_source is not document_uri; it says what the container queried, while the record’s own document_uri says which document this run describes.

pattern_id: str | None
origin: pyxsd.locations.IssueLocation | None
document_uri: str | None
pattern_ordinal: int | None = None
kind: pyxsd.schematron.ir.PatternKind = 'pattern'
roots: tuple[pyxsd.xdm.nodes.XdmNode, ...] | None = None
title: str | None = None
role: str | None = None
documents_source: str | None = None
class pyxsd.schematron.model.FiredRule

One rule that matched one context node in one pattern.

A fired rule is retained even when every check passed or produced no report. context is the matched instance node; node identity, not a path string, distinguishes repeated firings. pattern_ordinal is the producing pattern or group’s position in the compiled schema’s native order, the identity it shares with its active-pattern record and outcomes. visited_count is the number of items the 2025 @visit-each expression selected: None when the rule has no @visit-each, 0 when it selected nothing, and the sequence length otherwise. visited_preview is at most VISITED_PREVIEW_LIMIT leading items, so a firing never retains an unbounded sequence; each outcome still keeps its own visited item. The preview preserves native identity for the serializer, it is not a second copy of the result. The visited items never replace context: the outer matched node remains the rule-selection identity, while each outcome also retains its own visited item.

firing_id is the runtime-assigned identity of this firing within its report. It is a native pairing key, never an authored identifier and never a fabricated SVRL attribute; identifier-less group rules that fire at one node stay distinct through it. visit_each_source is the compiled @visit-each expression text, flag its resolved rule flag token list, and role its resolved rule role.

pattern_id: str | None
rule_id: str | None
context: pyxsd.xdm.nodes.XdmNode
origin: pyxsd.locations.IssueLocation | None
document_uri: str | None
pattern_ordinal: int | None = None
visited_count: int | None = None
visited_preview: tuple[pyxsd.xdm.values.XdmItem, ...] = ()
firing_id: int | None = None
visit_each_source: str | None = None
flag: tuple[str, ...] = ()
role: str | None = None
class pyxsd.schematron.model.SchematronOutcome

One failed assertion or successful report.

kind distinguishes an assert whose effective boolean value was false from a report whose effective boolean value was true. test is the compiled test’s source text and context the rule’s matched node. subjects holds the subject nodes in selection order: the rule context when neither the check nor the rule declares a subject, an empty tuple for an explicitly empty selection, and every selected node otherwise. primary_subject is the first selected subject, or the rule context when the selection is empty; serializers use it for the generic location without dropping the remaining subjects.

message is the check’s evaluated message, and diagnostics and properties are its referenced reusable messages in authored reference order. flags is the check’s flag token list, inherited from the rule when the check declares none. language, role, severity, see, fpi, and icon are retained as resolved strings; no severity is inferred from a flag, and a 2025 severity never changes the outcome kind, validity, or generic issue severity. pattern_ordinal is the producing pattern or group’s position in the compiled schema’s native order, the identity it shares with its active-pattern record and fired rules.

visited is the 2025 visit-each item whose focus produced this outcome, and visited_ordinal is its zero-based position in the sequence. Both are None for a rule without @visit-each. context always stays the outer matched rule node, so the two identities never collapse. A visited node that belongs to an instance tree supplies the default subject; an atomic item, or a synthetic node with no tree root, supplies no subject and therefore no invented path or byte span. primary_subject still falls back to the real outer context in that case.

firing_id is the runtime-assigned identity of the firing that produced this outcome, the same value carried by its FiredRule. It pairs outcomes with their own firing even when several identifier-less group rules fire at one node; it is never an authored identifier or an SVRL attribute.

kind: OutcomeKind
test: str
context: pyxsd.xdm.nodes.XdmNode
pattern_id: str | None
rule_id: str | None
check_id: str | None
origin: pyxsd.locations.IssueLocation | None
document_uri: str | None
message: SchematronMessage | None = None
subjects: tuple[pyxsd.xdm.nodes.XdmNode, ...] = ()
diagnostics: tuple[DiagnosticMessage, ...] = ()
properties: tuple[PropertyMessage, ...] = ()
flags: tuple[str, ...] = ()
language: str | None = None
role: str | None = None
see: str | None = None
fpi: str | None = None
icon: str | None = None
pattern_ordinal: int | None = None
severity: str | None = None
visited: pyxsd.xdm.values.XdmItem | None = None
visited_ordinal: int | None = None
firing_id: int | None = None
property primary_subject: pyxsd.xdm.nodes.XdmNode

The first subject, or the rule context when none was selected.

Return type:

pyxsd.xdm.nodes.XdmNode

class pyxsd.schematron.model.SchematronReport

The immutable result of one native validation.

schema and instance are the inputs the report describes; they are excluded from equality and repr so a report compares by its own findings. phase is the phase selector the caller supplied, including a dynamic #ANY token. resolved_phase is the native authored phase that selection actually chose, or None when every pattern ran without a selected phase. SVRL and JSON report the resolved identity; they never serialize a pseudo-selector as a phase name. Outcomes retain production order. is_valid is true exactly when no assertion failed: successful reports never invalidate an instance.

documents holds every instance document this validation owned, in first-seen order: the supplied primary document followed by each distinct admitted subordinate document. It is the native ownership set serializers use to decide whether a message-part or visited node has a real instance location; a constructed temporary tree or foreign document is not in it. Like the inputs, it is excluded from equality and repr.

schema: pyxsd.schematron.ir.CompiledSchema
instance: pyxsd.xdm.nodes.XdmNode
phase: str | None
active_patterns: tuple[ActivePattern, ...]
fired_rules: tuple[FiredRule, ...]
outcomes: tuple[SchematronOutcome, ...]
resolved_phase: str | None = None
documents: tuple[pyxsd.xdm.nodes.XdmDocument, ...] = ()
property failed_assertions: tuple[SchematronOutcome, ...]

Outcomes produced by assertions whose test was false.

Return type:

tuple[SchematronOutcome, …]

property successful_reports: tuple[SchematronOutcome, ...]

Outcomes produced by reports whose test was true.

Return type:

tuple[SchematronOutcome, …]

property is_valid: bool

Whether the instance has no failed assertion.

Return type:

bool

to_validation_report()

Project failed assertions and successful reports to generic issues.

A failed assertion becomes an error with code schematron-failed-assert and a successful report becomes a warning with code schematron-successful-report. The outcome kind alone selects the severity; flag values never do. Each issue points at the outcome’s primary subject and carries the native identifiers, flags, metadata, message, all subjects, diagnostics, and properties in its details.

Return type:

pyxsd.validation.ValidationReport

to_svrl()

Serialize this report as ISO 2025 SVRL.

Serialization reads only the native active-set, fired-rule, and outcome records. No instance text is reparsed, no XSLT is run, and the output contains no generator marker. Firing identity pairs outcomes with their own firing, and a document location is emitted only where the grammar’s anyURI type can represent it.

Return type:

str

to_json()

Serialize this report as deterministic, object-explicit JSON.

The payload states the outcome kind, firing identity, identifiers, flags, link metadata, message parts, subject paths and spans, diagnostics, properties, the caller’s phase selector, the resolved phase identity, document identity, and validity with plain JSON values only.

Return type:

str