Skip to content

Commit

Permalink
Addressing Issue #223: now includes all simpleType definitions down t…
Browse files Browse the repository at this point in the history
…heir dependency graph (within a given set of definitions), preventing orphans when atomic datatypes are built on top of one another in XSD generation. (#227)
  • Loading branch information
wendellpiez authored Aug 23, 2022
1 parent 154a693 commit 1e08f4b
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion toolchains/xslt-M4/schema-gen/make-metaschema-xsd.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,32 @@
<!--<xsl:message expand-text="true">Types in library: { $types-library/xs:simpleType/@name }</xsl:message>-->
<xsl:variable name="all-used-types" select="//@as-type => distinct-values()"/>
<xsl:variable name="used-atomic-types" select="$type-map[@as-type = $all-used-types]"/>
<xsl:copy-of select="$types-library/xs:simpleType[@name = $used-atomic-types]"/>

<!-- these aren't enough as some of them have further dependencies -->
<!--<xsl:copy-of select="$types-library/xs:simpleType[@name = $used-atomic-types]"/>-->
<xsl:sequence select="$types-library/xs:simpleType[@name = $used-atomic-types] => m:gather-types()"/>
</xs:schema>
</xsl:template>

<xsl:key name="simpleType-by-name" match="xs:simpleType" use="@name"/>

<!--Given a set of simpletypes such as in ../../../schema/xml/metaschema-datatypes.xsd i.e. $types-library -->
<xsl:function name="m:gather-types">
<xsl:param name="so-far" as="element()*"/>
<!-- picks up all types referenced as a restriction/@base -->
<xsl:variable name="base-types" select="$so-far/xs:restriction/key('simpleType-by-name',@base)"/>
<xsl:choose>
<!-- if there are any new ones, add and recurse -->
<xsl:when test="exists($base-types except $so-far)">
<xsl:sequence select="m:gather-types($so-far | $base-types)"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="$so-far"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>


<xsl:template match="namespace | json-base-uri"/>

<xsl:template mode="top-level-docs" match="*"/>
Expand Down

0 comments on commit 1e08f4b

Please sign in to comment.