Blame xsl/xccdf_1.1_to_1.2.xsl

Packit 517ee8
Packit 517ee8
Packit 517ee8
Packit 517ee8
Copyright 2012 Red Hat Inc., Durham, North Carolina.
Packit 517ee8
All Rights Reserved.
Packit 517ee8
Packit 517ee8
This library is free software; you can redistribute it and/or
Packit 517ee8
modify it under the terms of the GNU Lesser General Public
Packit 517ee8
License as published by the Free Software Foundation; either
Packit 517ee8
version 2.1 of the License, or (at your option) any later version.
Packit 517ee8
 
Packit 517ee8
This library is distributed in the hope that it will be useful,
Packit 517ee8
but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 517ee8
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 517ee8
Lesser General Public License for more details.
Packit 517ee8
 
Packit 517ee8
You should have received a copy of the GNU Lesser General Public
Packit 517ee8
License along with this library; if not, write to the Free Software
Packit 517ee8
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Packit 517ee8
 
Packit 517ee8
Authors:
Packit 517ee8
      Martin Preisler <mpreisle@redhat.com>
Packit 517ee8
-->
Packit 517ee8
Packit 517ee8
Packit 517ee8
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
Packit 517ee8
  xmlns:xccdf_11="http://checklists.nist.gov/xccdf/1.1"
Packit 517ee8
  xmlns:xccdf_12="http://checklists.nist.gov/xccdf/1.2"
Packit 517ee8
Packit 517ee8
  version="1.0">
Packit 517ee8
 
Packit 517ee8
  <xsl:output method="xml" indent="yes"/>
Packit 517ee8
Packit 517ee8
  <xsl:param name="reverse_DNS"/>
Packit 517ee8
Packit 517ee8
  <xsl:key name="profiles" match="/xccdf_11:Benchmark/xccdf_11:Profile" use="@id"/>
Packit 517ee8
  <xsl:key name="rules" match="/xccdf_11:Benchmark//xccdf_11:Rule" use="@id"/>
Packit 517ee8
  <xsl:key name="groups" match="/xccdf_11:Benchmark//xccdf_11:Group" use="@id"/>
Packit 517ee8
  <xsl:key name="values" match="/xccdf_11:Benchmark//xccdf_11:Value" use="@id"/>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
       verbatim, every template that is more specifically matched that this
Packit 517ee8
       will take precedence -->  
Packit 517ee8
  <xsl:template match="@*|node()">
Packit 517ee8
    <xsl:copy>
Packit 517ee8
      <xsl:apply-templates select="@*|node()"/>
Packit 517ee8
    </xsl:copy>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="xccdf_11:*"> 
Packit 517ee8
    <xsl:choose>
Packit 517ee8
      
Packit 517ee8
      <xsl:when test="local-name()='platform-definitions' or local-name()='Platform-Specification' or local-name()='cpe-list' or local-name()='impact-metric'">
Packit 517ee8
        
Packit 517ee8
             XSLT itself ignores all nodes inside <xsl:comment> except TEXT
Packit 517ee8
             nodes, so we can't use that. -->
Packit 517ee8
        <xsl:text disable-output-escaping="yes"><--</xsl:text>
Packit 517ee8
        This element has been deprecated and was removed from XCCDF 1.2!
Packit 517ee8
Packit 517ee8
        <xsl:element name="{local-name()}">
Packit 517ee8
          <xsl:apply-templates select="@*"/>
Packit 517ee8
          <xsl:apply-templates/>
Packit 517ee8
        </xsl:element>
Packit 517ee8
        <xsl:text disable-output-escaping="yes">--></xsl:text>
Packit 517ee8
      </xsl:when>
Packit 517ee8
      <xsl:otherwise>
Packit 517ee8
        <xsl:element name="{local-name()}" namespace="http://checklists.nist.gov/xccdf/1.2">
Packit 517ee8
          
Packit 517ee8
               now we want to apply templates to all attributes of it and all subelements -->
Packit 517ee8
          <xsl:apply-templates select="@*"/>
Packit 517ee8
          <xsl:apply-templates/>
Packit 517ee8
        </xsl:element>
Packit 517ee8
      </xsl:otherwise>
Packit 517ee8
    </xsl:choose>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@id[parent::xccdf_11:Benchmark]"> 
Packit 517ee8
    <xsl:variable name="old_id" select="."/>
Packit 517ee8
Packit 517ee8
    <xsl:attribute name="id">
Packit 517ee8
      <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_benchmark_', $old_id)"/>
Packit 517ee8
    </xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@id[parent::xccdf_11:Profile]">
Packit 517ee8
    <xsl:variable name="old_id" select="."/>
Packit 517ee8
Packit 517ee8
    <xsl:attribute name="id">
Packit 517ee8
      <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_profile_', $old_id)"/>
Packit 517ee8
    </xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@id[parent::xccdf_11:Rule]">
