ソースXML:
<MP>
<Name>pol</Name>
<PRules>
<PRule order="1" name="r1">
<Conditions>
<Condition eleName="eth" value="05">05</Condition>
<Condition eleName="dest" value="32">32</Condition>
</Conditions>
</PRule>
<PRule order="2" name="r2">
<Conditions>
<Condition eleName="eth" value="04">04</Condition>
</Conditions>
<Actions>
<Action name="xyz"/>
</Actions>
</PRule>
</PRules>
</MP>
属性eleName="eth"の条件ノードを削除する必要がある場合。条件が空の場合に条件ノードを削除した後、完全なPRuleノードも削除する必要があります。
次のXSLTを適用しました。
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template name="attributeTemplate" match="Condition[@elementName='eth']"/>
<xsl:template match="PRule[descendant::Conditions[not(@*)]]"/>
</xsl:stylesheet>
しかし、結果は次のようになります。
<MP>
<Name>pol</Name>
</PRules>
</MP>
XMLを次のように変換するために必要な変更
<MP>
<Name>pol</Name>
<PRules>
<PRule name="r1" order="1">
<Conditions>
<Condition eleName="dest" value="32">32</Condition>
</Conditions>
</PRule>
</PRules>
</MP>
xslファイルで何がうまくいかなかったのかわかりません。基本的に、Conditionsが空の場合は、親PRuleノードを削除したかったのです。