Skip to content

Commit

Permalink
More CPRT; some tutorial mods
Browse files Browse the repository at this point in the history
  • Loading branch information
wendellpiez committed Nov 19, 2024
1 parent 5b208b9 commit 94298a1
Show file tree
Hide file tree
Showing 19 changed files with 267 additions and 421 deletions.
35 changes: 23 additions & 12 deletions projects/CPRT-import/PRODUCE_SP800-171-OSCAL.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<p:store href="temp/{ $doc-code }_01_extracted.xml" serialization="map{ 'indent': true() }"
message="[PRODUCE_SP800-171-OSCAL] Saving intermediate result temp/{ $doc-code }_01_extracted.xml"/>


<p:validate-with-relax-ng assert-valid="true" message="[PRODUCE_SP800-171-OSCAL] Validating JSON extract against reduced schema">
<p:with-input port="schema">
<!-- @content-type text/plain triggers RNC evaluation -->
Expand All @@ -73,13 +74,15 @@
<p:store href="temp/{ $doc-code }_02_expanded.xml" serialization="map{ 'indent': true() }"
message="[PRODUCE_SP800-171-OSCAL] Saving intermediate result temp/{ $doc-code }_02_expanded.xml"/>


<p:xslt>
<p:with-input port="stylesheet" href="src/cprt-reduce.xsl"/>
</p:xslt>

<p:store href="temp/{ $doc-code }_03_declarative.xml" serialization="map{ 'indent': true() }"
message="[PRODUCE_SP800-171-OSCAL] Saving intermediate result temp/{ $doc-code }_03_declarative.xml"/>



<!-- Next step: convert all brackets in //text to <bracket>...</bracket> and try parsing ... -->

