Skip to content

Commit c09211d

Browse files
authored
Merge pull request #2071 from jan-cerny/references_html
Improve references in HTML guides and reports
2 parents f5ac1d3 + 953c6b5 commit c09211d

File tree

4 files changed

+72
-46
lines changed

4 files changed

+72
-46
lines changed

xsl/xccdf-guide-impl.xsl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,9 @@ Authors:
254254
</tr>
255255

256256

257-
<tr><td>Identifiers and References</td><td class="identifiers">
258-
<xsl:call-template name="item-idents-refs">
259-
<xsl:with-param name="item" select="$item"/>
260-
</xsl:call-template>
261-
</td></tr>
257+
<xsl:call-template name="item-idents-refs">
258+
<xsl:with-param name="item" select="$item"/>
259+
</xsl:call-template>
262260

263261
<tr><td colspan="2"><div class="remediation-description">
264262
<xsl:for-each select="$item/cdf:fixtext">
@@ -515,7 +513,10 @@ Authors:
515513
<table class="table table-striped table-bordered">
516514
<tbody>
517515
<tr><td>Identifiers and References</td><td class="identifiers">
518-
<xsl:call-template name="item-idents-refs">
516+
<xsl:call-template name="item-idents">
517+
<xsl:with-param name="item" select="$item"/>
518+
</xsl:call-template>
519+
<xsl:call-template name="item-refs">
519520
<xsl:with-param name="item" select="$item"/>
520521
</xsl:call-template>
521522
</td></tr>

xsl/xccdf-references.xsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Authors:
4141
<xsl:template name="convert-reference-url-to-name">
4242
<xsl:param name="href"/>
4343
<xsl:choose>
44+
<xsl:when test="key('reference_names', $href)">
45+
<xsl:value-of select="key('reference_names', $href)"/>
46+
</xsl:when>
4447
<xsl:when test="starts-with($href, 'http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-53')">
4548
<xsl:text>NIST SP 800-53</xsl:text>
4649
</xsl:when>

xsl/xccdf-report-impl.xsl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -809,14 +809,9 @@ Authors:
809809
</xsl:call-template>
810810
</td>
811811
</tr>
812-
<tr><td>Identifiers and References</td><td class="identifiers">
813-
<!-- XCCDF 1.2 spec says that idents in rule-result should be copied from
814-
the Rule itself. That means that we can just use the same code as guide
815-
and just use idents from Rule. -->
816-
<xsl:call-template name="item-idents-refs">
817-
<xsl:with-param name="item" select="$item"/>
818-
</xsl:call-template>
819-
</td></tr>
812+
<xsl:call-template name="item-idents-refs">
813+
<xsl:with-param name="item" select="$item"/>
814+
</xsl:call-template>
820815
<xsl:if test="cdf:override">
821816
<tr><td colspan="2">
822817
<xsl:for-each select="cdf:override">

xsl/xccdf-share.xsl

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Authors:
3131
<xsl:param name="verbosity"/>
3232

3333
<xsl:key name="values" match="//cdf:Value" use="concat(ancestor::cdf:Benchmark/@id, '|', @id)"/>
34+
<xsl:key name="reference_names" match="//cdf:Benchmark/cdf:reference" use="@href"/>
3435

3536
<xsl:template name="rule-result-tooltip">
3637
<xsl:param name="ruleresult"/>
@@ -64,26 +65,6 @@ Authors:
6465
</xsl:choose>
6566
</xsl:template>
6667

67-
<xsl:template match="cdf:reference" mode="reference">
68-
<xsl:choose>
69-
<xsl:when test="@href">
70-
<a href="{@href}">
71-
<xsl:choose>
72-
<xsl:when test="text()">
73-
<xsl:value-of select="text()"/>
74-
</xsl:when>
75-
<xsl:otherwise>
76-
<xsl:value-of select="@href"/>
77-
</xsl:otherwise>
78-
</xsl:choose>
79-
</a>
80-
</xsl:when>
81-
<xsl:otherwise>
82-
<xsl:value-of select="text()"/>
83-
</xsl:otherwise>
84-
</xsl:choose>
85-
</xsl:template>
86-
8768
<xsl:template name="item-title">
8869
<xsl:param name="item"/>
8970
<xsl:param name="profile"/>
@@ -104,25 +85,71 @@ Authors:
10485

