﻿<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sm="http://schemas.microsoft.com/sdm/Windows/ServerManager/Configuration/2007/1"
version="1.0">
  <!-- Transform to xml that can be used to install all roles, role services, and features that were discovered as installed in the output query. -->
  <xsl:output indent="no" />
  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="sm:ServerManagerConfigurationQuery">
    <xsl:element name="ServerManagerConfiguration" namespace="http://schemas.microsoft.com/sdm/Windows/ServerManager/Configuration/2007/1">
      <xsl:attribute name="Action">Install</xsl:attribute>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>
  <xsl:template match="sm:Role">
    <xsl:if test="@Id and @Installed='true' and count(sm:RoleService) = 0">
      <xsl:element name="Role" namespace="http://schemas.microsoft.com/sdm/Windows/ServerManager/Configuration/2007/1">
        <xsl:attribute name="Id">
          <xsl:value-of select="@Id"/>
        </xsl:attribute>
      </xsl:element>
    </xsl:if>
    <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="sm:RoleService">
    <xsl:if test="@Id and @Installed='true' and count(sm:RoleService) = 0">
      <xsl:element name="RoleService" namespace="http://schemas.microsoft.com/sdm/Windows/ServerManager/Configuration/2007/1">
        <xsl:attribute name="Id">
          <xsl:value-of select="@Id"/>
        </xsl:attribute>
      </xsl:element>
    </xsl:if>
    <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="sm:Feature">
    <xsl:if test="@Id and @Installed='true' and count(sm:Feature) = 0">
      <xsl:element name="Feature" namespace="http://schemas.microsoft.com/sdm/Windows/ServerManager/Configuration/2007/1">
        <xsl:attribute name="Id">
          <xsl:value-of select="@Id"/>
        </xsl:attribute>
      </xsl:element>
    </xsl:if>
    <xsl:apply-templates/>
  </xsl:template>
</xsl:stylesheet>
