Skip to content

Commit 76ff697

Browse files
galtmaj-stein-nist
authored andcommitted
Test finish phase, plus minor XSLT enhancements and fixes (#1377)
XSLT - Remove template that provides link to source, because metadata phase accomplished that - Add "[last()]" predicate when passing through elements that cannot appear twice - Align with schema by passing through revisions, document-id, location, and group/link but not control/annotation - Align with schema for param insertions, `<insert type="param" id-ref="...">` - Align with schema and spec for keeping items, `<prop name="keep" value="always">` XSpec - Add tests at the level of individual templates
1 parent dfb56e0 commit 76ff697

File tree

2 files changed

+591
-185
lines changed

2 files changed

+591
-185
lines changed

src/utils/util/resolver-pipeline/oscal-profile-resolve-finish.xsl

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,72 +16,72 @@
1616
</xsl:template>
1717

1818
<!-- Finalizing profile resolution into a catalog:
19-
reordering metadata, group and control contents to valid order
20-
removing loose orphan parameters
21-
orphans given inside controls are retained
22-
removing unclaimed inventory
23-
defined as any 'citation' or 'resource' in back matter
24-
without something somewhere linking to it
25-
19+
- Reordering metadata, group and control contents to valid order
20+
- Removing loose orphan parameters
21+
- Orphans given inside controls are retained
22+
- Removing extra elements of types that permit at most one
23+
- Use [last()] instead of [1] to accommodate the case of
24+
replacing a title during modify phase. The modify phase
25+
adds the title following the original one.
26+
- Some "[last()]" expressions are expected to have no effect
27+
if input documents are schema-valid but are included to
28+
avoid producing schema-invalid output.
29+
- Removing unclaimed inventory, defined as any 'resource'
30+
in back matter without something somewhere linking to it
2631
2732
What we are not doing:
28-
removing broken links
29-
remove opqr and xsi namespaces (that happens in the shell)
33+
- Removing broken links
34+
- Remove opr and xsi namespaces (that happens in the shell)
3035
-->
3136
<!-- An XQuery run on a metaschema can return a sequence of instructions
3237
3338
let $where := 'metadata'
3439
for $n in (//*:define-assembly[@name=$where]/*:model/*/(@name | @ref))
3540
return <apply-templates mode="#current" select="{ $n }"/>
3641
42+
Caveat: This query does not account for elements that can occur at most once,
43+
or aliasing via use-name.
3744
-->
3845

39-
<xsl:param name="path-to-source" as="xs:string?"/>
40-
41-
<xsl:template match="metadata/link[@rel='resolution-source']">
42-
<!-- splicing together a path with '/' -->
43-
<link rel="resolution-source" href="{string-join(
44-
($path-to-source[matches(.,'\S')],replace(@href,'.*/','')), '/')}">
45-
<xsl:apply-templates></xsl:apply-templates>
46-
</link>
47-
</xsl:template>
48-
4946
<xsl:template match="catalog">
5047
<xsl:copy copy-namespaces="no">
5148
<xsl:apply-templates mode="#current" select="@*"/>
52-
<xsl:apply-templates mode="#current" select="metadata"/>
49+
<xsl:apply-templates mode="#current" select="metadata[last()]"/>
5350
<xsl:apply-templates mode="#current" select="opr:*"/>
5451
<xsl:apply-templates mode="#current" select="param"/>
5552
<xsl:apply-templates mode="#current" select="control"/>
5653
<xsl:apply-templates mode="#current" select="group"/>
57-
<xsl:apply-templates mode="#current" select="back-matter"/>
54+
<xsl:apply-templates mode="#current" select="back-matter[last()]"/>
5855
</xsl:copy>
5956
</xsl:template>
6057

