使用 xslt 将子元素添加到 xml 中的列表不起作用



>我有源代码xml:

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

我想将一个元素附加到<targets>列表中。我正在尝试使用 xslt:

<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/targets">
<xsl:copy>
<xsl:copy-of select="@*" />
<target xsi:type="File" name="general"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

但是,我只是进行了身份转换,新元素没有添加到列表中。

元素targets属于t命名空间,因此查询应/t:nlog/t:targets

最新更新