この XSLT 1.0 変換:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xmi="http://www.omg.org/spec/XMI/20110701">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xmi:XMI[not(*[2])]">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="xmi:XMI[not(*[2])]/*">
<xsl:copy>
<xsl:apply-templates select="node()|@* | ../@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
次の XML ドキュメントに適用した場合:
<xmi:XMI attribute="2"
xmlns:xmi="http://www.omg.org/spec/XMI/20110701"
xmlns:a="A" >
<namespace:node attribute2="att" xmlns:namespace="some:namespace">
...
</namespace:node>
<otherNode/>
</xmi:XMI>
必要な正しい結果が生成されます(変更なし):
<xmi:XMI xmlns:xmi="http://www.omg.org/spec/XMI/20110701" xmlns:a="A" attribute="2">
<namespace:node xmlns:namespace="some:namespace" attribute2="att">
...
</namespace:node>
<otherNode/>
</xmi:XMI>
この XML ドキュメントに適用すると:
<xmi:XMI attribute="2"
xmlns:xmi="http://www.omg.org/spec/XMI/20110701"
xmlns:a="A" >
<namespace:node attribute2="att" xmlns:namespace="some:namespace">
...
</namespace:node>
</xmi:XMI>
ここでも、必要な正しい結果が生成されます(xmi:XMI
要素が「削除」され、その属性がその唯一の子にコピーされます)。
<namespace:node xmlns:namespace="some:namespace"
xmlns:xmi="http://www.omg.org/spec/XMI/20110701" xmlns:a="A"
attribute="2" attribute2="att">
...
</namespace:node>