XSL如何使用属性更改复制相同的+添加副本

Ale*_*lex 3 xslt templates copy mode

我需要复制一个节点及其子节点:

  • 第一个:一个相同的副本
  • 然后是修改后的副本,其中一些属性值已更改

以下是要更改的摘录:

<Configuration
    Name="Debug|Win32"
    OutputDirectory=".\Debug"
    IntermediateDirectory=".\Debug"
    ATLMinimizesCRunTimeLibraryUsage="FALSE"
    CharacterSet="2">
    <Tool
        Name="VCCLCompilerTool"
        Optimization="0"
        BasicRuntimeChecks="3"
        RuntimeLibrary="1"
        AssemblerListingLocation=".\Debug/"
        ObjectFile=".\Debug/"
        ProgramDataBaseFileName=".\Debug/"
        WarningLevel="4"
        SuppressStartupBanner="TRUE"
        DebugInformationFormat="4"
        CompileAs="0"/>
</Configuration>
Run Code Online (Sandbox Code Playgroud)

在第二个副本中,我需要将所有"Debug"更改为"Release"和一些属性值.

谢谢

Ale*_*lex 5

谢谢Koynov

然而我找到了使用模板模式的解决方案:

<xsl:template match="Configuration[@Name='Debug|Win32']">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    <xsl:copy>
        <xsl:attribute name="WholeProgramOptimization">TRUE</xsl:attribute>
        <xsl:apply-templates select="@*|node()" mode="Release"/>
    </xsl:copy>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

使用此模板的所有属性:

    <xsl:template match="@*" mode="Release">
    <xsl:attribute name="{local-name()}">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text"     select="."/>
            <xsl:with-param name="replace"  select="'Debug'"/>
            <xsl:with-param name="with"     select="'Release'"/>
        </xsl:call-template>
    </xsl:attribute>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

当然还有"替换字符串"模板.

再次感谢.