0
これはfollowupの質問です。子ノードから2 xmlの一致するノードのチャイルドノードに属性をコピーします
私は今コピーする必要のある属性を持つxml2に子ノードを持っています。
XML1
<?xml version="1.0" encoding="utf-8"?>
<Products>
<Product prodId="123456" sellId="" colorId="">
<Supplier id="" name=""/>
<Misc lib="" />
</Product>
</Products>
XML2
<?xml version="1.0" encoding="utf-8"?>
<Products>
<Product>
<info prodId="123456" sellId="121" colorId="AD3">
<qnty lib="34">4</qnty>
</info>
<info prodId="23456" sellId="890" colorId="BM7">
<qnty lib="2">1</qnty>
</info>
</Product>
</Products>
今回、XML2のノードのqnty」の 'libに' 属性は、ノード 'その他' の 'LIB' 属性に行く必要があります。
は今、私のテンプレートは、検索
<xsl:param name="f1" select="'xml2.xml'"/>
<xsl:variable name="doc1" select="document($f1)"/>
<xsl:key name="k1" match="Products/Product/info" use="@prodId"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Products/Product" >
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:variable name="prodId" select="@prodId"/>
<xsl:for-each select="$doc1">
<xsl:copy-of select="key('k1', $prodId)/@sellId"/>
<xsl:copy-of select="key('k1', $prodId)/@colorId"/>
<xsl:apply-templates select="Products/Product/Misc"/>
<xsl:copy-of select="key('k1', $prodId)/qnty/@lib"/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
「libに」属性は「製品」ノードにではなく、子供に「その他」ノードを追加されます。