This conversion is :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="kLogicalChildren" match="nte"
use="generate-id(preceding-sibling::*
[self::pid or self::pv1]
[1])"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="pid|pv1">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select=
"key('kLogicalChildren', generate-id())"/>
</xsl:copy>
</xsl:template>
<xsl:template match="nte"/>
</xsl:stylesheet>
when applied to the provided XML document (corrected for correctness) :
<t>
<pid></pid>
<nte>
<nte-1>1</nte-1>
<nte-3>Note 1</nte-3>
</nte>
<nte></nte>
<pv1></pv1>
<nte></nte>
</t>
creates the desired, correct result :
<t>
<pid>
<nte>
<nte-1>1</nte-1>
<nte-3>Note 1</nte-3>
</nte>
<nte/>
</pid>
<pv1>
<nte/>
</pv1>
</t>
source
share