6158
<xsl:template match="metadata">
6259
<xsl:copy copy-namespaces="no">
6360
<xsl:apply-templates mode="#current" select="@*"/>
64-
<xsl:apply-templates mode="#current" select="title"/>
65-
<xsl:apply-templates mode="#current" select="published"/>
66-
<xsl:apply-templates mode="#current" select="last-modified"/>
67-
<xsl:apply-templates mode="#current" select="version"/>
68-
<xsl:apply-templates mode="#current" select="oscal-version"/>
69-
<xsl:apply-templates mode="#current" select="doc-id"/>
61+
<xsl:apply-templates mode="#current" select="title[last()]"/>
62+
<xsl:apply-templates mode="#current" select="published[last()]"/>
63+
<xsl:apply-templates mode="#current" select="last-modified[last()]"/>
64+
<xsl:apply-templates mode="#current" select="version[last()]"/>
65+
<xsl:apply-templates mode="#current" select="oscal-version[last()]"/>
66+
<xsl:apply-templates mode="#current" select="revisions[last()]"/>
67+
<xsl:apply-templates mode="#current" select="document-id"/>
7068
<xsl:apply-templates mode="#current" select="prop"/>
7169
<xsl:apply-templates mode="#current" select="link"/>
7270
<xsl:apply-templates mode="#current" select="role"/>
71+
<xsl:apply-templates mode="#current" select="location"/>
7372
<xsl:apply-templates mode="#current" select="party"/>
7473
<xsl:apply-templates mode="#current" select="responsible-party"/>
75-
<xsl:apply-templates mode="#current" select="remarks"/>
74+
<xsl:apply-templates mode="#current" select="remarks[last()]"/>
7675
</xsl:copy>
7776
</xsl:template>
7877

7978
<xsl:template match="group">
8079
<xsl:copy copy-namespaces="no">
8180
<xsl:apply-templates mode="#current" select="@*"/>
82-
<xsl:apply-templates mode="#current" select="title"/>
81+
<xsl:apply-templates mode="#current" select="title[last()]"/>
8382
<xsl:apply-templates mode="#current" select="param"/>
8483
<xsl:apply-templates mode="#current" select="prop"/>
84+
<xsl:apply-templates mode="#current" select="link"/>
8585

8686
<xsl:apply-templates mode="#current" select="part"/>
8787
<xsl:apply-templates mode="#current" select="control"/>
@@ -92,20 +92,23 @@
9292
<xsl:template match="control">
9393
<xsl:copy copy-namespaces="no">
9494
<xsl:apply-templates mode="#current" select="@*"/>
95-
<xsl:apply-templates mode="#current" select="title"/>
95+
<!-- Keep only the last title. There could be multiple titles if
96+
modify phase processed alter/add/title. -->
97+
<xsl:apply-templates mode="#current" select="title[last()]"/>
9698
<xsl:apply-templates mode="#current" select="param"/>
9799
<xsl:apply-templates mode="#current" select="prop"/>
98-
<xsl:apply-templates mode="#current" select="annotation"/>
99100
<xsl:apply-templates mode="#current" select="link"/>
100101
<xsl:apply-templates mode="#current" select="part"/>
101102
<xsl:apply-templates mode="#current" select="control"/>
102103
</xsl:copy>
103104
</xsl:template>
104105

105-
<xsl:key name="param-insertions" match="insert" use="@param-id"/>
106+
<xsl:key name="param-insertions" match="insert[@type='param']" use="@id-ref"/>
106107

107-
<xsl:template match="catalog/param[empty(key('param-insertions',@id))]
108-
| group/param[empty(key('param-insertions',@id))]"/>
108+
<!-- Suppress loose param elements that do not have corresponding insert element(s)
109+
and that do not have an explicit instruction to keep them. -->
110+
<xsl:template match="catalog/param[empty(key('param-insertions',@id))][not(prop[@name='keep'][@value='always'])]
111+
| group/param[empty(key('param-insertions',@id))][not(prop[@name='keep'][@value='always'])]"/>
109112

110113
<!-- Don't copy back-matter wrapper if it has no contents in result -->
111114
<xsl:template match="back-matter">
@@ -116,6 +119,8 @@
116119

117120
<xsl:key name="cross-reference" match="*[starts-with(@href,'#')]" use="substring-after(@href,'#')"/>
118121

119-
<xsl:template match="resource[empty(key('cross-reference',@uuid))][not(prop[@name='keep']='always')]"/>
122+
<!-- Suppress resource elements that are not referenced and that do not
123+
have an explicit instruction to keep them. -->
124+
<xsl:template match="resource[empty(key('cross-reference',@uuid))][not(prop[@name='keep'][@value='always'])]"/>
120125

121126
</xsl:stylesheet>

0 commit comments

Comments
 (0)