Skip to content

Commit

Permalink
content conversion fixes (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
wendellpiez authored and david-waltermire committed Jun 16, 2019
1 parent c349786 commit 62e6670
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 14 deletions.
19 changes: 17 additions & 2 deletions build/metaschema/json/produce-json-converter.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<xsl:variable name="root-name" select="/METASCHEMA/@root/string(.)"/>

<xsl:key name="definition-by-name" match="define-flag | define-field | define-assembly" use="@name"/>
<xsl:key name="callers-by-flags" match="define-field | define-assembly" use="flag/@name"/>
<xsl:key name="callers-by-flags" match="define-field | define-assembly" use="flag/@name | key/@name"/>
<xsl:key name="callers-by-field" match="define-assembly" use="model//(field|fields)/@named"/>

<!-- Produces composed metaschema (imports resolved) -->
<xsl:import href="../lib/metaschema-compose.xsl"/>
Expand Down Expand Up @@ -128,7 +129,21 @@
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>
<XSLT:template match="{$field-match}" priority="5" mode="json2xml">
<xsl:variable name="callers" select="key('callers-by-field',@name,$composed-metaschema)"/>
<xsl:comment expand-text="yes">{ $callers/(@name, @group-as) }</xsl:comment>
<xsl:variable name="full-field-match">
<xsl:for-each select="$callers/@name">
<xsl:if test="not(position() eq 1)"> | </xsl:if>
<xsl:text expand-text="true">*[@key='{.}']/{ $field-match}</xsl:text>
</xsl:for-each>
<xsl:for-each select="$callers/@group-as">
<xsl:text expand-text="true"> | *[@key='{.}']/{ $field-match} | *[@key='{.}']/*/{ $field-match} </xsl:text>
</xsl:for-each>
</xsl:variable>
<xsl:comment expand-text="yes">{ $full-field-match }</xsl:comment>
<xsl:comment expand-text="yes">{ $field-match }</xsl:comment>

<XSLT:template match="{$full-field-match}" priority="5" mode="json2xml">
<XSLT:element name="{@name}" namespace="{$target-namespace}">
<xsl:for-each select="key">
<XSLT:attribute name="{@name}" select="../@key"/>
Expand Down
4 changes: 4 additions & 0 deletions build/metaschema/lib/metaschema-check.sch
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@


<sch:rule context="m:key">
<sch:let name="decl" value="key('definition-by-name',@name,$composed-metaschema)"/>
<sch:assert test="count(../*[@name = current()/@name]) eq 1">Only one flag (or key) may be named
<sch:value-of select="@name"/>
</sch:assert>
<sch:assert test="exists($decl)" role="warning">No definition found for '<sch:value-of select="@name"/>' <sch:name/></sch:assert>
<sch:assert test="empty($decl) or empty(@datatype) or (@datatype = $decl/@datatype)" role="warning">Flag data type doesn't match: the definition has '<sch:value-of select="$decl/@datatype"/>'</sch:assert>
<sch:report test="@name=('RICHTEXT','STRVALUE')">Key should not be named "STRVALUE" or "RICHTEXT" (reserved names)</sch:report>
</sch:rule>

<sch:rule context="m:value-key">
Expand Down
2 changes: 1 addition & 1 deletion build/metaschema/lib/metaschema-compose.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
<xsl:template match="define-assembly" mode="collect-references">
<xsl:param name="ref-stack" tunnel="yes" required="yes"/>
<xsl:if test="not(@name = $ref-stack)">
<xsl:sequence select="(. | flag)/string(@name)"/>
<xsl:sequence select="(. | flag | key)/string(@name)"/>
<xsl:apply-templates select="model" mode="#current">
<xsl:with-param tunnel="true" name="ref-stack" select="$ref-stack,@name"/>
</xsl:apply-templates>
Expand Down
15 changes: 12 additions & 3 deletions build/metaschema/lib/metaschema-jsondocs-jekyll-uswds.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,19 @@
</xsl:template>

<xsl:template name="group-label">
<xsl:if test="matches(@group-as, '\S')">
<p>This object appears <i>unlabelled</i> in an array called <code xsl:expand-text="true"
<xsl:choose>
<xsl:when test="exists(child::key)">
<p>This object appears, with a label, as a property of an object called <code xsl:expand-text="true"
>{ @group-as }</code>.</p>
</xsl:when>
<xsl:when test="matches(@group-as, '\S')">
<p>This object appears <i>unlabelled</i> in an array called <code xsl:expand-text="true"
>{ @group-as }</code>.</p>
</xsl:if>
</xsl:when>
<xsl:otherwise>

</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="define-assembly">
Expand Down
10 changes: 5 additions & 5 deletions build/metaschema/lib/metaschema-xmldocs-jekyll-uswds.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="formal-name | description"/>
<xsl:if test="exists(flag)">
<xsl:if test="exists(flag | key)">
<xsl:variable name="modal">
<xsl:choose>
<xsl:when test="every $f in (flag) satisfies $f/@required='yes'">must</xsl:when>
Expand All @@ -153,7 +153,7 @@
</xsl:variable>
<xsl:variable name="noun">
<xsl:choose>
<xsl:when test="count(flag) gt 1">attributes</xsl:when>
<xsl:when test="count(flag|key) gt 1">attributes</xsl:when>
<xsl:otherwise>the attribute</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Expand Down Expand Up @@ -252,15 +252,15 @@

<xsl:template match="flag"/>

<xsl:template match="flag" mode="model">
<xsl:template match="flag | key" mode="model">
<li>
<a href="#{@name}">
<xsl:apply-templates select="@name"/>
</a>
<xsl:text> attribute </xsl:text>
<xsl:apply-templates select="@datatype"/>
<xsl:apply-templates select="@required"/>
<xsl:if test="not(@required)"> (<i>optional</i>)</xsl:if>
<xsl:if test="not(@required) and self::flag"> (<i>optional</i>)</xsl:if>
<xsl:apply-templates select="if (description) then description else key('definitions', @name)/description" mode="model"/>
<xsl:if test="valid-values or key('definitions', @named)/valid-values">
<xsl:apply-templates select="if (valid-values) then valid-values else key('definitions', @named)/valid-values"/>
Expand All @@ -280,7 +280,7 @@
<p>The <xsl:apply-templates select="../@name"/> element has the following contents<xsl:if
test="count(*) > 1"> (in order)</xsl:if>:</p>
<ul>
<xsl:apply-templates select="../flag" mode="model"/>
<xsl:apply-templates select="../flag | ../key" mode="model"/>
<xsl:apply-templates/>
</ul>
</div>
Expand Down
8 changes: 5 additions & 3 deletions build/metaschema/xml/produce-and-run-either-documentor.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

<!-- for development -->
<!--<xsl:param name="target-format" select="()"/>-->
<xsl:param name="target-format" as="xs:string">json</xsl:param>
<xsl:param name="output-path" as="xs:string">docs/content/documentation/schemas</xsl:param>
<xsl:param name="target-format" as="xs:string">xml</xsl:param>
<xsl:param name="output-path" as="xs:string">../../../docs/content/documentation/schemas</xsl:param>

<xsl:import href="../lib/metaschema-compose.xsl"/>
<xsl:variable name="source" select="$composed-metaschema"/>
Expand Down Expand Up @@ -56,7 +56,7 @@

<xsl:template match="/">
<xsl:result-document href="{$result-path}/{ $metaschema-code }.html" method="xhtml">
<xsl:message expand-text="yes">writing to {$result-path}/{ $metaschema-code }.html</xsl:message>
<xsl:call-template name="yaml-header">
<xsl:with-param name="overview" select="true()"></xsl:with-param>
</xsl:call-template>
Expand All @@ -66,6 +66,8 @@
<xsl:for-each select="$html-docs/*/html:body/html:div[contains-token(@class,'definition')]">
<xsl:result-document href="{$result-path}/{ $metaschema-code }_{@id}.html"
method="xhtml">
<xsl:message expand-text="yes">{$result-path}/{ $metaschema-code }_{@id}.html</xsl:message>

<xsl:call-template name="yaml-header">
<xsl:with-param name="tagname" select="string(@id)"/>
<xsl:with-param name="root" select="starts-with(html:h5[1],(@id || ' is the root' ))"/>
Expand Down
4 changes: 4 additions & 0 deletions build/metaschema/xml/produce-xml-converter.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
<xsl:value-of select="value-key"/>
</xsl:template>

<xsl:template priority="4" match="define-field[exists(flag/value-key)]" mode="text-key">
<XSLT:value-of select="@{flag[exists(value-key)]/@name}"/>
</xsl:template>

<!--<xsl:template priority="2" match="define-field[exists(flag/value-key)]" mode="text-key">
<XSLT:value-of select="string[@key='{ flag/value-key/../@name }']"/>
</xsl:template>-->
Expand Down

0 comments on commit 62e6670

Please sign in to comment.