Git Product home page Git Product logo

schematronmd's Introduction

SchematronMD

This repository contains a Velocity template to be used with the MagicDraw Report Wizard to generate a Schematron ruleset.

The ruleset

The rules generated by the VTL template protect against a class of syntactic errors relating to the use of the xsd:ID, xsd:IDREF and xsd:IDREFS data types.

The xsd:ID class of types are used in the Cast Vote Records and Election Results Reporting common data formats to conserve storage space. For example, it would be inefficient to repeat details about the a particular contest in an instance containing multiple CVRs.

Instead, reusable data is defined once and referenced when needed. However, a problem arises when the UML Model is converted to a concrete format such as XML Schema. The xsd:ID type is opaque, meaning it doesn't convey any details about the type it refers. Thus, the XML Schema cannot enforce the proper "wiring" of xsd:ID to and from xsd:IDREF and xsd:IDREFS.

Schematron rulesets are used to fill this gap. The VTL template automatically generates rules enforcing the types that can appear on either end of a directed association.

Rule patterns

There are two patterns of rules generated by the VTL template, forward lookups, and reverse lookups.

Forward Lookups

A forward lookup enforces the predicate of the form {X}Ids must point to an element of type {X}, where {X} is a type in the XML Schema.

Example

UML model showing relationship between Candidate and Party

Consider the type Candidate. It has an element PartyId to associate a candidate to one or more political parties. A schematron rule enforcing this relationship is given below:

<sch:rule context="element(*, err:Candidate)">
    <sch:assert test="not(id(err:PartyId)[not(. instance of element(*, err:Party))])">PartyId (<xsl:value-of select="err:PartyId" />) must point to an element of type Party</sch:assert>
</sch:rule>

id(err:PartyId) uses the XPath id function to return the element containing that id. It should be a type of Party! The predicate in the brackets, . instance of element(*, err:Party) checks exactly that.

The use of not in the above example at first glance appears confusing. For the rule to validate, it must not return any elements (an empty sequence casts to the boolean value of false). Thus we also negate the predicate, that it only returns an element when the instance is not of the desired type. Because we could potentially list multiple xsd:ID in an XSD:IDREFS, we cannot test the positive case without knowing the exact number expected, which cannot be done at compile time.

Reverse Lookups

Reverse lookups are used to validate that reusable data is referenced by other parts of the NIST 1500-XXX CDF instance. For example, it likely does not make sense to define a Candidate that is not used by any Contest, or a Party that is not used by any Candidate.

It is a judgement call if a particular set of reusable data needs to be referenced within the file. For example, a jurisdiction may want to include a Candidate that withdrew from an election. Because the Candidate might no longer referenced by a Contest, it would generate an error.

A reverse lookup enforces a predicate of the form {X} must have reference from {Y}, where {X} and {Y} are types in the XML Schema.

Example

Consider the following UML model and schematron rule:

UML model showing Candidate, RetentionContest and CandidateSelection classes

<sch:rule context="element(*, cdf:Candidate)">
    <sch:assert test="count(idref(current()/@ObjectId)[(local-name() = 'CandidateIds' and .. instance of element(*, cdf:CandidateSelection)) or (local-name() = 'CandidateId' and .. instance of element(*, cdf:RetentionContest))]) > 0">Candidate (<xsl:value-of select="current()/@ObjectId"/>) must have reference from CandidateSelection, RetentionContest</sch:assert>
</sch:rule>

The XPath function idref finds all the references to Candidate. We then apply a predicate that checks if the referencing type is one that is allowed, and if so, adds it to the count. In the above case, CandidateSelection and RetentionContest are able to reference Candidate. The rule passes as long as at least one type references Candidate.

schematronmd's People

Contributors

jdziurlaj avatar

Watchers

 avatar  avatar

schematronmd's Issues

Single Hit

It appears that the Schematron validation in Oxygen is single hit, i.e. for any given element, only a single element will match. This has implication for subtypes.

Recusive composing relationships

We may be missing some rules that match recursing composing relationships. The only one I know of is SubOfficeGroup in ERR and BD. We could likely do something like /BallotDefinition/OfficeGroup/child::SubOfficeGroup/OfficeIds.

Rules that satisfy parent must satisfy children

Rules that satisfy the child class, such as a reference from a composing GpUnit, must also satisfy that predicate in the child class. This will likely require storing all the XPath expressions for each class and concatenating them in the case of parent/child relationships.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.