Packit 517ee8
    <xsl:variable name="old_id" select="."/>
Packit 517ee8
Packit 517ee8
    <xsl:attribute name="id">
Packit 517ee8
      <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_rule_', $old_id)"/>
Packit 517ee8
    </xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@id[parent::xccdf_11:Group]">
Packit 517ee8
    <xsl:variable name="old_id" select="."/>
Packit 517ee8
Packit 517ee8
    <xsl:attribute name="id">
Packit 517ee8
      <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_group_', $old_id)"/>
Packit 517ee8
    </xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@id[parent::xccdf_11:Value]">
Packit 517ee8
    <xsl:variable name="old_id" select="."/>
Packit 517ee8
Packit 517ee8
    <xsl:attribute name="id">
Packit 517ee8
      <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_value_', $old_id)"/>
Packit 517ee8
    </xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@id[parent::xccdf_11:TestResult]">
Packit 517ee8
    <xsl:variable name="old_id" select="."/>
Packit 517ee8
Packit 517ee8
    <xsl:attribute name="id">
Packit 517ee8
      <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_testresult_', $old_id)"/>
Packit 517ee8
    </xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@style[parent::xccdf_11:Benchmark][.='SCAP_1.1']">
Packit 517ee8
    <xsl:attribute name="style">SCAP_1.2</xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@idref[parent::xccdf_11:*][not(parent::xccdf_11:platform)][not(parent::xccdf_11:requires)]">
Packit 517ee8
    <xsl:variable name="old_idref" select="."/>
Packit 517ee8
Packit 517ee8
    <xsl:attribute name="idref">
Packit 517ee8
      
Packit 517ee8
           change its format accordingly -->
Packit 517ee8
Packit 517ee8
      <xsl:choose>
Packit 517ee8
        <xsl:when test="key('profiles', $old_idref)">
Packit 517ee8
          <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_profile_', $old_idref)"/>
Packit 517ee8
        </xsl:when>
Packit 517ee8
Packit 517ee8
        <xsl:when test="key('rules', $old_idref)">
Packit 517ee8
          <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_rule_', $old_idref)"/>
Packit 517ee8
        </xsl:when>
Packit 517ee8
Packit 517ee8
        <xsl:when test="key('groups', $old_idref)">
Packit 517ee8
          <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_group_', $old_idref)"/>
Packit 517ee8
        </xsl:when>
Packit 517ee8
Packit 517ee8
        <xsl:when test="key('values', $old_idref)">
Packit 517ee8
          <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_value_', $old_idref)"/>
Packit 517ee8
        </xsl:when>
Packit 517ee8
        
Packit 517ee8
        <xsl:otherwise>
Packit 517ee8
          <xsl:value-of select="concat('dangling reference to ', $old_idref, '!')"/>
Packit 517ee8
        </xsl:otherwise>
Packit 517ee8
      </xsl:choose>
Packit 517ee8
    </xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
 
Packit 517ee8
  <xsl:template name="migrate-requires">
Packit 517ee8
    
Packit 517ee8
         It needs to have ' ' appended for this template to work! -->
Packit 517ee8
Packit 517ee8
    <xsl:param name="string"/>
Packit 517ee8
    <xsl:choose>
Packit 517ee8
      
Packit 517ee8
      <xsl:when test="$string=''">
Packit 517ee8
        
Packit 517ee8
      </xsl:when>
Packit 517ee8
      <xsl:otherwise>
Packit 517ee8
        <xsl:choose>
Packit 517ee8
          <xsl:when test="key('groups', substring-before($string, ' '))">
Packit 517ee8
           <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_group_', substring-before($string, ' '))"/>
Packit 517ee8
          </xsl:when>
Packit 517ee8
          <xsl:when test="key('rules', substring-before($string, ' '))">
Packit 517ee8
            <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_rule_', substring-before($string, ' '))"/>
Packit 517ee8
          </xsl:when>
Packit 517ee8
          <xsl:otherwise>
Packit 517ee8
            <xsl:value-of select="concat('dangling reference to ', substring-before($string, ' '), '!')"/>
Packit 517ee8
          </xsl:otherwise>
Packit 517ee8
        </xsl:choose>
Packit 517ee8
        
Packit 517ee8
        
Packit 517ee8
        <xsl:variable name="tail" select="substring-after($string, ' ')"/>
Packit 517ee8
        <xsl:if test="$tail!=''">
Packit 517ee8
          <xsl:text> </xsl:text>
Packit 517ee8
          <xsl:call-template name="migrate-requires">
Packit 517ee8
            <xsl:with-param name="string" select="$tail"/>
Packit 517ee8
          </xsl:call-template>
Packit 517ee8
        </xsl:if>
Packit 517ee8
      </xsl:otherwise>
Packit 517ee8
    </xsl:choose>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  <xsl:template match="@idref[parent::xccdf_11:requires]">
Packit 517ee8
    
