## Crane's CVA to Schematron XSLT for genericode

Import/include tree (in order of importance; reverse import order)

- Crane's CVA to Schematron XSLT for genericode - `Crane-cva2schXSLT.xsl`
  - Implementation of context/value association to Schematron - `Crane-Constraints2SchematronXSLT.xsl`
  - CVA support for genericode list-level definitions - `Crane-genericode-CodeList.xsl`

## 1. Crane's CVA to Schematron XSLT for genericode - `Crane-cva2schXSLT.xsl`

Filename: `Crane-cva2schXSLT.xsl`

Import statements:

- CVA support for genericode list-level definitions - `Crane-genericode-CodeList.xsl`
- Implementation of context/value association to Schematron - `Crane-Constraints2SchematronXSLT.xsl`

`$Id: Crane-cva2schXSLT.xsl,v 1.9 2013/02/07 19:40:41 admin Exp $`

A combination of stylesheets to convert an OASIS code list context association file for Genericode-expressed codelists.

Note that the output of this stylesheet is an XSLT stylesheet that must be run with any input file (possibly itself) to produce the required Schematron output file.

`ccs:comment select=" 'This CVA to Schematron implementation supports genericode code lists.' " (xsl:variable)`

> This string is added to the resulting Schematron assertion file to indicate which combination of stylesheets was used to create the Schematron schema.

## 2. Implementation of context/value association to Schematron - `Crane-Constraints2SchematronXSLT.xsl`

Path: `Crane-Constraints2SchematronXSLT.xsl`

`$Id: Crane-Constraints2SchematronXSLT.xsl,v 1.20 2010/05/19 15:29:58 gkholman Exp $`

A Schematron-based implementation of value validation supporting the OASIS Code List Representation Technical Committee specification of context/value association files. This implementation does not validate the query binding, but it does expect context-free addresses to be compatible with XPath 1 and XPath 2 syntax.

This stylesheet calls out to external template rules to accommodate the format of external code list enumerations, thus it is not hardwired to any particular document vocabulary or to the any particular representation of code lists.

It should not be necessary to modify this fragment in order to support any value list vocabulary definition. Rather, the importing stylesheet that imports this fragment would import a companion fragment that addresses all aspects of code list representation.

A stylesheet incorporating this fragment does not directly create a Schematron fragment. Rather, a standalone result XSLT stylesheet is created by this stylesheet. The resulting synthesized stylesheet can be run with no input or any input (any input is ignored) as it is self-contained. The output of running the resulting synthesized stylesheet is the Schematron pattern fragment needed for validation purposes.

Implementation restriction: at this time this script is checking individual code list association files for having non-conflicting prefixes for namespaces, but it is not checking the entire suite of prefixes for namespaces for every included file for unique usage of prefix values in the generated result. This may go unreported and cause a problem in the Schematron processing.

     Copyright (C) - Crane Softwrights Ltd.
                   - http://www.CraneSoftwrights.com/links/res-dev.htm

     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions are met:

     - Redistributions of source code must retain the above copyright notice,
       this list of conditions and the following disclaimer.
     - Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
     - The name of the author may not be used to endorse or promote products
       derived from this software without specific prior written permission.

     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
     NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
     TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

     Note: for your reference, the above is the "Modified BSD license", this text
         was obtained 2003-07-26 at http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5

`ccs:cva-namespace select="document('')/*/namespace::cva" (xsl:variable)`

> Makes namespace work more succinct in the stylesheet.

`ccs:sch-namespace select="document('')/*/namespace::sch" (xsl:variable)`

> Makes namespace work more succinct in the stylesheet.

`ccs:ids match="*[@xml:id]" use="normalize-space(@xml:id)" (xsl:key)`

> Keeps ids handy for uniqueness testing.

`ccs:valuetests match="ValueTest" use="normalize-space(@xml:id)" (xsl:key)`

> Keeps tests handy for reference.

`ccs:valuelists match="ValueList" use="normalize-space(@xml:id)" (xsl:key)`

> Keeps code lists handy for reference.

`ccs:metadatasets match="InstanceMetadataSet" use="normalize-space(@xml:id)" (xsl:key)`

> Keeps metadata sets handy for reference.

`ccs:assoc-file select="document('',/)" (xsl:variable)`

> This remembers the association file root node for the initial file only.

`ccs:assoc-uri (xsl:variable)`

> This sets the URI of the initial file to the empty string since it cannot be known automatically when using XSLT 1.0.

`encoding="ISO-8859-1" (xsl:output)`

> This makes the resulting file easy to view or to edit with an editor that does not support UTF-8 encoding.

`stylesheet-prefix="xslo" result-prefix="xsl" (xsl:namespace-alias)`

> This stylesheet creates another stylesheet, thus requiring aliasing of result tree fragments.

`match="/" (xsl:template)`

