2

私は2つのxmlファイルを持っています。要素の最後の出現の下にある xml ファイル データを別のファイルにコピーしたいと考えています。以下は私が持っているxmlです:

---------- xml-1---------------
<?xml version="1.0"?>
<parent>
....
<form id="1" name="world"/>
 <source id="1" name="abc1"/>
 <source id="2" name="abc2"/>
 <source id="3" name="abc3"/>
 <file id="1" name="xyz"/>
....
</parent> 

----------- xml-2--------------
<?xml version="1.0"?>
<root>
<source id="4" data="anything"/>
<source id="5" data="anything"/>
<source id="6" data="anything"/>
<source id="7" data="anything"/>
</root>


------------------The desired output I want-----------------
<?xml version="1.0"?>
<parent>
....
<source id="1" name="abc1"/>
<source id="2" name="abc2"/>
<source id="3" name="abc3"/>
<source id="4" data="anything"/>
<source id="5" data="anything"/>
<source id="6" data="anything"/>
<source id="7" data="anything"/>
<file id="1" name="xyz"
....
</parent> 



============== xslt I am using =============

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*" name="identity">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="source">
    <xsl:choose>
      <xsl:when test="'id=3'">
          <xsl:call-template name="identity"/>
          <xsl:copy-of select="document('file:///D:/Softwares/JEE    eclipse/JEEworkspace/Migration/TestMigrationWithoutDeletingProject/xml2.xml')/*/*"/>
      </xsl:when>
    </xsl:choose>
</xsl:template>
</xsl:stylesheet>

id 属性に基づいて見つけようとしていますが、xml-1 データのすべてのソース要素の後に xml-2 データをコピーしています。これについて私を助けてください。

4

1 に答える 1

0

あなたのコードには 2 つの小さな問題があると思います。

  • への呼び出しは、セクション<xsl:call-template name="identity"/>の外 (またはchooseセクションの前) にある必要があります。ところで、otherwiseセクションがないので、ここで使用するには少し短くなりxsl:ifます。
  • 正しい挿入ポイントのテストはtest="@id = 3"、用語"'id=3'"が単に常に生成される文字列であるためtrue()です。
于 2013-10-23T23:03:35.697 に答える