0

I have an xml document:

<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>

So if duplication node contains .Designer.cs file in file child then i want it to remove the entire node. So the output should be:

<xml>
<duplication>
<file path="C:\Hello\Test.Designer.cs" />
<file path="C:\Hello\Demo.Designer.cs" />
</duplication>
</xml>

What would be best way to do it? I would be running that on build pipeline in Azure. So i do not want heavy piece of code.

2
  • How about XSLT approach? Commented Oct 20, 2020 at 15:35
  • that would work Commented Oct 20, 2020 at 15:44

1 Answer 1

1

Please try the following XSLT.

XSLT 2.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>

XSLT 1.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>
Sign up to request clarification or add additional context in comments.

10 Comments

how do i run this? and what if i wanted to add more parameters?
Azure Logic App., it has Maps functionality.
i get an error, XSLT compile error, the files i am accessing is xml verison 1. if i change to version 1.0, it says ends-with() is unknown function
Azure Logic App. maps support XSLT 1.0, 2.0, and 3.0. When you create a new map, it allows to select version of XSLT
i am trying to run through console app in C#
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.