Skip to content

Commit

Permalink
Addressing usnistgov#174 cf also usnistgov/OSCAL#1020 - adjusting run…
Browse files Browse the repository at this point in the history
…time interfaces of generated JSON and XML converters
  • Loading branch information
wendellpiez committed Sep 27, 2021
1 parent 25a56e7 commit d3c87cf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@
<XSLT:output indent="true"/>
<xsl:text>&#xA;</xsl:text>
<xsl:comment> Processing architecture </xsl:comment>
<xsl:comment> $file should be a URI, absolute or relative to the XSLT transformation</xsl:comment>
<XSLT:param name="file" as="xs:anyURI?"/>
<xsl:comment> $file should be a path to the file </xsl:comment>
<XSLT:param name="file" as="xs:string?"/>
<xsl:comment> Pass in $produce=supermodel to produce OSCAL M4 supermodel intermediate format </xsl:comment>
<XSLT:param name="produce" as="xs:string">xml</XSLT:param><!-- set to 'supermodel' to produce supermodel intermediate -->

Expand All @@ -191,11 +191,15 @@

<XSLT:mode name="cast-md" on-no-match="shallow-copy"/>

<XSLT:template match="/" name="from-xdm-json-xml" expand-text="true">
<XSLT:template match="/">
<nm:ERROR>Error in XSLT invocation - an initial template (-it) is expected ('from-json' or 'from-xdm-json-xml'), but none is given</nm:ERROR>
</XSLT:template>

<XSLT:template name="from-xdm-json-xml" expand-text="true">
<!-- Take source to be JSON in XPath 3.1 (XDM) representation -->
<XSLT:param name="source">
<XSLT:choose>
<xsl:comment> evaluate { $file } as URI (absolute or relative to stylesheet)</xsl:comment>
<xsl:comment> evaluating $file as URI (absolute or relative to stylesheet)</xsl:comment>
<XSLT:when test="exists($file)">
<XSLT:try select="document($file)" xmlns:err="http://www.w3.org/2005/xqt-errors">
<XSLT:catch expand-text="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@

<XSLT:variable name="write-options" as="map(*)">
<XSLT:map>
<XSLT:map-entry key="'indent'" expand-text="true">{ $json-indent='yes' }</XSLT:map-entry>
<XSLT:map-entry key="'indent'" select="$json-indent='yes'"/>
</XSLT:map>
</XSLT:variable>

Expand Down
30 changes: 15 additions & 15 deletions toolchains/xslt-M4/testing/test-json-conversions.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0"
xmlns:metaschema="http://csrc.nist.gov/ns/metaschema/1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
type="metaschema:test-metaschema-conversions" name="test-metaschema-conversions">
type="metaschema:test-metaschema-json-conversion" name="test-metaschema-json-conversion">

<!-- &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& -->
<!-- Ports -->
Expand Down Expand Up @@ -44,7 +44,7 @@

<p:serialization port="Q.testdata-json-xml-source" indent="true"/>
<p:output port="Q.testdata-json-xml-source" primary="false">
<p:pipe port="testdata-json-xml" step="test-metaschema-conversions"/>
<p:pipe port="testdata-json-xml" step="test-metaschema-json-conversion"/>
</p:output>

<p:serialization port="S.testdata-supermodel" indent="true"/>
Expand All @@ -57,8 +57,8 @@
<p:pipe port="result" step="convert-supermodel-to-json-xml"/>
</p:output>

<p:serialization port="_J2.testdata-xml-result" indent="true" method="text"/>
<p:output port="_J2.testdata-xml-result" primary="false">
<p:serialization port="_J2.testdata-json-result" indent="true" method="text"/>
<p:output port="_J2.testdata-json-result" primary="false">
<p:pipe port="result" step="serialize-json"/>
</p:output>

Expand All @@ -70,7 +70,7 @@
<!-- &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& -->
<!-- Import (subpipeline) -->

<p:import href="../metaschema-compose.xpl"/>
<p:import href="../compose/metaschema-compose.xpl"/>

<!-- &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& -->
<!-- Pipeline -->
Expand Down Expand Up @@ -103,22 +103,22 @@
</p:input>
</p:xslt>

<p:identity name="make-json-converter"/>
<!--<p:xslt name="make-json-converter">
<!--<p:identity name="make-json-converter"/>-->
<p:xslt name="make-json-converter">
<p:input port="stylesheet">
<p:document href="../converter-gen/produce-json-converter.xsl"/>
</p:input>
</p:xslt>-->
</p:xslt>

<p:identity name="convert-json-testdata"/>
<!--<p:xslt name="convert-json-testdata">
<!--<p:identity name="convert-json-testdata"/>-->
<p:xslt name="convert-json-testdata">
<p:input port="source">
<p:pipe port="testdata-json-xml" step="test-metaschema-conversions"/>
<p:pipe port="testdata-json-xml" step="test-metaschema-json-conversion"/>
</p:input>
<p:input port="stylesheet">
<p:pipe step="make-json-converter" port="result"/>
</p:input>
</p:xslt>-->
</p:xslt>

<!-- Now going back downhill to JSON -->
<p:identity name="convert-supermodel-to-json-xml"/>
Expand Down Expand Up @@ -146,11 +146,11 @@
</p:identity>

<!-- Back downhill to XML -->
<p:identity name="convert-supermodel-to-xml"/>
<!--<p:xslt name="convert-supermodel-to-xml">
<!--<p:identity name="convert-supermodel-to-xml"/>-->
<p:xslt name="convert-supermodel-to-xml">
<p:input port="stylesheet">
<p:document href="../converter-gen/supermodel-to-xml.xsl"/>
</p:input>
</p:xslt>-->
</p:xslt>

</p:declare-step>
6 changes: 3 additions & 3 deletions toolchains/xslt-M4/testing/test-xml-conversions.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0"
xmlns:metaschema="http://csrc.nist.gov/ns/metaschema/1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
type="metaschema:test-metaschema-conversions" name="test-metaschema-conversions">
type="metaschema:test-metaschema-xml-conversion" name="test-metaschema-xml-conversion">

<!-- &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& -->
<!-- Ports -->
Expand Down Expand Up @@ -44,7 +44,7 @@

<p:serialization port="Q.testdata-xml-source" indent="true"/>
<p:output port="Q.testdata-xml-source" primary="false">
<p:pipe port="testdata-xml" step="test-metaschema-conversions"/>
<p:pipe port="testdata-xml" step="test-metaschema-xml-conversion"/>
</p:output>

<p:serialization port="S.testdata-supermodel" indent="true"/>
Expand Down Expand Up @@ -117,7 +117,7 @@
<!--<p:identity name="convert-xml-testdata"/>-->
<p:xslt name="convert-xml-testdata">
<p:input port="source">
<p:pipe port="testdata-xml" step="test-metaschema-conversions"/>
<p:pipe port="testdata-xml" step="test-metaschema-xml-conversion"/>
</p:input>
<p:input port="stylesheet">
<p:pipe step="make-xml-converter" port="result"/>
Expand Down

0 comments on commit d3c87cf

Please sign in to comment.