[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Merge 2 xmls : Loop through one xml and get elemen

Subject: Re: Merge 2 xmls : Loop through one xml and get elements from second xml
From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 1 Sep 2020 16:21:28 -0000
Re:  Merge 2 xmls : Loop through one xml and get elemen
Prady,

In your parameter declaration:

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

If your second document is named 'Orders_Part2.xsl', this should be
document('Orders_Part2.xsl') with quote marks to represent that the
argument is a string (not a path expression).

If it is actually named 'Orders_Part2.xml' then it should be
document('Orders_Part2.xml').

Then the xsl:value-of should refer to $doc2 (the parameter), not
$Orders_Part2 (which is not defined anywhere in this code).

As given, this would produce an error message -- which might give a clue as
to what is wrong.

If you back up and take the time to be careful about this stuff, you will
probably save time in the end.

Good luck,
Wendell


On Tue, Sep 1, 2020 at 11:41 AM Prady Prady prady.chin@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Martin,
>
> 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="/">
>
>     <OrdersEmailInputMsg>
>
>       <EmailOrdersInfo>
>
>         <Orders>
>
>           <xsl:for-each select="$doc2/order">
>
>             <order>
>
>               <OrderNumber>
>
>                 <xsl:value-of select="order_number"/>
>
>               </OrderNumber>
>
>                 <Product>
>
>                 <xsl:value-of select="porduct_id"/>
>
>               </Product>
>
>               <Amount>
>
>                 <xsl:variable name="amt">
>
>                   <xsl:call-template name="getAmount">
>
>                     <xsl:with-param name="ordernum" select="order_number"/>
>
>                   </xsl:call-template>
>
>                 </xsl:variable>
>
>                 <xsl:value-of select="$amt"/>
>
>               </Amount>
>
>             </Order>
>
>           </xsl:for-each>
>
>         </Orders>
>
>       </EmailOrdersInfo>
>
>     </OrdersEmailInputMsg>
>
>   </xsl:template>
>
>   <xsl:template name="getAmount">
>
>     <xsl:param name="ordernum"/>
>
>         <xsl:value-of
> select="$Orders_Part2/orders/order_num[$ordernum]/amount"/>
>
>   </xsl:template>
>   ==================
>
> On Tue, 1 Sep 2020 at 10:57, Martin Honnen martin.honnen@xxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>> Am 01.09.2020 um 15:51 schrieb Prady Prady prady.chin@xxxxxxxxx:
>> > 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: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
>> > get  "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">
>> >         <xsl:copy>
>> >           <xsl:apply-templates select="@* | node()"/>
>> >           <xsl:variable name="ordernumber" select="order_number"/>
>> >           <xsl:for-each select="$doc2">
>> >             <xsl:apply-templates select="key('order',
>> >     $ordernumber)/amount"/>
>> >           </xsl:for-each>
>> >         </xsl:copy>
>> >     </xsl:template>
>> >
>> >     plus the identity transformation
>> >
>> >     <xsl:template match="@* | node()">
>> >         <xsl:copy>
>> >           <xsl:apply-templates select="@* | node()"/>
>> >         </xsl:copy>
>> >     </xsl:template>
>> >
>> >
>> >
>> >      >>>     =================
>> >      >>>     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/174322> (by
> email <>)
>


-- 
...Wendell Piez... ...wendell -at- nist -dot- gov...
...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.