4

インポートが存在しない場合、XSLT は現在インポートを挿入します。

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    ...
    ...
    <Import Project="$(SolutionDir)BuildShared.targets" />
</Project>

最初のノードとして挿入する必要があります

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(SolutionDir)BuildShared.targets" />
    ...
    ...
</Project>

template.xsl;

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="http://schemas.microsoft.com/developer/msbuild/2003">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match='@*|node()'>
        <xsl:copy>
            <xsl:apply-templates select='@*|node()'/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="/ms:Project[not(ms:Import[@Project='$(SolutionDir)BuildConfiguration.targets'])]">
        <xsl:copy>          
            <xsl:apply-templates select="node()|@*"/>
            <Import xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Project="$(SolutionDir)BuildConfiguration.targets"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

import と apply-templates 行を交換すると、次のようになります。

runtime error: file template.xsl line 9 element copy

Attribute nodes must be added before any child nodes to an element.

4

1 に答える 1

5

ただあなたxsl:apply-templatesのためにnode()そして@*別々に:

<xsl:template match="/ms:Project[not(ms:Import[@Project='$(SolutionDir)BuildConfiguration.targets'])]">
    <xsl:copy>          
        <xsl:apply-templates select="@*"/>
        <Import xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Project="$(SolutionDir)BuildConfiguration.targets"/>
        <xsl:apply-templates select="node()"/>
    </xsl:copy>
</xsl:template>
于 2012-06-07T06:22:34.817 に答える