Packit 517ee8
    <xsl:variable name="old_idref" select="."/>
Packit 517ee8
    <xsl:attribute name="idref"><xsl:call-template name="migrate-requires"><xsl:with-param name="string" select="concat($old_idref, ' ')"/></xsl:call-template></xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@value-id[parent::xccdf_11:*]">
Packit 517ee8
    <xsl:variable name="old_value_id" select="."/>
Packit 517ee8
Packit 517ee8
    <xsl:attribute name="value-id">
Packit 517ee8
      
Packit 517ee8
           change its format accordingly -->
Packit 517ee8
Packit 517ee8
      <xsl:choose>
Packit 517ee8
        <xsl:when test="key('values', $old_value_id)">
Packit 517ee8
          <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_value_', $old_value_id)"/>
Packit 517ee8
        </xsl:when>
Packit 517ee8
Packit 517ee8
        <xsl:otherwise>
Packit 517ee8
          <xsl:value-of select="concat('dangling reference to ', $old_value_id, '!')"/>
Packit 517ee8
        </xsl:otherwise>
Packit 517ee8
      </xsl:choose>
Packit 517ee8
    </xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@extends[parent::xccdf_11:Group]">
Packit 517ee8
    <xsl:variable name="old_extends" select="."/>
Packit 517ee8
Packit 517ee8
    <xsl:attribute name="extends">
Packit 517ee8
      <xsl:choose>
Packit 517ee8
       <xsl:when test="key('groups', $old_extends)">
Packit 517ee8
          <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_group_', $old_extends)"/>
Packit 517ee8
        </xsl:when>
Packit 517ee8
        <xsl:otherwise>
Packit 517ee8
          <xsl:value-of select="concat('dangling reference to ', $old_extends, '!')"/>
Packit 517ee8
        </xsl:otherwise>
Packit 517ee8
      </xsl:choose>
Packit 517ee8
    </xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@extends[parent::xccdf_11:Rule]">
Packit 517ee8
    <xsl:variable name="old_extends" select="."/>
Packit 517ee8
Packit 517ee8
    <xsl:attribute name="extends">
Packit 517ee8
      <xsl:choose>
Packit 517ee8
       <xsl:when test="key('rules', $old_extends)">
Packit 517ee8
          <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_rule_', $old_extends)"/>
Packit 517ee8
        </xsl:when>
Packit 517ee8
        <xsl:otherwise>
Packit 517ee8
          <xsl:value-of select="concat('dangling reference to ', $old_extends, '!')"/>
Packit 517ee8
        </xsl:otherwise>
Packit 517ee8
      </xsl:choose>
Packit 517ee8
    </xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@extends[parent::xccdf_11:Value]">
Packit 517ee8
    <xsl:variable name="old_extends" select="."/>
Packit 517ee8
Packit 517ee8
    <xsl:attribute name="extends">
Packit 517ee8
      <xsl:choose>
Packit 517ee8
       <xsl:when test="key('values', $old_extends)">
Packit 517ee8
          <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_value_', $old_extends)"/>
Packit 517ee8
        </xsl:when>
Packit 517ee8
        <xsl:otherwise>
Packit 517ee8
          <xsl:value-of select="concat('dangling reference to ', $old_extends, '!')"/>
Packit 517ee8
        </xsl:otherwise>
Packit 517ee8
      </xsl:choose>
Packit 517ee8
    </xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="@extends[parent::xccdf_11:Profile]">
Packit 517ee8
    <xsl:variable name="old_extends" select="."/>
Packit 517ee8
Packit 517ee8
    <xsl:attribute name="extends">
Packit 517ee8
      <xsl:choose>
Packit 517ee8
       <xsl:when test="key('profiles', $old_extends)">
Packit 517ee8
          <xsl:value-of select="concat('xccdf_', $reverse_DNS, '_profile_', $old_extends)"/>
Packit 517ee8
        </xsl:when>
Packit 517ee8
        <xsl:otherwise>
Packit 517ee8
          <xsl:value-of select="concat('dangling reference to ', $old_extends, '!')"/>
Packit 517ee8
        </xsl:otherwise>
Packit 517ee8
      </xsl:choose>
Packit 517ee8
    </xsl:attribute>
Packit 517ee8
  </xsl:template>
Packit 517ee8
Packit 517ee8
  
Packit 517ee8
  <xsl:template match="xccdf_11:sub">
Packit 517ee8
    <xsl:element name="{local-name()}" namespace="http://checklists.nist.gov/xccdf/1.2">
Packit 517ee8
      <xsl:apply-templates select="@*"/>
Packit 517ee8
      <xsl:apply-templates/>
Packit 517ee8
      <xsl:attribute name="use">legacy</xsl:attribute>
Packit 517ee8
    </xsl:element>
Packit 517ee8
  </xsl:template>
Packit 517ee8
</xsl:stylesheet>
Packit 517ee8