0

基本的な 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>
4

2 に答える 2

1

ヒント: xml では大文字と小文字が区別されます。入力 xml では、Request 要素に属性 URL があります。しかし、xslt には @Url があります。では、これを作ってみてください

<xsl:template match="Request[@URL='www.google.com'] "/>
于 2013-09-04T16:55:18.167 に答える