File: shared_xccdf2table-stig.xslt

package info (click to toggle)
scap-security-guide 0.1.39-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 31,836 kB
  • sloc: xml: 129,736; python: 7,462; sh: 3,796; makefile: 27
file content (198 lines) | stat: -rw-r--r-- 6,599 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cdf="http://checklists.nist.gov/xccdf/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml">

<!-- setting the external variable $notes identifies a file from which to add notes,
	 but set to nothing by default -->
<xsl:param name="notes" select="''" />

<xsl:variable name="notegroup" select="document($notes)/notegroup" />

	<xsl:template match="/">
		<html>
		<head>
			<title>Rules In <xsl:value-of select="/cdf:Benchmark/cdf:title" /><xsl:if test="$notes"> with Notes for Transition to <xsl:value-of select="$product_short_name" /> Consensus</xsl:if></title>
		</head>
		<body>
			<br/>
			<br/>
			<div style="text-align: center; font-size: x-large; font-weight:bold">
			Rules In <i><xsl:value-of select="/cdf:Benchmark/cdf:title" /></i><xsl:if test="$notes"> with Notes for Transition to <xsl:value-of select="$product_short_name" /> Consensus</xsl:if>
			</div>
			<br/>
			<br/>
			<xsl:apply-templates select="cdf:Benchmark"/>
		</body>
		</html>
	</xsl:template>


	<xsl:template match="cdf:Benchmark">
		<xsl:call-template name="table-style" />

		<table>
			<thead>
			<xsl:choose>
			<xsl:when test="$notes">
			<td>
			<table class="bbl">
				<tr><td class="bl">Title</td></tr>
				<tr><td>V-ID</td></tr>
				<tr><td>CCI</td></tr>
				<tr><td>CAT</td></tr>
			</table>
			</td>
			</xsl:when>
			<xsl:otherwise>
				<td>V-ID</td>
				<td>CCI</td>
				<td>CAT</td>
				<td>Title</td>
			</xsl:otherwise>
			</xsl:choose>
				<td>Description</td>
				<td>Check Procedures</td>
				<td>Fixtext</td>
			<xsl:if test='$notes'>
				<td>Notes</td>
			</xsl:if>
			</thead>

                <xsl:apply-templates select=".//cdf:Group" />
		</table>
	</xsl:template>


	<xsl:template name="rule-output">
          <xsl:param name="vulnid"/>
		<tr>
			<xsl:choose>
			<xsl:when test="$notes">
			<td>
			<table class="bl">
					<tr><td><xsl:value-of select="cdf:Rule/cdf:title" /></td></tr>
					<tr><td><xsl:value-of select="@id"/></td></tr>
					<!--<tr><td><xsl:value-of select="cdf:title" /></td></tr>-->
					<tr><td><xsl:value-of select="cdf:Rule/@severity" /></td></tr>
			</table>
			</td>
			</xsl:when>
			<xsl:otherwise>
				<td><xsl:value-of select="@id"/></td> 
				<td> <xsl:value-of select="cdf:Rule/cdf:ident" /></td>
				<!--<td> <xsl:value-of select="cdf:title" /></td>-->
				<td> <xsl:value-of select="cdf:Rule/@severity" /></td>
				<td> <xsl:value-of select="cdf:Rule/cdf:title" /></td>
			</xsl:otherwise>
			</xsl:choose>
			<td> <xsl:call-template name="extract-vulndiscussion"><xsl:with-param name="desc" select="cdf:Rule/cdf:description"/></xsl:call-template> </td>
			<td> <xsl:apply-templates select="cdf:Rule/cdf:check/cdf:check-content/node()"/> </td>
			<td> <xsl:apply-templates select="cdf:Rule/cdf:fixtext/node()"/> </td>
			<xsl:if test='$notes'>
				<td> <table><xsl:call-template name="print-notes"><xsl:with-param name="vulnid" select="@id"/></xsl:call-template> </table> </td>
			</xsl:if>
		</tr>
     </xsl:template>


	<xsl:template match="cdf:Group">
        <xsl:call-template name="rule-output" select="cdf:Rule">
		    <xsl:with-param name="vulnid" select="@id" />
        </xsl:call-template>
	</xsl:template>


    <xsl:template name="print-notes">
            <xsl:param name="vulnid"/>
		<xsl:for-each select="$notegroup/note">
        	<xsl:call-template name="search_vulnidlist" select="note">
		    	<xsl:with-param name="vulnid_sought" select="$vulnid" />
		    	<xsl:with-param name="vulnid_list" select="@ref" />
        	</xsl:call-template>
		</xsl:for-each>

    </xsl:template>


  <xsl:template name="search_vulnidlist">
     <xsl:param name="vulnid_sought"/>
     <xsl:param name="vulnid_list"/>
     <xsl:variable name="delim" select="','" />
      <xsl:choose>
        <xsl:when test="$delim and contains($vulnid_list, $delim)">
			<xsl:call-template name="note-output" >
      			<xsl:with-param name="vulnid_sought" select="$vulnid_sought" />
   				<xsl:with-param name="vulnid_found" select="substring-before($vulnid_list, $delim)" />
			</xsl:call-template>

         <!-- recurse for additional vuln ids in list -->
			<xsl:call-template name="search_vulnidlist">
				<xsl:with-param name="vulnid_sought" select="$vulnid_sought" />
				<xsl:with-param name="vulnid_list" select="substring-after($vulnid_list, $delim)" />
			</xsl:call-template>
		</xsl:when>

		<xsl:otherwise>
			<xsl:call-template name="note-output" >
      			<xsl:with-param name="vulnid_sought" select="$vulnid_sought" />
   				<xsl:with-param name="vulnid_found" select="$vulnid_list" />
			</xsl:call-template>
		</xsl:otherwise>

	</xsl:choose>
  </xsl:template>


 <!-- output note text if vuln ID matches -->
  <xsl:template name="note-output">
     <xsl:param name="vulnid_sought"/>
     <xsl:param name="vulnid_found"/>
	 <xsl:variable name="vulnid_found_normal" select="normalize-space($vulnid_found)"  />
	 <xsl:variable name="vulnid_expanded" select="concat('V-', $vulnid_found_normal)"  />
	 <xsl:if test="$vulnid_sought=$vulnid_expanded">
		<tr><td><xsl:value-of select="@auth"/>: <xsl:value-of select="." /></td></tr>
	 </xsl:if>

 </xsl:template>


    <!-- remove any encoded non-XCCDF tags. -->
    <!-- continue to wonder: -->
    <!-- 1) why this is not in the XCCDF spec, if it's needed by one of its major users, or -->
    <!-- 2) why this garbage is ever exported by VMS -->
    <!-- this should be removed as soon as SRGs don't include this detritus -->
  <xsl:template name="extract-vulndiscussion">
	<xsl:param name="desc"/>
	<xsl:if test="contains($desc, '&lt;VulnDiscussion&gt;')">
		<xsl:variable name="desc_info" select="substring-before($desc, '&lt;/VulnDiscussion&gt;')"/>
		<xsl:value-of select="substring-after($desc_info, '&lt;VulnDiscussion&gt;')"/>
	</xsl:if>
	<xsl:if test="not(contains($desc, '&lt;VulnDiscussion&gt;'))">
		<xsl:apply-templates select="$desc"/>
	</xsl:if>
  </xsl:template>




	<!-- getting rid of XHTML namespace -->
	<xsl:template match="xhtml:*">
		<xsl:element name="{local-name()}">
 			<xsl:apply-templates select="node()|@*"/>
		</xsl:element>
	</xsl:template>

	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>

	<xsl:template match="cdf:description">
		<xsl:apply-templates select="@*|node()" />
	</xsl:template>

	<xsl:template match="cdf:rationale">
		<xsl:apply-templates select="@*|node()" />
	</xsl:template>

</xsl:stylesheet>