Skip to content

Commit

Permalink
Now addressing feature request usnistgov#438
Browse files Browse the repository at this point in the history
  • Loading branch information
wendellpiez authored and david-waltermire committed Aug 16, 2019
1 parent 1ad5bdc commit ecb26ec
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 91 deletions.
10 changes: 7 additions & 3 deletions build/metaschema/lib/metaschema-common-html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
identifier is called for, and may appear in file names of schema artifacts.</p>
</xsl:template>

<xsl:template match="m:METASCHEMA/m:schema-version">
<p>Version of this schema: <xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="m:description" mode="model">
<br class="br"/>
<i style="font-size: smaller">
Expand Down Expand Up @@ -126,7 +130,7 @@
</xsl:template>

<xsl:template match="*" mode="serialize">
<xsl:call-template name="indent-for-pre"/>
<!--<xsl:call-template name="indent-for-pre"/>-->

<code class="tag">&lt;<xsl:value-of select="name(.)"/>
<xsl:for-each select="@*">
Expand All @@ -143,11 +147,11 @@
<xsl:with-param name="hot" select="boolean(text()[normalize-space(.)])"/>
</xsl:apply-templates>

<xsl:if test="not(text()[normalize-space(.)])">
<!--<xsl:if test="not(text()[normalize-space(.)])">
<xsl:call-template name="indent-for-pre">
<xsl:with-param name="endtag" select="true()"/>
</xsl:call-template>
</xsl:if>
</xsl:if>-->
<code class="tag">&lt;/<xsl:value-of select="name(.)"/>
<xsl:text>&gt;</xsl:text>
</code>
Expand Down
18 changes: 7 additions & 11 deletions build/metaschema/lib/metaschema-jsondocs-jekyll-uswds.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@

<xsl:import href="metaschema-common-html.xsl"/>
<xsl:import href="metaschema-docs-util.xsl"/>

<xsl:param name="schema-path" select="document-uri(/)"/>

<xsl:variable name="metaschema-code" select="/*/short-name || '-json'"/>



<xsl:strip-space elements="*"/>

<xsl:preserve-space elements="p li pre i b em strong a code q"/>
Expand Down Expand Up @@ -56,18 +59,11 @@
<xsl:template match="METASCHEMA">
<xsl:variable name="definitions" select="define-assembly | define-field | define-flag"/>
<div class="METASCHEMA">
<h5 xsl:expand-text="true">The JSON Schema for the { short-name } format can be found at
<a href="$schema-path">{ $schema-path }</a></h5>
<xsl:apply-templates select="* except $definitions"/>
<xsl:for-each select="key('definitions', @root)">
<h5>
<xsl:text>The root object of this schema is </xsl:text>
<a href="#{@name}">
<xsl:apply-templates select="@name"/>
</a>
</h5>
<!-- <xsl:call-template name="make-element-map"/>-->
</xsl:for-each>
<xsl:apply-templates select="$definitions"/>
</div>
<xsl:apply-templates select="$definitions"/>
</xsl:template>


Expand Down
93 changes: 25 additions & 68 deletions build/metaschema/lib/metaschema-xmldocs-jekyll-uswds.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<xsl:import href="metaschema-common-html.xsl"/>
<xsl:import href="metaschema-docs-util.xsl"/>

<xsl:param name="schema-path" select="document-uri(/)"/>

<xsl:variable name="metaschema-code" select="/*/short-name || '-xml'"/>

<xsl:strip-space elements="*"/>
Expand Down Expand Up @@ -47,26 +49,14 @@
</html>
</xsl:template>



<!-- only works when XML-to-JSON converter is in the import tree -->
<xsl:template match="description | remarks" mode="jsonize"/>

<xsl:template match="METASCHEMA">
<xsl:variable name="definitions" select="define-assembly | define-field | define-flag"/>
<div class="METASCHEMA">
<h5 xsl:expand-text="true">The XML Schema for the { short-name } format can be found at
<a href="$schema-path">{ $schema-path }</a></h5>
<xsl:apply-templates select="* except $definitions"/>
<xsl:for-each select="key('definitions', @root)">
<h5>
<xsl:text>The root object (element) of this schema is </xsl:text>
<a href="#{@name}">
<xsl:apply-templates select="@name"/>
</a>
</h5>
<!-- <xsl:call-template name="make-element-map"/>-->
</xsl:for-each>
<xsl:apply-templates select="$definitions"/>
</div>
<xsl:apply-templates select="$definitions"/>
</xsl:template>


Expand All @@ -81,14 +71,6 @@
<p>The XML namespace for elements conformant to this schema:
<code><xsl:apply-templates/></code></p>
</xsl:template>

