Skip to content

Commit

Permalink
Rectifying several small glitches on definitions page, links etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
wendellpiez committed Jun 7, 2021
1 parent e91db9c commit 8c36782
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 30 deletions.
1 change: 0 additions & 1 deletion toolchains/xslt-M4/compose/make-model-map.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<xsl:variable name="in-xml" select="$reference/@in-xml"/>
<xsl:variable name="with-remarks" select="$reference/remarks"/>


<xsl:element name="{ $type }" namespace="http://csrc.nist.gov/ns/oscal/metaschema/1.0">
<xsl:for-each select="self::define-assembly[empty(model)]">
<xsl:attribute name="as-type">empty</xsl:attribute>
Expand Down
43 changes: 21 additions & 22 deletions toolchains/xslt-M4/document/common-definitions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<xsl:apply-templates select="remarks"/>

<xsl:apply-templates select="$definitions" mode="model-view">
<!--<xsl:sort select="(root-name,use-name,@name)[1]"/>-->
<xsl:sort select="(root-name,use-name,@name)[1]"/>
</xsl:apply-templates>

</div>
Expand Down Expand Up @@ -157,22 +157,15 @@

<xsl:template match="define-flag" mode="model"/>

<xsl:template match="define-assembly | define-field" mode="model">
<xsl:variable name="metaschema-type" select="replace(name(),'^define\-','')"/>
<xsl:for-each-group select="flag | define-flag | model/*" group-by="true()" expand-text="true">
<details open="open">
<summary>{ if (count(current-group()) ne 1) then 'Properties' else 'Property' } ({ count(current-group()) })</summary>

<div class="model { $metaschema-type }-model">
<xsl:apply-templates select="current-group()" mode="model-view"/>
</div>
</details>
</xsl:for-each-group>
<xsl:template match="define-assembly | define-field" mode="model" expand-text="true">
<xsl:comment> { name() } model goes here</xsl:comment>
<xsl:message>{ name() } model override failing...</xsl:message>
</xsl:template>

<xsl:template match="define-assembly | define-field | define-flag | assembly | field | flag" mode="model-view">
<xsl:variable name="level" select="count(. | ancestor::define-assembly | ancestor::define-field)"/>
<xsl:variable name="is-inline" select="exists(ancestor::model)"/>
<!-- level must be parameterized for dynamically generated flags on the JSON side -->
<xsl:param name="level" select="count(. | ancestor::define-assembly | ancestor::define-field)"/>
<xsl:variable name="is-inline" select="empty(parent::METASCHEMA)"/>
<xsl:variable name="header-tag" select="if ($level le 6) then ('h' || $level) else 'p'"/>
<xsl:variable name="definition" as="element()">
<xsl:apply-templates select="." mode="find-definition"/>
Expand Down Expand Up @@ -206,7 +199,12 @@

<xsl:apply-templates select="(.|$definition)/(root-name, use-name, group-as, json-value-key, json-key)"/>
<xsl:call-template name="remarks-group">
<xsl:with-param name="these-remarks" select="$definition/remarks, remarks"/>
<xsl:with-param name="these-remarks" as="element(remarks)*">
<!-- returns remarks off the definition, which could be self::node(). -->
<xsl:sequence select="$definition/remarks"/>
<!-- after, adds any local remarks on a reference -->
<xsl:sequence select="(self::assembly|self::field|self::flag)/remarks"/>
</xsl:with-param>
</xsl:call-template>
<xsl:apply-templates select="constraint"/>

Expand All @@ -222,7 +220,6 @@

<xsl:template name="remarks-group">
<xsl:param name="these-remarks" select="child::remarks"/>

<xsl:comment> remarks group goes here</xsl:comment>
<xsl:message> remarks-group override failing...</xsl:message>
</xsl:template>
Expand Down Expand Up @@ -262,12 +259,14 @@
<xsl:template match="constraint">
<xsl:variable name="constraints"
select="descendant::allowed-values | descendant::matches | descendant::has-cardinality | descendant::is-unique | descendant::index-has-key | descendant::index"/>
<details>
<summary>
<xsl:text expand-text="true">Constraint{ if (count($constraints) ne 1) then 's' else '' } ({ count($constraints) })</xsl:text>
</summary>
<xsl:apply-templates/>
</details>
<xsl:if test="exists($constraints)">
<details>
<summary>
<xsl:text expand-text="true">Constraint{ if (count($constraints) ne 1) then 's' else '' } ({ count($constraints) })</xsl:text>
</summary>
<xsl:apply-templates/>
</details>
</xsl:if>
</xsl:template>

<xsl:template match="constraint//*">
Expand Down
64 changes: 63 additions & 1 deletion toolchains/xslt-M4/document/json/json-definitions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,68 @@ exclude-result-prefixes="#all">
</p>
</xsl:template>

<xsl:template match="define-assembly | define-field" mode="model">
<xsl:variable name="metaschema-type" select="replace(name(),'^define\-','')"/>
<xsl:for-each-group select="flag | define-flag | model/*" group-by="true()" expand-text="true">
<details open="open">
<summary>{ if (count(current-group()) ne 1) then 'Properties' else 'Property' } ({ count(current-group()) })</summary>
<div class="model { $metaschema-type }-model">
<xsl:apply-templates select="current-group()" mode="model-view"/>
</div>
</details>
</xsl:for-each-group>
</xsl:template>



<!-- fields with flags become objects with properties, one of which holds the nominal
field value - it is represented by a proxy -->
<xsl:template match="define-field[exists(flag|define-flag)]" mode="model">
<xsl:variable name="level" select="count(. | ancestor::define-assembly | ancestor::define-field)"/>
<xsl:variable name="value-name" as="xs:string">
<xsl:apply-templates select="." mode="get-field-value-name"/>
</xsl:variable>
<xsl:variable as="element()" name="value-property-proxy" expand-text="true">
<m:define-flag name="{$value-name}" value-proxy="true" required="yes">
<xsl:attribute name="_metaschema-json-id" select="@_metaschema-json-id || '/' || $value-name"/>
<xsl:copy-of select="@as-type | @_metaschema-xml-id"/>
<m:formal-name>{ formal-name } Value</m:formal-name>
<xsl:apply-templates select="." mode="get-field-value-description"/>
</m:define-flag>
</xsl:variable>
<xsl:variable name="metaschema-type" select="'field'"/>
<xsl:for-each-group select="flag | define-flag | $value-property-proxy" group-by="true()" expand-text="true">
<details open="open">
<summary>{ if (count(current-group()) ne 1) then 'Properties' else 'Property' } ({ count(current-group()) })</summary>
<div class="model { $metaschema-type }-model">
<xsl:apply-templates select="current-group()" mode="model-view">
<!-- we pass in $level so the proxy has one -->
<xsl:with-param name="level" select="$level + 1"/>
</xsl:apply-templates>
</div>
</details>
</xsl:for-each-group>
</xsl:template>

<xsl:template match="*" mode="get-field-value-name" as="xs:string">STRVALUE</xsl:template>

<xsl:template match="*[@as-type=('markup-line','markup-multiline')]" mode="get-field-value-name" as="xs:string">RICHTEXT</xsl:template>

<xsl:template match="*[exists(json-value-key)]" mode="get-field-value-name" as="xs:string">
<xsl:value-of select="json-value-key"/>
</xsl:template>

<xsl:template priority="2" match="*[exists(json-value-key/@flag-name)]" mode="get-field-value-name" as="xs:string">
<xsl:value-of select="'{' || json-value-key/@flag-name || '}'"/>
</xsl:template>

<xsl:template match="*" mode="get-field-value-description">
<m:description>This property provides the (nominal) value for this object as a whole.</m:description>
</xsl:template>

<xsl:template priority="2" match="*[exists(json-value-key/@flag-name)]" mode="get-field-value-description">
<m:description>A property whose name is distinct from assigned properties for this object is taken as its (nominal) value, while its key is taken to be the value of the <code><xsl:value-of select="json-value-key/@flag-name"/></code> property.</m:description>
</xsl:template>

<xsl:template match="short-name" mode="converter-link" expand-text="true">
<p>
Expand Down Expand Up @@ -63,7 +125,7 @@ exclude-result-prefixes="#all">
<xsl:variable name="xml-definitions-link" select="$path-to-common || $xml-definitions-page"/>

<xsl:template name="remarks-group">
<xsl:param name="these-remarks" select="child::remarks"/>
<xsl:param name="these-remarks" select="child::remarks" as="element(remarks)*"/>
<xsl:for-each-group select="$these-remarks[not(contains-token(@class,'xml'))]" group-by="true()">
<div class="remarks-group usa-prose">
<details open="open">
Expand Down
2 changes: 1 addition & 1 deletion toolchains/xslt-M4/document/xml/xml-definitions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ exclude-result-prefixes="#all">
</xsl:template>

<xsl:template name="remarks-group">
<xsl:param name="these-remarks" select="child::remarks"/>
<xsl:param name="these-remarks" select="child::remarks" as="element(remarks)*"/>
<xsl:for-each-group select="$these-remarks[not(contains-token(@class,'json'))]" group-by="true()">
<div class="remarks-group usa-prose">
<details open="open">
Expand Down
5 changes: 0 additions & 5 deletions toolchains/xslt-M4/make-any-metaschema-docs.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@
<p:pipe port="result" step="composed"/>
</p:output>

<!--<p:serialization port="_c.composed-and-annotated" indent="true"/>
<p:output port="_c.composed-and-annotated" primary="false">
<p:pipe port="result" step="annotate-composition"/>
</p:output>-->

<p:serialization port="_d.abstract-model-map" indent="true"/>
<p:output port="_d.abstract-model-map" primary="false">
<p:pipe port="result" step="make-abstract-map"/>
Expand Down

0 comments on commit 8c36782

Please sign in to comment.