Control which fill repeater fields using xml file

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

Control which fill repeater fields using xml file

pumbosha
This post was updated on .
Hallo

I want to create control in orbeon which:

1. Make possibility to upload xml file from user
2. Create repeats of repeater control. Repeats should contains value from specific nodes of uploaded xml.

For example:

1. User uploaded file:

<root>
  <child>child1</child>
  <child>child2</child>
</root>

2. User select some existing repeater name, and this repeater should be fill with two repeats. One should contains String 'child1' and second: 'child2'.

I know that this can be difficult, but I want to some tips maybe.

For example, we can suppose that instance 'source' contains xml code (as above: root with children), instance 'xpath' contains xpath to the specific nodes (in this case: //root/child) and repeater name is in instance 'repeaterName'. How can I add repeats with nodes from xml?
I try something like:

<xf:action context="instance('source')" ev:event="xforms-submit-done">
    <xf:var as="xs:string" name="control-value" select="saxon:evaluate(instance('xpath'))"/> 
    <xf:var as="xs:string" name="control-name" select="saxon:evaluate(instance('repeaterName'))"/>
    <xf:setvalue ref="xxf:instance('fr-form-instance')//*[name() = $control-name]/repeat" value="$control-value"/> 
</xf:action>

I know it is wrong, because I have to use something like 'for' loop, but I don't know how.
Maybe someone can give me some tutorial which contains issues similar to above.

Regards,
Tom
Reply | Threaded
Open this post in threaded view
|

Re: Control which fill repeater fields using xml file

Alessandro  Vernet
Administrator
Hi Tom,

To do a loop in XForms, you would use the "iterate" attribute (see link to the spec below). But things are tricky in your case, as you need to iterate on 2 data structures: the uploaded data and the nodes you're inserting, and I imagine it's possible that you might not have enough "slots" available in fr-form-instance for the data that was uploaded. Of maybe you have too many "slots", in which case you might want to remove the unused "slots". But in any case, iterate="" will be part of the solution.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Control which fill repeater fields using xml file

pumbosha
Thank You. Iterate works with uploaded xml file. But, as You said, there is a problem associated with unknown number of repeats ('slots'). In my idea, it should insert repeats in iterate loop. If xml file has for example three nodes, then three repeats should be inserted do repeater dynamically. Is it possible ? If not, have you some other idea how to reach that effect?
Reply | Threaded
Open this post in threaded view
|

Re: Control which fill repeater fields using xml file

Alessandro  Vernet
Administrator
Hi Tom,

Indeed, I think that this is what I would do. If there is no other data in those rows, i.e. all the data comes from the uploaded XML, then you could start by deleting all the existing rows in fr-form-data, and as you iterate, at each step, insert a new "row" (form the your-grid-template instance), and populate it.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Control which fill repeater fields using xml file

pumbosha
Allesandro, thank You for help. I was able to do it without iterate. User makes repeater on his own and give id of it to the control. Control which has uploaded xml file and id of repeater, is adding content of xml to main-instance (fr-form-instance) and automatically repeater is filling by values from xml file. One condition is the name of repeater and its internal controls have to have the same names like in xml (structure of repeater with internal controls must be identical with xml file), but this is no problem, for me. Regards
Reply | Threaded
Open this post in threaded view
|

Re: Control which fill repeater fields using xml file

Alessandro  Vernet
Administrator
Tom, indeed, if the format of the XML is the same in the uploaded data as in the subtree of fr-form-instance you wish to replace, then an xf:delete and xf:insert should do it. I'm glad you have a solution that works for your use case.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet