Proposal
see irc raw log : http://www.w3.org/2008/02/04-forms-irc#T16-52-24, and irc minutes : http://www.w3.org/2008/02/04-forms-minutes.html
We will decided to create an action setcontent which does the same as setvalue but allows elements as child XML.
Using insert to insert inline specified xml
<xf:insert ...>
<xf:origin>
<inline-created-element>element contents</inline-created-element>
</xf:origin>
</xf:insert>
We will also add a simplified action for setting XML contents.
Adding static inline XML: <xf:setcontent ref="my-el">
<my-snippet>
<sub-element>text</sub-element>
</my-snippet>
</xf:setcontent>
Adding dynamic inline XML: <xf:setcontent ref="my-el">
<xf:element name="instance('i2')/name">
<xf:attribute name="'static-attr-name'">static-value</xf:attribute>
<xf:attribute name="'static-attr-name2'" value="instance('i2')/attr-value"/>
<xf:attribute name="instance('i2')/attr-value">static-value</xf:attribute>
<static-child>text</static-child>
</xf:element>
</xf:setcontent>
The setcontent action should be smart enough, to only do a rebuild if the content are XML elements and not if it is just text contents
Erik's Notes
I am not a big fan of xf:setcontent: this can be easily done with a template instance for static content. It would be convenient for sure, but it tries too much to be yet another template language, and we already have enough of those: XSLT, XQuery. Another approach, as discussed, could be XPath functions. This could be done instead or in addition to the above.
Inserting an element by QName: <xf:insert context="parent" origin="element('foo:bar')"/>
Inserting an attribute by QName: <xf:insert context="parent" origin="attribute('foo:bar')"/>
Inserting an attribute by QName with non-empty value: <xf:insert context="parent" origin="attribute('foo:bar', 'my-value')"/>
The benefit of this solution:
- Simple: just add two functions, which look a bit like the XQuery element and attribute constructors
- No need for a plethora of new actions and elements: xf:insert does the job, that's it
- Super easy for implementors
Original Text
The insert action gives us the power to create new nodes based on a templated
given by origin. But there is no way to create a new node when no origin template exists.
I want to be able to create a node, giving its parent, its type (element, attribute, text, etc.), it's QName, and optionally an initial string value.
<create ref="parent" nodetype="element" name="child">literal</create>
The value attribute could be added to provide an xpath for determining the literal.
It can easily fail with no-op if the QName prefix is undefined in the context of the parent, if the nodetype cannot be created as a child of the parent, etc.
This is an ease of authoring action that combines a special kind of insert with setvalue.
Sets the rebuild, recalculate, revalidate, refresh flags.
Should dispatch xforms-insert on successful completion.