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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2012 Red Hat Inc., Durham, North Carolina.
All Rights Reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Authors:
Martin Preisler <mpreisle@redhat.com>
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xccdf_11="http://checklists.nist.gov/xccdf/1.1"
xmlns:xccdf_12="http://checklists.nist.gov/xccdf/1.2"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="reverse_DNS"/>
<xsl:key name="profiles" match="/xccdf_11:Benchmark/xccdf_11:Profile" use="@id"/>
<xsl:key name="rules" match="/xccdf_11:Benchmark//xccdf_11:Rule" use="@id"/>
<xsl:key name="groups" match="/xccdf_11:Benchmark//xccdf_11:Group" use="@id"/>
<xsl:key name="values" match="/xccdf_11:Benchmark//xccdf_11:Value" use="@id"/>
<!-- This is the generic matched template that by default copies everything
verbatim, every template that is more specifically matched that this
will take precedence -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Deals with namespace change (xccdf 1.1 -> xccdf 1.2) -->
<xsl:template match="xccdf_11:*"> <!-- select just elements from xccdf 1.1 -->
<xsl:choose>
<!-- Remove deprecated elements -->
<xsl:when test="local-name()='platform-definitions' or local-name()='Platform-Specification' or local-name()='cpe-list' or local-name()='impact-metric'">
<!-- We will do a trick here to "comment" the deprecated elements,
XSLT itself ignores all nodes inside <xsl:comment> except TEXT
nodes, so we can't use that. -->
<xsl:text disable-output-escaping="yes"><--</xsl:text>
This element has been deprecated and was removed from XCCDF 1.2!
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:element>
<xsl:text disable-output-escaping="yes">--></xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{local-name()}" namespace="http://checklists.nist.gov/xccdf/1.2">
<!-- We have basically added an element with the same local name but xccdf 1.2 namespace,
now we want to apply templates to all attributes of it and all subelements -->
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Deals with the new enforced id format of Benchmark -->
<xsl:template match="@id[parent::xccdf_11:Benchmark]">
<xsl:variable name="old_id" select="."/>
<xsl:attribute name="id">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_benchmark_', $old_id)"/>
</xsl:attribute>
</xsl:template>
<!-- Deals with the new enforced id format of Rule -->
<xsl:template match="@id[parent::xccdf_11:Profile]">
<xsl:variable name="old_id" select="."/>
<xsl:attribute name="id">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_profile_', $old_id)"/>
</xsl:attribute>
</xsl:template>
<!-- Deals with the new enforced id format of Rule -->
<xsl:template match="@id[parent::xccdf_11:Rule]">
<xsl:variable name="old_id" select="."/>
<xsl:attribute name="id">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_rule_', $old_id)"/>
</xsl:attribute>
</xsl:template>
<!-- Deals with the new enforced id format of Group -->
<xsl:template match="@id[parent::xccdf_11:Group]">
<xsl:variable name="old_id" select="."/>
<xsl:attribute name="id">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_group_', $old_id)"/>
</xsl:attribute>
</xsl:template>
<!-- Deals with the new enforced id format of Value -->
<xsl:template match="@id[parent::xccdf_11:Value]">
<xsl:variable name="old_id" select="."/>
<xsl:attribute name="id">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_value_', $old_id)"/>
</xsl:attribute>
</xsl:template>
<!-- Deals with the new enforced id format of TestResult -->
<xsl:template match="@id[parent::xccdf_11:TestResult]">
<xsl:variable name="old_id" select="."/>
<xsl:attribute name="id">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_testresult_', $old_id)"/>
</xsl:attribute>
</xsl:template>
<!-- Change style from SCAP_1.1 to SCAP_1.2 -->
<xsl:template match="@style[parent::xccdf_11:Benchmark][.='SCAP_1.1']">
<xsl:attribute name="style">SCAP_1.2</xsl:attribute>
</xsl:template>
<!-- idrefs -->
<!-- we want to migrate all @idrefs except platform's, we don't migrate requires/@idref here, it's handled elsewhere -->
<xsl:template match="@idref[parent::xccdf_11:*][not(parent::xccdf_11:platform)][not(parent::xccdf_11:requires)]">
<xsl:variable name="old_idref" select="."/>
<xsl:attribute name="idref">
<!-- Our goal here is to figure out which item the idref references and
change its format accordingly -->
<xsl:choose>
<xsl:when test="key('profiles', $old_idref)">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_profile_', $old_idref)"/>
</xsl:when>
<xsl:when test="key('rules', $old_idref)">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_rule_', $old_idref)"/>
</xsl:when>
<xsl:when test="key('groups', $old_idref)">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_group_', $old_idref)"/>
</xsl:when>
<xsl:when test="key('values', $old_idref)">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_value_', $old_idref)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('dangling reference to ', $old_idref, '!')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
<xsl:template name="migrate-requires">
<!-- The string parameter represents text content of the requires attribute
It needs to have ' ' appended for this template to work! -->
<xsl:param name="string"/>
<xsl:choose>
<!-- requires contain space delimited references, we will strip them one by one -->
<xsl:when test="$string=''">
<!-- we are done -->
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="key('groups', substring-before($string, ' '))">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_group_', substring-before($string, ' '))"/>
</xsl:when>
<xsl:when test="key('rules', substring-before($string, ' '))">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_rule_', substring-before($string, ' '))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('dangling reference to ', substring-before($string, ' '), '!')"/>
</xsl:otherwise>
</xsl:choose>
<!-- we test whether the tail is empty to avoid inserting one extra space -->
<xsl:variable name="tail" select="substring-after($string, ' ')"/>
<xsl:if test="$tail!=''">
<xsl:text> </xsl:text>
<xsl:call-template name="migrate-requires">
<xsl:with-param name="string" select="$tail"/>
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="@idref[parent::xccdf_11:requires]">
<!-- We intentionally concat @idref and a space, this is required for the called template to work properly -->
<xsl:variable name="old_idref" select="."/>
<xsl:attribute name="idref"><xsl:call-template name="migrate-requires"><xsl:with-param name="string" select="concat($old_idref, ' ')"/></xsl:call-template></xsl:attribute>
</xsl:template>
<!-- value-ids -->
<xsl:template match="@value-id[parent::xccdf_11:*]">
<xsl:variable name="old_value_id" select="."/>
<xsl:attribute name="value-id">
<!-- Our goal here is to figure out which item the value-id references and
change its format accordingly -->
<xsl:choose>
<xsl:when test="key('values', $old_value_id)">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_value_', $old_value_id)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('dangling reference to ', $old_value_id, '!')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
<!-- Group/@extends -->
<!-- If present, update extends attribute -->
<xsl:template match="@extends[parent::xccdf_11:Group]">
<xsl:variable name="old_extends" select="."/>
<xsl:attribute name="extends">
<xsl:choose>
<xsl:when test="key('groups', $old_extends)">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_group_', $old_extends)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('dangling reference to ', $old_extends, '!')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
<!-- Rule/@extends -->
<!-- If present, update extends attribute -->
<xsl:template match="@extends[parent::xccdf_11:Rule]">
<xsl:variable name="old_extends" select="."/>
<xsl:attribute name="extends">
<xsl:choose>
<xsl:when test="key('rules', $old_extends)">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_rule_', $old_extends)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('dangling reference to ', $old_extends, '!')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
<!-- Value/@extends -->
<!-- If present, update extends attribute -->
<xsl:template match="@extends[parent::xccdf_11:Value]">
<xsl:variable name="old_extends" select="."/>
<xsl:attribute name="extends">
<xsl:choose>
<xsl:when test="key('values', $old_extends)">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_value_', $old_extends)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('dangling reference to ', $old_extends, '!')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
<!-- Profile/@extends -->
<!-- If present, update extends attribute -->
<xsl:template match="@extends[parent::xccdf_11:Profile]">
<xsl:variable name="old_extends" select="."/>
<xsl:attribute name="extends">
<xsl:choose>
<xsl:when test="key('profiles', $old_extends)">
<xsl:value-of select="concat('xccdf_', $reverse_DNS, '_profile_', $old_extends)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('dangling reference to ', $old_extends, '!')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
<!-- add the @legacy attribute to <sub> elements -->
<xsl:template match="xccdf_11:sub">
<xsl:element name="{local-name()}" namespace="http://checklists.nist.gov/xccdf/1.2">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
<xsl:attribute name="use">legacy</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
|