Skip to content

Commit

Permalink
Additional refactoring of build scripts and supporting files (usnistg…
Browse files Browse the repository at this point in the history
…ov#37)

* integrated schema generation unit tests with new build scripting
* Work in progress on metaschema-related updates towards OSCAL SSP conversion roundtrips.
* added required top-level property to all unit-test JSON schema files
* Added XSD targets for unit testing
* oXygen project file for metaschema testing
* Updated project file
* Test coverage and planning docs
* added unit test for collapse
* fixed a bug in the test script causing expected schema files to not be compared.
* Addressing Issue usnistgov#11: JSON Schema missing constraint at root
* Adding metaschema documentation. usnistgov#16 usnistgov/OSCAL#596
* Added CI/CD files for website.
* Added Github issue templates.
* Addressing usnistgov#12, supporting collapsibility of fields.
* Fixed website build error.
* Updating website contents and CI/CD configuration.
* Patch to catch up metaschema implementation to latest changes in the OSCAL repo.
* fixed broken links in documentation
* updated repository documentation to fix broken links
* added configuration support to build scripts
* Implemented content converter generation in build scripts
* Removed references to local files for usnistgov/OSCAL#566
* integrated schema generation unit tests with new build scripting
* Now accounting for json-value-key/json-key combination
* removed extra files

Co-authored-by: Wendell Piez <[email protected]>
  • Loading branch information
david-waltermire and wendellpiez authored Feb 5, 2020
1 parent e2388bf commit dd329a9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
49 changes: 33 additions & 16 deletions toolchains/oscal-m2/json/produce-json-converter.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<xsl:namespace name="m">http://csrc.nist.gov/ns/oscal/1.0/md-convertor</xsl:namespace>
<XSLT:output indent="yes" method="xml"/>

<xsl:comment expand-text="true"> OSCAL { @root} conversion stylesheet supports JSON->XML conversion </xsl:comment>
<xsl:comment expand-text="true"> OSCAL { @root } conversion stylesheet supports JSON->XML conversion </xsl:comment>

<XSLT:param name="target-ns" as="xs:string?" select="'{$composed-metaschema/METASCHEMA/namespace/normalize-space(.)}'"/>
<!--<XSLT:param name="target-ns" as="xs:string?" select="'{namespace/normalize-space(.)}'"/>-->
Expand Down Expand Up @@ -73,7 +73,7 @@
<!-- local flag definitions (given in field or assembly definitions) do require templates -->
<xsl:template match="flag[@name]" mode="make-template" expand-text="true">
<!-- Making a template to match a flag in context of its parent -->
<xsl:comment> 000 Handling flag "{ ../@name}/@{ @name }" 000 </xsl:comment>
<xsl:comment> *** Handling flag "{ ../@name}/@{ @name }" *** </xsl:comment>

<xsl:variable name="match-step" expand-text="yes" as="xs:string">*[@key='{@name}']</xsl:variable>
<xsl:variable name="match-patterns" as="xs:string*">
Expand All @@ -83,7 +83,7 @@
<xsl:text>*[@key='{@name}']/{$match-step}</xsl:text>
<xsl:for-each select="$group-names">
<xsl:text> | *[@key='{ . }']/{$match-step}</xsl:text>
<xsl:text> | array[@key='{ . }']/*/{$match-step}</xsl:text>
<xsl:text> | *[@key='{ . }']/*/{$match-step}</xsl:text>
</xsl:for-each>
</xsl:value-of>
</xsl:for-each>
Expand All @@ -100,7 +100,7 @@

<xsl:template match="define-flag" expand-text="true">
<!-- Flags won't be producing elements in the regular traversal -->
<xsl:comment> 000 Handling flag @{ @name } 000 </xsl:comment>
<xsl:comment> *** Handling flag @{ @name } *** </xsl:comment>
<xsl:variable name="flag-name" select="@name"/>
<XSLT:template match="*[@key='{@name}']" priority="6" mode="json2xml"/>

Expand Down Expand Up @@ -178,7 +178,7 @@
<xsl:template match="define-field[@as-type='markup-multiline']">
<xsl:variable name="group-names" select="distinct-values(key('references-by-name',@name)/group-as/@name)"/>
<xsl:variable name="single-match" as="xs:string" expand-text="true">*[@key='{@name}']</xsl:variable>
<xsl:variable name="group-matches" as="xs:string*" select="$group-names ! ('*[@key=''' || . || '''] | array[@key=''' || . || ''']/*')"/>
<xsl:variable name="group-matches" as="xs:string*" select="$group-names ! ('*[@key=''' || . || '''] | *[@key=''' || . || ''']/*')"/>
<xsl:variable name="field-match" select="string-join(($single-match,$group-matches),' | ')"/>

<xsl:comment expand-text="yes">{ $field-match }</xsl:comment>
Expand Down Expand Up @@ -207,15 +207,12 @@

<xsl:variable name="group-names" select="distinct-values(key('references-by-name',@name)/group-as/@name)"/>
<xsl:variable name="single-match" as="xs:string" expand-text="true">*[@key='{@name}']</xsl:variable>
<xsl:variable name="group-matches" as="xs:string*" select="$group-names ! ('*[@key=''' || . || '''] | array[@key=''' || . || ''']/*')"/>
<xsl:variable name="group-matches" as="xs:string*" select="$group-names ! ('*[@key=''' || . || '''] | *[@key=''' || . || ''']/*')"/>
<xsl:variable name="root-match" as="xs:string?" select="if (@name=../@root) then '/map[empty(@key)]' else ()"/>
<xsl:variable name="field-match" select="string-join(($single-match,$group-matches,$root-match),' | ')"/>

<!--<xsl:variable name="field-match" as="xs:string">*[@key='{@name}']{
@group-as/(' | *[@key=''' || . || '''] | array[@key=''' || . || ''']/*') }{
if (@name=../@root) then ' | /map[empty(@key)]' else ()}</xsl:variable>-->
<xsl:comment> 000 Handling field "{ @name }" 000 </xsl:comment>
<xsl:comment> 000 NB - template matching 'array' overrides this one 000 </xsl:comment>

<xsl:comment> *** Handling field "{ @name }" *** </xsl:comment>
<!--<xsl:variable name="callers" select="key('definitions-by-fields',@name,$composed-metaschema)"/>-->
<!--<xsl:comment expand-text="yes">{ $callers/(@name, @group-as) }</xsl:comment>-->
<!--<xsl:variable name="full-field-match">
Expand All @@ -230,29 +227,49 @@
<!--<xsl:comment expand-text="yes">{ $full-field-match }</xsl:comment>-->
<xsl:comment expand-text="yes">{ $field-match }</xsl:comment>

<xsl:comment> *** NB - template matching 'array' overrides this one *** </xsl:comment>
<XSLT:template match="{$field-match}" priority="5" mode="json2xml">
<XSLT:element name="{@name}" namespace="{$target-namespace}">
<XSLT:apply-templates select="*" mode="as-attribute"/>
<xsl:for-each select="json-key">
<XSLT:attribute name="{@flag-name}" select="../@key"/>
<xsl:comment>Flag '{ @flag-name }' is the key on an assembly or field (map) with a json-key.</xsl:comment>
<XSLT:attribute name="{@flag-name}" select="@key"/>
</xsl:for-each>
<XSLT:apply-templates select="*" mode="as-attribute"/>
<!--<xsl:for-each select="json-value-key[matches(@flag-name,'\S')]">
<xsl:comment>The current key becomes flag '{ @flag-name }'</xsl:comment>
<XSLT:attribute name="{@flag-name}" select="(self::map/@key, parent::array/@key)[1]"/>
</xsl:for-each>-->
<xsl:apply-templates select="." mode="field-text"/>
</XSLT:element>
</XSLT:template>


<!-- A template to place the key value on an attribute -->
<xsl:for-each select="child::json-key">
<!-- A template to place the key value on an attribute -->
<XSLT:template priority="2" match="({ $field-match})/string[@key='{@flag-name}']" mode="as-attribute">
<XSLT:attribute name="{@flag-name}">
<XSLT:apply-templates mode="#current"/>
</XSLT:attribute>
</XSLT:template>

<xsl:comment> To supervene template priority="5" matching "{ $field-match }" in the case of an object grouped
in a map, by virtue of json-key assignments to flags on that object... </xsl:comment>
<XSLT:template match="map[@key=({string-join($group-names ! ('''' || . || ''''),' ')})]"
mode="json2xml" priority="6">
<XSLT:apply-templates mode="#current"/>
</XSLT:template>


</xsl:for-each>

<!-- BUT - we want to prevent the value field (indicated by value key) from appearing as
an attribute (in this context only) -->
<xsl:for-each select="json-value-key[empty(@flag-name)]">

<!--<XSLT:template priority="7" match="*[@key='information-type-id']/string[@key='id'] | *[@key='information-type-ids']/*/string[@key='id']" mode="json2xml">
<xsl:apply-templates mode="#current"/>
</XSLT:template>-->

<XSLT:template
match="({$field-match})/string[@key='{.}']"
mode="as-attribute"/>
Expand Down Expand Up @@ -390,8 +407,8 @@

<xsl:variable name="full-match" as="xs:string" select="string-join(($single-match,$group-matches,$root-match),' | ')"/>

<xsl:comment> 000 Handling assembly "{ @name }" 000 </xsl:comment>
<xsl:comment> 000 NB - template matching 'array' overrides this one 000 </xsl:comment>
<xsl:comment expand-text="true"> *** Handling assembly "{ @name }" *** </xsl:comment>
<xsl:comment> *** NB - template matching 'array' overrides this one *** </xsl:comment>
<xsl:variable name="assembly-construction">
<XSLT:element name="{@name}" namespace="{$target-namespace}">
<xsl:for-each select="child::json-key">
Expand Down
6 changes: 5 additions & 1 deletion toolchains/oscal-m2/xml/produce-xml-converter.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@
<XSLT:with-param name="key">
<xsl:value-of select="@ref"/>
</XSLT:with-param>
<xsl:if test="not(@in-xml='UNWRAPPED')">
<XSLT:with-param name="wrapped" select="true()"/>
</xsl:if>
</XSLT:call-template>
</XSLT:for-each>
</xsl:template>
Expand Down Expand Up @@ -398,9 +401,10 @@

<XSLT:template name="prose">
<XSLT:param name="key" select="'{ $markdown-blocks-label }'"/>
<XSLT:param name="wrapped" select="false()"/>
<XSLT:variable name="blocks"
select="p | ul | ol | pre | h1 | h2 | h3 | h4 | h5 | h6 | table"/>
<XSLT:if test="exists($blocks)">
<XSLT:if test="exists($blocks) or $wrapped">
<XSLT:variable name="string-sequence" as="element()*">
<XSLT:apply-templates mode="md" select="$blocks"/>
</XSLT:variable>
Expand Down

0 comments on commit dd329a9

Please sign in to comment.