pyxsd.schematron.model ====================== .. py:module:: pyxsd.schematron.model .. autoapi-nested-parse:: 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 :class:`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 ---------- .. autoapisummary:: pyxsd.schematron.model.OutcomeKind pyxsd.schematron.model.VISITED_PREVIEW_LIMIT Classes ------- .. autoapisummary:: pyxsd.schematron.model.MessagePart pyxsd.schematron.model.SchematronMessage pyxsd.schematron.model.DiagnosticMessage pyxsd.schematron.model.PropertyMessage pyxsd.schematron.model.ActivePattern pyxsd.schematron.model.FiredRule pyxsd.schematron.model.SchematronOutcome pyxsd.schematron.model.SchematronReport Module Contents --------------- .. py:data:: OutcomeKind .. py:data:: VISITED_PREVIEW_LIMIT :value: 10 .. py:class:: 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. .. py:attribute:: text :type: str .. py:attribute:: nodes :type: tuple[pyxsd.xdm.nodes.XdmNode, ...] :value: () .. py:attribute:: name :type: str | None :value: None .. py:attribute:: attributes :type: tuple[tuple[str, str], ...] :value: () .. py:attribute:: children :type: tuple[MessagePart, ...] :value: () .. py:class:: SchematronMessage One check, diagnostic, or property message as native structured parts. .. py:attribute:: parts :type: tuple[MessagePart, ...] .. py:property:: text :type: str The flattened string value of every part, in authored order. .. py:class:: 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. .. py:attribute:: id :type: str .. py:attribute:: message :type: SchematronMessage .. py:attribute:: origin :type: pyxsd.locations.IssueLocation | None .. py:attribute:: language :type: str | None .. py:attribute:: role :type: str | None .. py:class:: 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. .. py:attribute:: id :type: str .. py:attribute:: message :type: SchematronMessage .. py:attribute:: origin :type: pyxsd.locations.IssueLocation | None .. py:attribute:: language :type: str | None .. py:attribute:: role :type: str | None .. py:attribute:: scheme :type: str | None .. py:class:: 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. .. py:attribute:: pattern_id :type: str | None .. py:attribute:: origin :type: pyxsd.locations.IssueLocation | None .. py:attribute:: document_uri :type: str | None .. py:attribute:: pattern_ordinal :type: int | None :value: None .. py:attribute:: kind :type: pyxsd.schematron.ir.PatternKind :value: 'pattern' .. py:attribute:: roots :type: tuple[pyxsd.xdm.nodes.XdmNode, ...] | None :value: None .. py:attribute:: title :type: str | None :value: None .. py:attribute:: role :type: str | None :value: None .. py:attribute:: documents_source :type: str | None :value: None .. py:class:: 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. .. py:attribute:: pattern_id :type: str | None .. py:attribute:: rule_id :type: str | None .. py:attribute:: context :type: pyxsd.xdm.nodes.XdmNode .. py:attribute:: origin :type: pyxsd.locations.IssueLocation | None .. py:attribute:: document_uri :type: str | None .. py:attribute:: pattern_ordinal :type: int | None :value: None .. py:attribute:: visited_count :type: int | None :value: None .. py:attribute:: visited_preview :type: tuple[pyxsd.xdm.values.XdmItem, ...] :value: () .. py:attribute:: firing_id :type: int | None :value: None .. py:attribute:: visit_each_source :type: str | None :value: None .. py:attribute:: flag :type: tuple[str, ...] :value: () .. py:attribute:: role :type: str | None :value: None .. py:class:: 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 :class:`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. .. py:attribute:: kind :type: OutcomeKind .. py:attribute:: test :type: str .. py:attribute:: context :type: pyxsd.xdm.nodes.XdmNode .. py:attribute:: pattern_id :type: str | None .. py:attribute:: rule_id :type: str | None .. py:attribute:: check_id :type: str | None .. py:attribute:: origin :type: pyxsd.locations.IssueLocation | None .. py:attribute:: document_uri :type: str | None .. py:attribute:: message :type: SchematronMessage | None :value: None .. py:attribute:: subjects :type: tuple[pyxsd.xdm.nodes.XdmNode, ...] :value: () .. py:attribute:: diagnostics :type: tuple[DiagnosticMessage, ...] :value: () .. py:attribute:: properties :type: tuple[PropertyMessage, ...] :value: () .. py:attribute:: flags :type: tuple[str, ...] :value: () .. py:attribute:: language :type: str | None :value: None .. py:attribute:: role :type: str | None :value: None .. py:attribute:: see :type: str | None :value: None .. py:attribute:: fpi :type: str | None :value: None .. py:attribute:: icon :type: str | None :value: None .. py:attribute:: pattern_ordinal :type: int | None :value: None .. py:attribute:: severity :type: str | None :value: None .. py:attribute:: visited :type: pyxsd.xdm.values.XdmItem | None :value: None .. py:attribute:: visited_ordinal :type: int | None :value: None .. py:attribute:: firing_id :type: int | None :value: None .. py:property:: primary_subject :type: pyxsd.xdm.nodes.XdmNode The first subject, or the rule context when none was selected. .. py:class:: 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. .. py:attribute:: schema :type: pyxsd.schematron.ir.CompiledSchema .. py:attribute:: instance :type: pyxsd.xdm.nodes.XdmNode .. py:attribute:: phase :type: str | None .. py:attribute:: active_patterns :type: tuple[ActivePattern, ...] .. py:attribute:: fired_rules :type: tuple[FiredRule, ...] .. py:attribute:: outcomes :type: tuple[SchematronOutcome, ...] .. py:attribute:: resolved_phase :type: str | None :value: None .. py:attribute:: documents :type: tuple[pyxsd.xdm.nodes.XdmDocument, ...] :value: () .. py:property:: failed_assertions :type: tuple[SchematronOutcome, ...] Outcomes produced by assertions whose test was false. .. py:property:: successful_reports :type: tuple[SchematronOutcome, ...] Outcomes produced by reports whose test was true. .. py:property:: is_valid :type: bool Whether the instance has no failed assertion. .. py:method:: 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``. .. py:method:: 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. .. py:method:: 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.