Xml XSLT基于属性删除元素
我正在努力学习一些基本的XSLT。我想从一些XML中删除一个元素,这取决于它是否具有特定属性 XML看起来是这样的:Xml XSLT基于属性删除元素,xml,xslt,Xml,Xslt,我正在努力学习一些基本的XSLT。我想从一些XML中删除一个元素,这取决于它是否具有特定属性 XML看起来是这样的: <root> <Request URL="www.google.com"> <id name="google"/> </Request> <Request URL="www.yahoo.com"> <id name="yahoo"/> </
<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>
您的XML源具有属性名“URL”,但您正在尝试匹配“URL”。提示:XML区分大小写。在输入xml中,请求元素中有属性URL。但是在xslt中有@Url。所以试着做这个
<xsl:template match="Request[@URL='www.google.com'] "/>