Two answers:
You don't really need an initial type element
Your original instance can simply be:
<subInstance/>
And then you can insert into the subInstance
element with:
<xf:action ev:event="xforms-model-construct">
<xf:insert
context="instance('subInstance')"
origin="instance('defaultType')/type""/>
</xf:action>
Using context
without nodeset
or ref
says that you want to insert into the node pointed to by context
.
You can still do what you want but with XForms 2.0 support
If you want to keep the original nested type
element, you could write this:
<xf:action ev:event="xforms-model-construct">
<xf:insert
nodeset="instance('subInstance')"
origin="
xf:element(
'subInstance',
instance('defaultType')/type
)
"/>
</xf:action>
- By targeting the root element of the destination instance, the entire instance will be replaced. This is already the case with XForms 1.1.
- With the
origin
attribute's use of the xf:element()
function from XForms 2.0, you can dynamically create an XML document rooted at subInstance
and containing only the type
elements from the defaultType
instance.
To make this even more modern, you would replace nodeset
with ref
, as nodeset
is deprecated in XForms 2.0:
<xf:action ev:event="xforms-model-construct">
<xf:insert
ref="instance('subInstance')"
origin="
xf:element(
'subInstance',
instance('defaultType')/type
)
"/>
</xf:action>