<!-- Picks up implicit 'selection' markup; ODP reference codes, and escaped markup (<a href=" etc.) -->
Expand Down Expand Up @@ -136,32 +139,40 @@
<p:store href="temp/{ $doc-code }_04-enhanced.xml" serialization="map{ 'indent': true() }"
message="[PRODUCE_SP800-171-OSCAL] Saving intermediate result temp/{ $doc-code }_04_enhanced.xml"/>


<p:xslt>
<p:with-input port="stylesheet" href="src/cprt-link-odps.xsl"/>
</p:xslt>

<p:validate-with-schematron assert-valid="true" message="[PRODUCE_SP800-171-OSCAL] Validating CPRT XML for referential integrity">
<p:with-input port="schema" href="src/cprt-ready.sch"/>
</p:validate-with-schematron>

<p:insert match="/*" position="before">
<p:with-input port="insertion">
<p:inline><?xml-model href="../src/cprt-ready.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
</p:inline>
</p:with-input>
</p:insert>

<p:xslt>
<p:with-input port="stylesheet" href="src/cprt-group-references.xsl"/>
</p:xslt>

<p:store href="temp/{ $doc-code }_05-linked.xml" serialization="map{ 'indent': true() }"
message="[PRODUCE_SP800-171-OSCAL] Saving intermediate result temp/{ $doc-code }_05-linked.xml"/>

<!-- Next: Schematron the CPRT data set for link integrity -
things nested properly? starts-with(@id,../@id)
do parameters line up?
are [Assignment: ] and [SELECT strings accounted for?
-->

<!--<p:xslt>
<p:with-input port="stylesheet" href="src/crpt-to-oscal.xsl"/>

<p:xslt>
<p:with-input port="stylesheet" href="src/cprt-to-oscal.xsl"/>
</p:xslt>

<p:xslt>
<p:with-input port="stylesheet" href="src/cprt-oscal-finish.xsl"/>
</p:xslt>

<p:store href="{ $doc-code }_oscal.xml" serialization="map{ 'indent': true() }"
message="[PRODUCE_SP800-171-OSCAL] Saving intermediate result { $doc-code }_oscal.xml"/>-->
<p:variable name="hash" select="/*/@uuid/tokenize(.,'-')[1]"/>
<p:store href="{ $doc-code }_{ $hash }_xp3-oscal.xml" serialization="map{ 'indent': false() }"
message="[PRODUCE_SP800-171-OSCAL] Saving intermediate result { $doc-code }_{ $hash }_xp3-oscal.xml"/>

</p:declare-step>
5 changes: 2 additions & 3 deletions projects/CPRT-import/src/cprt-link-odps.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@
</xsl:copy>
</xsl:template>


<!-- A few pointers are misdirected ... -->
<!-- A few pointers are misdirected, so we direct them properly here ... -->
<xsl:template priority="11" match="security_requirement[@id=('SR-03.04.06.c','SR-03.11.02.b','SR-03.11.02.c')]//assignment">
<xsl:copy>
<xsl:attribute name="odp-ref-id" select="../../determination/odp/@id"/>
<xsl:attribute name="odp-ref-id" select="ancestor::security_requirement/determination/odp/@id"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
Expand Down
2 changes: 1 addition & 1 deletion projects/CPRT-import/src/cprt-ready.sch
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ No [Assign or [Select substrings remain
<sch:rule context="cprt:select_from">
<sch:assert test="empty(../* except .)">Expecting <sch:name/> here to be a singleton.</sch:assert>
</sch:rule>
<sch:rule context="cprt:text | cprt:title | cprt:external_reference | cprt:a | cprt:assignment | cprt:selection | cprt:odp-ref | cprt:choice | cprt:incorporated_into">
<sch:rule context="cprt:text | cprt:title | cprt:external_reference | cprt:a | cprt:assignment | cprt:selection | cprt:odp-ref | cprt:choice | cprt:incorporated_into | cprt:label">
<sch:report test="matches(.,'\[Assign','i')">Parameter assignment appears in plain text.</sch:report>
<sch:report test="matches(.,'\[Select','i')">Parameter value selection appears in plain text.</sch:report>
</sch:rule>
Expand Down
156 changes: 136 additions & 20 deletions projects/CPRT-import/src/cprt-to-oscal.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

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

<xsl:import href="xslt3-functions/random-util.xsl"/>


<xsl:template match="*">
<xsl:element name="cprt:{ name() }" namespace="http://csrc.nist.gov/ns/cprt">
<xsl:copy-of select="@*"/>
Expand All @@ -22,11 +21,13 @@

<!-- overrides testing template in imported XSLT -->
<xsl:template match="/">


<xsl:apply-templates/>
</xsl:template>

<xsl:template match="/*">
<catalog uuid="{x3f:make-uuid( current-date() )}">
<catalog>
<metadata>
<title>SP 800-171 [OSCAL transcoded version PROVISIONAL FOR TESTING]</title>
<last-modified>{ current-dateTime() }</last-modified>
Expand All @@ -45,20 +46,39 @@

<xsl:template match="title">
<title>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</title>
</xsl:template>

<xsl:template match="requirement">
<control>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</control>
</xsl:template>

<xsl:template match="requirement/withdraw_reason">
<prop name="status" value="withdrawn"/>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="withdraw_reason/text"/>

<xsl:template match="withdraw_reason/addressed_by">
<link rel="addressed-by" href="#sp800-171_{ . }"/>
</xsl:template>

<xsl:template match="withdraw_reason/incorporated_into">
<link rel="incorporated-into" href="#sp800-171_{ . }"/>
</xsl:template>

<xsl:template match="@id">
<xsl:attribute name="id">sp800-171_{ . }</xsl:attribute>
</xsl:template>

<xsl:template match="external_reference">
<link class="reference">
<link rel="related">
<xsl:apply-templates/>
</link>
</xsl:template>
Expand All @@ -70,19 +90,37 @@
</xsl:template>

<xsl:template match="text">
<p>
<xsl:apply-templates/>
</p>
<p>
<xsl:apply-templates/>
</p>
</xsl:template>

<xsl:template match="link[starts-with(@href,'#')]">
<link>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</link>
</xsl:template>

<xsl:template match="link/@href[starts-with(.,'#')]">
<xsl:attribute name="href">#sp800-171_{ replace(.,'^#','') }</xsl:attribute>
</xsl:template>


<xsl:template match="a">
<a>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</a>

</xsl:template>

<xsl:variable name="cprt-linkstring" as="xs:string">#/cprt/framework/version/SP_800_171_3_0_0/home?element=</xsl:variable>

<xsl:template match="a/@href[starts-with(.,$cprt-linkstring)]">
<xsl:attribute name="href" select="'#sp800-171_' || substring-after(.,$cprt-linkstring)"/>
</xsl:template>


<xsl:template match="examine | interview | test">
<part name="{ local-name() }" id="sp800-171_{@id}">
<xsl:apply-templates/>
Expand All @@ -91,27 +129,58 @@


<xsl:template match="examine/text | interview/text | test/text">
<xsl:apply-templates select="selection"/>
<xsl:if test="* except selection[1]">
<xsl:apply-templates select="select_from"/>
<xsl:if test="exists(* except select_from[1])">
<xsl:message terminate="yes">unexpected contents at { path(.) }</xsl:message>
</xsl:if>
</xsl:template>


<xsl:template match="examine/text/selection | interview/text/selection | test/text/selection">
<xsl:template match="examine/text/select_from | interview/text/select_from | test/text/select_from">
<xsl:for-each select="tokenize(.,';\s*')">
<p>
<xsl:text>{ . }</xsl:text>
</p>
</xsl:for-each>
</xsl:template>

<!--<xsl:template match="odp">



<xsl:template match="security_requirement">
<part name="statement">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</part>
</xsl:template>

<xsl:template priority="6" match="security_requirement/title">
<prop name="label" value="{ . }"/>
</xsl:template>

<xsl:template match="determination">
<part name="item">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</part>
</xsl:template>


<xsl:template match="odp">
<param id="sp800-171_{@id}">
<xsl:if test="odp_type/@id='single_entry' and empty(title)">
<label>{ replace(odp_statement/text,'^organization-defined\s*','') }</label>
</xsl:if>
<xsl:apply-templates/>
</param>
</xsl:template>

<xsl:template match="odp/text/choice">
<choice>
<xsl:apply-templates/>
</choice>
</xsl:template>

<xsl:template match="odp/title">
<label>
<xsl:apply-templates/>
Expand All @@ -120,20 +189,67 @@

<xsl:template match="odp/text">
<usage>
<xsl:apply-templates/>
<p>
<xsl:apply-templates/>
</p>
</usage>
</xsl:template>

<xsl:template priority="101" match="odp/text[exists(choice)]">
<select>
<xsl:if test="starts-with(.,'one or more')">
<xsl:attribute name="how-many">one-or-more</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="choice"/>
</select>
</xsl:template>

<xsl:template match="odp/odp_statement">
<guideline>
<xsl:apply-templates/>
</guideline>
</xsl:template>-->
</xsl:template>

<xsl:template match="odp/odp_type"/>

<!--<xsl:template match="odp/odp_type"/>-->
<xsl:template match="REFERENCES">
<back-matter>
<xsl:apply-templates/>
</back-matter>
</xsl:template>

<xsl:template match="odp-ref | assignment | selection">
<insert type="param" id-ref="sp800-171_{ @odp-ref-id }"/>
</xsl:template>

<xsl:template match="odp-ref">
<insert type="param" id-ref="sp800-171_{ @ref-id }"/>
</xsl:template>

<xsl:template match="reference">
<resource>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</resource>
</xsl:template>

<!-- Used to retrieve ODPs from implicit references in <assignment> -->
<xsl:key name="odp-by-statement" match="odp" use="odp_statement/normalize-space(.)"/>
<xsl:template match="reference/label">
<title>
<xsl:apply-templates/>
</title>
</xsl:template>

<xsl:template match="reference/title">
<citation>
<text>
<xsl:apply-templates/>
</text>
</citation>
</xsl:template>

<xsl:template match="reference/text" priority="12">
<rlink href="{ normalize-space(.) }"/>
</xsl:template>


</xsl:stylesheet>
14 changes: 9 additions & 5 deletions tutorial/PRODUCE-TUTORIAL-MARKDOWN.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
<p:directory-list path="source/{ $lesson_key }" max-depth="unbounded" include-filter="(_src\.html|png)$"/>

<!-- is there a better way to annotate a directory list with full paths?
or: make a step out of this and import it -->
<p:xslt name="directory">
or: make a step out of this and import it XXXX -->
<p:label-elements name="directory"
match="c:file" attribute="path" label="ancestor-or-self::*/@xml:base => string-join('')"/>

<!--<p:xslt name="directory">
<p:with-input port="stylesheet">
<p:inline expand-text="false">
<xsl:stylesheet version="3.0">
Expand All @@ -36,13 +39,14 @@
</xsl:stylesheet>
</p:inline>
</p:with-input>
</p:xslt>
</p:xslt>-->


<p:for-each name="files">
<p:with-input select="descendant::c:file[ends-with(@path,'_src.html')]"/>
<!-- Remember that each input node is a root for its own tree - hence XPath context -->
<p:variable name="path" select="/*/@path => p:urify()"/>
<p:variable name="project-uri" select="p:urify('.')"/>
<p:variable name="path" select="/*/@path => resolve-uri()"/>
<p:variable name="project-uri" select="resolve-uri('.')"/>

<!--<p:identity message="[PRODUCE-TUTORIAL-MARKDOWN] Loading {$path} "/>-->
<p:load href="{$path}" message="[PRODUCE-TUTORIAL-MARKDOWN] Loading {$path} "/>
Expand Down
Loading

0 comments on commit 94298a1

Please sign in to comment.