Reputation: 5389
I have an xml like
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Error"
internalLogFile="internal-nlog.txt">
<targets async="true">
<target xsi:type="Null" name="blackhole" />
</targets>
<rules>
<logger name="*" minlevel="Error" writeTo="exceptions"/>
<logger name="Microsoft.AspNetCore.*" minlevel="Trace" writeTo="blackhole" final="true"/>
</rules>
</nlog>
I have defined a xslt like
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:t="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/t:nlog/t:targets">
<xsl:copy>
<xsl:copy-of select="@*|node()" />
<target xsi:type="Bugsnag" name="bugsnag" apikey="xxx" AppType="${{app}}" ReleaseStage="Development" />
</xsl:copy>
</xsl:template>
<xsl:template match="/t:nlog/t:rules">
<xsl:copy>
<logger name="*" minlevel="Error" writeTo="bugsnag" />
<xsl:copy-of select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
This does the transformation almost the way I need, except that it adds xlmns
and xlmns:t
attributes to the output like
<?xml version="1.0" encoding="utf-8"?><nlog autoReload="true" internalLogLevel="Error" internalLogFile="internal-nlog.txt" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets async="true">
<target xsi:type="Null" name="blackhole" />
<target xsi:type="Bugsnag" name="bugsnag" apikey="xxx" AppType="${app}" ReleaseStage="Development" xmlns="" xmlns:t="http://www.nlog-project.org/schemas/NLog.xsd" /></targets>
<rules>
<logger name="*" minlevel="Error" writeTo="bugsnag" xmlns="" xmlns:t="http://www.nlog-project.org/schemas/NLog.xsd" />
<logger name="*" minlevel="Error" writeTo="exceptions" />
<logger name="Microsoft.AspNetCore.*" minlevel="Trace" writeTo="blackhole" final="true" />
</rules>
</nlog>
How can I prevent xslt from automatically adding that namespace to the element?
Upvotes: 0
Views: 33
Reputation: 167591
Use
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:t="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="t">
Upvotes: 1