Copying value from one XML instance to another

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Copying value from one XML instance to another

quinquin2209
Hi,

I have 2 XML, one is a purchase order, and another is a shipping order.

My goal is to create a form for user to prepare a shipping order. To ease this process, I would like to copy some of the information from a purchase order to the shipping order, such that user does not need to re-input.

I know that I can use bind to copy a node value from one instance to another. For example:

<xforms:bind nodeset="instance('so-instance')/TotalAmount calculate="instance('po-instance')/Payment/TotalAmount"/>

However, I am not sure how I can copy repeated node from PO to SO. In the PO, there are multiple OrderLineItem. I have to copy some of the values in this line item into the CargoLineItem under SO.

Conceptually, I think I can achieve it by

<xforms:action ev:event="xforms-ready" > 
   <xforms:repeat context="instance('doc-instance')" nodeset="OrderLineItem" id="repeat-copy">
      <xforms:insert context="instance('so-instance')" nodeset="CargoLineItem" at="last()" position="after" origin="instance('cargo-line-item-template')"/>
       
   </xforms:repeat>
</xforms:action>

However, it does not work since repeat cannot be used in an action.

Can anyone suggest if I can achieve it using xform? Or I should use XSL to do the transformation first?

Queenie
Reply | Threaded
Open this post in threaded view
|

Re: Copying value from one XML instance to another

Erik Bruchez
Administrator
Sure you can. I am not sure exactly what you need to copy, but  
xforms:insert allows you to copy multiple nodes at a time. If you want  
to copy all the OrderLineItem after the CargoLineItem, you can write  
something like this:

<xforms:action ev:event="xforms-ready">
     <xforms:insert context="instance('so-instance')"
                    nodeset="CargoLineItem" at="last()" position="after"
                    origin="instance('doc-instance')/OrderLineItem"/>
</xforms:action>

But maybe you have something more complex in mind?

-Erik

On Mar 17, 2008, at 12:05 AM, quinquin2209 wrote:

>
> Hi,
>
> I have 2 XML, one is a purchase order, and another is a shipping  
> order.
>
> My goal is to create a form for user to prepare a shipping order. To  
> ease
> this process, I would like to copy some of the information from a  
> purchase
> order to the shipping order, such that user does not need to re-input.
>
> I know that I can use bind to copy a node value from one instance to
> another. For example:
>
> <xforms:bind nodeset="instance('so-instance')/TotalAmount
> calculate="instance('po-instance')/Payment/TotalAmount"/>
>
> However, I am not sure how I can copy repeated node from PO to SO.  
> In the
> PO, there are multiple OrderLineItem. I have to copy some of the  
> values in
> this line item into the CargoLineItem under SO.
>
> Conceptually, I think I can achieve it by
>
> <xforms:action ev:event="xforms-ready" >
>   <xforms:repeat context="instance('doc-instance')"  
> nodeset="OrderLineItem"
> id="repeat-copy">
>      <xforms:insert context="instance('so-instance')"
> nodeset="CargoLineItem" at="last()" position="after"
> origin="instance('cargo-line-item-template')"/>
>       <!-- then bind value from the order line item to the newly  
> addedd
> cargo line item-->
>   </xforms:repeat>
> </xforms:action>
>
> However, it does not work since repeat cannot be used in an action.
>
> Can anyone suggest if I can achieve it using xform? Or I should use  
> XSL to
> do the transformation first?
>
> Queenie
> --
> View this message in context: http://www.nabble.com/Copying-value-from-one-XML-instance-to-another-tp16089377p16089377.html
> Sent from the ObjectWeb OPS - Users mailing list archive at  
> Nabble.com.
>
>
> --
> You receive this message as a subscriber of the [hidden email]  
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Copying value from one XML instance to another

quinquin2209
Thanks for your reply.

The case is bit complex and the OrderLineItem in PO cannot be copied into SO directly since the OrderLineItem and CargoLineItem has different structure. The XML instance of SO is a blank template like the following:

<SO>
  <TotalAmount></TotalAmount>
  <CargoLineItem>
       <Measure>
           <Quantity></Quantity>
       </Measure>
       <ItemId></ItemId>
  </CargoLineItem>
</SO>

And the PO contains information which should be copied to the SO

