Skip to main content

Schematron

Struct Schematron 

Source
pub struct Schematron { /* private fields */ }
Expand description

A compiled Schematron schema, ready to validate instances.

Implementations§

Source§

impl Schematron

Source

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.

Source

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.

Source

pub fn compile_str(text: &str) -> Result<Schematron, XsltError>

Compile a Schematron schema directly from its text. Convenience wrapper.

Source

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.

Source

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.xsliso_abstract_expand.xsliso_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

Source

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.

Source

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.

Source

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.

Source

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 no defaultPhase, 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.

Trait Implementations§

Source§

impl Debug for Schematron

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.