Re: [Xsltforms-support] [PATCH] Adding extra XPath functions
Brought to you by:
alain-couthures
From: COUTHURES A. <ala...@ag...> - 2010-04-10 20:18:23
|
Hello, Yes there was a regression about prefixes... Here is a working example with the latest SVN version: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:local="http://example.com/local" local:dummy="dummy"> <head> <title>Testing local XPath functions</title> <script> XPathCoreFunctions['http://example.com/local sample'] = new XPathFunction(false, XPathFunction.DEFAULT_NONE, false, function() { return "a test"; } ); </script> <xf:model> <xf:instance> <dummy xmlns=""/> </xf:instance> </xf:model> </head> <body> <p>This is <xf:output value="local:sample()" />.</p> </body> </html> Thanks! -Alain > OK, i worked around it on Firefox! > > Just use the default xpath NS when registering functions: > http://www.w3.org/2005/xpath-functions > and invoke it without prefix! > > > Both FF and IE have problem with the time of registration. > Apart from Chrome, the 'load' event seems to run after init-code has run, > so the xpath-to-js xsl template fails. > > The patch is still needed for IE and Chrome > if you want to use different NS > (which does not work on FF...). > > > Note that all browsers work OK: > * without the patch, and > * without the extra NS declaration > as long as any new xpath functions gets registered under the NS: > http://www.w3.org/2005/xpath-functions. > > This trick allows even for redefinition of existent functions. > > > Happy XPathing! > Kostis > > > file: testNewFuncs.xml > ---------------------------- > <?xml version="1.0" encoding="UTF-8"?> > <?xml-stylesheet href="xsltforms/xsltforms.xsl" type="text/xsl"?> > <?xsltforms-options debug="yes"?> > <html xmlns="http://www.w3.org/1999/xhtml" > xmlns:xf="http://www.w3.org/2002/xforms" > > <head> > <title>Testing User-Defined XPath functions</title> > <script > > XPathCoreFunctions['http://www.w3.org/2005/xpath-functions new-func'] = > new XPathFunction(false, XPathFunction.DEFAULT_NONE, false, > function() { return "NEW FUNC"; } ); > </script> > <xf:model> > <xf:instance> > <data xmlns="">HellO </data> > </xf:instance> > </xf:model> > </head> > <body> > <p><xf:output value="/data" /> to <xf:output value="concat('My ', > new-func())" />.</p> > > </body> > </html> > > On Fri, Apr 9, 2010 at 8:21 AM, Kostis Anagnostopoulos > <ank...@gm...> wrote: > >> I was too quick to report "success!"... >> >> I tested on different browsers, and >> * on Chrome it is OK. >> >> * On firefox it does not find the correct NS :-( >> As an aid, i see that the xslt's result root node (the html element) >> does not contain the 'local' NS. >> I then tried the dummy attribute workaround but nothing. >> >> * On IE7 it does not locate the extra function, >> although the XPath expression seems OK, >> and the function's namspace is correct. >> It seems that the the registration code for the extra function does not work! >> >> >> It needs more work, particularly on firefox.... >> >> >> Kostis >> >> >> On Fri, Apr 9, 2010 at 4:00 AM, Kostis Anagnostopoulos >> <ank...@gm...> wrote: >> >>> Hi David, >>> >>> The problem (i think) was that the newer XPath expression parsing templates >>> (as of rev361) >>> for each xpath-expression they filled-in the contents of the variable >>> 'xexprs' with a nodeset >>> created out of the blue, so it had no NS attached - thus, your >>> xmlns:local="..." declaration was lost. >>> >>> I solved it just by embeding the <xexprs> nodeset within a node from >>> the source document, >>> just by copying the current node. >>> >>> Note that I have not tested the patch thorougly, >>> it just makes your test-case to run ok. >>> For a quicker setup, you can mannually patch the final 'xsltforms.xsl' >>> file in line: 197 >>> >>> Regards >>> Kostis >>> >>> >>> >>> On Tue, Mar 30, 2010 at 9:26 PM, David Cato <ot...@cr...> wrote: >>> >>>> <?xml version="1.0" encoding="UTF-8"?> >>>> <?xml-stylesheet href="xsltforms/xsltforms.xsl" type="text/xsl"?> >>>> <html xmlns="http://www.w3.org/1999/xhtml" >>>> xmlns:xf="http://www.w3.org/2002/xforms" >>>> xmlns:local="http://example.com/local"> >>>> <head> >>>> <title>Testing local XPath functions</title> >>>> <script> >>>> window.addEventListener('load', function() { >>>> XPathCoreFunctions['http://example.com/local sample'] = >>>> new XPathFunction(false, XPathFunction.DEFAULT_NONE, false, >>>> function() { return "a test"; } ); >>>> }, false); >>>> </script> >>>> <xf:model> >>>> <xf:instance> >>>> <data xmlns=""> >>>> <PersonGivenName/> >>>> </data> >>>> </xf:instance> >>>> </xf:model> >>>> </head> >>>> <body> >>>> <p>This is <xf:output value="local:sample()" />.</p> >>>> <p>Type your first name in the input box. <br/> >>>> If you are running XForms, the output should be displayed in the output area.</p> >>>> <xf:input ref="PersonGivenName" incremental="true"> >>>> <xf:label>Please enter your first name: </xf:label> >>>> </xf:input> >>>> <br /> >>>> <xf:output value="concat('Hello ', PersonGivenName, '. We hope you like XForms!')"> >>>> <xf:label>Output: </xf:label> >>>> </xf:output> >>>> </body> >>>> </html> >>>> >>>> >> ------------------------------------------------------------------------ >> >> ------------------------------------------------------------------------------ >> Download Intel® Parallel Studio Eval >> Try the new software tools for yourself. Speed compiling, find bugs >> proactively, and fine-tune applications for parallel performance. >> See why Intel Parallel Studio got high marks during beta. >> http://p.sf.net/sfu/intel-sw-dev >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Xsltforms-support mailing list >> Xsl...@li... >> https://lists.sourceforge.net/lists/listinfo/xsltforms-support >> |