Re: [Xsltforms-support] User defined function not working in xf:bind
Brought to you by:
alain-couthures
From: Alain C. <ala...@ag...> - 2013-01-01 21:03:26
|
Hello Matthew, > I have attempted to define a local function to do this: > > <script> > XPathCoreFunctions["http://www.w3.org/2005/xpath-functions ends-with"]= > new XPathFunction( > false, > XPathFunction.DEFAULT_NONE, > false, > function(x) { > return this.indexOf(x, this.length - x.length) !== -1; > } > ); > </script> I had to rename XSLTForms global Javascript objects to avoid name conflicts with frameworks: "XPathCoreFunctions" has been renamed "XsltForms_xpathCoreFunctions". When defining an XPath function for XSLTForms, parameters casting has to be considered so I rewrote this function and added it to the others (the namespace is not correct... but it's the default one...): "http://www.w3.org/2005/xpath-functions ends-with" : new XsltForms_xpathFunction(false, XsltForms_xpathFunction.DEFAULT_NONE, false, function(string, postfix) { if (arguments.length !== 2) { throw XsltForms_xpathFunctionExceptions.endsWithInvalidArgumentsNumber; } var s = XsltForms_globals.stringValue(string); var p = XsltForms_globals.stringValue(postfix); return s.substr(s.length - p.length, p.length) === p; } ), Defining your own Javascript function is another possibility (parameters are always passed as strings): <script> function js_ends_with(s,end) { return s.indexOf(end, s.length - end.length) !== -1; } </script> > I am using r559 build and Chrome. > XPath ends-with() function is now supported in r566. Thank you for your feedbacks! -Alain |