Comments? Feedback?

This wiki does not yet support public comments (a limitation of Google Sites), so we encourage you to post your comments either:

On Twitter by responding to @orbeon.

On our community mailing list: subscribe sending an email to ops-users-subscribe@ow2.org (content of subject/body doesn't matter), you'll get a response with the email to use to send your message to the community mailing list.

Recent site activity

How-to guides‎ > ‎XForms Logic‎ > ‎

Run an external XSLT transformation from XForms

The problem

XForms features a series of data manipulation actions:
  • <xforms:setvalue>
  • <xforms:insert>
  • <xforms:delete>
These suffice very often, but sometimes you might want to use XSLT instead to transform XML data instead. But how?

See also: Run an embedded XSLT transformation from XForms

The service solution

A simple, cross-implementation solution consists in sending the XML data to transform to a service. The service performs the transformation, and returns the result.

A submission can look like this:

<xforms:submission id="transform-submission"
                   method="post" ref="instance('source')"
                   resource="http://example.org/service/transform"
                   replace="instance" instance="destination"/>

This submission:
  • Takes XML data stored in instance called source
  • Performs an HTTP POST of that XML data to the service
  • Returns the result into the instance called destination

You can (but you don't have to!) implement a transformation service directly in Orbeon Forms. See Implement a transformation service for details about how to implement a transformation service.

The call-xpl() solution

Orbeon XForms also features an extension XPath function, xxforms:call-xpl(). This function allows calling an XPL pipeline directly, without exposing it as a service.

In this case, instead of using a submission, use <xforms:insert>:

<xforms:insert nodeset="instance('destination')"
               origin="xxforms:call-xpl('oxf:/apps/my-app/my-transform.xpl', 'data',
                                        instance('source'), 'data')"
/>

This:
  • replaces the root element of the destination instance
  • with the result of the call to xxforms:call-xpl()
The xxforms:call-xpl() function parameters are:
  1. the URL of the XPL pipeline to execute
  2. the name of the pipeline input to pass
  3. the content of the pipeline input to pass
  4. the name of the pipeline output to read
Here is an example pipeline running an XSLT transformation:

<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline"
          xmlns:oxf="http://www.orbeon.com/oxf/processors">

    <p:param type="input" name="data"/>
    <p:param type="output" name="data"/>

    <p:processor name="oxf:xslt">
        <p:input name="data" href="#data"/>
        <p:input name="config" href="my-transform.xsl"/>
        <p:output name="data" ref="data"/>
    </p:processor>

</p:config>

NOTE: If you are using separate deployment, the service and XSLT transformation must be present in the Orbeon WAR file, instead of within your application.