I could not find a good approach of copying the repeated node values to another repeated nodes. In common programming language i mean to say copy the contents of one array to another array.
<xforms:instance id="main-instance">
<contacts>
<contact>
<contact-id>111</contact-id>
<contact-name></contact-name>
<contact-location></contact-location>
</contact>
<contact>
<contact-id>222</contact-id>
<contact-name></contact-name>
<contact-location></contact-location>
</contact>
<contact>
<contact-id>333</contact-id>
<contact-name></contact-name>
<contact-location></contact-location>
</contact>
</contacts>
<alternate-contacts>
<contact>
<alt-contact-id></alt-contact-id>
<control-id></control-id>
<control-rules></control-rules>
<tranmission-method></tranmission-method>
</contact>
<contact>
<alt-contact-id></alt-contact-id>
<control-id></control-id>
<control-rules></control-rules>
<tranmission-method></tranmission-method>
</contact>
<contact>
<alt-contact-id></alt-contact-id>
<control-id></control-id>
<control-rules></control-rules>
<tranmission-method></tranmission-method>
</contact>
</alternate-contacts>
</xforms:instance>
When a checkbox is checked(event to start the action), i should copy the 1st contact-id
value into 1st alt-contact-id
and so on.
<xforms:action ev:event="xforms-value-changed">
//TO DO here
</xforms:action>
Please provide your ideas
Edit: So when the checkbox is checked, the <alternate-contacts>
node should look like this
<alternate-contacts>
<contact>
<alt-contact-id>111</alt-contact-id>
<control-id></control-id>
<control-rules></control-rules>
<tranmission-method></tranmission-method>
</contact>
<contact>
<alt-contact-id>222</alt-contact-id>
<control-id></control-id>
<control-rules></control-rules>
<tranmission-method></tranmission-method>
</contact>
<contact>
<alt-contact-id>333</alt-contact-id>
<control-id></control-id>
<control-rules></control-rules>
<tranmission-method></tranmission-method>
</contact>
</alternate-contacts>
You're looking for the iterate
attribute1, introduced in the upcoming by XForms 2.0, but already supported by Orbeon Forms, which you seem to be using based on the tag on your question. With it, you can write:
<xforms:action iterate="/root/contacts/contact">
<xforms:var name="position" value="position()"/>
<xforms:var name="id" value="contact-id"/>
<xforms:setvalue ref="/root/alternate-contacts/contact[$position]/alt-contact-id" value="$id"/>
</xforms:action>
Also see a full example using this code.
1 This feature has been supported for long, and you had to use xxforms:iterate="…"
to denote this was an extension, but since this is soon going to be standard, you can now just use iterate="…"
.