<PO>
  <Payment>
     <TotalAmount>15</TotalAmount>
  </Payment>
  <OrderLineItem> 
     <LineItemId>1</LineItemId>
     <Quantity>15</Quantity>
  </OrderLineItem>
  <OrderLineItem> 
     <LineItemId>1</LineItemId>
     <Quantity>15</Quantity>
  </OrderLineItem>
</PO>

When xforms-ready is triggered, I expect the following should be done:

For each OrderLineItem in PO
   Insert a CargoLineItem into SO (there is a CargoLineItemTemplate instance for insert)
   Copy the value OrderLineItem/LineItemId into CargoLineItem/LineItemId
   Copy the value OrderLineItem/Quantity into CargoLineItem/Measure/Quantity

I am not sure how I can loop through the OrderLineItem in PO in the xforms-ready event.

Any suggestion on how it can be done?


Queenie


Erik Bruchez wrote
Sure you can. I am not sure exactly what you need to copy, but  
xforms:insert allows you to copy multiple nodes at a time. If you want  
to copy all the OrderLineItem after the CargoLineItem, you can write  
something like this:

<xforms:action ev:event="xforms-ready">
     <xforms:insert context="instance('so-instance')"
                    nodeset="CargoLineItem" at="last()" position="after"
                    origin="instance('doc-instance')/OrderLineItem"/>
</xforms:action>

But maybe you have something more complex in mind?

-Erik

On Mar 17, 2008, at 12:05 AM, quinquin2209 wrote:

>
> Hi,
>
> I have 2 XML, one is a purchase order, and another is a shipping  
> order.
>
> My goal is to create a form for user to prepare a shipping order. To  
> ease
> this process, I would like to copy some of the information from a  
> purchase
> order to the shipping order, such that user does not need to re-input.
>
> I know that I can use bind to copy a node value from one instance to
> another. For example:
>
> <xforms:bind nodeset="instance('so-instance')/TotalAmount
> calculate="instance('po-instance')/Payment/TotalAmount"/>
>
> However, I am not sure how I can copy repeated node from PO to SO.  
> In the
> PO, there are multiple OrderLineItem. I have to copy some of the  
> values in
> this line item into the CargoLineItem under SO.
>
> Conceptually, I think I can achieve it by
>
> <xforms:action ev:event="xforms-ready" >
>   <xforms:repeat context="instance('doc-instance')"  
> nodeset="OrderLineItem"
> id="repeat-copy">
>      <xforms:insert context="instance('so-instance')"
> nodeset="CargoLineItem" at="last()" position="after"
> origin="instance('cargo-line-item-template')"/>
>      
>   </xforms:repeat>
> </xforms:action>
>
> However, it does not work since repeat cannot be used in an action.
>
> Can anyone suggest if I can achieve it using xform? Or I should use  
> XSL to
> do the transformation first?
>
> Queenie
> --
> View this message in context: http://www.nabble.com/Copying-value-from-one-XML-instance-to-another-tp16089377p16089377.html
> Sent from the ObjectWeb OPS - Users mailing list archive at  
> Nabble.com.
>
>
> --
> You receive this message as a subscriber of the ops-users@ow2.org  
> mailing list.
> To unsubscribe: mailto:ops-users-unsubscribe@ow2.org
> For general help: mailto:sympa@ow2.org?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws

--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/



--
You receive this message as a subscriber of the ops-users@ow2.org mailing list.
To unsubscribe: mailto:ops-users-unsubscribe@ow2.org
For general help: mailto:sympa@ow2.org?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: Copying value from one XML instance to another

Alessandro Vernet
Administrator
Queenie,

On Mon, Mar 17, 2008 at 7:10 PM, quinquin2209
<[hidden email]> wrote:
>  I am not sure how I can loop through the OrderLineItem in PO in the
>  xforms-ready event.

The attribute xxforms:iterate should do exactly what you need here.
This has been added recently, so you'll need a nightly build. For
documentation and examples see:

http://www.orbeon.com/ops/doc/reference-xforms-2#exforms-iterate

Alex
--
Orbeon Forms - Web 2.0 Forms, open-source, for the Enterprise
Orbeon's Blog: http://www.orbeon.com/blog/
Personal Blog: http://avernet.blogspot.com/


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws