<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="msxsl"
>
  <xsl:output method="xml" indent="yes"/>

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

  <xsl:variable name="primary-doc" select="/"/>

  <xsl:variable name="mainNodes" select="document('BaseType.xsd')//xs:schema/xs:complexType[@name='baseAdminType']/xs:all/xs:element[not(@name='Hidden')]/@name" />

  <xsl:template match="/Admin">
    <xsl:copy>

      <xsl:copy-of select="@*"/>

      <xsl:apply-templates/>

      <xsl:for-each select="$mainNodes">
        <xsl:variable name="temp" select="current()"/>
        <xsl:if test="not($primary-doc//Admin/*[local-name()=$temp])">
          <xsl:element name="{current()}"></xsl:element>
        </xsl:if>
      </xsl:for-each>

    </xsl:copy>

  </xsl:template>

</xsl:stylesheet>
