我有一个xml文档:
<xml>
<duplication>
<file path="C:\Hello\Test.Designer.cs" />
<file path="C:\Hello\Demo.Designer.cs" />
</duplication>
<duplication>
<file path="C:\Hello\Test.cs" />
<file path="C:\Hello\Demo.cs" />
</duplication>
</xml>因此,如果复制节点在文件子文件中包含.Designer.cs文件,那么我希望它删除整个节点。因此,产出应该是:
<xml>
<duplication>
<file path="C:\Hello\Test.Designer.cs" />
<file path="C:\Hello\Demo.Designer.cs" />
</duplication>
</xml>最好的方法是什么?我会在Azure的建设管道上运行。所以我不想要沉重的代码。
发布于 2020-10-20 15:56:23
请尝试以下XSLT。
XSLT2.0
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="duplication[file[not(ends-with(@path, '.Designer.cs'))]]">
</xsl:template>
</xsl:stylesheet>XSLT1.0
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="duplication[file[not(contains(@path, '.Designer.cs'))]]">
</xsl:template>
</xsl:stylesheet>https://stackoverflow.com/questions/64448082
复制相似问题