Friday, 9 May 2008

Orbeon, inline XSLT and GET parameters

A couple of (hopefully) useful notes here -

If you're creating XForms and you're using Orbeon (which is a damn fine choice if you ask me ;)), then you may want to pass params to the form at some stage:

so you call your form using something like this:



To get at the values you pass in, you can do the following:

- Edit the page-flow.xml file in your folder, so you have something like this:



Note here that the default-submission refers to a file:
default-submission="/path-to-your/test.xml"

You'll need to create that XML structure, it can have no values or you can put values in there which will act as 'defaults'.

test.xml will look something like this:



in your view.xhtml, in the model, add something like this:



You can now XPath into your parameters using instance('my-params')/first and so on.

If you're using Orbeon 3.7 (either a nightly build or when it's released), you have the option to use the xxforms:get-request-parameter to grab the parameters and put them into an instance. To do this, first create an empty instance in your model:



And create an action (also in the model) like this:



If you call your form with an id parameter, you should find that xf:setvalue will write that request parameter into the params instance.

Finally, it may be the case that you need to fire an XSLT transform inside the view.xhtml. I've heard warnings that this can be expensive in terms of processing, but I found that the following code worked, so thought I'd make a note here.

In the body of your XForm, a block of code like this:


Will be executed by an XSLT processor. That example may be useful to someone.

Thanks go to everyone at the OPS forum http://www.nabble.com/ObjectWeb-OPS---Users-f2537.html who have been very helpful whenever I've had questions.

1 comment:

Matthew Rawlings said...

Thanks! You showed two techniques to solve a common problem. Both techniques were explained much more clearly and simply than the documentation does.