Search code examples
asp.netxmlvisual-studio-2012slowcheetah

SlowCheetah transforms wrong element in my xml


I have a web.config file, which I want to transform using SlowCheetah. The relevant fragment looks like this:

<configuration>
    <location path="ui/cms">
        <system.web>
            <authorization>
                <allow roles="AAA" />
            </authorization>
        </system.web>
    </location>
    <location path="WebServices">
        <system.web>
            <authorization>
                <allow roles="BBB" />
            </authorization>
        </system.web>
    </location>
</configuration>

I want to transform value BBB to CCC, so I wrote my Web.CCC.config transformation file:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <location path="WebServices">
        <system.web>
            <authorization>
                <allow roles="CCC" xdt:Transform="Replace" />
            </authorization>
        </system.web>
    </location>
</configuration>

Unfortunately, it results in CCC being inserted into <location path="ui/cms"> instead of <location path="WebServices"> - probably because it is the first one it locates in my web.config file.

How can I make SlowCheetah notice the different path parameter, and replace the correct node in my xml file?


Solution

  • As it turns out, this can be obtained using xdt:Locator in a transformation file.

    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
        <location path="WebServices" xdt:Locator="Match(path)>
            <system.web>
                <authorization>
                    <allow roles="CCC" xdt:Transform="Replace" />
                </authorization>
            </system.web>
        </location>
    </configuration>
    

    Hope it helps anyone. Rubber duck debugging seems to work even with SO.