10586
<xsl:template name="item-idents-refs">
10687
<xsl:param name="item"/>
107-
10888
<xsl:if test="$item/cdf:ident">
109-
<p>
110-
<span class="label label-info" title="A globally meaningful identifiers for this rule. MAY be the name or identifier of a security configuration issue or vulnerability that the rule remediates. By setting an identifier on a rule, the benchmark author effectively declares that the rule instantiates, implements, or remediates the issue for which the name was assigned.">Identifiers:</span>&#160;
111-
<xsl:for-each select="$item/cdf:ident">
112-
<xsl:apply-templates mode="ident" select="."/>
113-
<xsl:if test="position() != last()">, </xsl:if>
114-
</xsl:for-each>
115-
</p>
89+
<tr>
90+
<td>
91+
<span class="label label-info" title="A globally meaningful identifiers for this rule. MAY be the name or identifier of a security configuration issue or vulnerability that the rule remediates. By setting an identifier on a rule, the benchmark author effectively declares that the rule instantiates, implements, or remediates the issue for which the name was assigned.">Identifiers:</span>
92+
</td>
93+
<td class="identifiers">
94+
<xsl:call-template name="item-idents">
95+
<xsl:with-param name="item" select="$item"/>
96+
</xsl:call-template>
97+
</td>
98+
</tr>
11699
</xsl:if>
117100
<xsl:if test="$item/cdf:reference">
101+
<tr>
102+
<td>
103+
<span class="label label-default" title="Provide a reference to a document or resource where the user can learn more about the subject of the Rule or Group.">References:</span>
104+
</td>
105+
<td class="identifiers">
106+
<xsl:call-template name="item-refs">
107+
<xsl:with-param name="item" select="$item"/>
108+
</xsl:call-template>
109+
</td>
110+
</tr>
111+
</xsl:if>
112+
</xsl:template>
113+
114+
<xsl:template name="item-idents">
115+
<xsl:param name="item"/>
118116
<p>
119-
<span class="label label-default" title="Provide a reference to a document or resource where the user can learn more about the subject of the Rule or Group.">References:</span>&#160;
120-
<xsl:for-each select="$item/cdf:reference">
121-
<xsl:apply-templates mode="reference" select="."/>
117+
<xsl:for-each select="$item/cdf:ident">
118+
<xsl:apply-templates mode="ident" select="."/>
122119
<xsl:if test="position() != last()">, </xsl:if>
123120
</xsl:for-each>
124121
</p>
125-
</xsl:if>
122+
</xsl:template>
123+
124+
<xsl:template name="item-refs">
125+
<xsl:param name="item"/>
126+
<table class="table table-striped table-bordered">
127+
<xsl:for-each select="$item/cdf:reference">
128+
<xsl:variable name="href" select="@href"/>
129+
<xsl:if test="not(preceding-sibling::cdf:reference[@href=$href])">
130+
<tr>
131+
<td>
132+
<a href="{@href}">
133+
<xsl:choose>
134+
<xsl:when test="key('reference_names', $href)">
135+
<xsl:value-of select="key('reference_names', $href)"/>
136+
</xsl:when>
137+
<xsl:otherwise>
138+
<xsl:value-of select="@href"/>
139+
</xsl:otherwise>
140+
</xsl:choose>
141+
</a>
142+
</td>
143+
<td>
144+
<xsl:for-each select="$item/cdf:reference[@href=$href]">
145+
<xsl:value-of select="text()"/>
146+
<xsl:if test="position() != last()">, </xsl:if>
147+
</xsl:for-each>
148+
</td>
149+
</tr>
150+
</xsl:if>
151+
</xsl:for-each>
152+
</table>
126153
</xsl:template>
127154

128155
<!-- works for both XCCDF Rule elements and rule-result elements -->

0 commit comments

Comments
 (0)