Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wendellpiez committed Feb 22, 2021
1 parent cb7d7ba commit 854159a
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 210 deletions.
10 changes: 9 additions & 1 deletion test-suite/worked-examples/anthology/anthology_metaschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ Under 'widget'
</constraint>
</define-assembly>

<define-field name="redundant">
<formal-name>Extra</formal-name>
<description>Discard me</description>
</define-field>

<define-flag name="id" as-type="NCName">
<formal-name>Identifier</formal-name>
<description>A distinct code</description>
Expand Down Expand Up @@ -253,7 +258,10 @@ Under 'widget'
<define-assembly name="include">
<formal-name>Include other</formal-name>
<description>Some other sort of markup altogether</description>
<define-flag name="lang"/>
<define-flag name="lang">
<formal-name>Language</formal-name>
<description>Describing the notation used</description>
</define-flag>
<model>
<any/>
</model>
Expand Down
8 changes: 4 additions & 4 deletions toolchains/xslt-M4/compose/metaschema-compose-debug.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<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="_3_digested" indent="true"/>
<p:output port="_3_digested" primary="false">
Expand Down Expand Up @@ -57,11 +57,11 @@
</p:input>
</p:xslt>

<!-- No longer filtering definitions reachable from nominal root <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
26 changes: 12 additions & 14 deletions toolchains/xslt-M4/compose/metaschema-reduce2.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
<xsl:variable name="show-warnings" as="xs:string">no</xsl:variable>
<xsl:variable name="verbose" select="lower-case($show-warnings) = ('yes', 'y', '1', 'true')"/>

<xsl:key name="global-assembly-definition" match="METASCHEMA/define-assembly[not(@scope='local')]" use="@name"/>
<xsl:key name="global-field-definition" match="METASCHEMA/define-field[not(@scope='local')]" use="@name"/>
<xsl:key name="global-assembly-definition" match="METASCHEMA/define-assembly" use="@name"/>
<xsl:key name="global-field-definition" match="METASCHEMA/define-field" use="@name"/>


<!-- ====== ====== ====== ====== ====== ====== ====== ====== ====== ====== ====== ====== -->
<!-- Pass Three: filter definitions (2) - keep only top-level definitions that are actually
called by references in the models.
called by references in the models descending from assemblies with root-name.
Note that we ignore flag definitions, which can stay,
since all flag definitions are rewritten into local declarations,
Expand All @@ -30,22 +31,22 @@
<xsl:mode on-no-match="shallow-copy"/>

<xsl:variable name="assembly-references" as="xs:string*">
<xsl:for-each select="//METASCHEMA/define-assembly[not(@scope='local')]">
<xsl:sequence select="string(@name)"/>
<xsl:for-each select="/METASCHEMA/define-assembly[exists(root-name)]">
<xsl:sequence select="string(@name)"/>
<xsl:apply-templates select="model" mode="collect-assembly-references">
<xsl:with-param name="assembly-refs" tunnel="yes" select="string(@name)"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:variable>

<xsl:variable name="field-references" as="xs:string*">
<xsl:apply-templates select="//METASCHEMA/define-assembly[not(@scope='local')]" mode="collect-field-references">
<xsl:apply-templates select="/METASCHEMA/define-assembly[exists(root-name)]" mode="collect-field-references">
<xsl:with-param name="field-refs" tunnel="yes" select="()"/>
</xsl:apply-templates>
</xsl:variable>

<xsl:variable name="flag-references" as="xs:string*">
<xsl:apply-templates select="//METASCHEMA/define-assembly[not(@scope='local')]" mode="collect-flag-references">
<xsl:apply-templates select="/METASCHEMA/define-assembly[exists(root-name)]" mode="collect-flag-references">
<xsl:with-param name="flag-refs" tunnel="yes" select="()"/>
</xsl:apply-templates>
</xsl:variable>
Expand Down Expand Up @@ -85,7 +86,8 @@
</xsl:call-template>
</xsl:template>

<!-- 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 --> <!-- Modes collecting sets of strings naming definitions
<!-- 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 -->
<!-- Modes collecting sets of strings naming definitions
we actually need, by traversing the definitions tree from the declared root;
recursive models are accounted for. -->

Expand All @@ -97,12 +99,12 @@
<xsl:apply-templates select=".//assembly" mode="#current"/>
</xsl:template>

<xsl:template match="model[exists(@ref)]" mode="collect-assembly-references">
<!--<xsl:template match="model[exists(@ref)]" mode="collect-assembly-references">
<xsl:param name="assembly-refs" tunnel="yes" select="()"/>
<xsl:apply-templates select="key('global-assembly-definition',@ref)" mode="#current">
<xsl:with-param name="assembly-refs" tunnel="yes" select="$assembly-refs,string(@ref)"/>
</xsl:apply-templates>
</xsl:template>
</xsl:template>-->

<xsl:template match="assembly" mode="collect-assembly-references">
<xsl:param name="assembly-refs" tunnel="yes" select="()"/>
Expand All @@ -125,10 +127,6 @@
<xsl:apply-templates select=".//assembly" mode="#current"/>
</xsl:template>

<xsl:template match="model[exists(@ref)]" mode="collect-field-references">
<xsl:apply-templates select="key('global-assembly-definition',@ref)" mode="#current"/>
</xsl:template>

<xsl:template match="assembly" mode="collect-field-references collect-flag-references">
<xsl:param name="assembly-refs" tunnel="yes" select="()"/>
<xsl:if test="not(@ref = $assembly-refs)">
Expand Down
177 changes: 0 additions & 177 deletions toolchains/xslt-M4/compose/metaschema-reduce3.xsl

