基本的な XSLT に苦労しています。特定の属性があるかどうかに応じて、XML から要素を削除したいと考えています。
XML は次のようになります。
<root>
<Request URL="www.google.com">
<id name="google"/>
</Request>
<Request URL="www.yahoo.com">
<id name="yahoo"/>
</Request>
</root>
URL が「www.google.com」の場合は Request 要素を削除し、要素と も削除したいので、次のようになります。
<root>
<Request URL="www.yahoo.com">
<id name="yahoo"/>
</Request>
</root>
私はこれまでのところ以下を持っていますが、うまくいきません:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--identity template copies everything forward by default-->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!--empty template suppresses this attribute-->
<xsl:template match="Request[@Url='www.google.com']"/>
</xsl:stylesheet>