Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用XSL合并XML文件会删除匹配的元素_Xml_Xslt - Fatal编程技术网

使用XSL合并XML文件会删除匹配的元素

使用XSL合并XML文件会删除匹配的元素,xml,xslt,Xml,Xslt,我一直在使用XSL合并XML文件,但遇到了一个问题 我希望将新xml插入的元素被删除,并且引入了一个新的不需要的元素 以下是我正在使用的XSL: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:sch

我一直在使用XSL合并XML文件,但遇到了一个问题

我希望将新xml插入
的元素被删除,并且引入了一个新的不需要的元素

以下是我正在使用的XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                        xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
                        extension-element-prefixes="msxsl" >

<xsl:output method="xml" indent="yes" />

    <xsl:template match="@*|node()">

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

    </xsl:template>

    <xsl:template match="Shapes">
        <xsl:for-each select="document('..\TempReportData\TextXML_Output.xml')/Job/Benchtops/Benchtop">
            <xsl:copy>
                <xsl:apply-templates select="document('..\DesignMaster\EmptyShapeElement.xml')" />
            </xsl:copy>
        </xsl:for-each>
    </xsl:template>

下面是第一个XML文件:

<?xml version="1.0"?>
<EXPORT>
<CAM>
    <Version V="3_0_0">
      <Project Computer_Name="CW032" User_Name="Sflores">
        <!--Offer-->
        <Offer Code="J021368">
          <!--Client-->
          <Customer Code="8"/>
          <!--Top-->
          <Top Id="1">
            <Shapes>
            </Shapes>
            <Texts>
            </Texts>
            <TextsLav>
              <!--Working Texts-->
            </TextsLav>
            <Dimensions>
            </Dimensions>
            <FreeElements>
              <!--Elementi senza assegnazione-->
            </FreeElements>
          </Top>
        </Offer>
      </Project>
    </Version>
</CAM>
</EXPORT>
<?xml version="1.0"?>
<Job>
<Job_Number>B90512</Job_Number>
<Job_Address></Job_Address>
<Benchtops>
<Benchtop>
<Cabinet_Type>Benchtop</Cabinet_Type>
<Page>Page 1</Page>
<Room>Kitchen</Room>
<Top_number>TOP(2257)</Top_number>
<Length>2641mm</Length>
<Width>800mm</Width>
<Width2>2641mm</Width2>
</Benchtop>
<Benchtop>
<Cabinet_Type>Benchtop</Cabinet_Type>
<Page>Page 1</Page>
<Room>Kitchen</Room>
<Top_number>TOP(2260)</Top_number>
<Length>2772mm</Length>
<Width>600mm</Width>
<Width2>2772mm</Width2>
</Benchtop>
</Benchtops>
</Job>

下面是第二个XML文件:

<?xml version="1.0"?>
<EXPORT>
<CAM>
    <Version V="3_0_0">
      <Project Computer_Name="CW032" User_Name="Sflores">
        <!--Offer-->
        <Offer Code="J021368">
          <!--Client-->
          <Customer Code="8"/>
          <!--Top-->
          <Top Id="1">
            <Shapes>
            </Shapes>
            <Texts>
            </Texts>
            <TextsLav>
              <!--Working Texts-->
            </TextsLav>
            <Dimensions>
            </Dimensions>
            <FreeElements>
              <!--Elementi senza assegnazione-->
            </FreeElements>
          </Top>
        </Offer>
      </Project>
    </Version>
</CAM>
</EXPORT>
<?xml version="1.0"?>
<Job>
<Job_Number>B90512</Job_Number>
<Job_Address></Job_Address>
<Benchtops>
<Benchtop>
<Cabinet_Type>Benchtop</Cabinet_Type>
<Page>Page 1</Page>
<Room>Kitchen</Room>
<Top_number>TOP(2257)</Top_number>
<Length>2641mm</Length>
<Width>800mm</Width>
<Width2>2641mm</Width2>
</Benchtop>
<Benchtop>
<Cabinet_Type>Benchtop</Cabinet_Type>
<Page>Page 1</Page>
<Room>Kitchen</Room>
<Top_number>TOP(2260)</Top_number>
<Length>2772mm</Length>
<Width>600mm</Width>
<Width2>2772mm</Width2>
</Benchtop>
</Benchtops>
</Job>

