これは、ID変換の上に構築することで実現できます。まず、 @refが「no」のサブジェクト要素を無視するためのテンプレートが必要になります
<xsl:template match="subject[@ref='no']" />
また、@ refが「yes」のサブジェクト要素の場合、その子だけを出力する別のテンプレートがあります
<xsl:template match="subject[@ref='yes']">
<xsl:apply-templates select="node()"/>
</xsl:template>
実際、@refが「yes」または「no」にしかできない場合は、このテンプレートの一致を単純化し<xsl:template match="subject">
て、「no」の@refを持たないすべての要素に一致させることができます。
これが完全なXSLTです
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="subject[@ref='no']" />
<xsl:template match="subject">
<xsl:apply-templates select="node()"/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
サンプルXMLに適用すると、次のように出力されます。
<testing>
<firstname> tom </firstname>
</testing>