Re: XPath extension functions in XForms

Hi Elliotte,

> Do any of the existing XForms engines add their own vendor-sepcific
> extension functions to XPath? That is, functions that are not standard
> parts of XForms 1.0? if so, can anyone provide or point me to more
> details about these functions?

As David says, there are extensions in use, and these fall into two
categories. The first are those that are specific to a particular
implementation and the second are those that try to conform to some
standard, such as EXSLT.

You've reminded me that our formsPlayer documentation is woefully out
of date, but it's here:

  <http://www.formsplayer.com/node/655>

The kind of things that we have added in the 'proprietary' category are:

  fp:serialise()
  fp:HTMLserialise()

These functions allow you to take mark-up that is stored in an
instance and make it part of the document, either directly inline
(serialise) or viewable for debugging purposes (HTMLserialise). These
are very old functions which we will be deprecating soon, in favour of
using xf:output with @mediatype which is supported in XForms 1.1.


  globalInstance()

This is documented on the site, but essentially allows you to access
an instance that is not in the same model as the evaluation context
for the expression being evaluated. We hope that a function like this
will be available in the future in XForms itself.


> Also, must such functions be namespaced and prefixed like XSLT extension
> functions? Or can they be simple local names like sin(). cos(), and tan()?

I think best practice says that they should really be prefixed. And
ideally you should refer to them in the 'functions' attribute on
xf:model if you want to be sure that you don't fail on a processor
that doesn't support your function. (Or more precisely, you want to
force a predictable failure on non-supporting processors.)


> Finally, do any vendors provide a means for users to write their own
> extension functions? If so, can anyone provide or point me to more
> details about the relevant APIs?

formsPlayer supports this in two ways as detailed here:

  <http://www.formsplayer.com/node/440>

In summary, the first technique allows you to write a normal
JavaScript function and then call it from XPath using a specific
prefix, such as:

  <xf:setvalue ref="a" value="js:myfunc(b)" />

(The link above will take you to an example of this, which shows how
to use the extension features to control a 3D viewer from
formsPlayer.)

I know that other implementations also allow JavaScript to be called
from XPath, although there is no standard for the namespace used, as
yet.


The second technique is to give XPath expressions access to methods in
COM components (at least on Windows). Once again, examples are
available from the link above. Although this technique is
non-standard, as you can imagine it wouldn't take much to come up with
a standard way to give XForms processors access to platform-specific
components that are installed on a device.

Regards,

Mark

-- 
  Mark Birbeck, formsPlayer

  mark.birbeck@x-port.net | +44 (0) 20 7689 9232
  http://www.formsPlayer.com | http://internet-apps.blogspot.com

  standards. innovation.

Received on Monday, 9 July 2007 12:52:30 UTC