<!-- <xsl:template priority="5"
match="
define-flag[not(@show-docs = 'xml' or @show-docs = 'xml json')] |
define-field[not(@show-docs = 'xml' or @show-docs = 'xml json')] |
define-assembly[not(@show-docs = 'xml' or @show-docs = 'xml json')]"/>-->


<xsl:template match="define-assembly | define-field | define-flag" mode="link-here">
<a href="#{ @name }"><xsl:value-of select="@name"/></a>
</xsl:template>
Expand Down Expand Up @@ -307,16 +289,26 @@
<xsl:apply-templates select="remarks"/>
<pre>
<xsl:apply-templates select="*" mode="as-example"/>
</pre>
</pre>
<!--<xsl:text>&#xA;{% endhighlight %}&#xA;</xsl:text>-->
</div>
</li>
</ul>
</xsl:template>

<xsl:template match="text()[not(matches(.,'\S'))]" mode="serialize">
<xsl:param name="hot" select="false()"/>
<xsl:if test="$hot">
<xsl:value-of select="."/>
</xsl:if>
</xsl:template>

<xsl:template match="*" mode="serialize">
<!--<xsl:call-template name="indent-for-pre"/>-->

<!-- goes $hot when inline markup is found -->
<xsl:param name="hot" select="false()"/>
<!--<xsl:if test="not($hot)">
<xsl:call-template name="indent-for-pre"/>
</xsl:if>-->
<xsl:text>&#xA;&lt;</xsl:text>
<xsl:value-of select="local-name(.)"/>
<xsl:for-each select="@*">
Expand All @@ -329,56 +321,20 @@
<xsl:text>&gt;</xsl:text>

<xsl:apply-templates mode="serialize">
<xsl:with-param name="hot" select="boolean(text()[normalize-space(.)])"/>
<xsl:with-param name="hot" select="$hot or boolean(text()[normalize-space(.)])"/>
</xsl:apply-templates>

<!--<xsl:if test="not($hot)">
<xsl:call-template name="indent-for-pre"/>
</xsl:if>-->
<xsl:if test="not(text()[normalize-space(.)])">&#xA;</xsl:if>
<xsl:text>&lt;/</xsl:text>
<xsl:value-of select="local-name(.)"/>
<xsl:text>&gt;</xsl:text>
</xsl:template>


<xsl:output name="jsonish" indent="yes" method="text" use-character-maps="delimiters"/>

<xsl:character-map name="delimiters">
<xsl:output-character character="&lt;" string="\u003c"/>
<xsl:output-character character="&gt;" string="\u003e"/>
</xsl:character-map>

<xsl:param name="json-indent" as="xs:string">yes</xsl:param>

<xsl:mode name="rectify" on-no-match="shallow-copy"/>

<xsl:template mode="rectify" xpath-default-namespace="http://www.w3.org/2005/xpath-functions"
match="/*/@key | array/*/@key"/>

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

<!-- Modes xml2json and rectify are in the XML-to-JSON conversion XSLTs for the different formats respectively -->
<xsl:template match="*" mode="jsonize">
<xsl:variable name="xpath-json">
<xsl:apply-templates select="." mode="xml2json"/>
</xsl:variable>
<xsl:variable name="rectified">
<xsl:apply-templates select="$xpath-json" mode="rectify"/>
</xsl:variable>
<xsl:choose>
<!-- this test fails when the modes are not available, so a text brick comes back with no elements -->
<xsl:when test="exists($rectified/*) and empty($rectified/(node() except *))">
<xsl:value-of select="xml-to-json($rectified, $write-options)"/>
</xsl:when>
<xsl:otherwise>
<xsl:text expand-text="true">Example for '{ parent::example/../@name }' not JSONized -- </xsl:text>
<xsl:copy-of select="$xpath-json"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<!-- <xsl:template mode="get-example" match="example">
<xsl:apply-templates select="*" mode="as-example"/>
</xsl:template>-->
Expand All @@ -391,6 +347,7 @@
<xsl:apply-templates select="$example/*" mode="as-example"/>
</xsl:template>-->

<!-- mode as-example filters metaschema elements from elements representing examples -->
<xsl:template match="m:*" xmlns:m="http://csrc.nist.gov/ns/oscal/metaschema/1.0"
mode="as-example"/>

Expand Down Expand Up @@ -435,7 +392,7 @@
<xsl:template mode="metaschema-type" match="define-field">, with text contents</xsl:template>
<xsl:template mode="metaschema-type" match="*[@as-type='markup-line']" priority="2">, with mixed text and (inline prose) element contents</xsl:template>
<xsl:template mode="metaschema-type" match="*[@as-type='markup-multiline']" priority="2">, as prose content: paragraphs, lists etc.</xsl:template>
<xsl:template mode="metaschema-type" match="define-assembly">, with its element contents</xsl:template>
<xsl:template mode="metaschema-type" match="define-assembly">, with element contents</xsl:template>

<xsl:template match="*" mode="metaschema-type">
<xsl:message>Matching <xsl:value-of select="local-name()"/></xsl:message>
Expand Down
26 changes: 23 additions & 3 deletions build/metaschema/xml/produce-and-run-either-documentor.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,26 @@
<!--<xsl:param name="target-format" select="()"/>-->
<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:param name="schema-path">
<xsl:choose>
<xsl:when test="$target-format = 'xml'">
<xsl:choose>
<xsl:when test="/METASCHEMA/short-name='oscal-catalog'">https://github.com/usnistgov/OSCAL/blob/master/xml/schema/oscal_catalog_schema.xsd</xsl:when>
<xsl:when test="/METASCHEMA/short-name='oscal-profile'">https://github.com/usnistgov/OSCAL/blob/master/xml/schema/oscal_profile_schema.xsd</xsl:when>
<xsl:otherwise expand-text="true">NO XML SCHEMA PATH GIVEN FOR SCHEMA { /METASCHEMA/short-name }</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$target-format = 'json'">
<xsl:choose>
<xsl:when test="/METASCHEMA/short-name='oscal-catalog'">https://github.com/usnistgov/OSCAL/blob/master/json/schema/oscal_catalog_schema.json</xsl:when>
<xsl:when test="/METASCHEMA/short-name='oscal-profile'">https://github.com/usnistgov/OSCAL/blob/master/json/schema/oscal_profile_schema.json</xsl:when>
<xsl:otherwise expand-text="true">NO XML SCHEMA PATH GIVEN FOR SCHEMA { /METASCHEMA/short-name }</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>NO SCHEMA PATH - FORMAT NOT RECOGNIZED</xsl:otherwise>
</xsl:choose>
</xsl:param>

<xsl:import href="../lib/metaschema-compose.xsl"/>
<xsl:variable name="source" select="$composed-metaschema"/>

Expand All @@ -31,7 +50,7 @@
'stylesheet-location' : 'produce-either-documentor.xsl',
'source-node' : $source,
'stylesheet-params' : map { xs:QName('target-format'): $target-format,
xs:QName('schema-path'): document-uri(/),
xs:QName('schema-path'): $schema-path,
xs:QName('example-converter-xslt'): $example-converter-xslt-path
} }" />

Expand All @@ -58,10 +77,11 @@
<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:with-param name="overview" select="true()"/>
</xsl:call-template>

<xsl:sequence select="$html-docs/*/html:body/(* except child::html:div[contains-token(@class,'definition')])"/>

</xsl:result-document>
<xsl:for-each select="$html-docs/*/html:body/html:div[contains-token(@class,'definition')]">
<xsl:result-document href="{$result-path}/{ $metaschema-code }_{@id}.html"
Expand Down
16 changes: 10 additions & 6 deletions build/metaschema/xml/produce-either-documentor.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<xsl:call-template name="furniture"/>
<xsl:comment> XHHXXHHXXHHXXHHXXHHXXHHXXHHXXHHXXHHXXHHXXHHXXHHXXHHXXHHXXHHXXHHX </xsl:comment>
<xsl:text>&#xA;</xsl:text>


<xsl:apply-templates/>


Expand Down Expand Up @@ -98,14 +100,16 @@
<XSLT:import href="../lib/metaschema-{$target-format}docs-jekyll-uswds.xsl"/>
<XSLT:preserve-space elements="*"/>

<XSLT:param name="schema-path" select="'{ $schema-path }'"/>

<XSLT:variable name="home" select="/"/>
<XSLT:key name="declarations-by-name"
match="define-field | define-assembly | define-flag" use="@name"/>
<!--<XSLT:key name="declarations-by-name"
match="define-field | define-assembly | define-flag" use="@name"/>-->

<!-- output method must be text for good markdown including unescaped code snips -->
<XSLT:output method="text"/>
<!--<XSLT:output method="text"/>-->

<XSLT:template priority="5"
<!--<XSLT:template priority="5"
match="define-assembly[exists(@acquire-from)] |
define-field[exists(@acquire-from)] |
define-flag[exists(@acquire-from)]"
Expand All @@ -118,7 +122,7 @@
<XSLT:if test="empty($definition)">
<XSLT:comment expand-text="true"> No definition found for { $defining } in { $module } at { /METASCHEMA/import[@name=$module]/@href }</XSLT:comment>
</XSLT:if>
</XSLT:template>
</XSLT:template>-->

<XSLT:template match="node() | @*" mode="expand-example">
<XSLT:copy copy-namespaces="no">
Expand All @@ -132,7 +136,7 @@

<XSLT:template match="/">
<XSLT:variable name="html">
<XSLT:for-each select="$expanded/*">
<XSLT:for-each select="$expanded">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<XSLT:call-template name="css"/>
Expand Down

0 comments on commit ecb26ec

Please sign in to comment.