Skip to content

Commit 3ca36fb

Browse files
galtmaj-stein-nist
authored andcommitted
Follow keep instruction for back-matter resources (#1378)
If a back-matter resource has a keep instruction, the spec requirement "req-backmatter-keep" says not to replace the resource unless a later one also has a keep instruction.
1 parent 76ff697 commit 3ca36fb

File tree

2 files changed

+132
-3
lines changed

2 files changed

+132
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,18 @@
110110
<back-matter>
111111
<!-- Using combination logic on back matter elements. -->
112112
<xsl:for-each-group select="back-matter/* | selection/back-matter/*" group-by="(@opr:id,@uuid,generate-id())[1]">
113+
<xsl:variable name="last" as="element(resource)" select="current-group()[last()]"/>
114+
<!-- The final phase needs the ability to keep unreferenced
115+
back matter items based on keep instructions, so the merge
116+
phase must preserve these items. -->
117+
<xsl:variable name="keepers" as="element(resource)*"
118+
select="current-group()[child::prop[@name='keep' and @value='always']]"/>
113119
<xsl:call-template name="combine-elements">
114-
<!-- Take last one in group because of spec
115-
requirement id="req-backmatter-dupe". -->
116-
<xsl:with-param name="who" select="current-group()[last()]" as="element(resource)"/>
120+
<!-- Take last one in group because of spec requirement
121+
id="req-backmatter-dupe". -->
122+
<!-- Take last item with keep instruction, because
123+
of spec requirement id="req-backmatter-keep". -->
124+
<xsl:with-param name="who" select="$keepers[last()] | $last" as="element(resource)+"/>
117125
</xsl:call-template>
118126
</xsl:for-each-group>
119127
</back-matter>

src/utils/util/resolver-pipeline/testing/3_merged/merge.xspec

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,127 @@
494494
</back-matter>
495495
</x:expect>
496496
</x:scenario>
497+
<x:scenario label="Testing keep instructions: Three resources with same uuid, where">
498+
<x:scenario label="1st has keep instruction and others do not">
499+
<x:context>
500+
<catalog>
501+
<selection uuid="xyz-tiny_catalog">
502+
<control id="x1"><title>Control X1</title></control>
503+
<back-matter>
504+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
505+
<title>Ref BBB, first</title>
506+
<prop name="keep" value="always"/>
507+
</resource>
508+
</back-matter>
509+
</selection>
510+
<selection uuid="xyz-tiny_catalog2">
511+
<control id="x2"><title>Control X2</title></control>
512+
<back-matter>
513+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
514+
<title>Ref BBB, second</title>
515+
</resource>
516+
</back-matter>
517+
</selection>
518+
<back-matter>
519+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
520+
<title>Ref BBB, third</title>
521+
</resource>
522+
</back-matter>
523+
</catalog>
524+
</x:context>
525+
<x:call template="combine-back-matter"/>
526+
<x:expect label="back-matter with 1st and 3rd items. 2nd item was superseded by 3rd item.">
527+
<back-matter>
528+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
529+
<title>Ref BBB, first</title>
530+
<prop name="keep" value="always"/>
531+
</resource>
532+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
533+
<title>Ref BBB, third</title>
534+
</resource>
535+
</back-matter>
536+
</x:expect>
537+
</x:scenario>
538+
<x:scenario label="1st and 3rd have keep instruction and 2nd does not">
539+
<x:context>
540+
<catalog>
541+
<selection uuid="xyz-tiny_catalog">
542+
<control id="x1"><title>Control X1</title></control>
543+
<back-matter>
544+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
545+
<title>Ref BBB, first</title>
546+
<prop name="keep" value="always"/>
547+
</resource>
548+
</back-matter>
549+
</selection>
550+
<selection uuid="xyz-tiny_catalog2">
551+
<control id="x2"><title>Control X2</title></control>
552+
<back-matter>
553+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
554+
<title>Ref BBB, second</title>
555+
</resource>
556+
</back-matter>
557+
</selection>
558+
<back-matter>
559+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
560+
<title>Ref BBB, third</title>
561+
<prop name="keep" value="always"/>
562+
</resource>
563+
</back-matter>
564+
</catalog>
565+
</x:context>
566+
<x:call template="combine-back-matter"/>
567+
<x:expect label="back-matter with last item only.">
568+
<back-matter>
569+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
570+
<title>Ref BBB, third</title>
571+
<prop name="keep" value="always"/>
572+
</resource>
573+
</back-matter>
574+
</x:expect>
575+
</x:scenario>
576+
<x:scenario label="1st and 2nd have keep instruction and 3rd does not">
577+
<x:context>
578+
<catalog>
579+
<selection uuid="xyz-tiny_catalog">
580+
<control id="x1"><title>Control X1</title></control>
581+
<back-matter>
582+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
583+
<title>Ref BBB, first</title>
584+
<prop name="keep" value="always"/>
585+
</resource>
586+
</back-matter>
587+
</selection>
588+
<selection uuid="xyz-tiny_catalog2">
589+
<control id="x2"><title>Control X2</title></control>
590+
<back-matter>
591+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
592+
<title>Ref BBB, second</title>
593+
<prop name="keep" value="always"/>
594+
</resource>
595+
</back-matter>
596+
</selection>
597+
<back-matter>
598+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
599+
<title>Ref BBB, third</title>
600+
</resource>
601+
</back-matter>
602+
</catalog>
603+
</x:context>
604+
<x:call template="combine-back-matter"/>
605+
<x:expect label="back-matter with 2nd and 3rd items. 1st item was superseded by 2nd item.">
606+
<back-matter>
607+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
608+
<title>Ref BBB, second</title>
609+
<prop name="keep" value="always"/>
610+
</resource>
611+
<resource uuid="0050231f-4fd0-43d6-8fa0-431367cd83e2">
612+
<title>Ref BBB, third</title>
613+
</resource>
614+
</back-matter>
615+
</x:expect>
616+
</x:scenario>
617+
</x:scenario>
497618
<x:scenario label="No back matter in input context">
498619
<x:context>
499620
<catalog>

0 commit comments

Comments
 (0)