B90512
台阶
第1页
厨房
顶部(2257)
2641mm
800毫米
2641mm
台阶
第1页
厨房
顶部(2260)
2772毫米
600毫米
2772毫米
下面是我需要插入的XML:

             <!--Shape-->
              <Shape Id="1">
                <!--Material-->
                <Material Class_Code="MATCL010006"/>
                <Principal_Structure Id="1">
                  <!--Polygon-->
                </Principal_Structure>
                <LayerTexts>
                  <!--Texts for material and thickness-->
                </LayerTexts>
              </Shape>

我得到的结果是:

<?xml version="1.0"?>
<EXPORT>
<CAM>
<Version V="3_0_0">
<Project Computer_Name="CW032" User_Name="Sflores">
<!--Offer-->
<Offer Code="B90512">
<!--Client-->
<Customer Code="8"></Customer>
<!--Top-->
<Top Id="1">
<Benchtop>
<!--Shape-->
<Shape Id="1">
<!--Material-->
<Material Class_Code="MATCL010006"></Material>
<Principal_Structure Id="1">
<!--Polygon-->
</Principal_Structure>
<LayerTexts>
<!--Texts for material and thickness-->
</LayerTexts>
</Shape>
</Benchtop>
<Benchtop>
<!--Shape-->
<Shape Id="1">
<!--Material-->
<Material Class_Code="MATCL010006"></Material>
<Principal_Structure Id="1">
<!--Polygon-->
</Principal_Structure>
<LayerTexts>
<!--Texts for material and thickness-->
</LayerTexts>
</Shape>
</Benchtop>
<Texts></Texts>
<TextsLav>
<!--Working Texts-->
</TextsLav>
<Dimensions></Dimensions>
<FreeElements>
<!--Elementi senza assegnazione-->
</FreeElements>
</Top>
</Offer>
</Project>
</Version>
</CAM>

请注意,现在缺少
元素,并且插入了
元素

输出应如下所示:

<?xml version="1.0"?>
    <EXPORT>
    <CAM>
    <Version V="3_0_0">
    <Project Computer_Name="CW032" User_Name="Sflores">
    <!--Offer-->
    <Offer Code="B90512">
    <!--Client-->
    <Customer Code="8"></Customer>
    <!--Top-->
    <Top Id="1">
    <Shapes>
    <!--Shape-->
    <Shape Id="1">
    <!--Material-->
    <Material Class_Code="MATCL010006"></Material>
    <Principal_Structure Id="1">
    <!--Polygon-->
    </Principal_Structure>
    <LayerTexts>
    <!--Texts for material and thickness-->
    </LayerTexts>
    </Shape>
    <!--Shape-->
    <Shape Id="1">
    <!--Material-->
    <Material Class_Code="MATCL010006"></Material>
    <Principal_Structure Id="1">
    <!--Polygon-->
    </Principal_Structure>
    <LayerTexts>
    <!--Texts for material and thickness-->
    </LayerTexts>
    </Shape>
    </Shapes>
    <Texts></Texts>
    <TextsLav>
    <!--Working Texts-->
    </TextsLav>
    <Dimensions></Dimensions>
    <FreeElements>
    <!--Elementi senza assegnazione-->
    </FreeElements>
    </Top>
    </Offer>
    </Project>
    </Version>
    </CAM>


非常感谢您的帮助。

问题在于模板匹配
形状

<xsl:template match="Shapes">
    <xsl:for-each select="document('..\TempReportData\TextXML_Output.xml')/Job/Benchtops/Benchtop">
        <xsl:copy>
            <xsl:apply-templates select="document('..\DesignMaster\EmptyShapeElement.xml')" />
        </xsl:copy>
    </xsl:for-each>
</xsl:template>

哦,酷。工作得很好。我想这会很简单。非常感谢Tim C