[Top] [All Lists]

Re: [xsl] Merge 2 xmls : Loop through one xml and get elements from second xml

2020-09-01 10:41:15

Why can't I do something like this?  But below one i*s NOT working .. *

*I need to know how to select amount based on the supplied order num: *
    <xsl:value-of select="$Orders_Part2/orders*/order_num[$ordernum]*
/amount"/>  ==> not working

 <xsl:param name="doc2" select="document(Orders_Part2.xsl)"/>

  <xsl:template match="/">




          <xsl:for-each select="$doc2/order">



                <xsl:value-of select="order_number"/>



                <xsl:value-of select="porduct_id"/>



                <xsl:variable name="amt">

                  <xsl:call-template name="getAmount">

                    <xsl:with-param name="ordernum" select="order_number"/>



                <xsl:value-of select="$amt"/>








  <xsl:template name="getAmount">

    <xsl:param name="ordernum"/>



On Tue, 1 Sep 2020 at 10:57, Martin Honnen 
martin(_dot_)honnen(_at_)gmx(_dot_)de <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Am 01.09.2020 um 15:51 schrieb Prady Prady 
Is there any other simpler way..

What do you consider simple or simpler? Using XSLT 2 or 3? Sure, go ahead

<xsl:template match="order">
     <xsl:apply-templates select="@* | node(), key('order',
$ordernumber, $doc2)/amount"/>

All I have to do is:

Loop thru first xml:
add elements from first xml
get  "amount" from second xml where order number matches and create this

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


    <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">
          <xsl:apply-templates select="@* | node()"/>
          <xsl:variable name="ordernumber" select="order_number"/>
          <xsl:for-each select="$doc2">
            <xsl:apply-templates select="key('order',

    plus the identity transformation

    <xsl:template match="@* | node()">
          <xsl:apply-templates select="@* | node()"/>

     >>>     =================
     >>>     Merge 2 xmls : Loop through one xml and get elements from
    second xml
     >>>     I have 2 xmls(Orders_Part1.xml,Orders_Part2.xml). I have to
    build the
     >>>     3rd xml ( Orders.xml) .

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
<Prev in Thread] Current Thread [Next in Thread>