XSLTForms/setnode

The  action is an experimental extension of XForms, helpful for updating an instance document with the output of an XSLT transformation (see the transform function) or with the output of a mixed-content editor (see the discussion of using TinyMCE as an XForms control).

The action is indicated using the  element. It has three crucial attributes:


 * The  attribute is a single-node binding attribute which indicates the target node.
 * The  attribute specifies the node(s) which should replace the children of the target node; its value is the serialized XML form of the nodes.
 * The  attribute specifies the node which should replace the target node; its value is the serialized XML form of the replacement node.

The  and   attributes are mutually exclusive; one or the other must be specified, but not both. As is usual when representing serialized XML within an attribute value, the left angle brackets and ampersands in the serialized form must be escaped.

The value of the  or   attribute is parsed as XML to produce DOM nodes, and the resulting nodes replace either the children of the target node, or the target node itself.

Example
The following example shows a trigger which replaces an instance named  with a new document.

Using with
A perhaps more common usage of  is to update an instance with the result of running an XSLT stylesheet or a mixed-content editor, both of which return strings with the serialized-XML form of their result.

Suppose we have an input instance which the user can modify through the form, and an XSLT stylesheet which can process the input instance and create an SVG diagram representing some information from the instance. To allow the user to generate a fresh diagram, we could supply a trigger specified as follows:

This assumes that we have an instance named, where the output of the transformation should go. It also assumes that there is a switch statement somewhere with a case named, which displays the generated SVG.

Achieving similar effects in standard XForms 1.1
In standard XForms 1.1, one way to achieve similar effects is to submit the string (the serialized XML) to a server which reflects it back unchanged, with the MIME type  (or similar), and specify that the submission updates the instance in question.

The example given above would be rewritten as:

The  submission submits the string value of the   instance to the server, which reflects it back as XML (so the browser parses it and updates the instance normally):

The CGI script on the server does nothing but return the submitted data, labeled as XML:

Achieving similar effects in standard XForms 2.0
To achieve similar effects in XForms 2.0, one can use the  action, using the XForms 2.0   function in the value of the   attribute.

[Example needed.]