Subject: Re: [xsl] Merge 2 xmls : Loop through one xml and get elements from second xml From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 1 Sep 2020 14:57:28 -0000 |
Is there any other simpler way..
<xsl:template match="order"> <xsl:copy> <xsl:apply-templates select="@* | node(), key('order', $ordernumber, $doc2)/amount"/> </xsl:copy> </xsl:template>
All I have to do is:
Loop thru first xml: add elements from first xml getB "amount" from second xml where order number matches and create this Or
Can you explain what is being done?
The suggested approach processes the first XML with the identity transformation to copy everything, with the exception of of the "order" elements, where it additionally gets the "amount" from the second XML, using a key to establish the match and selection based on the order number.
> But I need to use only XSLT 1.0
Declare
<xsl:param name="doc2" select="document('Orders_Part2.xml')"/>
and a key
<xsl:key name="order" match="order" use="order_number"/>
then use
<xsl:template match="order"> B B <xsl:copy> B B B <xsl:apply-templates select="@* | node()"/> B B B <xsl:variable name="ordernumber" select="order_number"/> B B B <xsl:for-each select="$doc2"> B B B B <xsl:apply-templates select="key('order', $ordernumber)/amount"/> B B B </xsl:for-each> B B </xsl:copy> </xsl:template>
plus the identity transformation
<xsl:template match="@* | node()"> B B <xsl:copy> B B B <xsl:apply-templates select="@* | node()"/> B B </xsl:copy> </xsl:template>
>>>B B B ================= >>>B B B Merge 2 xmls : Loop through one xml and get elements from second xml >>> >>>B B B I have 2 xmls(Orders_Part1.xml,Orders_Part2.xml). I have to build the >>>B B B 3rd xml ( Orders.xml) .
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Merge 2 xmls : Loop throu, Liam R. E. Quin liam | Thread | Re: [xsl] Merge 2 xmls : Loop throu, Prady Prady prady.ch |
Re: [xsl] Merge 2 xmls : Loop throu, Prady Prady prady.ch | Date | Re: [xsl] Merge 2 xmls : Loop throu, Liam R. E. Quin liam |
Month |