| 1 |
<?xml version="1.0" encoding="UTF-8" ?> |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
<xsl:stylesheet version="1.1" |
| 25 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 26 |
xmlns:htm="http://www.w3.org/1999/xhtml" |
| 27 |
xmlns="http://www.w3.org/1999/xhtml" |
| 28 |
xmlns:h="http://www.w3.org/1999/xhtml" |
| 29 |
xmlns:fn="http://www.w3.org/2005/xpath-functions" |
| 30 |
xmlns:exsl="http://exslt.org/common" |
| 31 |
xmlns:func="http://exslt.org/functions" |
| 32 |
xmlns:s="http://open-scap.org/" |
| 33 |
xmlns:cdf="http://checklists.nist.gov/xccdf/1.2" |
| 34 |
xmlns:dc="http://purl.org/dc/elements/1.1/" |
| 35 |
xmlns:edate="http://exslt.org/dates-and-times"> |
| 36 |
|
| 37 |
|
| 38 |
<xsl:param name='oscap-version'/> |
| 39 |
<xsl:param name='verbosity'/> |
| 40 |
<xsl:param name='pwd'/> |
| 41 |
|
| 42 |
|
| 43 |
<xsl:variable name='now' select='edate:date-time()'/> |
| 44 |
|
| 45 |
<xsl:variable name='generator' select="'OpenSCAP stylesheet'"/> |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
<xsl:template match="text()" mode='sub'> |
| 55 |
<xsl:value-of select="."/> |
| 56 |
</xsl:template> |
| 57 |
|
| 58 |
|
| 59 |
<xsl:template match="cdf:fix//cdf:instance" mode='sub'> |
| 60 |
<xsl:variable name='ctx' select='@context'/> |
| 61 |
<xsl:choose> |
| 62 |
<xsl:when test='ancestor::cdf:rule-result'> |
| 63 |
<abbr class='replace' title='context: {$ctx}'><xsl:value-of select='ancestor::cdf:rule-result/cdf:instance[@context=$ctx]'/></abbr> |
| 64 |
</xsl:when> |
| 65 |
<xsl:otherwise><abbr class='cdf-sub-context' title='replace with actual {$ctx} context'><xsl:value-of select='$ctx'/></abbr></xsl:otherwise> |
| 66 |
</xsl:choose> |
| 67 |
</xsl:template> |
| 68 |
|
| 69 |
|
| 70 |
<xsl:template match="cdf:sub" mode='sub'> |
| 71 |
<xsl:variable name="subid" select="./@idref"/> |
| 72 |
<xsl:variable name="plain" select="ancestor::cdf:Benchmark/cdf:plain-text[@id=$subid]"/> |
| 73 |
<xsl:variable name="val" select="ancestor::cdf:Benchmark//cdf:Value[@id=$subid]"/> |
| 74 |
<xsl:choose> |
| 75 |
<xsl:when test='$plain'><abbr class='xccdf-plain-text' title="text: {$subid}"><xsl:value-of select="$plain"/></abbr></xsl:when> |
| 76 |
<xsl:otherwise><abbr class='cdf-sub-value' title="value: {$subid} ({$val/cdf:title})"><xsl:value-of select="$val/cdf:value"/></abbr></xsl:otherwise> |
| 77 |
</xsl:choose> |
| 78 |
</xsl:template> |
| 79 |
|
| 80 |
|
| 81 |
<xsl:template match='htm:object[starts-with(@data, "#xccdf:value:")]' mode='sub'> |
| 82 |
<xsl:variable name='id' value='substring(@data, 13)'/> |
| 83 |
<xsl:variable name='sub' select='ancestor::cdf:TestResult/cdf:target-facts/cdf:fact[@name=$id]/text()|ancestor::cdf:Benchmark//cdf:Value[@id=$id]/cdf:value[1]/text()|ancestor::cdf:Benchmark/cdf:plain-text[@id=$id][1]/text()'/> |
| 84 |
<xsl:choose> |
| 85 |
<xsl:when test='$sub'><xsl:value-of select='$sub[1]'/></xsl:when> |
| 86 |
<xsl:otherwise><xsl:value-of select='.'/></xsl:otherwise> |
| 87 |
</xsl:choose> |
| 88 |
</xsl:template> |
| 89 |
|
| 90 |
|
| 91 |
<xsl:template match='htm:object[starts-with(@data, "#xccdf:title:")]' mode='sub'> |
| 92 |
<xsl:variable name='id' value='substring(@data, 13)'/> |
| 93 |
<xsl:variable name='sub' select='ancestor::cdf:Benchmark//cdf:Group/cdf:title|ancestor::cdf:Benchmark//cdf:Rule/cdf:title|ancestor::cdf:Benchmark//cdf:Value/cdf:title'/> |
| 94 |
<xsl:choose> |
| 95 |
<xsl:when test='$sub'><xsl:value-of select='$sub[1]'/></xsl:when> |
| 96 |
<xsl:otherwise><xsl:value-of select='.'/></xsl:otherwise> |
| 97 |
</xsl:choose> |
| 98 |
</xsl:template> |
| 99 |
|
| 100 |
|
| 101 |
<xsl:template match='htm:a[starts-with(@href, "#xccdf:link:")]' mode='sub'> |
| 102 |
<xsl:variable name='id' value='substring(@href, 12)'/> |
| 103 |
<xsl:copy> |
| 104 |
<xsl:copy-of select='@*'/> |
| 105 |
<xsl:attribute name='href'><xsl:apply-templates select='@href' mode='sub'><xsl:with-param name='id' select='$id'/></xsl:apply-templates></xsl:attribute> |
| 106 |
<xsl:apply-templates select="node()" mode='sub'/> |
| 107 |
</xsl:copy> |
| 108 |
</xsl:template> |
| 109 |
|
| 110 |
|
| 111 |
<xsl:template match='@href' mode='sub'><xsl:param name='id'/>#item-<xsl:value-of select='$id'/></xsl:template> |
| 112 |
|
| 113 |
|
| 114 |
<xsl:template match="htm:*" mode='sub'> |
| 115 |
<xsl:element name="{local-name()}"> |
| 116 |
<xsl:copy-of select="@*"/> |
| 117 |
<xsl:apply-templates select="./text() | ./*" mode='sub'/> |
| 118 |
</xsl:element> |
| 119 |
</xsl:template> |
| 120 |
|
| 121 |
|
| 122 |
<xsl:template match='node()|@*' mode='sub'><xsl:copy><xsl:copy-of select='@*'/><xsl:apply-templates select='node()' mode='sub'/></xsl:copy></xsl:template> |
| 123 |
|
| 124 |
<xsl:template match='cdf:description|cdf:fix|cdf:fixtext|cdf:front-matter|cdf:rear-matter|cdf:rationale|cdf:warning' mode='sub'> |
| 125 |
<xsl:copy><xsl:copy-of select='@*'/><xsl:apply-templates select='node()' mode='sub'/></xsl:copy> |
| 126 |
</xsl:template> |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
<xsl:param name='profile'/> |
| 131 |
<xsl:param name='keep-profiles'/> |
| 132 |
<xsl:param name='clean-profile-notes'/> |
| 133 |
|
| 134 |
<xsl:variable name='theprofile' select='/cdf:Benchmark/cdf:Profile[@id=$profile]'/> |
| 135 |
|
| 136 |
|
| 137 |
<xsl:template mode='profile' match='node()|@*'> |
| 138 |
<xsl:copy><xsl:apply-templates mode='profile' select="node()|@*"/></xsl:copy> |
| 139 |
</xsl:template> |
| 140 |
|
| 141 |
|
| 142 |
<xsl:template mode='profile' match='cdf:Profile'> |
| 143 |
<xsl:if test='$keep-profiles'> |
| 144 |
<xsl:copy><xsl:apply-templates mode='profile' select="node()|@*"/></xsl:copy> |
| 145 |
</xsl:if> |
| 146 |
</xsl:template> |
| 147 |
|
| 148 |
|
| 149 |
<xsl:template mode='profile' match='cdf:Group|cdf:Rule'> |
| 150 |
<xsl:variable name='id' select='@id'/> |
| 151 |
<xsl:variable name='cid' select='@cluster-id'/> |
| 152 |
<xsl:variable name='sel' select='$theprofile/cdf:select[@idref=$id or @idref=$cid][1]'/> |
| 153 |
<xsl:variable name='rr' select='$theprofile/cdf:refine-rule[@idref=$id or @idref=$cid][1]'/> |
| 154 |
<xsl:copy> |
| 155 |
<xsl:apply-templates select='@*' mode='profile'/> |
| 156 |
<xsl:if test='self::cdf:Rule and $rr'><xsl:copy-of select='$rr/@role|$rr/@severity|$rr/@weight'/></xsl:if> |
| 157 |
<xsl:if test='$sel'><xsl:attribute name='selected'><xsl:value-of select='$sel/@selected'/></xsl:attribute></xsl:if> |
| 158 |
<xsl:apply-templates mode='profile' select="node()"/> |
| 159 |
</xsl:copy> |
| 160 |
</xsl:template> |
| 161 |
|
| 162 |
|
| 163 |
<xsl:template mode='profile' match='cdf:check'> |
| 164 |
<xsl:variable name='name' select='name()'/> |
| 165 |
<xsl:variable name='rule' select='ancestor::cdf:Rule[1]'/> |
| 166 |
<xsl:variable name='rr' select='$theprofile/cdf:refine-rule[@idref=$rule/@id or @idref=$rule/@cluster-id][1]'/> |
| 167 |
<xsl:for-each select='self::*[@selector=$rr/@selector or ((not(@selector) or @selector="") and count($rule/*[name()=$name][@selector=$rr/@selector])=0)]'> |
| 168 |
<xsl:copy><xsl:apply-templates mode='profile' select="node()|@*"/></xsl:copy> |
| 169 |
</xsl:for-each> |
| 170 |
</xsl:template> |
| 171 |
|
| 172 |
|
| 173 |
<xsl:template mode='profile' match='cdf:profile-note'> |
| 174 |
<xsl:if test='not($clean-profile-notes) or (@tag = $theprofile/@note-tag)'> |
| 175 |
<xsl:copy><xsl:apply-templates mode='profile' select="node()|@*"/></xsl:copy> |
| 176 |
</xsl:if> |
| 177 |
</xsl:template> |
| 178 |
|
| 179 |
|
| 180 |
<xsl:template mode='profile' match='cdf:Value'> |
| 181 |
<xsl:variable name='id' select='@id'/> |
| 182 |
<xsl:variable name='cid' select='@cluster-id'/> |
| 183 |
<xsl:variable name='rv' select='$theprofile/cdf:refine-value[@idref=$id or @idref=$cid][1]'/> |
| 184 |
<xsl:variable name='sv' select='$theprofile/cdf:set-value[@idref=$id or @idref=$cid][1]'/> |
| 185 |
<xsl:copy> |
| 186 |
<xsl:apply-templates select='@*' mode='profile'/> |
| 187 |
<xsl:if test='$rv'><xsl:copy-of select='$rv/@operator'/></xsl:if> |
| 188 |
<xsl:apply-templates mode='profile' select="cdf:status|cdf:version|cdf:title|cdf:description|cdf:warning|cdf:question|cdf:reference"/> |
| 189 |
<xsl:choose> |
| 190 |
<xsl:when test='$sv'><cdf:value><xsl:value-of select='$sv'/></cdf:value></xsl:when> |
| 191 |
<xsl:otherwise><xsl:apply-templates mode='profile' select="cdf:value"/></xsl:otherwise> |
| 192 |
</xsl:choose> |
| 193 |
<xsl:apply-templates mode='profile' select="cdf:default|cdf:match|cdf:lower-bound|cdf:upper-bound|cdf:choices|cdf:source"/> |
| 194 |
</xsl:copy> |
| 195 |
</xsl:template> |
| 196 |
|
| 197 |
|
| 198 |
<xsl:template mode='profile' match='cdf:value|cdf:default|cdf:match|cdf:lower-bound|cdf:upper-bound|cdf:choices'> |
| 199 |
<xsl:variable name='val' select='ancestor::cdf:Value'/> |
| 200 |
<xsl:variable name='name' select='name()'/> |
| 201 |
<xsl:variable name='rv' select='$theprofile/cdf:refine-value[@idref=$val/@id or @idref=$val/@cluster-id][1]'/> |
| 202 |
<xsl:for-each select='self::*[@selector=$rv/@selector or ((not(@selector) or @selector="") and count($val/*[name()=$name][@selector=$rv/@selector])=0)]'> |
| 203 |
<xsl:copy><xsl:apply-templates mode='profile' select="node()|@*"/></xsl:copy> |
| 204 |
</xsl:for-each> |
| 205 |
</xsl:template> |
| 206 |
|
| 207 |
|
| 208 |
<xsl:template mode='profile' match='@selector[not(ancestor::cdf:Profile)]'/> |
| 209 |
|
| 210 |
|
| 211 |
<xsl:template match='/'> |
| 212 |
<xsl:apply-templates mode='apply-profile'/> |
| 213 |
</xsl:template> |
| 214 |
|
| 215 |
<xsl:template mode='apply-profile' match='cdf:Benchmark'> |
| 216 |
<xsl:call-template name='warn-unresolved'/> |
| 217 |
<xsl:apply-templates select='.' mode='profile'/> |
| 218 |
</xsl:template> |
| 219 |
|
| 220 |
|
| 221 |
<xsl:param name='profile'/> |
| 222 |
<xsl:param name='substitute' select='1'/> |
| 223 |
|
| 224 |
<xsl:variable name='warn-unresolved' select='1'/> |
| 225 |
|
| 226 |
|
| 227 |
<xsl:variable name='benchmark.s1'> |
| 228 |
<xsl:call-template name='warn-unresolved'/> |
| 229 |
<xsl:apply-templates select='/cdf:Benchmark' mode='profile'> |
| 230 |
<xsl:with-param name='p' select='/cdf:Benchmark/cdf:Profile[@id=$profile]'/> |
| 231 |
</xsl:apply-templates> |
| 232 |
</xsl:variable> |
| 233 |
|
| 234 |
<xsl:variable name='benchmark.s2'> |
| 235 |
<xsl:choose> |
| 236 |
<xsl:when test='$substitute'><xsl:apply-templates select='exsl:node-set($benchmark.s1)/cdf:Benchmark' mode='sub'/></xsl:when> |
| 237 |
<xsl:otherwise><xsl:copy-of select='$benchmark.s1'/></xsl:otherwise> |
| 238 |
</xsl:choose> |
| 239 |
</xsl:variable> |
| 240 |
|
| 241 |
<xsl:variable name='root' select='exsl:node-set($benchmark.s2)/cdf:Benchmark'/> |
| 242 |
|
| 243 |
<xsl:template name='warn-unresolved'> |
| 244 |
<xsl:if test='$warn-unresolved and cdf:Benchmark[not(@resolved=1)][not(@resolved="true")]'> |
| 245 |
<xsl:message>WARNING: Processing an unresolved XCCDF document. This may have unexpected results.</xsl:message> |
| 246 |
</xsl:if> |
| 247 |
</xsl:template> |
| 248 |
|
| 249 |
|
| 250 |
</xsl:stylesheet> |