pyxsd.schematron.schema¶
Public facade for standalone ISO Schematron compilation and validation.
One SchematronSchema holds the immutable compiled schema produced by
the source-load, resource-closure, abstract-expansion, and compilation stages.
It may be shared: every SchematronSchema.validate() call opens its own
expression session, variables, document registry, and execution budget, so no
per-instance state or parser posture crosses validations.
Top-level sch:param declarations are immutable compiled definitions with
query-fragment defaults, and SchematronSchema.validate() accepts
session-local parameters overrides for them. Top-level library
xsl:param declarations use the separate stylesheet_parameters channel
because the two namespaces can collide. Typed sch:let/@as variables,
dynamic check metadata, and XSLT 3.0 message text value templates evaluate
through the same per-validation session.
Raw schema and instance sources are admitted once through the supplied
ResourcePolicy or XML parser policy. An
already-built XDM document or node is used unchanged, and a captured common
Document contributes exactly its coherent
to_xdm() tree. A document without a capture, or
with a replaced root or edited bound tree, raises
XdmInputError; its raw source is never reparsed.
A compile-time resource policy authorizes schema includes, external extends,
and imported XSLT declarations. The whole closure compiles inside the policy’s
per-compilation scope, and every dependency read names its containing resource
as the base, so no dependency is ever authorized as a fresh root. It is not
validation authority: a validation without an explicit resource_policy
reads only local files, so callers grant instance and subordinate-document
access per validation.
Classes¶
One immutable compiled Schematron schema, safe to share. |
Functions¶
|
Compile one Schematron schema; shorthand for |
Module Contents¶
- class pyxsd.schematron.schema.SchematronSchema(compiled)¶
One immutable compiled Schematron schema, safe to share.
Construct one with
compile()or the module-levelcompile(). The object stores no per-instance resources or budgets; a validation receives fresh state.- Parameters:
compiled (pyxsd.schematron.ir.CompiledSchema)
- classmethod compile(source, *, query_binding=None, resource_policy=None, xml_policy=None, xml_limits=None, limits=None)¶
Load, resolve, expand, and compile one Schematron schema.
sourceis a local path, bytes-like object, or readable text/binary stream. A remote reference requires an authorizingresource_policy; without one it is a policy denial rather than a filesystem path.resource_policyowns reading and parsing the schema and every include, external extends, and XSLT module it names. The whole closure compiles inside the policy’s per-compilation scope, the same scopepyxsd.compile()enters, so a policy that distinguishes a root from a dependency authorizes none of those reads as a fresh root and accounts every one against the same closure budgets.xml_policyandxml_limitsconfigure parsing only when no resource policy is supplied; combining them is rejected before any input is read. They govern the root and every dependency parsed without a policy, so a bound the root satisfies also bounds each include and external extends.query_bindingoverrides the authored@queryBinding.limitsbounds resource closure, expansion, and expression compilation. Each field is one compile-stage budget:max_expanded_elementscounts the elements that includes, external extends, and abstract expansion produce together, so a value every stage fits alone can still be exhausted by their sum. Compile failures raiseSchematronErrorsubclasses with the responsible source occurrence where one exists.- Parameters:
source (SchematronSource)
query_binding (str | None)
resource_policy (pyxsd.resource_policy.ResourcePolicy | None)
xml_policy (pyxsd.xml_policy.XmlParserPolicy | None)
xml_limits (pyxsd.xml_policy.XmlLimits | None)
limits (pyxsd.schematron.limits.SchematronCompileLimits | None)
- Return type:
- validate(instance, *, phase=None, parameters=None, stylesheet_parameters=None, resource_policy=None, xml_policy=None, xml_limits=None, limits=None)¶
Validate one instance against this compiled schema.
instanceis a raw local path, bytes-like object, or readable stream, an XDM document or subtree, or a captured commonDocument. Raw input is read once and those admitted bytes are parsed separately by the source index and the XDM builder, plus the supplied policy’s parser when one is present; every view describes the same revision. XDM input passes through unchanged; a common document contributes its coherentto_xdm()tree and is never reparsed. Parser options are rejected for already-parsed input.phaseselects the active patterns.Noneand#DEFAULTuse the schema’sdefaultPhasewhen declared and otherwise activate every pattern;#ALLactivates every pattern without phase variables or a phase@from;#ANYevaluates only declared 2025phase/@whenconditions in document order and selects the first true phase, or activates every pattern when none match. Any other value names a declared phase and ignores that phase’s@when. A selected named or default phase may bound the original document’s candidate roots with@from, intersected with any supplied validation subtree; subordinatepattern/@documentsdocuments stay unrestricted. An unknown name raisesSchematronEvaluationErrorwithstage="phase".parameterssupplies values for the compiled schema’s top-levelsch:paramdeclarations. pyxsd implements the standard’s optional user-supplied value this way: a key must name a declared parameter and a value is a primitive, XDM item, or sequence, converted through the host’s XDM machinery. An undeclared name, an unsupported Python value, or a failed conversion raisesSchematronEvaluationErrorwithstage="parameters". Overrides are session-local and never mutate the compiled schema; omitted parameters keep their evaluated defaults.stylesheet_parameterssupplies values for the schema’s top-level libraryxsl:paramdeclarations, a separate channel fromparametersbecause a schema parameter and anxsl:paramcan share a lexical name. Keys are the host’s Clark-name, EQName, or lexical-QName parameter names; values pass through the host’s XDM conversion and each declaration’s@astype. An undeclared or static name, a duplicate expanded name, a failed conversion, or a missing required parameter (including an XSLT 3.0 typed parameter with no default) raisesSchematronEvaluationErrorwithstage="parameters". Omitted defaulted parameters keep their declared default, and XSLT 2.0 does not apply the XSLT 3.0 implicit-mandatory rule. Bindings are session-local.resource_policyauthorizes raw instances and every subordinatedocument()/doc()/pattern/@documentsread. Compilation authority is never reused, soNonereaches only local files.limitsbounds retained outcomes and shared execution work; an exhausted limit raisesSchematronLimitErrorand never returns a partial report.- Parameters:
instance (SchematronSource | pyxsd.xdm.nodes.XdmDocument | pyxsd.xdm.nodes.XdmNode | pyxsd.document.Document)
phase (str | None)
parameters (collections.abc.Mapping[str, Any] | None)
stylesheet_parameters (collections.abc.Mapping[str, Any] | None)
resource_policy (pyxsd.resource_policy.ResourcePolicy | None)
xml_policy (pyxsd.xml_policy.XmlParserPolicy | None)
xml_limits (pyxsd.xml_policy.XmlLimits | None)
limits (pyxsd.schematron.limits.SchematronValidationLimits | None)
- Return type:
- pyxsd.schematron.schema.compile(source, *, query_binding=None, resource_policy=None, xml_policy=None, xml_limits=None, limits=None)¶
Compile one Schematron schema; shorthand for
SchematronSchema.compile.Every argument has the same meaning as on the class method. The result is immutable and may serve concurrent validations of distinct documents.
- Parameters:
source (SchematronSource)
query_binding (str | None)
resource_policy (pyxsd.resource_policy.ResourcePolicy | None)
xml_policy (pyxsd.xml_policy.XmlParserPolicy | None)
xml_limits (pyxsd.xml_policy.XmlLimits | None)
limits (pyxsd.schematron.limits.SchematronCompileLimits | None)
- Return type: