backplane-import/backplanejs — Issue #53: Add support for custom functions when evaluating XPath with native DOM
Author: backplane-import
Created: 2011-10-15 03:11:12+00:00
State: open

### Imported from backplanejs Google Code [issue 53](http://code.google.com/p/backplanejs/issues/detail?id=53).

Reporter
markbirbeck

Date
3 May 2010 8:26:22 PM UTC

In the expression:

a/b[func(d)]

the function func() needs to be a reference to a JavaScript function that is
callable during evaluation (i.e., a non-standard function).

To implement this whilst still using a native DOM, the expression would
need to be cracked open and the separate parts evaluated individually. In
the example above we'd need to do the following:

1. Get the node referred to by "d" and then retrieve the value; let's say it's
'2'.
2. Call the JavaScript function with the value returned from step 1, i.e.,
func( 2 ). Let's say this function returns 6.
3. Insert the value returned from step 2 into the XPath expression and then
evaluate the XPath expression.

This needs to be generic, since functions can appear anywhere in an XPath
expression. For example:

func2(a/b[func(c/d)])

Note also that since XPath already comes with some built-in functions we
can't simply check for anything of the form "abc()" -- we'll have to check
for the extension functions by name.