> This is the processing of the root node of all CVA files being processed (which initially is the first one but this also triggers for the root of referenced CVA files).

> Parameter `assoc-file`

> > The document node of the CVA file being processed.

> Parameter `assoc-uri`

> > The URI string for the CVA file being processed.

### 2.1. Templates in regard of creating Schematron rules.

`ccs:add-rules (xsl:template)`

> Add the rules from the context association file to the result.

> Parameter `assoc-file`

> > The document node of the association file being processed.

> Parameter `assoc-uri`

> > The URI string of the association file being processed.

`ccs:add-tests (xsl:template)`

> Add the tests needed for the rules to the result.

> Parameter `assoc-file`

> > The document node of the association file being processed.

> Parameter `assoc-uri`

> > The URI string of the association file being processed.

`ccs:gather-context match="Context" (xsl:template)`

> Create one rule for each context in the association file, gathering the information from all of the lists referenced.

> Parameter `assoc-uri`

> > The URI string of the association file being processed.

> Parameter `value-references`

> > The string of identifiers of `<ValueList>` and `<ValueTest>` elements that have not net been gathered.

> Parameter `valuetests-referenced`

> > The node set of value tests referenced.

> Parameter `valuelists-referenced`

> > The node set of references to external lists referenced.

`match="*" mode="ccs:Identification" (xsl:template)`

> Copy needed Identification nodes without namespaces.

`ccs:compose-rule (xsl:template)`

> Compose a Schematron rule expressing the asserted constraint.

> Parameter `context`

> > The context for which the rules are being made.

> Parameter `assertion`

> > The text of the assembled assertion (which may be limited to a non- assertion of simply "( true() ) ", which can be ignored.

> Parameter `values-identifier`

> > The identifier token for the value list being cited.

> Parameter `address`

> > The XPath context of the item being tested.

> Parameter `assoc-uri`

> > The URI string of the association file being processed.

> Parameter `mark`

> > The name token of a characterization of the rule and assertion.

`ccs:compose-violation-report (xsl:template)`

> Compose the default report of a context violation.

> Parameter `values-identifier`

> > The identifier token for the value list being cited.

> Parameter `assoc-uri`

> > The URI string of the association file being processed.

> Parameter `address`

> > The XPath address of the item with the violation.

`match="node()" mode="ccs:sch-only" (xsl:template)`

> Copy message content from the CVA file to the Schematron file.

`match="sch:*" mode="ccs:sch-only" (xsl:template)`

> Schematron elements in the message content need to go out without a namespace.

### 2.2. Validating the CVA file content business rules

`ccs:forbidden (xsl:variable)`

> Most characters not allowed in a part of an attribute or element name (this is not meant to be rigourous, just strong enough for obvious errors); assumes the axis is removed and the prefix and name are separate.

`ccs:check-inconsistencies (xsl:template)`

> Consistency checks for user's expression of constraints.

`ccs:check-code-list-uri-attribute (xsl:template)`

> Confirm that the current node URI attribute points to a code list specification.

> Parameter `check-only-document-existence`

> > For the masquerading code list file, there are no constraints other than it exists and is of the correct document type.

### 2.3. Infinite include loop checking

`ccs:check-infinite-loops (xsl:template)`

> Begin walk through include tree looking for an infinite loop.

`ccs:check-given-include-tree (xsl:template)`

> Recurse through nested include directives looking for a loop.

> Parameter `root-node-ids`

> > Collection of document nodes of included CVA files.

> Parameter `uri`

> > The association file URI string (not known for invocation CVA file) of the included CVA.

> Parameter `last-uri`

> > The association file URI string (not known for invocation CVA file) of the including CVA.

### 2.4. Diagnostics

`ccs:report-current-node-context (xsl:template)`

> Diagnostic function to report context for errors.

## 3. CVA support for genericode list-level definitions - `Crane-genericode-CodeList.xsl`

Path: `Crane-genericode-CodeList.xsl`

`$Id: Crane-genericode-CodeList.xsl,v 1.14 2013/02/07 19:21:11 admin Exp $`

Support for an implementation of the OASIS context/value association files of genericode files.

This fragment supports external code list expressions of code list values written using either genericode 0.4 or genericode 1.0, where those files use only simple values for keys.

`ccs:apos select=""'"" (xsl:variable)`

> A convenience variable for later use.

`ccs:code-list-confirm-instance (xsl:template)`

> Determine the presence of a document with the expected document element.

> Returns the string of an error message if there is a problem

> Parameter `valuelist`

> > The supplied declaration of the external value list

> Parameter `doc`

> > The root node of the external value list

> Parameter `check-only-document-existence`

> > For the masquerading code list file, there are no constraints other than it exists and is of the correct document type.

`ccs:code-list-make-rule (xsl:template)`

> Build Schematron `<rule>` elements using the selection of available values.

> Note the liberal use of newline sequences in the result using `<xsl:text>` in order to make the end result legible to a reader; these have no effect on the well-formedness of the result or the Schematron validation.

> Parameter `context`

> > The context for which the rules are being made.

> Parameter `address`

> > The XPath address of the information item being tested.

> Parameter `valuelists-referenced`

> > The `<ValueList>` elements being referenced by the context.

> Parameter `assoc-uri`

> > The URI string of the association file being processed.

`ccs:check-value-validity (xsl:template)`

> Check the value at the current node is acceptable for the implementation of XPath string checks.

> Parameter `list`

> > The supplied declaration of the external value list

### 3.1. Replicating identification information

For use in the second pass, the three sources of metadata are copied here in order of precedence, such that during the second pass the first metadata item encountered is the one used.

`match="ValueList" (xsl:template)`

> For each value list, copy the internal masquerading, the external masquarading, and the actual metadata.

> Parameter `assoc-uri`

> > The URI string of the association file being processed.

`match="Annotation" mode="ccs:Identification" (xsl:template)`

> Annotations are not needed

### 3.2. Metadata templates for second pass

`ccs:global-stylesheet-properties (xsl:template)`

> Prepare any XSLT global constructs.

`match="InstanceMetadataSet" (xsl:template)`

> Create a callable template for synthesizing metadata checks.

> Note that this has a lot of cosmetics in order to be visually verifiable in the end result.

> Parameter `assoc-uri`

> > The URI string of the association file being processed.

## 4. Index

A C F G I M R S V

A

- `ccs:add-rules` (Templates in regard of creating Schematron rules. - `Crane-Constraints2SchematronXSLT.xsl`)
- `ccs:add-tests` (Templates in regard of creating Schematron rules. - `Crane-Constraints2SchematronXSLT.xsl`)
- `ccs:apos` (CVA support for genericode list-level definitions - `Crane-genericode-CodeList.xsl`)
- `ccs:assoc-file` (Implementation of context/value association to Schematron - `Crane-Constraints2SchematronXSLT.xsl`)
- `ccs:assoc-uri` (Implementation of context/value association to Schematron - `Crane-Constraints2SchematronXSLT.xsl`)

C

- `ccs:check-code-list-uri-attribute` (Validating the CVA file content business rules - `Crane-Constraints2SchematronXSLT.xsl`)
- `ccs:check-given-include-tree` (Infinite include loop checking - `Crane-Constraints2SchematronXSLT.xsl`)
- `ccs:check-inconsistencies` (Validating the CVA file content business rules - `Crane-Constraints2SchematronXSLT.xsl`)
- `ccs:check-infinite-loops` (Infinite include loop checking - `Crane-Constraints2SchematronXSLT.xsl`)
- `ccs:check-value-validity` (CVA support for genericode list-level definitions - `Crane-genericode-CodeList.xsl`)
- `ccs:code-list-confirm-instance` (CVA support for genericode list-level definitions - `Crane-genericode-CodeList.xsl`)
- `ccs:code-list-make-rule` (CVA support for genericode list-level definitions - `Crane-genericode-CodeList.xsl`)
- `ccs:comment` (Crane's CVA to Schematron XSLT for genericode - `Crane-cva2schXSLT.xsl`)
- `ccs:compose-rule` (Templates in regard of creating Schematron rules. - `Crane-Constraints2SchematronXSLT.xsl`)
- `ccs:compose-violation-report` (Templates in regard of creating Schematron rules. - `Crane-Constraints2SchematronXSLT.xsl`)
- `ccs:cva-namespace` (Implementation of context/value association to Schematron - `Crane-Constraints2SchematronXSLT.xsl`)

F

- `ccs:forbidden` (Validating the CVA file content business rules - `Crane-Constraints2SchematronXSLT.xsl`)

G

- `ccs:gather-context` (Templates in regard of creating Schematron rules. - `Crane-Constraints2SchematronXSLT.xsl`)
- `ccs:global-stylesheet-properties` (Metadata templates for second pass - `Crane-genericode-CodeList.xsl`)

I

- `ccs:ids` (Implementation of context/value association to Schematron - `Crane-Constraints2SchematronXSLT.xsl`)

M

- `ccs:metadatasets` (Implementation of context/value association to Schematron - `Crane-Constraints2SchematronXSLT.xsl`)

R

- `ccs:report-current-node-context` (Diagnostics - `Crane-Constraints2SchematronXSLT.xsl`)

S

- `ccs:sch-namespace` (Implementation of context/value association to Schematron - `Crane-Constraints2SchematronXSLT.xsl`)

V

- `ccs:valuelists` (Implementation of context/value association to Schematron - `Crane-Constraints2SchematronXSLT.xsl`)
- `ccs:valuetests` (Implementation of context/value association to Schematron - `Crane-Constraints2SchematronXSLT.xsl`)