Skip to content

Commit

Permalink
Posting wip XSLT and Schematron - results are posted to usnistgov#86
Browse files Browse the repository at this point in the history
  • Loading branch information
wendellpiez committed Oct 17, 2022
1 parent e4022c7 commit 9028879
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/nist.gov/SP800-53/rev5/xml/issue86-content-analysis.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt3"
xmlns:sqf="http://www.schematron-quickfix.com/validator/process"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math">

<sch:ns prefix="o" uri="http://csrc.nist.gov/ns/oscal/1.0"/>

<xsl:variable name="family-id-regex" as="xs:string">AC|AT|AU|CA|CM|CP|IA|IR|MA|MP|PE|PL|PM|PS|PT|RA|SA|SC|SI|SR</xsl:variable>

<xsl:variable expand-text="true" name="control-id-regex">({ $family-id-regex })\-\d\d?</xsl:variable>


<sch:pattern>

<sch:rule context="o:p | o:li | o:label">
<sch:report test="exists(child::text()[matches(string(.),$control-id-regex)])">Detecting untagged control ID</sch:report>
<!--<sch:report role="warning" test="contains(string(.),'(')">Detecting ( parenthesis</sch:report>-->
</sch:rule>
</sch:pattern>

</sch:schema>
101 changes: 101 additions & 0 deletions src/nist.gov/SP800-53/rev5/xml/list-untagged-refs.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
exclude-result-prefixes="xs math"
xpath-default-namespace="http://csrc.nist.gov/ns/oscal/1.0"
xmlns="http://csrc.nist.gov/ns/oscal/1.0"
version="3.0">

<xsl:variable name="family-id-regex" as="xs:string">AC|AT|AU|CA|CM|CP|IA|IR|MA|MP|PE|PL|PM|PS|PT|RA|SA|SC|SI|SR</xsl:variable>

<xsl:variable expand-text="true" name="control-id-regex">({ $family-id-regex })\-\d\d?</xsl:variable>

<xsl:variable name="id-segment" as="xs:string">(\p{Ps}([a-z]+|\d+)\p{Pe})</xsl:variable>

<!-- control ID followed by anything but . , ; or space -->
<xsl:variable expand-text="true" name="component-id-regex">{ $control-id-regex }(_ODP)?{ $id-segment }*</xsl:variable>

<xsl:output indent="true"/>

<xsl:variable name="filtered">
<xsl:apply-templates select="/*" mode="filter"/>
</xsl:variable>

<xsl:template match="*" mode="filter">
<xsl:where-populated>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="#current"/>
</xsl:copy>
</xsl:where-populated>
</xsl:template>

<xsl:template mode="filter" match="comment() | processing-instruction()"/>

<xsl:template mode="filter" match="text()"/>

<xsl:template mode="filter" match="a"/>

<xsl:template mode="filter" match="text()[matches(string(.),$control-id-regex)]">
<text>
<xsl:copy-of select="."/>
</text>
</xsl:template>


<!-- @%%%@ @%%%@ @%%%@ @%%%@ @%%%@ @%%%@ @%%%@ @%%%@ @%%%@ @%%%@ @%%%@ @%%%@ @%%%@ -->

<xsl:template match="/">
<listing>
<!--<summary>
<xsl:apply-templates select="$filtered//text" mode="report"/>
</summary>-->
<dump>
<xsl:sequence select="$filtered"/>
</dump>
</listing>
</xsl:template>

<xsl:template match="text" mode="report" expand-text="true">
<xsl:variable name="here" select="."/>
<xsl:analyze-string select="string(.)" regex="{$component-id-regex}">
<xsl:matching-substring>
<ref>
<xsl:apply-templates mode="report-location" select="$here"/>
<xsl:text> points to { string( regex-group(0) ) }</xsl:text>
</ref>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>

<xsl:template match="*" mode="report-location">
<xsl:apply-templates select="parent::*" mode="report-location"/>
<xsl:text expand-text="true">/{ name() }</xsl:text>
</xsl:template>

<xsl:template match="text" mode="report-location">
<xsl:apply-templates select="parent::*" mode="report-location"/>
</xsl:template>

<xsl:template match="part | param | control" mode="report-location" expand-text="true">{ name()}[@id='{ @id }']</xsl:template>

<xsl:template match="part[empty(@id)]" mode="report-location">
<xsl:apply-templates select="parent::*" mode="report-location"/>
<xsl:text expand-text="true">/{ name()}[@name='{ @name }']</xsl:text>
</xsl:template>

<!--
<control class="SP800-53-enhancement" id="ac-3.7">
<param id="ac-03.07_odp.02">
<guideline>
<p>
<text>users authorized to assume roles (defined in AC-03(07)_ODP[01]) are defined;</text>
</p>
</guideline>
</param>
</control>
-->

<xsl:template match="param[@id='ac-03.07_odp.02']/guideline/p/text()[.=$mods/in]"
</xsl:stylesheet>
54 changes: 54 additions & 0 deletions src/nist.gov/SP800-53/rev5/xml/xsd-ws-assess.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
exclude-result-prefixes="xs math"
version="3.0">

<xsl:output indent="true" method="text"/>

<xsl:variable name="aggregated" as="element()*">
<xsl:for-each-group select="$element-set/element" group-by="@name">
<element name="{current-grouping-key()}" permits-text="{ every $p in (current-group()/@permits-text) satisfies $p = 'true'}"/>
</xsl:for-each-group>
</xsl:variable>

<xsl:template match="/*">
<xsl:value-of select="$aggregated[@permits-text='true']/@name" separator=" | "/>
</xsl:template>

<xsl:variable name="element-set">
<xsl:apply-templates select="//xs:element" mode="report"/>
</xsl:variable>

<xsl:template match="xs:element" mode="report">
<xsl:variable name="permits-text" as="xs:boolean">
<xsl:apply-templates select="." mode="permit-text"/>
</xsl:variable>
<element name="{@name}" permits-text="{ $permits-text }"/>
</xsl:template>

<xsl:template mode="permit-text" match="*">
<xsl:sequence select="false()"/>
</xsl:template>

<xsl:template mode="permit-text" match="xs:element[xs:complexType/@mixed='true']">
<xsl:sequence select="true()"/>
</xsl:template>

<xsl:template mode="permit-text" match="xs:element[xs:simpleType]">
<xsl:sequence select="true()"/>
</xsl:template>

<xsl:template mode="permit-text" match="xs:complexType[@mixed='true'] | xs:complexType[exists(xs:simpleContent)] | xs:simpleType">
<xsl:sequence select="true()"/>
</xsl:template>


<xsl:template mode="permit-text" match="xs:element[exists(@type)]">
<xsl:apply-templates select="key('type-by-name',@type)" mode="#current"/>
</xsl:template>

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

</xsl:stylesheet>

0 comments on commit 9028879

Please sign in to comment.