以下に示すように、2 つの xml ファイルを結合したいと考えています。しかし、私が持っている質問は、参加するIDを持ってこれをどのように行うかです. IDではなくPOSITIONに関して結合したい。次のファイルに対してこれをどのように行いますか?
ファイル 1:
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<data>
<title>Title1</title>
<description>Description1</description>
</data>
<data>
<title>Title2</title>
<description>Description2</description>
</data>
</catalog>
ファイル 2:
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<data>
<author>Author1</author>
<date>12/34/5678</date>
</data>
<data>
<author>Author2</author>
<date>87/65/4321</date>
</data>
</catalog>
出力:
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<data>
<title>Title1</title>
<description>Description1</description>
<author>Author1</author>
<date>12/34/5678</date>
</data>
<data>
<title>Title2</title>
<description>Description2</description>
<author>Author2</author>
<date>87/65/4321</date>
</data>
</catalog>
ID
以下の XSLT を使用する共通フィールドがある場合、これを行う方法は知っていますが、POSITION で結合するにはどうすればよいですか?
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes" />
<xsl:variable name="with" select="'File2.xml'" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="scene">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
<xsl:variable name="info" select="document($with)/catalog/data[id=current()/id]/." />
<xsl:for-each select="$info/*">
<xsl:if test="name()!='myid'">
<xsl:copy-of select="." />
</xsl:if>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:transform>