<xf:action ev:event="xforms-model-construct">
<xf:insert nodeset="instance('subInstance')/type" origin="instance('defaultType')/type"/>
</xf:action>
I want to populate an instance based on another one. I can do this using xf:insert as shown above.
However, I realised that the instance 'subInstance' must contain an empty type element before starting the xf:inserts.
<subInstance>
<type/>
</subInstance>
So after all the xf:inserts, I need do the following to delete the first empty one:
<xf:delete nodeset="instance('subInstance')/type" at="1" />
Is there something wrong with this method or is there a way I can insert directly without an initial empty ?
Two answers:
You don't really need an initial type element
Your original instance can simply be:
And then you can insert into the
subInstanceelement with:Using
contextwithoutnodesetorrefsays that you want to insert into the node pointed to bycontext.You can still do what you want but with XForms 2.0 support
If you want to keep the original nested
typeelement, you could write this:originattribute's use of thexf:element()function from XForms 2.0, you can dynamically create an XML document rooted atsubInstanceand containing only thetypeelements from thedefaultTypeinstance.To make this even more modern, you would replace
nodesetwithref, asnodesetis deprecated in XForms 2.0: