Skip to content

Commit

Permalink
Refactored and simplified composition pipeline supporting definitions…
Browse files Browse the repository at this point in the history
… declared to be 'local' at top level (#76); now with unit testing
  • Loading branch information
wendellpiez authored and david-waltermire committed Nov 13, 2020
1 parent 464a418 commit 63b57ad
Show file tree
Hide file tree
Showing 33 changed files with 381 additions and 1,854 deletions.
1 change: 0 additions & 1 deletion toolchains/xslt-M4/SEF/make-xsd-sef.json

This file was deleted.

30 changes: 29 additions & 1 deletion toolchains/xslt-M4/compose/metaschema-collect.xsl
Expand Up @@ -22,7 +22,9 @@
<!-- ====== ====== ====== ====== ====== ====== ====== ====== ====== ====== ====== ====== -->
<!-- Aggregate metaschema imports without further processing anything.
Trace nominal sources.
Defend against endless loops. -->
Defend against endless loops.
Also expands top-level declarations marked scope='local' into local declarations, while removing them. -->

<xsl:mode name="acquire" on-no-match="shallow-copy"/>

Expand Down Expand Up @@ -55,4 +57,30 @@
</xsl:choose>
</xsl:template>

<xsl:key name="top-level-local-assembly-definition-by-name"
match="METASCHEMA/define-assembly[@scope='local']" use="@name"/>

<xsl:key name="top-level-local-field-definition-by-name"
match="METASCHEMA/define-field[@scope='local']" use="@name"/>

<xsl:key name="top-level-local-flag-definition-by-name"
match="METASCHEMA/define-flag[@scope='local']" use="@name"/>

<xsl:template mode="acquire" match="assembly[exists( key('top-level-local-assembly-definition-by-name',@ref) )]">
<xsl:copy-of select="key('top-level-local-assembly-definition-by-name',@ref) "/>
</xsl:template>

<xsl:template mode="acquire" match="field[exists( key('top-level-local-field-definition-by-name',@ref) )]">
<xsl:copy-of select="key('top-level-local-field-definition-by-name',@ref) "/>
</xsl:template>

<xsl:template mode="acquire" match="flag[exists( key('top-level-local-flag-definition-by-name',@ref) )]">
<xsl:copy-of select="key('top-level-local-flag-definition-by-name',@ref) "/>
</xsl:template>

<xsl:template mode="acquire"
match="METASCHEMA/define-assembly[@scope='local'] |
METASCHEMA/define-field[@scope='local'] |
METASCHEMA/define-flag[@scope='local']"/>

</xsl:stylesheet>
12 changes: 6 additions & 6 deletions toolchains/xslt-M4/compose/metaschema-compose-debug.xpl
Expand Up @@ -25,13 +25,13 @@
<p:pipe port="result" step="reduce1"/>
</p:output>

<p:serialization port="_3_reduced2" indent="true"/>
<!--<p:serialization port="_3_reduced2" indent="true"/>
<p:output port="_3_reduced2" primary="false">
<p:pipe port="result" step="reduce2"/>
</p:output>
</p:output>-->

<p:serialization port="_4_digested" indent="true"/>
<p:output port="_4_digested" primary="false">
<p:serialization port="_3_digested" indent="true"/>
<p:output port="_3_digested" primary="false">
<p:pipe port="result" step="digest"/>
</p:output>

Expand All @@ -57,11 +57,11 @@
</p:input>
</p:xslt>

<p:xslt name="reduce2">
<!-- No longer filtering definitions reachable from nominal root <p:xslt name="reduce2">
<p:input port="stylesheet">
<p:document href="metaschema-reduce2.xsl"/>
</p:input>
</p:xslt>
</p:xslt>-->

<p:xslt name="digest">
<p:input port="stylesheet">
Expand Down
42 changes: 34 additions & 8 deletions toolchains/xslt-M4/compose/testing/1_collected/collect-result.html
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test Report for C:/Users/wap1/Documents/usnistgov/OSCAL/build/metaschema/toolchains/xslt-M4/compose/metaschema-collect.xsl (passed: 1 / pending: 0 / failed: 0 / total: 1)</title>
<title>Test Report for C:/Users/wap1/Documents/usnistgov/OSCAL/build/metaschema/toolchains/xslt-M4/compose/metaschema-collect.xsl (passed: 2 / pending: 0 / failed: 0 / total: 2)</title>
<style type="text/css">/****************************************************************************/
/* File: test-report.css */
/* Author: Jeni Tennison */
Expand Down Expand Up @@ -511,7 +511,7 @@
<h1>Test Report</h1>
<p>Stylesheet: <a href="file:/C:/Users/wap1/Documents/usnistgov/OSCAL/build/metaschema/toolchains/xslt-M4/compose/metaschema-collect.xsl">C:/Users/wap1/Documents/usnistgov/OSCAL/build/metaschema/toolchains/xslt-M4/compose/metaschema-collect.xsl</a></p>
<p>XSpec: <a href="file:/C:/Users/wap1/Documents/usnistgov/OSCAL/build/metaschema/toolchains/xslt-M4/compose/testing/1_collected/collect.xspec">C:/Users/wap1/Documents/usnistgov/OSCAL/build/metaschema/toolchains/xslt-M4/compose/testing/1_collected/collect.xspec</a></p>
<p>Tested: 15 October 2020 at 16:36</p>
<p>Tested: 16 October 2020 at 11:59</p>
<h2>Contents</h2>
<table class="xspec">
<colgroup>
Expand All @@ -524,15 +524,22 @@ <h2>Contents</h2>
<thead>
<tr>
<th></th>
<th class="totals">passed: 1</th>
<th class="totals">passed: 2</th>
<th class="totals">pending: 0</th>
<th class="totals">failed: 0</th>
<th class="totals">total: 1</th>
<th class="totals">total: 2</th>
</tr>
</thead>
<tbody>
<tr class="successful">
<th><a href="#top_scenario1">Modular Assembly</a></th>
<th><a href="#top_scenario1">Working metaschema</a></th>
<th class="totals">1</th>
<th class="totals">0</th>
<th class="totals">0</th>
<th class="totals">1</th>
</tr>
<tr class="successful">
<th><a href="#top_scenario2">Metaschema skeleton</a></th>
<th class="totals">1</th>
<th class="totals">0</th>
<th class="totals">0</th>
Expand All @@ -541,19 +548,38 @@ <h2>Contents</h2>
</tbody>
</table>
<div id="top_scenario1">
<h2 class="successful">Modular Assembly<span class="scenario-totals">passed: 1 / pending: 0 / failed: 0 / total: 1</span></h2>
<h2 class="successful">Working metaschema<span class="scenario-totals">passed: 1 / pending: 0 / failed: 0 / total: 1</span></h2>
<table class="xspec" id="table_scenario1">
<colgroup>
<col style="width:75%" />
<col style="width:25%" />
</colgroup>
<tbody>
<tr class="successful">
<th>Modular Assembly</th>
<th>Working metaschema</th>
<th>passed: 1 / pending: 0 / failed: 0 / total: 1</th>
</tr>
<tr class="successful">
<td>Modules collected, no loops</td>
<td>Success</td>
</tr>
</tbody>
</table>
</div>
<div id="top_scenario2">
<h2 class="successful">Metaschema skeleton<span class="scenario-totals">passed: 1 / pending: 0 / failed: 0 / total: 1</span></h2>
<table class="xspec" id="table_scenario2">
<colgroup>
<col style="width:75%" />
<col style="width:25%" />
</colgroup>
<tbody>
<tr class="successful">
<th>Metaschema skeleton</th>
<th>passed: 1 / pending: 0 / failed: 0 / total: 1</th>
</tr>
<tr class="successful">
<td>Basic metaschema composition</td>
<td>Modules collected, no loops</td>
<td>Success</td>
</tr>
</tbody>
Expand Down
55 changes: 54 additions & 1 deletion toolchains/xslt-M4/compose/testing/1_collected/collect.xspec
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0"
xmlns:opr="http://csrc.nist.gov/ns/oscal/profile-resolution" xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="../../metaschema-collect.xsl">
xmlns:opr="http://csrc.nist.gov/ns/oscal/profile-resolution" xmlns:x="http://www.jenitennison.com/xslt/xspec"
stylesheet="../../metaschema-collect.xsl">

<!-- metaschema-collect.xsl does two things:
- merges modular metaschemas into a single tree of metaschemas
Expand All @@ -15,5 +16,57 @@
<x:context href="../working_metaschema.xml"/>
<x:expect label="Modules collected, no loops" href="working_metaschema-COLLECTED.xml"/>
</x:scenario>

<x:scenario label="Metaschema skeleton">
<!-- Mysteriously, sometimes select="*" makes XSpec problems go away, other times not. -->
<x:context mode="acquire">
<METASCHEMA module="...">
<define-assembly name="root">
<root-name>root-assembly</root-name>
<flag ref="top-level-flag"/>
<define-flag name="local-flag">
<formal-name>Locally defined flag</formal-name>
<description>XXX</description>
</define-flag>
<model>
<field ref="top-level-global-field"/>
<field ref="top-level-local-field"/>
<define-field name="local-field">
<formal-name>Locally defined field</formal-name>
<description>XXX</description>
</define-field>
</model>
</define-assembly>
<define-field name="top-level-global-field"/>
<define-field name="top-level-local-field" scope="local"/>
<define-flag name="top-level-flag"/>
</METASCHEMA>
</x:context>
<x:expect label="Modules collected, no loops">
<METASCHEMA module="...">
<define-assembly name="root">
<root-name>root-assembly</root-name>
<flag ref="top-level-flag"/>
<define-flag name="local-flag">
<formal-name>Locally defined flag</formal-name>
<description>XXX</description>
</define-flag>
<model>
<field ref="top-level-global-field"/>
<define-field name="top-level-local-field" scope="local"/>
<define-field name="local-field">
<formal-name>Locally defined field</formal-name>
<description>XXX</description>
</define-field>
</model>
</define-assembly>
<define-field name="top-level-global-field"/>

<define-flag name="top-level-flag"/>
</METASCHEMA>

</x:expect>
</x:scenario>


</x:description>
@@ -1,75 +1,70 @@
<METASCHEMA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0"
module="...">
<schema-name module="...">OSCAL TEST Format</schema-name>
<schema-version module="...">0.0</schema-version>
<short-name module="...">oscal-test</short-name>
<namespace module="...">http://csrc.nist.gov/ns/metaschema/test</namespace>
<remarks module="...">
<p module="...">For exercising Metaschema semantics with respect to modular assembly and composition.</p>
module="file:/C:/Users/wap1/Documents/usnistgov/OSCAL/build/metaschema/toolchains/xslt-M4/compose/testing/working_metaschema.xml">
<schema-name>OSCAL TEST Format</schema-name>
<schema-version>0.0</schema-version>
<short-name>oscal-test</short-name>
<namespace>http://csrc.nist.gov/ns/metaschema/test</namespace>
<remarks>
<p>For exercising Metaschema semantics with respect to modular assembly and composition.</p>
</remarks>
<METASCHEMA abstract="yes"
module="...">
<schema-name module="...">OSCAL Control Catalog Format</schema-name>
<schema-version module="...">1.0.0-milestone3</schema-version>
<short-name module="...">oscal-catalog</short-name>
<namespace module="...">http://csrc.nist.gov/ns/metaschema/test</namespace>
<remarks module="...">
<p module="...">For exercising Metaschema semantics with respect to modular assembly and composition.</p>
</remarks>
<define-assembly name="module-assembly" module="...">
<formal-name module="...">Assembly defined in a module</formal-name>
<description module="...">XXX</description>
<define-flag name="local-flag" module="...">
<formal-name module="...">Locally defined flag</formal-name>
<description module="...">XXX</description>
module="file:/C:/Users/wap1/Documents/usnistgov/OSCAL/build/metaschema/toolchains/xslt-M4/compose/testing/module_metaschema.xml">
<schema-name>OSCAL TEST Format Module</schema-name>
<schema-version>0.0</schema-version>
<short-name>oscal-test</short-name>
<namespace>http://csrc.nist.gov/ns/metaschema/test</namespace>
<define-assembly name="module-assembly">
<formal-name>Assembly defined in a module</formal-name>
<description>XXX</description>
<define-flag name="local-flag">
<formal-name>Locally defined flag</formal-name>
<description>XXX</description>
</define-flag>
<model module="...">
<field ref="module-global-field" module="..."/>
<field ref="module-top-level-local-field" module="..."/>
<define-field name="module-local-field" module="...">
<formal-name module="...">Locally defined field</formal-name>
<description module="...">XXX</description>
<model>
<field ref="module-global-field"/>
<define-field name="module-top-level-local-field" scope="local">
<formal-name>Field, defined in a module as 'local', should appear as 'local'</formal-name>
<description>ZZZ</description>
</define-field>
<define-field name="module-local-field">
<formal-name>Locally defined field</formal-name>
<description>XXX</description>
</define-field>
</model>
</define-assembly>
<define-field name="module-global-field" module="...">
<formal-name module="...">Field, defined in a module (global by default)</formal-name>
<description module="...">XXX</description>
</define-field>
<define-field name="module-top-level-local-field" scope="local" module="...">
<formal-name module="...">Field, defined in a module as 'local'</formal-name>
<description module="...">XXX</description>
<define-field name="module-global-field">
<formal-name>Field, defined in a module (global by default)</formal-name>
<description>XXX</description>
</define-field>
</METASCHEMA>
<define-assembly name="root" module="...">
<formal-name module="...">Nominal root</formal-name>
<description module="...">XXX</description>
<root-name module="...">root-assembly</root-name>
<flag ref="top-level-flag" module="..."/>
<define-flag name="local-flag" module="...">
<formal-name module="...">Locally defined flag</formal-name>
<description module="...">XXX</description>
<define-assembly name="root">
<formal-name>Nominal root</formal-name>
<description>XXX</description>
<root-name>root-assembly</root-name>
<flag ref="top-level-flag"/>
<define-flag name="local-flag">
<formal-name>Locally defined flag</formal-name>
<description>XXX</description>
</define-flag>
<model module="...">
<field ref="top-level-global-field" module="..."/>
<field ref="top-level-local-field" module="..."/>
<define-field name="local-field" module="...">
<formal-name module="...">Locally defined field</formal-name>
<description module="...">XXX</description>
<model>
<field ref="top-level-global-field"/>
<define-field name="top-level-local-field" scope="local">
<formal-name>Field, defined at top level as 'local'</formal-name>
<description>XXX</description>
</define-field>
<define-field name="local-field">
<formal-name>Locally defined field</formal-name>
<description>XXX</description>
</define-field>
</model>
</define-assembly>
<define-field name="top-level-global-field" module="...">
<formal-name module="...">Field, defined at top level (global by default)</formal-name>
<description module="...">XXX</description>
</define-field>
<define-field name="top-level-local-field" scope="local" module="...">
<formal-name module="...">Field, defined at top level as 'local'</formal-name>
<description module="...">XXX</description>
<define-field name="top-level-global-field">
<formal-name>Field, defined at top level (global by default)</formal-name>
<description>XXX</description>
</define-field>
<define-flag name="top-level-flag" module="...">
<formal-name module="...">Flag, defined at top level</formal-name>
<description module="...">XXX</description>
<define-flag name="top-level-flag">
<formal-name>Flag, defined at top level</formal-name>
<description>XXX</description>
</define-flag>
</METASCHEMA>

0 comments on commit 63b57ad

Please sign in to comment.