This file was deleted.

8 changes: 4 additions & 4 deletions toolchains/xslt-M4/metaschema-compose.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<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="_3_digested" indent="true"/>
<p:output port="_3_digested" primary="false">
Expand Down Expand Up @@ -57,11 +57,11 @@
</p:input>
</p:xslt>

<!--<p:xslt name="reduce2">
<p:xslt name="reduce2">
<p:input port="stylesheet">
<p:document href="compose/metaschema-reduce2.xsl"/>
</p:input>
</p:xslt>-->
</p:xslt>

<p:xslt name="digest">
<p:input port="stylesheet">
Expand Down
8 changes: 7 additions & 1 deletion toolchains/xslt-M4/nist-metaschema-COMPOSE.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@

<!-- The $transformation-sequence declares transformations to be applied in order. -->
<xsl:variable name="transformation-sequence">

<!-- Collects metaschema modules and renames definitions scoped locally to their modules -->
<nm:transform version="3.0">compose/metaschema-collect.xsl</nm:transform>
<!-- Removes overwritten definitions (imported but subsequently rewritten) -->
<nm:transform version="3.0">compose/metaschema-reduce1.xsl</nm:transform>
<!--<nm:transform version="3.0">compose/metaschema-reduce2.xsl</nm:transform>-->
<!-- Removes unused definitions (not descended from an assembly defined for the root) -->
<nm:transform version="3.0">compose/metaschema-reduce2.xsl</nm:transform>
<!-- Flattens, normalizes and (to come) expands examples -->
<nm:transform version="3.0">compose/metaschema-digest.xsl</nm:transform>

</xsl:variable>

<xsl:function name="nm:compose-metaschema">
Expand Down
2 changes: 1 addition & 1 deletion toolchains/xslt-M4/nist-metaschema-MAKE-JSON-DOCS.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<xsl:variable name="transformation-sequence">
<nm:transform version="3.0">compose/metaschema-collect.xsl</nm:transform>
<nm:transform version="3.0">compose/metaschema-reduce1.xsl</nm:transform>
<!--<nm:transform version="3.0">compose/metaschema-reduce2.xsl</nm:transform>-->
<nm:transform version="3.0">compose/metaschema-reduce2.xsl</nm:transform>
<nm:transform version="3.0">compose/metaschema-digest.xsl</nm:transform>
<nm:transform version="3.0">document/json/json-docs-hugo-uswds.xsl</nm:transform>
</xsl:variable>
Expand Down
2 changes: 1 addition & 1 deletion toolchains/xslt-M4/nist-metaschema-MAKE-JSON-MAP.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<xsl:variable name="transformation-sequence">
<nm:transform version="3.0">compose/metaschema-collect.xsl</nm:transform>
<nm:transform version="3.0">compose/metaschema-reduce1.xsl</nm:transform>
<!--<nm:transform version="3.0">compose/metaschema-reduce2.xsl</nm:transform>-->
<nm:transform version="3.0">compose/metaschema-reduce2.xsl</nm:transform>
<nm:transform version="3.0">compose/metaschema-digest.xsl</nm:transform>
<nm:transform version="3.0">compose/make-model-map.xsl</nm:transform>
<nm:transform version="3.0">compose/unfold-model-map.xsl</nm:transform>
Expand Down
2 changes: 1 addition & 1 deletion toolchains/xslt-M4/nist-metaschema-MAKE-JSON-SCHEMA.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<xsl:variable name="transformation-sequence">
<nm:transform version="3.0">compose/metaschema-collect.xsl</nm:transform>
<nm:transform version="3.0">compose/metaschema-reduce1.xsl</nm:transform>
<!--<nm:transform version="3.0">compose/metaschema-reduce2.xsl</nm:transform>-->
<nm:transform version="3.0">compose/metaschema-reduce2.xsl</nm:transform>
<nm:transform version="3.0">compose/metaschema-digest.xsl</nm:transform>
<nm:transform version="3.0">schema-gen/make-json-schema-metamap.xsl</nm:transform>
<nm:transform version="3.0">lib/xpath-json-to-json.xsl</nm:transform>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<!-- first compose the metaschema -->
<nm:transform version="3.0">compose/metaschema-collect.xsl</nm:transform>
<nm:transform version="3.0">compose/metaschema-reduce1.xsl</nm:transform>
<!--<nm:transform version="3.0">compose/metaschema-reduce2.xsl</nm:transform>-->
<nm:transform version="3.0">compose/metaschema-reduce2.xsl</nm:transform>
<nm:transform version="3.0">compose/metaschema-digest.xsl</nm:transform>

<!-- next produce definition map -->
Expand Down
2 changes: 1 addition & 1 deletion toolchains/xslt-M4/nist-metaschema-MAKE-XML-DOCS.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<xsl:variable name="transformation-sequence">
<nm:transform version="3.0">compose/metaschema-collect.xsl</nm:transform>
<nm:transform version="3.0">compose/metaschema-reduce1.xsl</nm:transform>
<!--<nm:transform version="3.0">compose/metaschema-reduce2.xsl</nm:transform>-->
<nm:transform version="3.0">compose/metaschema-reduce2.xsl</nm:transform>
<nm:transform version="3.0">compose/metaschema-digest.xsl</nm:transform>
<nm:transform version="3.0">document/xml/xml-docs-hugo-uswds.xsl</nm:transform>
</xsl:variable>
Expand Down
Loading

0 comments on commit 854159a

Please sign in to comment.