To
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()">
<xsl:sort select="EEE/@type" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
you just need to add a template
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()">
<xsl:sort select="EEE/@type" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="DD[not(EEE/@type = 'foo')]"/>
that ensures those DD
elements with EEE/@type
not equal 'foo'
are not copied.