Aggregate instances when performing submission

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Aggregate instances when performing submission

ncrofts
Hi,

If you have an XForms model containing two (or more) data instances, what is the recommended way to then perform an XML submission which requires bits of data from both instances?

For example,

<xf:instance id="alpha">
   <alpha>
       Some data...      
   </alpha>
</xf:instance>

<xf:instance id="beta">
   <beta>
       Some more data...      
   </beta>
</xf:instance>

<xf:instance id="result">
   <result>
       Some data...      
   </result>
</xf:instance>

As far as I am aware the submission mechanism only allows you to reference data from a single instance e.g.

<xf:submission id="do-alpha" method="post" resource="alpha" ref="instance('alpha')" replace="instance" instance="resullt"/>
       

Therefore when you need to process data from two separate instances I believe it is necessary to copy data from one instance to the other thus duplicating data. This is really awkward and gets messy very quickly.

Is there an easier way to do this? For example is there a way to aggregate the data from multiple instances when you submit? For example something like:

<xf:submission id="do-alpha-beta" method="post" resource="alpha-beta" ref="aggregate('data', instance('alpha'), instance('beta'))" replace="instance" instance="resullt"/>

This approach doesn't work at the moment, but would seem to be a nice way of creating the required instance data on-the-fly.

One other alternative I could think of would be to aggregate the data sources when the page is constructed, but this is just pushing the problem to the XPL rather than the XForm code.


Any thoughts on this would be much appreciated.

Regards,
Neil


Reply | Threaded
Open this post in threaded view
|

Re: Aggregate instances when performing submission

Erik Bruchez
Administrator
Neil,

I haven't tried this, but you could try to use the xxforms:element() function:

<xforms:submission ref="xxforms:element('result', (instance('alpha'),
instance('beta')))">

-Erik

On Tue, Oct 25, 2011 at 4:24 AM, ncrofts <[hidden email]> wrote:

> Hi,
>
> If you have an XForms model containing two (or more) data instances, what is
> the recommended way to then perform an XML submission which requires bits of
> data from both instances?
>
> For example,
>
> <xf:instance id="alpha">
>   <alpha>
>       Some data...
>   </alpha>
> </xf:instance>
>
> <xf:instance id="beta">
>   <beta>
>       Some more data...
>   </beta>
> </xf:instance>
>
> <xf:instance id="result">
>   <result>
>       Some data...
>   </result>
> </xf:instance>
>
> As far as I am aware the submission mechanism only allows you to reference
> data from a single instance e.g.
>
> <xf:submission id="do-alpha" method="post" resource="alpha"
> ref="instance('alpha')" replace="instance" instance="resullt"/>
>
>
> Therefore when you need to process data from two separate instances I
> believe it is necessary to copy data from one instance to the other thus
> duplicating data. This is really awkward and gets messy very quickly.
>
> Is there an easier way to do this? For example is there a way to aggregate
> the data from multiple instances when you submit? For example something
> like:
>
> <xf:submission id="do-alpha-beta" method="post" resource="alpha-beta"
> ref="aggregate('data', instance('alpha'), instance('beta'))"
> replace="instance" instance="resullt"/>
>
> This approach doesn't work at the moment, but would seem to be a nice way of
> creating the required instance data on-the-fly.
>
> One other alternative I could think of would be to aggregate the data
> sources when the page is constructed, but this is just pushing the problem
> to the XPL rather than the XForm code.
>
>
> Any thoughts on this would be much appreciated.
>
> Regards,
> Neil
>
>
>
>
> --
> View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/Aggregate-instances-when-performing-submission-tp3936413p3936413.html
> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>
>


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Aggregate instances when performing submission

ncrofts
Hi Erik,

Thanks for this suggestion. This seems to be along the right lines, but unfortunately the xxforms:element() function throws an exception when passed more than two arguments e.g.

2011-10-26 09:51:58,970 ERROR XFormsServer  - xforms-submit-error - setting throwable {throwable: "org.orbeon.saxon.trans.XPathException: XPath syntax error at char 39 in {...lement('result', $form, $data}:
    Cannot find a matching 3-argument function named {http://orbeon.org/oxf/xml/xforms}element()
        at org.orbeon.saxon.expr.ExpressionParser.grumble(ExpressionParser.java:149)
        at org.orbeon.saxon.expr.ExpressionParser.parseFunctionCall(ExpressionParser.java:1852)

It is tantalisingly close to being a solution though, as when you just pass in two arguments it does behave as you would expect e.g. passes an instance to the pipeline comprising a root element name and a child element.

Am I missing a technique to make the xxforms:element function accept a third argument to create a composite element? Or is this a feature that you think could be added to Orbeon Forms relatively easily?



Regards,
Neil



 
Reply | Threaded
Open this post in threaded view
|

Re: Aggregate instances when performing submission

ncrofts
Hi Erik.

Isn't it typical, as soon as I press the button to send my "it doesn't work" message, I re-read the manual and realise that to pass in a set of nodes to the xxforms:element function that you need to surround the second argument with brackets (). The following does indeed solve the problem I encountered:

<xforms:submission id="do-alpha-beta" method="post" resource="alpha-beta" ref="xxforms:element('result', ($alpha, $beta))" replace="instance" instance="result"/>

Many thanks for pointing me in the right direction once again.

Regards,
Neil
       
Reply | Threaded
Open this post in threaded view
|

Re: Re: Aggregate instances when performing submission

Erik Bruchez
Administrator
In reply to this post by ncrofts
Neil,

In my example I only pass 2 arguments: the second one is a sequence,
between `()`. So try:

xxforms:element('result', ($form, $data))

-Erik

On Wed, Oct 26, 2011 at 2:12 AM, ncrofts <[hidden email]> wrote:

> Hi Erik,
>
> Thanks for this suggestion. This seems to be along the right lines, but
> unfortunately the xxforms:element() function throws an exception when passed
> more than two arguments e.g.
>
> 2011-10-26 09:51:58,970 ERROR XFormsServer  - xforms-submit-error - setting
> throwable {throwable: "org.orbeon.saxon.trans.XPathException: XPath syntax
> error at char 39 in {...lement('result', $form, $data}:
>    Cannot find a matching 3-argument function named
> {http://orbeon.org/oxf/xml/xforms}element()
>        at
> org.orbeon.saxon.expr.ExpressionParser.grumble(ExpressionParser.java:149)
>        at
> org.orbeon.saxon.expr.ExpressionParser.parseFunctionCall(ExpressionParser.java:1852)
>
> It is tantalisingly close to being a solution though, as when you just pass
> in two arguments it does behave as you would expect e.g. passes an instance
> to the pipeline comprising a root element name and a child element.
>
> Am I missing a technique to make the xxforms:element function accept a third
> argument to create a composite element? Or is this a feature that you think
> could be added to Orbeon Forms relatively easily?
>
>
>
> Regards,
> Neil
>
>
>
>
>
> --
> View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/Aggregate-instances-when-performing-submission-tp3936413p3939913.html
> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>
>


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws