Skip to content

odd_relax

Write the RELAX NG schema for a compiled ODD (the result of compiled_odd), as the TEI Stylesheets' odd2relax does: opm odd compile --format rng.

opm.odd_relax

Translate a compiled ODD into RELAX NG, as the TEI Stylesheets' odd2relax does.

Expects the output of compiled_odd: one schemaSpec with every selected spec already merged (no moduleRef, @source, or @mode left to resolve). The translation follows what the TEI Stylesheets do in odds/odd2relax.xsl, odds/teiodds.xsl and odds/classatts.xsl.

  • Names. Each element, macro or class becomes a define named from its ident, with the spec's @prefix or the schemaSpec's. A model class is a choice of its members (notAllowed if empty). An attribute class becomes <class>.attributes, with parent-class refs and one <class>.attribute.<ident> per attribute.
  • Attributes. An element refs its classes' .attributes patterns. If its attList overrides a class attribute, that class is expanded attribute by attribute and the override is merged in.
  • Content. ODD content maps to RELAX NG: sequence → group (or list when it holds only dataRef), alternate → choice, @minOccurs / @maxOccurs → repetition patterns, classRef/@expand → the class members, anyElement → its own pattern. Datatypes are written inline; embedded RELAX NG in content is copied through.
  • Clean-up. Refs to specs the schema omits are dropped, along with empty patterns and unreachable definitions.

Does not embed Schematron (constraintSpec), and skips Guidelines chapters cited by listRef.

odd_to_rng

odd_to_rng(tree: _Element) -> _Element

The RELAX NG grammar for the compiled ODD tree.

Source code in src/opm/odd_relax.py
def odd_to_rng(tree: etree._Element) -> etree._Element:
    """The RELAX NG ``grammar`` for the compiled ODD *tree*."""
    return _Translator(tree).grammar()