pub struct Schematron { /* private fields */ }Expand description
A compiled Schematron schema, ready to validate instances.
Implementations§
Source§impl Schematron
impl Schematron
Sourcepub fn compile(schema_doc: &Document) -> Result<Schematron, XsltError>
pub fn compile(schema_doc: &Document) -> Result<Schematron, XsltError>
Compile a parsed Schematron schema document. The document
MUST have been parsed in namespace-aware mode — Schematron
is namespace-driven (rule contexts and assertion tests use
prefixes declared by <sch:ns> elements).
Returns XsltError::InvalidStylesheet for structural
problems (no <schema> root, missing test= on assert,
etc.) — reusing XsltError keeps the public surface small.
Sourcepub fn compile_with_loader(
schema_doc: &Document,
loader: &dyn Loader,
base: Option<&str>,
) -> Result<Schematron, XsltError>
pub fn compile_with_loader( schema_doc: &Document, loader: &dyn Loader, base: Option<&str>, ) -> Result<Schematron, XsltError>
Compile a Schematron schema, resolving any <sch:include>
references via loader. base is the URI of the containing
schema (used by crate::loader::Loader::load for relative
href resolution); pass None when relative resolution isn’t
needed.
<sch:include href="other.sch"/> is supported at schema-,
pattern-, and rule-level: the referenced document’s content
is spliced in as if it had been inlined at the include site.
Fragment IDs (href="other.sch#frag") are honoured — when
present, the element in the loaded doc whose id="frag"
supplies the spliced content; without a fragment, the loaded
doc’s root supplies it.
Sourcepub fn compile_str(text: &str) -> Result<Schematron, XsltError>
pub fn compile_str(text: &str) -> Result<Schematron, XsltError>
Compile a Schematron schema directly from its text. Convenience wrapper.
Sourcepub fn compile_str_with_loader(
text: &str,
loader: &dyn Loader,
base: Option<&str>,
) -> Result<Schematron, XsltError>
pub fn compile_str_with_loader( text: &str, loader: &dyn Loader, base: Option<&str>, ) -> Result<Schematron, XsltError>
Compile a Schematron schema from its text, resolving any
<sch:include> references via loader. See
Schematron::compile_with_loader for include semantics.
Sourcepub fn compile_iso(
schema_text: &str,
base_dir: &str,
loader: &dyn Loader,
) -> Result<IsoSchematronValidator, XsltError>
pub fn compile_iso( schema_text: &str, base_dir: &str, loader: &dyn Loader, ) -> Result<IsoSchematronValidator, XsltError>
Compile via the official ISO Schematron XSLT pipeline:
run the schema through iso_dsdl_include.xsl →
iso_abstract_expand.xsl → iso_svrl_for_xslt1.xsl, then
use the generated SVRL-emitting validator stylesheet as
the actual validator. Output: a Schematron whose
validate method runs the validator stylesheet against
the instance and parses the SVRL findings.
loader resolves xsl:import references inside the
pipeline stylesheets (iso_svrl_for_xslt1.xsl imports
iso_schematron_skeleton_for_xslt1.xsl). base_dir is
where the pipeline xsl files live; use the host’s local
copy of lxml’s isoschematron/resources/xsl/iso-schematron-xslt1/.
Compared to Schematron::compile_str (our native
implementation), the ISO pipeline understands <abstract>
patterns, <extends>, and <include> references — at the
cost of being slower and depending on those vendored XSLT
files on disk. Use compile_str for simple schemas; use
compile_iso when you need full Schematron 1.6 features.
Source§impl Schematron
impl Schematron
Sourcepub fn validate_str(
&self,
instance_text: &str,
) -> Result<ValidationReport, XsltError>
pub fn validate_str( &self, instance_text: &str, ) -> Result<ValidationReport, XsltError>
Validate an instance from source text. Convenience wrapper
that parses with namespace_aware: true — required for
Schematron’s prefix-based rule contexts to resolve.
Sourcepub fn validate_str_with_phase(
&self,
instance_text: &str,
phase: &str,
) -> Result<ValidationReport, XsltError>
pub fn validate_str_with_phase( &self, instance_text: &str, phase: &str, ) -> Result<ValidationReport, XsltError>
Validate an instance from source text, running only the
patterns active under phase. See Schematron::validate_with_phase
for phase semantics.
Sourcepub fn validate(
&self,
instance_doc: &Document,
) -> Result<ValidationReport, XsltError>
pub fn validate( &self, instance_doc: &Document, ) -> Result<ValidationReport, XsltError>
Validate instance_doc against this schema. Returns a
ValidationReport with every failed assert and
successful report. The instance document MUST have been
parsed in namespace-aware mode if any rule contexts or
assertion tests use prefixed names; use
Schematron::validate_str for the common case.
Sourcepub fn validate_with_phase(
&self,
instance_doc: &Document,
phase: &str,
) -> Result<ValidationReport, XsltError>
pub fn validate_with_phase( &self, instance_doc: &Document, phase: &str, ) -> Result<ValidationReport, XsltError>
Validate instance_doc, running only the patterns active
under phase. ISO Schematron §6.5 — phases let a schema
expose multiple validation profiles from one declaration set.
Special phase names:
"#ALL"— run every pattern (the no-phase default)."#DEFAULT"— run the phase named by<schema defaultPhase=…>; if the schema has nodefaultPhase, falls back to#ALL.
Any other name is looked up in the schema’s <sch:phase>
declarations. An unknown name (one that isn’t #ALL, isn’t
#DEFAULT, and doesn’t match a declared phase id) returns
Err(InvalidStylesheet) so callers see the typo instead of
silently validating against zero patterns.