0

1 つの XSLT ファイル内で、最初に 1 つの XML ファイルを開き、子を持つ要素を抽出してから、その要素を 2 番目の XML ファイルに詰め込む方法はありますか?

1 つの XSLT で実行できない場合、言語の選択は vb スクリプトになります。

ここでさまざまな例を見てきましたが、混乱しているだけで、それらの大部分を理解していません。

XML1からノードを抽出するために私が取り組んでいるXSLは次のとおりです。

  <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output 
      method="xml"
      omit-xml-declaration="yes" 
      indent="yes"
      encoding="ISO-8859-1"/>
    <xsl:template match="/">
    <xsl:copy-of select="root/Collection/Item/." />
    </xsl:template> 
    </xsl:stylesheet> 

結果のアイテムを取得し、同じ XPATH のルート/コレクションで XML2 に追加したいと考えています。

この回答から、XML を memvar に返す vb スクリプトがあります

XML1:

<root>
 <collection1>
  <item attr1, attr2...>  ---this is what I am getting
   <more>
   </more>
  </item>
 <collection1>
 <collection2>
  <item attr1, attr2...>
   <more>
   </more>
  </item>
 <collection2>
 ...
 <collection_n>
  <item attr1, attr2...>
   <more>
   </more>
  </item>
 <collection_n>
</root>

XML2:

<root>
 <collection1>
  <item attr1, attr2...>
   <more>
   </more>
  </item>
---- i want to insert node from XML1 here, only in collection1
 <collection1>
 <collection2>
  <item attr1, attr2...>
   <more>
   </more>
  </item>
 <collection2>
 ...
 <collection_n>
  <item attr1, attr2...>
   <more>
   </more>
  </item>
 <collection_n>
</root>

したがって、新しい XML2:

<root>
 <collection1>
  <item attr1, attr2...>
   <more>
   </more>
  </item>
  <item attr1, attr2...>
   <more>
   </more>
  </item>
 <collection1>
 <collection2>
  <item attr1, attr2...>
   <more>
   </more>
  </item>
 <collection2>
 ...
 <collection_n>
  <item attr1, attr2...>
   <more>
   </more>
  </item>
 <collection_n>
</root>
4

1 に答える 1

2

関数を使用してdocument()外部ドキュメントをロードし、変換を実行しているドキュメントとマージできるようにします。xsl:paramまたは、XSLT を呼び出すときにメモリ内に DOM ツリーとして保持している場合は、ノード セットとしてテンプレート パラメーター ( ) に指定することもできます。

私が約1週間前に回答したこの質問を見てください。これはまさに、複数のドキュメントから同じマージ ポイント (同じ XPath と考えてください) にあるコンテンツをマージする方法に関するものです。

それが役に立てば幸い。そうでない場合は、何が不明なのか、何を試みたのか、何がうまくいかなかったのかについて、より具体的な質問をしてください。

于 2012-05-17T21:05:12.090 に答える